Aufgrund einer Wartung wird GitLab am 21.09. zwischen 8:00 und 9:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 21.09. between 8:00 and 9:00 am.

Commit a468eadf authored by Jan Philipp Haller's avatar Jan Philipp Haller
Browse files

Bugfix isOptScopedVarable

parent ef6a1b34
......@@ -108,7 +108,7 @@ public class IpoptViewModel extends SolverViewModel {
code.replace(var.getName(), getIpoptVarRef(var));
}
for (MathValueSymbol var : getIndependentVariables()){
//code.replace(var.getName(), getIpoptIndex( var));
code.replace(var.getName(), getIpoptVarRef( var));
}
return result;
}
......@@ -124,12 +124,14 @@ public class IpoptViewModel extends SolverViewModel {
public MathMatrixVectorExpressionSymbol getStepSizeVectorSymbol(){
MathMatrixVectorExpressionSymbol result = null;
MathExpressionSymbol mathExpression = getStepSize();
//ToDo: Add CoCo to ensure this always holds.
if(mathExpression.isAssignmentExpression()) {
MathAssignmentExpressionSymbol assignExpression = (MathAssignmentExpressionSymbol) mathExpression;
MathExpressionSymbol assignChildExpression = assignExpression.getExpressionSymbol();
if(mathExpression != null) {
//ToDo: Add CoCo to ensure this always holds.
if (mathExpression.isAssignmentExpression()) {
MathAssignmentExpressionSymbol assignExpression = (MathAssignmentExpressionSymbol) mathExpression;
MathExpressionSymbol assignChildExpression = assignExpression.getExpressionSymbol();
result = (MathMatrixVectorExpressionSymbol) assignChildExpression;
result = (MathMatrixVectorExpressionSymbol) assignChildExpression;
}
}
return result;
}
......@@ -138,31 +140,43 @@ public class IpoptViewModel extends SolverViewModel {
String result = "";
MathExpressionSymbol mathExpression = getStepSize();
//ToDo: Add CoCo to ensure this always holds.
if(mathExpression.isAssignmentExpression()) {
MathAssignmentExpressionSymbol assignExpression = (MathAssignmentExpressionSymbol) mathExpression;
if(mathExpression != null) {
if (mathExpression.isAssignmentExpression()) {
MathAssignmentExpressionSymbol assignExpression = (MathAssignmentExpressionSymbol) mathExpression;
result = assignExpression.getNameOfMathValue();
result = assignExpression.getNameOfMathValue();
}
}
return result;
}
public int getStepSizeMin(){
String result = "";
MathMatrixVectorExpressionSymbol vectorExpressionSymbol = getStepSizeVectorSymbol();
MathNumberExpressionSymbol startExpression = (MathNumberExpressionSymbol) vectorExpressionSymbol.getStart();
return startExpression.getValue().getRealNumber().intValue();
int result = 0;
if(hasStepSize()) {
MathMatrixVectorExpressionSymbol vectorExpressionSymbol = getStepSizeVectorSymbol();
MathNumberExpressionSymbol startExpression = (MathNumberExpressionSymbol) vectorExpressionSymbol.getStart();
result = startExpression.getValue().getRealNumber().intValue();
}
return result;
}
public int getStepSizeMax(){
String result = "";
MathMatrixVectorExpressionSymbol vectorExpressionSymbol = getStepSizeVectorSymbol();
MathNumberExpressionSymbol endExpression = (MathNumberExpressionSymbol) vectorExpressionSymbol.getEnd();
return endExpression.getValue().getRealNumber().intValue();
int result = 0;
if(hasStepSize()) {
MathMatrixVectorExpressionSymbol vectorExpressionSymbol = getStepSizeVectorSymbol();
MathNumberExpressionSymbol endExpression = (MathNumberExpressionSymbol) vectorExpressionSymbol.getEnd();
result = endExpression.getValue().getRealNumber().intValue();
}
return result;
}
public int getStepSizeCount(){
return (getStepSizeMax()-getStepSizeMin()+1);
if(hasStepSize()) {
return (getStepSizeMax() - getStepSizeMin() + 1);
}else {
return 0;
}
}
public String getVariableInitialization(MathValueSymbol variable){
......@@ -195,6 +209,8 @@ public class IpoptViewModel extends SolverViewModel {
}
public String getConstraintUpperBound(MathOptimizationConditionSymbol constraint){
String hekp =constraint.getBoundedExpression().getTextualRepresentation();
if(constraint.getUpperBound().isPresent())
return constraint.getUpperBound().get().getTextualRepresentation();
else
......@@ -208,18 +224,37 @@ public class IpoptViewModel extends SolverViewModel {
return "-1E19";
}
public String getObjectiveFunctionWithIpoptVectorEntries() {
//getObjectiveFunction().
//replaceVariablesWithIpoptVectorEntry()
//ähnlich zu getConstraintForFG_Eval!
return "";
}
public String listClassesInScope(){
String result = "";
for ( Collection<Symbol> x : getIndependentVariables().get(0).getEnclosingScope().getLocalSymbols().values()){
result += ","+x.getClass().toString();
for(Symbol s : x){
result += ", "+s.getClass().toString();
if(!getIndependentVariables().isEmpty()) {
for (Collection<Symbol> x : getIndependentVariables().get(0).getEnclosingScope().getLocalSymbols().values()) {
result += "," + x.getClass().toString();
for (Symbol s : x) {
result += ", " + s.getClass().toString();
}
}
}
return result;
}
public String transformEMAMValueToVectorNotation(MathMatrixNameExpressionSymbol symbol, String VectorName, Integer indexOffset){
String result = "";
String MatrixName = symbol.getNameToAccess();
String MatrixIndex = symbol.getMathMatrixAccessOperatorSymbol().getTextualRepresentation();
result = VectorName + "[" + getIpoptVarRef(MatrixName)+" + "+ MatrixIndex + "]";
return result;
}
public String transformEMAMMatrixAccessToVectorNotation(MathMatrixNameExpressionSymbol symbol, String VectorName, Integer indexOffset){
String result = "";
String MatrixName = symbol.getNameToAccess();
......@@ -256,6 +291,11 @@ public class IpoptViewModel extends SolverViewModel {
return true;
}
for (MathNameExpressionSymbol value : accessVisitor.getMathNameExpressionSymbols()){
if(isOptScopedVariable(value.getNameToAccess()))
return true;
}
for (MathMatrixNameExpressionSymbol value : accessVisitor.getMathMatrixNameExpressionSymbols()){
if(isOptScopedVariable(value.getNameToAccess()))
return true;
......@@ -438,6 +478,8 @@ public class IpoptViewModel extends SolverViewModel {
private class MathAccessVisitor implements MathOptExpressionSymbolVisitor{
private List<MathMatrixNameExpressionSymbol> mathMatrixNameExpressionSymbols = new ArrayList<>();
private List<MathNameExpressionSymbol> mathNameExpressionSymbols = new ArrayList<>();
Set<MathExpressionSymbol> visited = new HashSet<>();
public MathAccessVisitor() {
......@@ -454,10 +496,19 @@ public class IpoptViewModel extends SolverViewModel {
mathMatrixNameExpressionSymbols.add(node);
}
@Override
public void visit(MathNameExpressionSymbol node) {
mathNameExpressionSymbols.add(node);
}
public List<MathMatrixNameExpressionSymbol> getMathMatrixNameExpressionSymbols() {
return mathMatrixNameExpressionSymbols;
}
public List<MathNameExpressionSymbol> getMathNameExpressionSymbols() {
return mathNameExpressionSymbols;
}
}
private class MathValueVisitor implements MathOptExpressionSymbolVisitor{
......
......@@ -148,6 +148,11 @@ public abstract class SolverViewModel extends ViewModelBase {
/* Derived values */
public Boolean hasObjectiveVariable() {
return objectiveVariable != null;
}
public String getObjectiveVariableName() {
if(objectiveVariable != null) {
return objectiveVariable.getName();
......
......@@ -16,9 +16,11 @@ typedef CPPAD_TESTVECTOR(CppAD::AD<double>) ADvector;
#define V_N_OPTVARS ${viewModel.getNumberOptimizationVariables()}
#define V_N_INDVARS ${viewModel.getNumberIndependentVariables()}
<#if viewModel.hasStepSize()>
// Step variable: ${viewModel.getStepSizeName()}
#define V_N_STEP_MAX ${viewModel.getStepSizeMax()?c}
#define V_N_STEP_MIN ${viewModel.getStepSizeMin()?c}
</#if>
//Offsets for ipopt vector
#define OPT_OFFSET 1
......@@ -73,6 +75,11 @@ namespace AnonymNS${viewModel.id}
<#list viewModel.getConstraintFunctions() as constr>
${viewModel.getConstraintForFG_Eval(constr)};
</#list>
//Debug: Simplified Constraint Functions
<#list viewModel.getSimplifiedConstraintFunctions() as constr>
${viewModel.getConstraintForFG_Eval(constr)};
</#list>
}
return;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment