Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40f4c66
commit 879a7e0
Showing
4 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
openmodelica/cruntime/optimization/basic/testAlgLoop10.mos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
58
openmodelica/cruntime/optimization/basic/testAlgLoop11.mos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |