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 eb449fc9 authored by Jan Philipp Haller's avatar Jan Philipp Haller
Browse files

Merge branch 'haller-temp' into Haller

# Conflicts:
#	src/main/java/de/monticore/lang/monticar/generator/cpp/mathopt/optimizationSolver/solver/ipopt/IpoptViewModel.java
parents eb43f352 a468eadf
......@@ -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,8 +124,8 @@ public class IpoptViewModel extends SolverViewModel {
public MathMatrixVectorExpressionSymbol getStepSizeVectorSymbol(){
MathMatrixVectorExpressionSymbol result = null;
MathExpressionSymbol mathExpression = getStepSize();
//ToDo: Add CoCo to ensure this always holds.
if(mathExpression != null) {
//ToDo: Add CoCo to ensure this always holds.
if (mathExpression.isAssignmentExpression()) {
MathAssignmentExpressionSymbol assignExpression = (MathAssignmentExpressionSymbol) mathExpression;
MathExpressionSymbol assignChildExpression = assignExpression.getExpressionSymbol();
......@@ -139,15 +139,13 @@ public class IpoptViewModel extends SolverViewModel {
public String getStepSizeName(){
String result = "";
MathExpressionSymbol mathExpression = getStepSize();
//ToDo: Add CoCo to ensure this always holds.
if(mathExpression != null) {
//ToDo: Add CoCo to ensure this always holds.
if (mathExpression.isAssignmentExpression()) {
MathAssignmentExpressionSymbol assignExpression = (MathAssignmentExpressionSymbol) mathExpression;
result = assignExpression.getNameOfMathValue();
}
}
return result;
}
......@@ -155,18 +153,18 @@ public class IpoptViewModel extends SolverViewModel {
public int getStepSizeMin(){
int result = 0;
MathMatrixVectorExpressionSymbol vectorExpressionSymbol = getStepSizeVectorSymbol();
if(vectorExpressionSymbol != null) {
if(hasStepSize()) {
MathMatrixVectorExpressionSymbol vectorExpressionSymbol = getStepSizeVectorSymbol();
MathNumberExpressionSymbol startExpression = (MathNumberExpressionSymbol) vectorExpressionSymbol.getStart();
result = startExpression.getValue().getRealNumber().intValue();
result = startExpression.getValue().getRealNumber().intValue();
}
return result;
}
public int getStepSizeMax(){
int result = 0;
MathMatrixVectorExpressionSymbol vectorExpressionSymbol = getStepSizeVectorSymbol();
if(vectorExpressionSymbol != null) {
if(hasStepSize()) {
MathMatrixVectorExpressionSymbol vectorExpressionSymbol = getStepSizeVectorSymbol();
MathNumberExpressionSymbol endExpression = (MathNumberExpressionSymbol) vectorExpressionSymbol.getEnd();
result = endExpression.getValue().getRealNumber().intValue();
}
......@@ -174,7 +172,11 @@ public class IpoptViewModel extends SolverViewModel {
}
public int getStepSizeCount(){
return (getStepSizeMax()-getStepSizeMin()+1);
if(hasStepSize()) {
return (getStepSizeMax() - getStepSizeMin() + 1);
}else {
return 0;
}
}
public String getVariableInitialization(MathValueSymbol variable){
......@@ -207,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
......@@ -220,6 +224,14 @@ public class IpoptViewModel extends SolverViewModel {
return "-1E19";
}
public String getObjectiveFunctionWithIpoptVectorEntries() {
//getObjectiveFunction().
//replaceVariablesWithIpoptVectorEntry()
//ähnlich zu getConstraintForFG_Eval!
return "";
}
public String listClassesInScope(){
String result = "";
if(!getIndependentVariables().isEmpty()) {
......@@ -233,6 +245,16 @@ public class IpoptViewModel extends SolverViewModel {
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();
......@@ -269,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;
......@@ -451,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() {
......@@ -467,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,8 +148,17 @@ public abstract class SolverViewModel extends ViewModelBase {
/* Derived values */
public Boolean hasObjectiveVariable() {
return objectiveVariable != null;
}
public String getObjectiveVariableName() {
return objectiveVariable.getName();
if(objectiveVariable != null) {
return objectiveVariable.getName();
}else{
return "";
}
}
public int getNumberIndependentVariables(){
......
......@@ -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;
}
......
......@@ -7,13 +7,17 @@ component BoundedConditionsTest{
out Q yOut;
implementation Math{
Q y = minimize(Q x)
(x*x) - 2 * x + 1;
minimize
Q x;
in
Q y = (x*x) - 2 * x + 1;
subject to
0 <= x <= 1;
0 <= 2*x <= 1;
end
xOut = x;
yOut = y;
}
}
......@@ -7,8 +7,10 @@ component ColRowMinTest{
out Q yOut;
implementation Math{
Q y = minimize(Q^{2,2} x)
x(1, :) * x(:, 1);
minimize
Q^{2,2} x;
in
Q y = x(1, :) * x(:, 1);
subject to
x(1, 1) >= 1;
x(1, 2) >= 2;
......
......@@ -7,8 +7,10 @@ component ConstMatrixSumMinimizationTest{
out Q yOut;
implementation Math{
Q y = minimize(Q x)
sum([0, 0, x, 0]);
minimize
Q x;
in
Q y = sum([0, 0, x, 0]);
subject to
-1 <= x <= 1;
end
......
......@@ -8,8 +8,10 @@ component ConstraintTest{
implementation Math{
Z n = 3;
Q(-2:5) y = minimize(Q(-1:1)^{3,3} x) // x(i) in [-1,1]; y in [-1, 5]
sum(x + x + x + x + x);
minimize
Q(-1:1)^{3,3} x; // x(i) in [-1,1]; y in [-1, 5]
in
Q(-2:5) y = sum(x + x + x + x + x);
subject to
(-3) <= (5 * x) <= (1); // => [-2,1]
x(1,1) == 0; // first element alway == 0
......
......@@ -12,8 +12,9 @@ component ExistingOptimizationVariableTest{
implementation Math{
// 1. scalar
Q x = 3;
minimize(x)
minimize
Q x = 3;
in
2 * x + 1;
subject to
-1 <= x <= 1;
......@@ -21,9 +22,10 @@ component ExistingOptimizationVariableTest{
xOut1 = x;
// 2. matrix
Q^{3,3} a = zeros(3,3);
Q b = minimize(a)
a(1, 1) * a(2, 2) * a(3, 3);
minimize
Q^{3,3} a = zeros(3,3);
in
Q b = a(1, 1) * a(2, 2) * a(3, 3);
subject to
-10 <= a <= 10;
end
......@@ -31,10 +33,13 @@ component ExistingOptimizationVariableTest{
bOut2 = b;
// 3. substituted
Q^{3,3} ainc = a + 1;
Q c = minimize(a)
Q c = minimize
Q^{3,3} a = zeros(3,3);
in
ainc(1, 1) * ainc(2, 2) * ainc(3, 3);
subject to
Q^{3,3} ainc = a + 1;
-20 <= a <= 20;
end
aOut3 = a;
......
......@@ -13,7 +13,9 @@ component HS71{
out Q yOut;
implementation Math{
Q y = minimize(Q^{4} x)
minimize
Q^{4} x;
in
x(1) * x(4) * (x(1) + x(2) + x(3)) + x(3);
subject to
x(1) * x(2) * x(3) * x(4) >= 25;
......
......@@ -18,14 +18,14 @@ component MPCTest {
minimize<n=1:10>
Q mpc_steering, Q mpc_acceleration;
in
Q error = mpc_acceleration;
Q error = angle(n) * 10;
subject to
Q(-1:1) angle = currentHeading;
Q(-10:200km/h) velocity = currentVelocity;
angle(n+1) == angle(n) + 1 / (velocity(n) * mpc_steering(n) * dT);
end
y=x;
y = error;
}
}
\ No newline at end of file
......@@ -7,8 +7,10 @@ component MatrixSumMinimizationTest1{
out Q yOut;
implementation Math{
Q y = minimize(Q^{2,2} x)
sum(x);
minimize
Q^{2,2} x;
in
Q y = sum(x);
subject to
x(1,1) >= 0;
x(1,2) >= 0;
......
......@@ -7,8 +7,10 @@ component MatrixSumMinimizationTest2{
out Q yOut;
implementation Math{
Q y = minimize(Q^{2,2} x)
sum(x);
minimize
Q^{2,2} x;
in
Q y = sum(x);
subject to
x >= 0;
end
......
......@@ -7,8 +7,10 @@ component MatrixTransposeMinimizationTest{
out Q yOut;
implementation Math{
Q y = minimize(Q^{2} x)
[1; 2; 3; 4]' * [x(1); x(2); 0; 0];
minimize
Q^{2} x;
in
Q y = [1; 2; 3; 4]' * [x(1); x(2); 0; 0];
subject to
x(1) >= 1;
x(2) >= 1;
......
......@@ -7,8 +7,10 @@ component ScalarMaximizationTest{
out Q yOut;
implementation Math{
Q z = maximize(Q x)
- x * x + 42;
maximize
Q x;
in
Q z = - x * x + 42;
subject to
x >= -10;
x <= 10;
......
......@@ -7,8 +7,10 @@ component ScalarMinimizationTest{
out Q yOut;
implementation Math{
Q y = minimize(Q x)
(x*x) - 2 * x + 1;
minimize
Q x;
in
Q y = (x*x) - 2 * x + 1;
subject to
x >= 0;
end
......
......@@ -8,8 +8,10 @@ component ScalarMultMinTest{
implementation Math{
Q y = minimize(Q x)
(([1,1] * [2;2]) * x);
minimize
Q x;
in
Q y = (([1,1] * [2;2]) * x);
subject to
x >= 5;
end
......
......@@ -23,8 +23,10 @@ component TransportationProblem{
Q ^{m, n} c = [2.5, 1.7, 1.8; 2.5, 1.8, 1.4];
// minimization problem
Q y = minimize(Q^{2, 3} x)
sum(c .* x);
minimize
Q^{2, 3} x;
in
Q y = sum(c .* x);
subject to
sum(x, 2) == A;
sum(x, 1) == b;
......
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