Commit 8d60bb83 authored by Christoph Richter's avatar Christoph Richter
Browse files

Made MathOpt tests stream testable

parent a3ac4374
......@@ -11,7 +11,7 @@ import java.util.List;
import static org.junit.Assert.assertNotNull;
public class CarModelGenerationTest {
public class CarModelGenerationTest extends BasicGenerationTest {
private static TaggingResolver symtab = EMAMOpt2CPPSymbolTableHelper.getInstance().createSymTabAndTaggingResolver("src/test/resources");
......@@ -25,6 +25,6 @@ public class CarModelGenerationTest {
@Test
public void carModelInstanceTest() throws IOException {
List<File> files = doGenerateModel("test.carmodel.carModelInstanceTest");
List<File> files = doGenerateModel("de.rwth.monticar.carmodel.carModelInstanceTest");
}
}
......@@ -43,22 +43,22 @@ public class GeneratorCplexSolverTest {
@Test
public void scalarMinimizationCMakeTest() throws IOException {
List<File> files = doGenerateModel("test.math.optimization.scalarMinimizationTest");
List<File> files = doGenerateModel("de.rwth.monticar.optimization.scalarMinimizationTest");
}
@Test
public void scalarMaximizationCMakeTest() throws IOException {
List<File> files = doGenerateModel("test.math.optimization.scalarMaximizationTest");
List<File> files = doGenerateModel("de.rwth.monticar.optimization.scalarMaximizationTest");
}
@Test
public void lPOptimizationCMakeTest() throws IOException {
List<File> files = doGenerateModel("test.math.optimization.lPOptimizationTest");
List<File> files = doGenerateModel("de.rwth.monticar.optimization.lPOptimizationTest");
}
@Test
public void constraintTest() throws IOException {
List<File> files = doGenerateModel("test.math.optimization.constraintTest");
List<File> files = doGenerateModel("de.rwth.monticar.optimization.constraintTest");
}
}
\ No newline at end of file
......@@ -15,7 +15,7 @@ import static org.junit.Assert.assertNotNull;
* Test class for GeneratorEMAMOpt2CMake
* @author Christoph Richter
*/
public class GeneratorEMAMOpt2CMakeTest {
public class GeneratorEMAMOpt2CMakeTest extends BasicGenerationTest {
/**
* symbol table as static class variable so it must be created only once
......@@ -32,78 +32,72 @@ public class GeneratorEMAMOpt2CMakeTest {
@Test
public void scalarMinimizationCMakeTest() throws IOException {
List<File> files = doGenerateModel("test.math.optimization.scalarMinimizationTest");
List<File> files = doGenerateModel("de.rwth.monticar.optimization.scalarMinimizationTest");
}
@Test
public void scalarMaximizationCMakeTest() throws IOException {
List<File> files = doGenerateModel("test.math.optimization.scalarMaximizationTest");
List<File> files = doGenerateModel("de.rwth.monticar.optimization.scalarMaximizationTest");
}
@Test
public void standardIpoptOptimizationTestCMakeTest() throws IOException {
List<File> files = doGenerateModel("test.math.optimization.standardIpoptOptimizationTest");
List<File> files = doGenerateModel("de.rwth.monticar.optimization.standardIpoptOptimizationTest");
}
@Test
public void lPOptimizationCMakeTest() throws IOException {
List<File> files = doGenerateModel("test.math.optimization.lPOptimizationTest");
List<File> files = doGenerateModel("de.rwth.monticar.optimization.lPOptimizationTest");
}
@Test
public void boundedConditionsCMakeTest() throws IOException {
List<File> files = doGenerateModel("test.math.optimization.boundedConditionsTest");
List<File> files = doGenerateModel("de.rwth.monticar.optimization.boundedConditionsTest");
}
@Test
public void forLoopConditionsCMakeTest() throws IOException {
List<File> files = doGenerateModel("test.math.optimization.forLoopConditionsTest");
List<File> files = doGenerateModel("de.rwth.monticar.optimization.forLoopConditionsTest");
}
@Test
public void existingOptimizationVariableCMakeTest() throws IOException {
List<File> files = doGenerateModel("test.math.optimization.existingOptimizationVariableTest");
List<File> files = doGenerateModel("de.rwth.monticar.optimization.existingOptimizationVariableTest");
}
@Test
public void matrixSumMinimization1Test() throws IOException {
List<File> files = doGenerateModel("test.math.optimization.matrixSumMinimizationTest1");
List<File> files = doGenerateModel("de.rwth.monticar.optimization.matrixSumMinimizationTest1");
}
@Test
public void matrixSumMinimization2Test() throws IOException {
List<File> files = doGenerateModel("test.math.optimization.matrixSumMinimizationTest2");
List<File> files = doGenerateModel("de.rwth.monticar.optimization.matrixSumMinimizationTest2");
}
@Test
public void constMatrixSumMinimizationTest() throws IOException {
List<File> files = doGenerateModel("test.math.optimization.constMatrixSumMinimizationTest");
List<File> files = doGenerateModel("de.rwth.monticar.optimization.constMatrixSumMinimizationTest");
}
@Test
public void colRowMinTest() throws IOException {
List<File> files = doGenerateModel("test.math.optimization.colRowMinTest");
List<File> files = doGenerateModel("de.rwth.monticar.optimization.colRowMinTest");
}
@Test
public void scalarMultMinTest() throws IOException {
List<File> files = doGenerateModel("test.math.optimization.scalarMultMinTest");
List<File> files = doGenerateModel("de.rwth.monticar.optimization.scalarMultMinTest");
}
@Test
public void matrixTransposeMinimizationTest() throws IOException {
List<File> files = doGenerateModel("test.math.optimization.matrixTransposeMinimizationTest");
List<File> files = doGenerateModel("de.rwth.monticar.optimization.matrixTransposeMinimizationTest");
}
@Test
public void constraintTest() throws IOException {
List<File> files = doGenerateModel("test.math.optimization.constraintTest");
List<File> files = doGenerateModel("de.rwth.monticar.optimization.constraintTest");
}
@Test
public void kinematicBicycleMPCCMakeTest() throws IOException {
List<File> files = doGenerateModel("test.math.optimization.mpc.kinematicBicycleMPC");
}
}
\ No newline at end of file
......@@ -18,7 +18,7 @@ import static org.junit.Assert.assertNotNull;
*
* @author Christoph Richter
*/
public class GeneratorEMAMOpt2CPPTest {
public class GeneratorEMAMOpt2CPPTest extends BasicGenerationTest {
/**
* symbol table as static class variable so it must be created only once
......@@ -29,7 +29,7 @@ public class GeneratorEMAMOpt2CPPTest {
* helper method to generate optimization models in CPP code
*/
protected static List<File> doGenerateOptimizationModel(String modelName) throws IOException {
ExpandedComponentInstanceSymbol componentSymbol = symtab.<ExpandedComponentInstanceSymbol>resolve(String.format("test.math.optimization.%s", modelName), ExpandedComponentInstanceSymbol.KIND).orElse(null);
ExpandedComponentInstanceSymbol componentSymbol = symtab.<ExpandedComponentInstanceSymbol>resolve(String.format("de.rwth.monticar.optimization.%s", modelName), ExpandedComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentSymbol);
GeneratorCPP generator = new GeneratorEMAMOpt2CPP();
generator.setGenerationTargetPath("./target/generated-sources-cpp/testMath/optimizationSolver/" + modelName);
......@@ -150,16 +150,4 @@ public class GeneratorEMAMOpt2CPPTest {
List<File> files = doGenerateOptimizationModel("matrixTransposeMinimizationTest");
}
/**
* Model predicive control
* Kindematic bicyle model
*/
@Test
public void testKinematicBicycleMPC() throws IOException {
List<File> files = doGenerateOptimizationModel("mpc.kinematicBicycleMPC");
// TODO: create reference solution
// String restPath = "testMath/optimizationSolver/";
// testFilesAreEqual(files, restPath);
}
}
\ No newline at end of file
......@@ -12,31 +12,14 @@ import java.nio.file.Paths;
import static org.junit.Assert.assertTrue;
public class GeneratorEMAMOpt2CppCliTest {
@BeforeClass
public static void initLog() {
LogConfig.init();
LogConfig.enableFailQuick(false);
}
@Before
public void clearFindings() {
LogConfig.getFindings().clear();
}
@AfterClass
public static void resetLog() {
LogConfig.getFindings().clear();
LogConfig.enableFailQuick(true);
}
public class GeneratorEMAMOpt2CppCliTest extends BasicGenerationTest {
@Test
public void testAutopilotCli() {
String targetDir = "target/generated-sources-cpp/cliTest/AutopilotMPC/";
public void testTrajectoryControllerCli() {
String targetDir = "target/generated-sources-cpp/cliTest/trajectoryControllerMPC/";
String[] args = {
"--models-dir=src/test/resources/",
"--root-model=de.rwth.armin.modeling.autopilot.autopilotMPC",
"--root-model=de.rwth.monticar.mpc.trajectoryControllerMPC",
"--output-dir=" + targetDir,
"--flag-generate-autopilot-adapter",
};
......@@ -44,7 +27,7 @@ public class GeneratorEMAMOpt2CppCliTest {
String[] positiveFileNames = {
"CMakeLists.txt",
"de_rwth_armin_modeling_autopilot_autopilotMPC.h",
"de_rwth_monticar_mpc_trajectoryControllerMPC.h",
"AutopilotAdapter.h",
"AutopilotAdapter.cpp",
};
......
package test.carmodel;
package de.rwth.monticar.carmodel;
component CarModelInstanceTest {
instance KinematicBicycleCarModel<0.1 s, 1 m, 1 m> kinematicBicycleCarModel;
......
package test.carmodel;
package de.rwth.monticar.carmodel;
component KinematicBicycleCarModel<Q dt = 0.1 s, Q l_f = 1 m, Q l_r = 1 m>
{
......
package test.carmodel;
package de.rwth.monticar.carmodel;
component MatlabCarModel<Q dt = 0.1 s, Q m = 2000 kg, Q a = 1.5 m, Q b = 1.5 m, Q cx = 150000, Q cy = 40000, Q ca = 0.5>
{
......
package test.math.optimization;
package de.rwth.monticar.optimization;
component BoundedConditionsTest{
ports out Q xOut,
out Q yOut;
implementation Math{
Q y = minimize(Q x)
(x*x) - 2 * x + 1;
......@@ -8,5 +12,7 @@ component BoundedConditionsTest{
0 <= x <= 1;
0 <= 2*x <= 1;
end
xOut = x;
yOut = y;
}
}
\ No newline at end of file
package test.math.optimization;
package de.rwth.monticar.optimization;
component ColRowMinTest{
implementation Math{
ports out Q^{2,2} xOut,
out Q yOut;
implementation Math{
Q y = minimize(Q^{2,2} x)
x(1, :) * x(:, 1);
subject to
......@@ -11,5 +14,7 @@ component ColRowMinTest{
x(2, 1) >= 1;
x(2, 2) >= 1;
end
xOut = x;
yOut = y;
}
}
\ No newline at end of file
package test.math.optimization;
package de.rwth.monticar.optimization;
component ConstMatrixSumMinimizationTest{
ports out Q xOut,
out Q yOut;
implementation Math{
Q y = minimize(Q x)
sum([0, 0, x, 0]);
subject to
-1 <= x <= 1;
end
// test
// assert(x = - 1)
// assert(y = - 1)
xOut = x;
yOut = y;
}
}
\ No newline at end of file
package test.math.optimization;
package de.rwth.monticar.optimization;
component ConstraintTest{
ports out Q(-1:1)^{3,3} xOut,
out Q yOut;
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);
subject to
......@@ -16,5 +19,7 @@ component ConstraintTest{
end
end // (3,1) in [-1,1] => accu == -5
// min res = 6.4 - 5 = 1.4
xOut = x;
yOut = y;
}
}
\ No newline at end of file
package test.math.optimization;
package de.rwth.monticar.optimization;
component ExistingOptimizationVariableTest{
implementation Math{
ports out Q xOut1,
out Q aOut2,
out Q bOut2,
out Q aOut3,
out Q cOut3;
implementation Math{
// 1. scalar
Q x = 3;
minimize(x)
......@@ -10,6 +17,7 @@ component ExistingOptimizationVariableTest{
subject to
-1 <= x <= 1;
end
xOut1 = x;
// 2. matrix
Q^{3,3} a = zeros(3,3);
......@@ -18,6 +26,8 @@ component ExistingOptimizationVariableTest{
subject to
-10 <= a <= 10;
end
aOut2 = a;
bOut2 = b;
// 3. substituted
Q^{3,3} ainc = a + 1;
......@@ -26,6 +36,7 @@ component ExistingOptimizationVariableTest{
subject to
-20 <= a <= 20;
end
aOut3 = a;
cOut3 = c;
}
}
\ No newline at end of file
package test.math.optimization;
package de.rwth.monticar.optimization;
component ForLoopConditionsTest{
ports out Q xOut,
out Q yOut;
implementation Math{
Q y = minimize(Q^{3} x)
x(1) * x(1) + x(2) * x(2) + x(3) * x(3);
......@@ -10,5 +14,7 @@ component ForLoopConditionsTest{
0 <= 2 * x(i) <= 2;
end
end
xOut = x;
yOut = y;
}
}
\ No newline at end of file
// transportation problem example (linear)
// see https://www.gams.com/products/simple-example/
package test.math.optimization;
package de.rwth.monticar.optimization;
component LPOptimizationTest{
ports out Q^{3, 2} xOut,
out Q yOut;
implementation Math
{
// define problem
......@@ -18,12 +22,14 @@ component LPOptimizationTest{
Q ^{m, n} c = [3, 2; 1, 5; 5, 4];
// minimization problem
minimize(Q^{3, 2} x)
Q y = minimize(Q^{3, 2} 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
package test.math.optimization;
package de.rwth.monticar.optimization;
component MatrixSumMinimizationTest1{
ports out Q^{2,2} xOut,
out Q yOut;
implementation Math{
Q y = minimize(Q^{2,2} x)
sum(x);
......@@ -10,5 +14,7 @@ component MatrixSumMinimizationTest1{
x(2,1) >= 0;
x(2,2) >= -5;
end
xOut = x;
yOut = y;
}
}
\ No newline at end of file
package test.math.optimization;
package de.rwth.monticar.optimization;
component MatrixSumMinimizationTest2{
ports out Q^{2,2} xOut,
out Q yOut;
implementation Math{
Q y = minimize(Q^{2,2} x)
sum(x);
subject to
x >= 0;
end
xOut = x;
yOut = y;
}
}
\ No newline at end of file
package test.math.optimization;
package de.rwth.monticar.optimization;
component MatrixTransposeMinimizationTest{
ports out Q^{2} xOut,
out Q yOut;
implementation Math{
Q y = minimize(Q^{2} x)
[1; 2; 3; 4]' * [x(1); x(2); 0; 0];
......@@ -9,6 +13,9 @@ component MatrixTransposeMinimizationTest{
x(2) >= 0;
end
xOut = x;
yOut = y;
// test
// x = [1,1]
// y = 3
......
package test.math.optimization;
package de.rwth.monticar.optimization;
component ScalarMaximizationTest{
ports out Q xOut,
out Q yOut;
implementation Math{
Q z = maximize(Q x)
- x * x + 42;
......@@ -8,5 +12,7 @@ component ScalarMaximizationTest{
x >= -10;
x <= 10;
end
yOut = z;
xOut = x;
}
}
\ No newline at end of file
package test.math.optimization;
package de.rwth.monticar.optimization;
component ScalarMinimizationTest{
ports out Q xOut,
out Q yOut;
......
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