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

Changes after attempted merge

parent 204e9b2d
...@@ -89,7 +89,9 @@ public class IpoptSolverGeneratorImplementation implements NLPSolverGeneratorImp ...@@ -89,7 +89,9 @@ public class IpoptSolverGeneratorImplementation implements NLPSolverGeneratorImp
objVar = "objectiveValue" + optimizationProblem.getId(); objVar = "objectiveValue" + optimizationProblem.getId();
//ToDo: modify call. Restriction: only same type? (Matrix opposed to skalar) //ToDo: modify call. Restriction: only same type? (Matrix opposed to skalar)
//Dynamic function call, better generated by vm //Dynamic function call, better generated by vm
result = String.format("%s::solveOptimizationProblemIpOpt(%s, %s%s);\n", vm.getCallSolverName(), vm.getOptimizationVariables().get(0).getName(), objVar, knownVariables); if(!vm.getOptimizationVariables().isEmpty()) {
result = String.format("%s::solveOptimizationProblemIpOpt(%s, %s%s);\n", vm.getCallSolverName(), vm.getOptimizationVariables().get(0).getName(), objVar, knownVariables);
}
// generate templates by view model // generate templates by view model
generateIpoptTemplates(vm, auxillaryFiles); generateIpoptTemplates(vm, auxillaryFiles);
necessaryIncludes.add(vm.getCallSolverName()); necessaryIncludes.add(vm.getCallSolverName());
......
...@@ -125,11 +125,13 @@ public class IpoptViewModel extends SolverViewModel { ...@@ -125,11 +125,13 @@ public class IpoptViewModel extends SolverViewModel {
MathMatrixVectorExpressionSymbol result = null; MathMatrixVectorExpressionSymbol result = null;
MathExpressionSymbol mathExpression = getStepSize(); MathExpressionSymbol mathExpression = getStepSize();
//ToDo: Add CoCo to ensure this always holds. //ToDo: Add CoCo to ensure this always holds.
if(mathExpression.isAssignmentExpression()) { if(mathExpression != null) {
MathAssignmentExpressionSymbol assignExpression = (MathAssignmentExpressionSymbol) mathExpression; if (mathExpression.isAssignmentExpression()) {
MathExpressionSymbol assignChildExpression = assignExpression.getExpressionSymbol(); MathAssignmentExpressionSymbol assignExpression = (MathAssignmentExpressionSymbol) mathExpression;
MathExpressionSymbol assignChildExpression = assignExpression.getExpressionSymbol();
result = (MathMatrixVectorExpressionSymbol) assignChildExpression; result = (MathMatrixVectorExpressionSymbol) assignChildExpression;
}
} }
return result; return result;
} }
...@@ -137,28 +139,38 @@ public class IpoptViewModel extends SolverViewModel { ...@@ -137,28 +139,38 @@ public class IpoptViewModel extends SolverViewModel {
public String getStepSizeName(){ public String getStepSizeName(){
String result = ""; String result = "";
MathExpressionSymbol mathExpression = getStepSize(); MathExpressionSymbol mathExpression = getStepSize();
//ToDo: Add CoCo to ensure this always holds.
if(mathExpression.isAssignmentExpression()) {
MathAssignmentExpressionSymbol assignExpression = (MathAssignmentExpressionSymbol) mathExpression;
result = assignExpression.getNameOfMathValue(); if(mathExpression != null) {
//ToDo: Add CoCo to ensure this always holds.
if (mathExpression.isAssignmentExpression()) {
MathAssignmentExpressionSymbol assignExpression = (MathAssignmentExpressionSymbol) mathExpression;
result = assignExpression.getNameOfMathValue();
}
} }
return result; return result;
} }
public int getStepSizeMin(){ public int getStepSizeMin(){
String result = ""; int result = 0;
MathMatrixVectorExpressionSymbol vectorExpressionSymbol = getStepSizeVectorSymbol(); MathMatrixVectorExpressionSymbol vectorExpressionSymbol = getStepSizeVectorSymbol();
MathNumberExpressionSymbol startExpression = (MathNumberExpressionSymbol) vectorExpressionSymbol.getStart(); if(vectorExpressionSymbol != null) {
return startExpression.getValue().getRealNumber().intValue(); MathNumberExpressionSymbol startExpression = (MathNumberExpressionSymbol) vectorExpressionSymbol.getStart();
result = startExpression.getValue().getRealNumber().intValue();
}
return result;
} }
public int getStepSizeMax(){ public int getStepSizeMax(){
String result = ""; int result = 0;
MathMatrixVectorExpressionSymbol vectorExpressionSymbol = getStepSizeVectorSymbol(); MathMatrixVectorExpressionSymbol vectorExpressionSymbol = getStepSizeVectorSymbol();
MathNumberExpressionSymbol endExpression = (MathNumberExpressionSymbol) vectorExpressionSymbol.getEnd(); if(vectorExpressionSymbol != null) {
return endExpression.getValue().getRealNumber().intValue(); MathNumberExpressionSymbol endExpression = (MathNumberExpressionSymbol) vectorExpressionSymbol.getEnd();
result = endExpression.getValue().getRealNumber().intValue();
}
return result;
} }
public int getStepSizeCount(){ public int getStepSizeCount(){
...@@ -210,11 +222,12 @@ public class IpoptViewModel extends SolverViewModel { ...@@ -210,11 +222,12 @@ public class IpoptViewModel extends SolverViewModel {
public String listClassesInScope(){ public String listClassesInScope(){
String result = ""; String result = "";
if(!getIndependentVariables().isEmpty()) {
for ( Collection<Symbol> x : getIndependentVariables().get(0).getEnclosingScope().getLocalSymbols().values()){ for (Collection<Symbol> x : getIndependentVariables().get(0).getEnclosingScope().getLocalSymbols().values()) {
result += ","+x.getClass().toString(); result += "," + x.getClass().toString();
for(Symbol s : x){ for (Symbol s : x) {
result += ", "+s.getClass().toString(); result += ", " + s.getClass().toString();
}
} }
} }
return result; return result;
......
...@@ -59,7 +59,7 @@ public class GeneratorEMAMOpt2CPPTest extends AbstractSymtabTest { ...@@ -59,7 +59,7 @@ public class GeneratorEMAMOpt2CPPTest extends AbstractSymtabTest {
@Test @Test
public void testMPCImplementation() throws IOException { public void testMPCImplementation() throws IOException {
doGenerateMathOptModel("mpcautopilot.torcsWrapper"); List<File> files = doGenerateMathOptModel("mpcautopilot.torcsWrapper");
// TODO: create reference solution // TODO: create reference solution
// String restPath = "testMath/optimizationSolver/"; // String restPath = "testMath/optimizationSolver/";
// testFilesAreEqual(files, restPath); // testFilesAreEqual(files, restPath);
......
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