Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from vruge/master
update dyn. optmization examples
- Loading branch information
Showing
7 changed files
with
140 additions
and
17 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
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,62 @@ | ||
// name: CombiTimeTable | ||
// status: correct | ||
|
||
loadModel(Modelica); | ||
getErrorString(); | ||
|
||
setCommandLineOptions("+g=Optimica"); | ||
getErrorString(); | ||
|
||
loadString(" | ||
optimization TimeTableTest(objectiveIntegrand = (x - timeTable.y[1])^2) | ||
input Real u(min = -10, max = 10); | ||
Real x(min = -5, max = 10); | ||
Modelica.Blocks.Sources.CombiTimeTable timeTable(table = [0,1; 1,3; 2,-3; 3,5; 4,7; 5, 0], extrapolation = Modelica.Blocks.Types.Extrapolation.HoldLastPoint); | ||
initial equation | ||
x = timeTable.y[1]; | ||
equation | ||
der(x) = u; | ||
end TimeTableTest; | ||
"); | ||
getErrorString(); | ||
|
||
optimize(TimeTableTest, numberOfIntervals=20, tolerance = 1e-8, stopTime = 5); | ||
getErrorString(); | ||
|
||
res := OpenModelica.Scripting.compareSimulationResults("TimeTableTest_res.mat","ReferenceFiles/TimeTableTest_ref.mat","TimeTableTest_res.csv",0.01,0.0001, | ||
{"u", | ||
"x"}); | ||
getErrorString(); | ||
|
||
// Result: | ||
// true | ||
// "" | ||
// true | ||
// "" | ||
// true | ||
// "" | ||
// record SimulationResult | ||
// resultFile = "TimeTableTest_res.mat", | ||
// simulationOptions = "startTime = 0.0, stopTime = 5.0, numberOfIntervals = 20, tolerance = 1e-08, method = 'optimization', fileNamePrefix = 'TimeTableTest', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''", | ||
// messages = " | ||
// Optimizer Variables | ||
// ======================================================== | ||
// State[0]:x(start = 0, nominal = 10, min = -5, max = 10, init = 1) | ||
// Input[1]:u(start = 0, nominal = 10, min = -10, max = 10) | ||
// -------------------------------------------------------- | ||
// number of nonlinear constraints: 0 | ||
// ======================================================== | ||
// stdout | info | Jacobian or SparsePattern is not generated or failed to initialize! Switch back to normal. | ||
// | ||
// ****************************************************************************** | ||
// This program contains Ipopt, a library for large-scale nonlinear optimization. | ||
// Ipopt is released as open source code under the Eclipse Public License (EPL). | ||
// For more information visit http://projects.coin-or.org/Ipopt | ||
// ****************************************************************************** | ||
// | ||
// " | ||
// 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,62 @@ | ||
// name: CombiTimeTablePeriodic | ||
// status: correct | ||
|
||
loadModel(Modelica); | ||
getErrorString(); | ||
|
||
setCommandLineOptions("+g=Optimica"); | ||
getErrorString(); | ||
|
||
loadString(" | ||
optimization TimeTableTest(objectiveIntegrand = (x - timeTable.y[1])^2) | ||
input Real u(min = -10, max = 10); | ||
Real x(min = -5, max = 10); | ||
Modelica.Blocks.Sources.CombiTimeTable timeTable(table = [0,1; 1,3; 2,-3; 3,5; 4,7; 5, 0], extrapolation = Modelica.Blocks.Types.Extrapolation.Periodic ); | ||
initial equation | ||
x = timeTable.y[1]; | ||
equation | ||
der(x) = u; | ||
end TimeTableTest; | ||
"); | ||
getErrorString(); | ||
|
||
optimize(TimeTableTest, numberOfIntervals=20, tolerance = 1e-8, stopTime = 5); | ||
getErrorString(); | ||
|
||
res := OpenModelica.Scripting.compareSimulationResults("TimeTableTest_res.mat","ReferenceFiles/TimeTableTest_ref.mat","TimeTableTest_res.csv",0.01,0.0001, | ||
{"u", | ||
"x"}); | ||
getErrorString(); | ||
|
||
// Result: | ||
// true | ||
// "" | ||
// true | ||
// "" | ||
// true | ||
// "" | ||
// record SimulationResult | ||
// resultFile = "TimeTableTest_res.mat", | ||
// simulationOptions = "startTime = 0.0, stopTime = 5.0, numberOfIntervals = 20, tolerance = 1e-08, method = 'optimization', fileNamePrefix = 'TimeTableTest', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''", | ||
// messages = " | ||
// Optimizer Variables | ||
// ======================================================== | ||
// State[0]:x(start = 0, nominal = 10, min = -5, max = 10, init = 1) | ||
// Input[1]:u(start = 0, nominal = 10, min = -10, max = 10) | ||
// -------------------------------------------------------- | ||
// number of nonlinear constraints: 0 | ||
// ======================================================== | ||
// stdout | info | Jacobian or SparsePattern is not generated or failed to initialize! Switch back to normal. | ||
// | ||
// ****************************************************************************** | ||
// This program contains Ipopt, a library for large-scale nonlinear optimization. | ||
// Ipopt is released as open source code under the Eclipse Public License (EPL). | ||
// For more information visit http://projects.coin-or.org/Ipopt | ||
// ****************************************************************************** | ||
// | ||
// " | ||
// 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
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
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
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