Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update the attribute(min,max,nominal) of know variable like inputs via parameters. * code is based on the comments in the function createStartValueEquations.
- Loading branch information
Showing
3 changed files
with
91 additions
and
21 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
69 changes: 69 additions & 0 deletions
69
testsuite/openmodelica/cruntime/optimization/basic/issue7969.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,69 @@ | ||
// name: issue7969 | ||
// status: correct | ||
|
||
// target: inputs attribute are set via parameters | ||
|
||
setCommandLineOptions("+gDynOpt"); | ||
getErrorString(); | ||
|
||
loadString(" | ||
model issue7969 | ||
input Real u(min = u_min, max = u_max, nominal=u_nominal); | ||
input Real u1(min = -a, nominal=a); | ||
input Real u2(max = p, min=p, nominal=2*p); | ||
Real totalCost = (x-20)^2 annotation(isMayer = true); | ||
parameter Real p = 10; | ||
parameter Real u_min = -11; | ||
parameter Real u_max = 12; | ||
parameter Real u_nominal = 10; | ||
parameter Real n = 10*p; | ||
parameter Real a = 11; | ||
Real x(start=1, fixed=true); | ||
equation | ||
der(x) = 1e-3*u - 1e-4*u1 + 1e-5*u2; | ||
end issue7969; | ||
"); | ||
getErrorString(); | ||
|
||
optimize(issue7969, numberOfIntervals=4, tolerance = 1e-8, stopTime = 2); | ||
getErrorString(); | ||
|
||
val(u, {0.5,2}); | ||
val(u1, {0.5,2}); | ||
val(u2, {0.5,2}); | ||
val(x, {0.5,2}); | ||
// Result: | ||
// true | ||
// "" | ||
// true | ||
// "" | ||
// record SimulationResult | ||
// resultFile = "issue7969_res.mat", | ||
// simulationOptions = "startTime = 0.0, stopTime = 2.0, numberOfIntervals = 4, tolerance = 1e-08, method = 'optimization', fileNamePrefix = 'issue7969', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''", | ||
// messages = "LOG_SUCCESS | info | The initialization finished successfully without homotopy method. | ||
// | ||
// Optimizer Variables | ||
// ======================================================== | ||
// State[0]:x(start = 1, nominal = 2, min = -Inf, max = +Inf, init = 1) | ||
// Input[1]:u(start = 0, nominal = 10, min = -11, max = 12) | ||
// Input[2]:u1(start = 0, nominal = 11, min = -11, max = +Inf) | ||
// Input[3]:u2(start = 10, nominal = 20, min = 10, max = 10) | ||
// -------------------------------------------------------- | ||
// number of nonlinear constraints: 0 | ||
// ======================================================== | ||
// | ||
// ****************************************************************************** | ||
// 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 https://github.com/coin-or/Ipopt | ||
// ****************************************************************************** | ||
// | ||
// LOG_SUCCESS | info | The simulation finished successfully. | ||
// " | ||
// end SimulationResult; | ||
// "" | ||
// {12.0,12.0} | ||
// {-11.0,-11.0} | ||
// {10.0,10.0} | ||
// {1.006600000063919,1.026400000255677} | ||
// endResult |