Opened 10 years ago

Last modified 7 years ago

#2736 accepted discussion

Final Constraints for Optimization missing

Reported by: Vitalij Ruge Owned by: Mahder Alemseged Gebremedhin
Priority: normal Milestone: Future
Component: Frontend Version: trunk
Keywords: Cc: Mahder Alemseged Gebremedhin

Description

Currently it's not possible to formulation final constraints in the optimization.
In the moment we support path constraints with Otimica Extension.

 Real a,b,c,d,e;
.....
constraint
 a*b + c/d < e

In Optimica it's possible to write for final constraints.

 Real a,b,c,d,e;
.....
constraint
 a(finaTime)*b(finalTime) + c(1.0)*d(finalTime) < b(1.0)

where finalTime is a real parameter 1.0, which is unknown sometimes.
Note: stopTime not equal finalTime!

There some issues with different time point and the case if finalTime is unknown.

It seem like the currently way in Modelica is to set marker via (Custom) annotations
see e.g. http://www.ep.liu.se/ecp/096/018/ecp14096018.pdf

It's would be nice to have something like

 Real a,b,c,d,e;
.....
constraint
 a*b + c/d < e annotation(finalConstraint = true)

The issue is that a*b + c/d < e is an equation and the annotation going missing in the BackEnd.
Alternative it should be possible to write

 Real a,b,c,d,e;
 Boolean f (finalConstraint = true);
.....
  equation
 f = a*b + c/d < e;

However custom annotations not really finished yet!
Therefore, I prefer for the first prototype similar implementation like constraint with

 Real a,b,c,d,e;
.....
equation
....
final constraint
 a*b + c/d < e;
constraint
...

Change History (13)

comment:1 by Mahder Alemseged Gebremedhin, 10 years ago

Owner: changed from somebody to Mahder Alemseged Gebremedhin
Status: newaccepted

comment:2 by Martin Sjölund, 10 years ago

Why not just use when terminal()?

comment:3 by Vitalij Ruge, 10 years ago

when terminal() sounds like native solution for me.

In the constraint environment I will get the error:
Error: Parse error: Only function call expressions may stand alone in an algorithm section
for

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

loadString("
optimization foo(objectiveIntegrand = (x)^2)
    input Real u(min = -10, max = 10);
    Real x(min = -5, max = 10);
  equation
    der(x) = u;
  constraint
    when terminal() then
       x == 7;
    end when;
end foo;
");

when time >= const would be nice solution for time points constraints, too.
Then we would only have problems with periodic constraints formulation like

x(startTime) == x(stopTime)
or
f(x(startTime), x(stopTime),startTime,stopTime) == 0

comment:4 by Vitalij Ruge, 10 years ago

Other simply idea can be to add new function

optimization foo(objectiveIntegrand = (x)^2)
    input Real u(min = -10, max = 10);
    Real x(min = -5, max = 10);
  equation
    der(x) = u;
  constraint
     optimizationFunctionForTimeConstraints(x == 7,time == stopTime);
end foo;


comment:5 by Vitalij Ruge, 10 years ago

Priority: highnormal

Since r22103 we can use annotation for final constraints terms.
Example:

model testFinalCon
  Real x1(start = 1, fixed = true);
  Real x2(start = -1, fixed = true);
  input Real u;

  Real final_con1(min = 0, max = 0) annotation(isFinalConstraint = true);
  Real final_con2(min = 0, max = 0) annotation(isFinalConstraint = true);
  Real cost annotation(isLagrange = true);

equation
  der(x1) = x2*u - x1;
  der(x2) = x1 + u;
  final_con1 = x1 - 2; //0 <= x1 - 2 <= 0 for t = tf
  final_con2 = x2 - 3;

  cost = u^2;
end testFinalCon;

However I think the constraint-environment is more user friendly. I hope in the future we can support when terminal() in constraint-environment.

comment:6 by Martin Sjölund, 10 years ago

Milestone: 1.9.11.9.2

This ticket was not closed for 1.9.1, which has now been released. It was batch modified for milestone 1.9.2 (but maybe an empty milestone was more appropriate; feel free to change it).

comment:7 by Martin Sjölund, 10 years ago

Milestone: 1.9.21.9.3

Milestone changed to 1.9.3 since 1.9.2 was released.

comment:8 by Martin Sjölund, 9 years ago

Milestone: 1.9.31.9.4

Moved to new milestone 1.9.4

comment:9 by Martin Sjölund, 9 years ago

Milestone: 1.9.41.9.5

Milestone pushed to 1.9.5

comment:10 by Martin Sjölund, 9 years ago

Milestone: 1.9.51.10.0

Milestone renamed

comment:11 by Martin Sjölund, 8 years ago

Milestone: 1.10.01.11.0

Ticket retargeted after milestone closed

comment:12 by Martin Sjölund, 8 years ago

Milestone: 1.11.01.12.0

Milestone moved to 1.12.0 due to 1.11.0 already being released.

comment:13 by Francesco Casella, 7 years ago

Milestone: 1.12.0Future

The milestone of this ticket has been reassigned to "Future".

If you think the issue is still valid and relevant for you, please select milestone 1.13.0 for back-end, code generation and run-time issues, or 2.0.0 for front-end issues.

If you are aware that the problem is no longer present, please select the milestone corresponding to the version of OMC you used to check that, and set the status to "worksforme".

In both cases, a short informative comment would be welcome.

Note: See TracTickets for help on using tickets.