Skip to content

Commit

Permalink
added test for simplifyConstraints
Browse files Browse the repository at this point in the history
  • Loading branch information
vruge authored and OpenModelica-Hudson committed Jun 5, 2015
1 parent e5f7de7 commit 40f4c66
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions openmodelica/cruntime/optimization/basic/Makefile
Expand Up @@ -38,6 +38,7 @@ testAlgLoop3.mos \
testAlgLoop4.mos \
testAlgLoop5.mos \
testAlgLoop6.mos \
testSimpliCon1.mos \
TFC.mos \
TFC2.mos \
TFC3.mos \
Expand Down
84 changes: 84 additions & 0 deletions openmodelica/cruntime/optimization/basic/testSimpliCon1.mos
@@ -0,0 +1,84 @@
// name: simplifyCon1
// status: correct

loadModel(Modelica);
getErrorString();

setCommandLineOptions("+gDynOpt");
getErrorString();

loadString("
model simplifyCon1
input Real u(min = -10, max = 10);
Real x(min = -5, max = 10);
Real con(min=-1,max=1) annotation(isConstraint = true);
Real con2(min=-1,max=1) annotation(isConstraint = true);
Real con3(min=-1,max=1) annotation(isConstraint = true);
Real con4(min=-1,max=1) annotation(isConstraint = true);
Real con5(min=-1,max=1) annotation(isConstraint = true);
Real con6(min=-1,max=1) annotation(isConstraint = true);
Real con7(min=-1,max=1) annotation(isConstraint = true);
Real con8(min=-1,max=1) annotation(isConstraint = true);
Real con9(min=-1,max=1) annotation(isConstraint = true);
Real cost =x annotation(isLagrange=true);
parameter Real p = 4;
final parameter Real p1 = 4;
initial equation
x = 0;
equation
con = 2*x;
con2 = p*u;
con3 = p*x;
con4 = p1*u;
con5 = p1*u;
con6 = p*x*p*sin(p);
con7 = x*u;
con8 = x*(time +1);
con9 = x*(p + 1);
der(x) = u-x;
end simplifyCon1;
");
getErrorString();

optimize(simplifyCon1, numberOfIntervals=20, tolerance = 1e-8, stopTime = 5);
getErrorString();

val(x,5);
val(u,5);
val(x,2);
val(u,2);


// Result:
// true
// ""
// true
// ""
// true
// ""
// record SimulationResult
// resultFile = "simplifyCon1_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 5.0, numberOfIntervals = 20, tolerance = 1e-08, method = 'optimization', fileNamePrefix = 'simplifyCon1', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = "
// Optimizer Variables
// ========================================================
// State[0]:x(start = 0, nominal = 0.0825843, min = -0.0825843, max = 0.0825843, init = 0)
// Input[1]:u(start = 0, nominal = 0.25, min = -0.25, max = 0.25)
// --------------------------------------------------------
// number of nonlinear constraints: 3
// ========================================================
//
// ******************************************************************************
// 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;
// ""
// -0.08258429430068139
// -0.08258429155929739
// -0.08258429430068139
// -0.08258429209272602
// endResult

0 comments on commit 40f4c66

Please sign in to comment.