Skip to content

Commit

Permalink
added test for loop2con
Browse files Browse the repository at this point in the history
  • Loading branch information
vruge authored and OpenModelica-Hudson committed Jun 10, 2015
1 parent 40f4c66 commit 879a7e0
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 0 deletions.
5 changes: 5 additions & 0 deletions openmodelica/cruntime/optimization/basic/Makefile
Expand Up @@ -38,6 +38,11 @@ testAlgLoop3.mos \
testAlgLoop4.mos \
testAlgLoop5.mos \
testAlgLoop6.mos \
testAlgLoop7.mos \
testAlgLoop8.mos \
testAlgLoop9.mos \
testAlgLoop10.mos \
testAlgLoop11.mos \
testSimpliCon1.mos \
TFC.mos \
TFC2.mos \
Expand Down
56 changes: 56 additions & 0 deletions openmodelica/cruntime/optimization/basic/testAlgLoop10.mos
@@ -0,0 +1,56 @@
// name: testAlgLoop10
// status: correct

setCommandLineOptions("+gDynOpt +d=loop2con");
//setCommandLineOptions("+gDynOpt");
getErrorString();

loadString("
model testAlgLoop10
Real x1(fixed=true,start=1,min=-2,max=2),x2(min=-2,max=2,start = -1, fixed=true);
input Real u(min=-1,max=1,start=1);
Real con(min=0,max=3) = (der(x2)+der(x1)+x1) annotation(isConstraint=true);
Real cost = (x1^2+x2^2) annotation(isMayer=true);
Real y1,y2;
equation
log(der(x1) + der(x2)+x1) = u*x1;
sin(der(x1))/(2+cos(der(x2))) = x2;
x1*y1 + x2*y2 = sin(time);
3*x1^2*y1 + cos(x2)*y2 = cos(time);
end testAlgLoop10;
");
getErrorString();

optimize(testAlgLoop10, numberOfIntervals=100, tolerance = 1e-12, simflags="-lv LOG_IPOPT_ERROR -optimizerNP 1 -ipopt_max_iter -1 -iif ReferenceFiles/testAlgLoop7_ref.mat -ipopt_init FILE -iim none",stopTime=0.5);
getErrorString();

res := OpenModelica.Scripting.compareSimulationResults("testAlgLoop10_res.mat","ReferenceFiles/testAlgLoop7_ref.mat","testFinalCon_diff.csv",0.01,0.0001,{"x1","x2"});
getErrorString();

// Result:
// true
// ""
// true
// ""
// record SimulationResult
// resultFile = "testAlgLoop10_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 0.5, numberOfIntervals = 100, tolerance = 1e-12, method = 'optimization', fileNamePrefix = 'testAlgLoop10', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_IPOPT_ERROR -optimizerNP 1 -ipopt_max_iter -1 -iif ReferenceFiles/testAlgLoop7_ref.mat -ipopt_init FILE -iim none'",
// messages = "
// Optimizer Variables
// ========================================================
// State[0]:x1(start = 1, nominal = 2, min = -2, max = 2, init = 1)
// State[1]:x2(start = -1, nominal = 2, min = -2, max = 2, init = -1)
// Input[2]:OMC$Input4(start = 0, nominal = 1, min = -Inf, max = +Inf)
// Input[3]:OMC$Input5(start = 0, nominal = 1, min = -Inf, max = +Inf)
// Input[4]:u(start = 0.864672, nominal = 1, min = -1, max = 1)
// --------------------------------------------------------
// number of nonlinear constraints: 3
// ========================================================
// stdout | info | Using values from file as initial guess.
//
// max_iter = -1"
// end SimulationResult;
// ""
// {"Files Equal!"}
// ""
// endResult
58 changes: 58 additions & 0 deletions openmodelica/cruntime/optimization/basic/testAlgLoop11.mos
@@ -0,0 +1,58 @@
// name: testAlgLoop11
// status: correct

setCommandLineOptions("+gDynOpt +d=extendsDynOpt");
//setCommandLineOptions("+gDynOpt");
getErrorString();

loadString("
model testAlgLoop11
Real x1(fixed=true,start=1,min=-2,max=2),x2(min=-2,max=2,start = -1, fixed=true);
input Real u(min=-1,max=1,start=1);
Real con(min=0,max=3) = (der(x2)+der(x1)+x1) annotation(isConstraint=true);
Real cost = (x1^2+x2^2) annotation(isMayer=true);
Real y1,y2;
equation
log(der(x1) + der(x2)+x1) = u*x1;
sin(der(x1))/(2+cos(der(x2))) = x2;
x1*y1 + x2*y2 = sin(time);
3*x1^2*y1 + cos(x2)*y2 = cos(time);
end testAlgLoop11;
");
getErrorString();

optimize(testAlgLoop11, numberOfIntervals=100, tolerance = 1e-12, simflags="-lv LOG_IPOPT_ERROR -optimizerNP 1 -ipopt_max_iter -1 -iif ReferenceFiles/testAlgLoop7_ref.mat -ipopt_init FILE -iim none",stopTime=0.5);
getErrorString();

res := OpenModelica.Scripting.compareSimulationResults("testAlgLoop11_res.mat","ReferenceFiles/testAlgLoop7_ref.mat","testFinalCon_diff.csv",0.01,0.0001,{"x1","x2"});
getErrorString();

// Result:
// true
// ""
// true
// ""
// record SimulationResult
// resultFile = "testAlgLoop11_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 0.5, numberOfIntervals = 100, tolerance = 1e-12, method = 'optimization', fileNamePrefix = 'testAlgLoop11', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_IPOPT_ERROR -optimizerNP 1 -ipopt_max_iter -1 -iif ReferenceFiles/testAlgLoop7_ref.mat -ipopt_init FILE -iim none'",
// messages = "
// Optimizer Variables
// ========================================================
// State[0]:x1(start = 1, nominal = 2, min = -2, max = 2, init = 1)
// State[1]:x2(start = -1, nominal = 2, min = -2, max = 2, init = -1)
// Input[2]:OMC$Input1(start = 0, nominal = 1, min = -Inf, max = +Inf)
// Input[3]:OMC$Input2(start = 3.10958, nominal = 4.10958, min = -Inf, max = +Inf)
// Input[4]:OMC$Input4(start = 0, nominal = 1, min = -Inf, max = +Inf)
// Input[5]:OMC$Input5(start = 0, nominal = 1, min = -Inf, max = +Inf)
// Input[6]:u(start = 0.864672, nominal = 1, min = -1, max = 1)
// --------------------------------------------------------
// number of nonlinear constraints: 5
// ========================================================
// stdout | info | Using values from file as initial guess.
//
// max_iter = -1"
// end SimulationResult;
// ""
// {"Files Equal!"}
// ""
// endResult
53 changes: 53 additions & 0 deletions openmodelica/cruntime/optimization/basic/testAlgLoop9.mos
@@ -0,0 +1,53 @@
// name: testAlgLoop9
// status: correct

setCommandLineOptions("+gDynOpt +d=loop2con");
//setCommandLineOptions("+gDynOpt");
getErrorString();

loadString("
model testAlgLoop9
Real x1(fixed=true,start=1,min=-2,max=2),x2(min=-2,max=2,start = -1, fixed=true);
input Real u(min=-1,max=1,start=1);
Real con(min=0,max=3) = (der(x2)+der(x1)+x1) annotation(isConstraint=true);
Real cost = (x1^2+x2^2) annotation(isMayer=true);
equation
log(der(x1) + der(x2)+x1) = u*x1;
sin(der(x1))/(2+cos(der(x2))) = x2;
end testAlgLoop9;
");
getErrorString();

optimize(testAlgLoop9, numberOfIntervals=100, tolerance = 1e-12, simflags="-lv LOG_IPOPT_ERROR -optimizerNP 1 -ipopt_max_iter -1 -iif ReferenceFiles/testAlgLoop7_ref.mat -ipopt_init FILE -iim none",stopTime=0.5);
getErrorString();

res := OpenModelica.Scripting.compareSimulationResults("testAlgLoop9_res.mat","ReferenceFiles/testAlgLoop7_ref.mat","testFinalCon_diff.csv",0.01,0.0001,{"x1","x2"});
getErrorString();

// Result:
// true
// ""
// true
// ""
// record SimulationResult
// resultFile = "testAlgLoop9_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 0.5, numberOfIntervals = 100, tolerance = 1e-12, method = 'optimization', fileNamePrefix = 'testAlgLoop9', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_IPOPT_ERROR -optimizerNP 1 -ipopt_max_iter -1 -iif ReferenceFiles/testAlgLoop7_ref.mat -ipopt_init FILE -iim none'",
// messages = "
// Optimizer Variables
// ========================================================
// State[0]:x1(start = 1, nominal = 2, min = -2, max = 2, init = 1)
// State[1]:x2(start = -1, nominal = 2, min = -2, max = 2, init = -1)
// Input[2]:OMC$Input2(start = 3.10958, nominal = 4.10958, min = -Inf, max = +Inf)
// Input[3]:OMC$Input3(start = -1.74447, nominal = 2.74447, min = -Inf, max = +Inf)
// Input[4]:u(start = 0.864672, nominal = 1, min = -1, max = 1)
// --------------------------------------------------------
// number of nonlinear constraints: 3
// ========================================================
// stdout | info | Using values from file as initial guess.
//
// max_iter = -1"
// end SimulationResult;
// ""
// {"Files Equal!"}
// ""
// endResult

0 comments on commit 879a7e0

Please sign in to comment.