Opened 11 years ago

Closed 11 years ago

#2601 closed defect (fixed)

attributes get lost for optimization models

Reported by: Lennart Ochel Owned by: Lennart Ochel
Priority: high Milestone: 1.9.1
Component: Backend Version: trunk
Keywords: Cc: Willi Braun, Bernhard Bachmann

Description

Some variable attributes get lost for the following model

setCommandLineOptions("+g=Optimica");
getErrorString();

loadString("
model BatchReactor
  Real x2;
  Real x1;
  Real y2(start =0, fixed=true, min=-0.1, max=1e4, nominal = 3);
  Real y1(start =1, fixed=true, min=-0.1, max=1e6, nominal = 2);

  input Real u(min=-0.1, max = 2.0, nominal = 1.0,start = 1.0);
equation
  x2 = a*y2;
  x1 = b*y1;
  b*der(y1) = -(u+u^2/2)*x1;
  a*der(y2) = u*x1;
end BatchReactor;

optimization nmpcBatchReactor(objective = cost)
  parameter Real a = 10;
  parameter Real b = 20;

  Real cost = -a*y2;
  extends BatchReactor(y1(start =1/b, fixed=true, min=0, max=1/b, nominal = 1/b),
                       y2(start =0, fixed=true, min=0, max=1/a, nominal = 1/a),
                                           u(min=0, max = 5.0, nominal = 1.0,start = 1.0));
end nmpcBatchReactor;
");
getErrorString();

optimize(nmpcBatchReactor, numberOfIntervals=20, tolerance = 1e-8,simflags="-lv LOG_IPOPT");
getErrorString();

If you run that mos-script, you will get the following output

true
""
true
""
record SimulationResult
    resultFile = "/home/lochel/Documents/tests/Opt/nmpcBatchReactor_res.mat",
    simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 20, tolerance = 1e-08, method = 'optimization', fileNamePrefix = 'nmpcBatchReactor', options = '', outputFormat = 'mat', variableFi
lter = '.*', measureTime = false, cflags = '', simflags = '-lv LOG_IPOPT'",
    messages = "Optimizer Variables
========================================================
State[0]:y1(start = 0.05, nominal = 0.05, min = -Inf, max = 0.05, init = 0.05)
State[1]:y2(start = 0, nominal = 0.1, min = -Inf, max = 0.1, init = 0)
Input[2]:u(start = 1, nominal = 1, min = 0, max = 5)
--------------------------------------------------------
========================================================
[…]

As you can see, the min-Attributes are wrong (should be 0.0).

The min attributes get readout from the *_init.xml file, and some attributes are missing:

  <ScalarVariable
  name = "y1"
  valueReference = "1000"
  variability = "continuous" isDiscrete = "false"
  causality = "internal" isValueChangeable = "true"
  alias = "noAlias"
  classIndex = "0" classType = "rSta"
  fileName = "&lt;interactive&gt;" startLine = "6" startColumn = "3" endLine = "6" endColumn = "64" fileWritable = "true">
  <Real useStart="false" start="0.0" fixed="true" useNominal="true" />
  </ScalarVariable>

Change History (6)

comment:1 by Lennart Ochel, 11 years ago

Using +d=dumpindxdae shows that the min attributes are somehow present correctly in the back end:

[…]
Known Variables (constants) (10)
========================================
1: input y1:STATE(1)(min = 0.0 max = 1.0 / b start = 1.0 / b fixed = true nominal = 1.0 / b ) .nmpcBatchReactor, .Real type: Real
2: input y2:STATE(1)(min = 0.0 max = 1.0 / a start = 0.0 fixed = true nominal = 1.0 / a ) .nmpcBatchReactor, .Real type: Real
3: input x1:VARIABLE() .nmpcBatchReactor, .Real type: Real
4: input x2:VARIABLE() .nmpcBatchReactor, .Real type: Real
5: input $TMP_mayerTerm:VARIABLE()  type: Real
6: input b:PARAM()  = 20.0 .nmpcBatchReactor, .Real type: Real
7: input a:PARAM()  = 10.0 .nmpcBatchReactor, .Real type: Real
8: input u:VARIABLE(min = 0.0 max = 5.0 start = 1.0 nominal = 1.0 ) .nmpcBatchReactor, .Real type: Real
9: input y2$pDERA$Py2:STATE_DER()  type: Real
10: input y1$pDERA$Py1:STATE_DER()  type: Real

[…]

########################################
dumpindxdae
########################################


Variables (5)
========================================
1: y1:STATE(1)(min = 0.0 max = 1.0 / b start = 1.0 / b fixed = true nominal = 1.0 / b ) .nmpcBatchReactor, .Real type: Real
2: y2:STATE(1)(min = 0.0 max = 1.0 / a start = 0.0 fixed = true nominal = 1.0 / a ) .nmpcBatchReactor, .Real type: Real
3: x1:VARIABLE() .nmpcBatchReactor, .Real type: Real
4: x2:VARIABLE() .nmpcBatchReactor, .Real type: Real
5: output $TMP_mayerTerm:VARIABLE()  type: Real
[…]

Vitalij, why occurs the dumpindxdae dump that often for optimization models? It seems that there are different DAEs with partially overlapping variables. Is that on purpose?

comment:2 by Lennart Ochel, 11 years ago

The max attribute is set correctly, because it is parameter dependent and therefore determined during initialization.

comment:3 by Lennart Ochel, 11 years ago

Probably I can fix it. I did some changes and get now:

========================================================
State[0]:y1(start = 0.05, nominal = 0.05, min = 0, max = 0.05, init = 0.05)
State[1]:y2(start = 0, nominal = 0.1, min = 0, max = 0.1, init = 0)
Input[2]:u(start = 1, nominal = 1, min = 0, max = 5)
--------------------------------------------------------

Unfortunately, now I get another error ...

comment:4 by Lennart Ochel, 11 years ago

Owner: changed from Vitalij Ruge to Lennart Ochel
Status: newaccepted

comment:5 by Lennart Ochel, 11 years ago

cross reference: this is somehow connected to #2597

comment:6 by Lennart Ochel, 11 years ago

Resolution: fixed
Status: acceptedclosed

Fixed in r19255.

Note: See TracTickets for help on using tickets.