How to express objective on final state?

5 posts / 0 new
Last post
janpeter
Offline
Joined: 2010-09-11
How to express objective on final state?

Hi

I have gone through the example in the manual and wonder how one express optimization where the objective is:

1) Maximize the final state

2) Maximize a function of the control variables at each instant

Would appreciate some input

Jan Peter

 

borlum
Offline
Joined: 2016-09-22
Maximizing final state

Hi Jan Peter,

Maximizing final state is possible, by simply maximizing your state at 'finalTime'. Thus letting your objective be:

objective = -x(finalTime)

Not quite sure I understand (2) :-)

- Joakim

janpeter
Offline
Joined: 2010-09-11
Hi,Thanks for your answer.

Hi,

Thanks for your answer. It works formally. But numerically a disaster though. Perhaps some options must be tuned. Let me explain.

The state variable that I want to maximize increase with time or can come to a halt for some time but never decrease, whatever the control variables. The goal is actually to maximize the increase of X (given some constraint) at each time instant. Due to the fact that X never decrease I thought I could translate the problem to maximise the final value (at a given time). In my first try I only knew how to formulate an integral objective function and I thought if I use say 10-X as my "objectiveIntegrand" it would also work (and X never goes over 10).  And I got the expected solution. Then I thought I clean this up by choosing a more proper objective function like X(finalState) but that give to me a strange solution. 

The formulation of objective function closest to the real problem is alternative 2). Try to explain it better. I would like to maximize a function of the control variables (given some constraints g) at each time instant. This function f is a function of control variables u and v and f(u,v) controls the growth of X. Thus the problem is something like:

optimization Example (objective....,  startTime=0, finalTime=10)                                   

   ...

   input Real u(min=0.0), v(min=0.0);

equation

    f = a*u + b*v;

    g = c*u + d*v;

    der(x) = f*x;

constraint

    g <=g_max;

end Example

 - - - 

The real code is somewhat longer with more state, but I think the above shows the core of the problem. If it is a help I can enclose the code, of course. This problem is by purpose made very small and can be solved by making an analytical solution of what combination of u and v gives maximal f given the contraint g and with this knowledge ad Modelica model could easilty be formed. However, for more realistic problems the analtyical solution of f is hard to calculate and therefore it would be good to use Optimica to express the model in this more free way.

I would actually be glad to get this right, soon.

Jan Peter

 

Update: Now I better understand the difference between using objectiveIntegrand and objective on final state. Since the problem with my parameters the optimal growth stops before final time. This solution I get when using the objectiveIntegrand kind since you get a penalty of reaching the max value later. Both solutions this gives the same final value fo x, but different trajectories. 

To formulate the problem along alternative 2) where we want to maximize f given constraings g is thus my main question now!

borlum
Offline
Joined: 2016-09-22
Derivative of cost

Okay, trying to deduce a bit; by having f as large as possible at each time t, then are you not just looking to maximize the integral of f?

 

janpeter
Offline
Joined: 2010-09-11
I just tried now to use

I just tried now to use objectiveIntegrand = f_max - f, but that give similar solution as objective = -x(finalTime).

That means no pressure to reach maximal x fast, but you get it in the end. 

If I try objective = f_max-f,  that just does not work "java error occurred, details were printed"

Do not understand that either.

Login or register to post comments