Commit 81c842b8 authored by Christoph Richter's avatar Christoph Richter
Browse files

Improvements

parent 2e95b6f8
......@@ -25,7 +25,7 @@
<Math.version>0.0.19-SNAPSHOT</Math.version>
<MathOpt.version>0.0.19-SNAPSHOT</MathOpt.version>
<Embedded-MontiArc-Math.version>0.0.19-SNAPSHOT</Embedded-MontiArc-Math.version>
<Embedded-MontiArc-Math-Opt.version>0.0.6-SNAPSHOT</Embedded-MontiArc-Math-Opt.version>
<Embedded-MontiArc-Math-Opt.version>0.0.7-SNAPSHOT</Embedded-MontiArc-Math-Opt.version>
<Embedded-montiarc-math-generator.version>0.0.23-SNAPSHOT</Embedded-montiarc-math-generator.version>
<Embedded-montiarc-math-middleware-generator.version>0.0.4-SNAPSHOT</Embedded-montiarc-math-middleware-generator.version>
<!-- .. Libraries .................................................. -->
......
package de.monticore.lang.monticar.generator.cpp;
import de.monticore.lang.embeddedmontiarcmathopt._symboltable.EMAMOptSymbolTableHelper;
import de.monticore.lang.monticar.generator.cpp.converter.MathConverter;
import de.monticore.lang.monticar.generator.optimization.MathOptimizer;
import de.monticore.lang.monticar.generator.optimization.ThreadingOptimizer;
import de.monticore.lang.monticar.generator.order.nfp.TagBreakpointsTagSchema.TagBreakpointsTagSchema;
import de.monticore.lang.monticar.generator.order.nfp.TagDelayTagSchema.TagDelayTagSchema;
import de.monticore.lang.monticar.generator.order.nfp.TagExecutionOrderTagSchema.TagExecutionOrderTagSchema;
......@@ -31,6 +34,9 @@ public class EMAMOpt2CPPSymbolTableHelper extends EMAMOptSymbolTableHelper {
}
public TaggingResolver createSymTabAndTaggingResolver(String... modelPath) {
MathConverter.resetIDs();
ThreadingOptimizer.resetID();
MathOptimizer.resetIDs();
Scope scope = createSymTab(modelPath);
TaggingResolver tagging = new TaggingResolver(scope, Arrays.asList(modelPath));
TagMinMaxTagSchema.registerTagTypes(tagging);
......
......@@ -186,6 +186,8 @@ public class ProblemAssignmentHandler {
addSingleConstraint(p, g, gL, gU, xL, xU, (MathOptimizationConditionSymbol) constraint, xMatrixElementConstraints);
if (!isConstraintOnOptVar(p, constraint) && (g.size() == size + 1)) {
g.set(g.size() - 1, replaceLoopVariable(g.lastElement(), loopConstraint.getForLoopHead().getNameLoopVariable(), Double.toString(i)));
} else {
xMatrixElementConstraints.set(xMatrixElementConstraints.size() - 1, replaceLoopVariable(xMatrixElementConstraints.lastElement(), loopConstraint.getForLoopHead().getNameLoopVariable(), Double.toString(i)));
}
} else if (constraint instanceof MathForLoopExpressionSymbol) {
addLoopConstraints(p, g, gL, gU, xL, xU, (MathForLoopExpressionSymbol) constraint, xMatrixElementConstraints);
......
......@@ -131,9 +131,11 @@ public class IpoptSolverGeneratorImplementation implements NLPSolverGeneratorImp
public List<CMakeFindModule> getCMakeDependencies() {
CMakeFindModule findCoinBlas = new CMakeFindModule("CoinBlas", "", "coinblas", new ArrayList<String>(), new ArrayList<String>(), false, true, true);
CMakeFindModule findCoinLapack = new CMakeFindModule("CoinLapack", "", "coinlapack", new ArrayList<String>(), new ArrayList<String>(), false, true, true);
CMakeFindModule findCoinMumps = new CMakeFindModule("CoinMumps", "", "coinmumps", new ArrayList<String>(), new ArrayList<String>(), false, true, true);
CMakeFindModule findIPOpt = new CMakeFindModule("Ipopt", "coin/IpNLP.hpp", "ipopt", new ArrayList<String>(), new ArrayList<String>(), true, true, true);
CMakeFindModule findCPPAD = new CMakeFindModule("CPPAD", "cppad/ipopt/solve.hpp", "", new ArrayList<String>(), new ArrayList<String>(), true, false, true);
return Arrays.asList(findCoinBlas, findIPOpt, findCPPAD);
return Arrays.asList(findCoinBlas, findCoinLapack, findCoinMumps, findIPOpt, findCPPAD);
}
}
......@@ -2,11 +2,14 @@ package de.monticore.lang.monticar.generator;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.cpp.EMAMOpt2CPPSymbolTableHelper;
import de.monticore.lang.monticar.generator.cpp.GeneratorEMAMOpt2CPP;
import de.monticore.lang.monticar.generator.middleware.impls.GeneratorImpl;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.List;
import static org.junit.Assert.assertNotNull;
......@@ -27,6 +30,13 @@ public class GeneratorEMAMOpt2CMakeTest extends BasicGenerationTest {
assertNotNull(componentInstanceSymbol);
GeneratorEMAMOpt2CMake generator = new GeneratorEMAMOpt2CMake();
generator.setGenerationTargetPath("./target/generated-sources-cmake/" + fullModelName.substring(fullModelName.lastIndexOf(".") + 1, fullModelName.length()) + "/src/");
for (GeneratorImpl g : generator.getGeneratorImpls()) {
GeneratorEMAMOpt2CPP gen = (GeneratorEMAMOpt2CPP) g;
gen.setGenerateCMake(true);
gen.setGenerateTests(true);
gen.setCheckModelDir(true);
gen.setModelsDirPath(Paths.get("src/test/resources"));
}
return generator.generate(componentInstanceSymbol, symtab);
}
......
......@@ -22,6 +22,7 @@ public class GeneratorEMAMOpt2CppCliTest extends BasicGenerationTest {
"--root-model=de.rwth.monticar.mpc.trajectoryControllerMPC",
"--output-dir=" + targetDir,
"--flag-generate-autopilot-adapter",
"--flag-generate-cmake",
};
GeneratorEMAMOpt2CppCli.main(args);
......
......@@ -28,7 +28,7 @@ component BicycleMPC<Q dt = 0.1, Q l_f = 1, Q l_r = 1, Z hp = 1>
Q dt = 0.1 s;
Q l_f = 1 m;
Q l_r = 1 m;
Z hp = 2;
Z hp = 1;
// create state vector
Q^{4} z;
......@@ -68,10 +68,13 @@ component BicycleMPC<Q dt = 0.1, Q l_f = 1, Q l_r = 1, Z hp = 1>
// minimization statement
Q error = minimize(u)
//abs(sum((zt - z_reft)' * costQ * (zt - z_reft)));
abs(sum(zt - z_reft));
subject to
u_min(1) <= u(1,1) <= u_max(1);
u_min(2) <= u(2,1) <= u_max(2);
for i=1:hp
u_min(1) <= u(1,i) <= u_max(1);
u_min(2) <= u(2,i) <= u_max(2);
end
end
// assign output
a = u(1,1);
......
// example problem, number 71 from the Hock-Schittkowsky test suite
// W. Hock and K. Schittkowski.
// Test examples for nonlinear programming codes.
// Lecture Notes in Economics and Mathematical Systems, 187, 1981.
// doi: 10.1007/978-3-642-48320-2.
package de.rwth.monticar.optimization;
component HS71{
ports out Q^{4} xOut,
out Q yOut;
implementation Math{
Q y = minimize(Q^{4} x)
x(1) * x(4) * (x(1) + x(2) + x(3)) + x(3);
subject to
x(1) * x(2) * x(3) * x(4) >= 25;
x(1) * x(1) + x(2) * x(2) + x(3) * x(3) + x(4) * x(4) == 40;
1 <= x;
x <= 5;
end
xOut = x;
yOut = y;
}
}
\ No newline at end of file
......@@ -11,18 +11,18 @@ component LPOptimizationTest{
implementation Math
{
// define problem
Q m = 3;
Q n = 2;
Q m = 2;
Q n = 3;
// define A, b
Q^{3, 1} A = [45; 60; 35];
Q^{2, 1} b = [50; 60];
Q^{2, 1} A = [350; 600];
Q^{3, 1} b = [325; 300; 275];
// cost matrix
Q ^{m, n} c = [3, 2; 1, 5; 5, 4];
Q ^{m, n} c = [2.5, 1.7, 1.8; 2.5, 1.8, 1.4];
// minimization problem
Q y = minimize(Q^{3, 2} x)
Q y = minimize(Q^{2, 3} x)
sum(c .* x);
subject to
sum(x, 2) == A;
......
// transportation problem example (linear)
// see https://www.gams.com/products/simple-example/
package de.rwth.monticar.optimization;
component TransportationProblem{
ports out Q^{3, 2} xOut,
out Q yOut;
implementation Math
{
// define problem
Q m = 2;
Q n = 3;
// define A, b
Q^{2, 1} A = [350; 600];
Q^{3, 1} b = [325; 300; 275];
// cost matrix
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);
subject to
sum(x, 2) == A;
sum(x, 1) == b;
x >= 0;
end
xOut = x;
yOut = y;
}
}
\ No newline at end of file
Supports Markdown
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