Optimize for particular value at a specific time

Use this forum to post Vensim related questions.
Post Reply
karankhosla
Senior Member
Posts: 107
Joined: Wed Nov 26, 2008 6:12 am

Optimize for particular value at a specific time

Post by karankhosla »

Greetings!

Please see the sample model I made; how can I optimize parameters to fulfill a value constraint and also a time constraint? I would like the population to be near 300 by time 20 (months).

Thanks!

Karan
Attachments
Population_Optimize.zip
(1.99 KiB) Downloaded 222 times
karankhosla
Senior Member
Posts: 107
Joined: Wed Nov 26, 2008 6:12 am

Post by karankhosla »

I presume one way would be too end the simulation at the time of interest and values would be optimized accordingly.
LAUJJL
Senior Member
Posts: 1426
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

optimize

Post by LAUJJL »

Hi Karan

You are right. You must put the final time equal 20 and optimize the population. But to optimize you must minimize the square of the difference between the desired population and the population at the final time. You do not have to integrate the square values. You must calculate a payoff that is equal to zero during the simulation and equal to the square at the end of the simulation and put that payoff in the vpd file with a weight of -1. Look for 'payoff computation' in the Vensim help. The calculation of the payoff is explained.
Regards.
JJ
karankhosla
Senior Member
Posts: 107
Joined: Wed Nov 26, 2008 6:12 am

Post by karankhosla »

Thanks JJ!
LAUJJL
Senior Member
Posts: 1426
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

optimize

Post by LAUJJL »

Hi Karan

Obviously the interval of possible nutrition is not wide enough.
Joined a model where you can have a final time later than 20 and does the job. I was obliged to modify the lookup to make it compatible to the extension of the interval of possible nutrition. Of course this is pure math and may not correspond to anything reality.
Regards.
JJ
Attachments
optimizelookup2.zip
(6.62 KiB) Downloaded 225 times
karankhosla
Senior Member
Posts: 107
Joined: Wed Nov 26, 2008 6:12 am

Post by karankhosla »

Thanks a lot JJ, yes it was just a trial to see if I could get fulfill a time constraint as well. I was just reviewing Geoff Coyle's book (the section on optimizing) he defines the objective function as a level of a penalty, e.g. pen.k = pen.j +dt*(Desired Population - Population)^2: pen0 = 0. Then minimize the penalty. Would this not work?
LAUJJL
Senior Member
Posts: 1426
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

Optîmize

Post by LAUJJL »

Hi Karan

I do not see any contradiction with Coyle's objective function.
Your objective is that at time 20 the population is equal to 300. One has then to define a payoff that is equal to 0 everywhere but when time = 20, because Vensim integrates automatically the defined payoff in the vpd file. See the 'payoff computation' explanation in the Vensim help.
I have not Coyle's book with me at the time. See my u to U message.
Regards.
JJ
karankhosla
Senior Member
Posts: 107
Joined: Wed Nov 26, 2008 6:12 am

Post by karankhosla »

Aha! JJ - Thank you!
LAUJJL
Senior Member
Posts: 1426
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

population

Post by LAUJJL »

Hi Karan

I think that the specifications of your problem you start from are ideal. It is extremely simple which is very good and you can still spend quite a lot of time, analyzing it and trying to test already at this level, the level of implementability which is fundamental if you want to build a useful model later on. You can run sensibility analysis with the parameters, desired population, desired time, nutrition, lookup effect that should be replaced by an algebraic formula to make sensibility analysis easier. Try all sorts of optimization. Build as many as possible reality checks (takes a lot of time to be expert with it and preferable to test with very simple models) etc...
Contrary to what is commonly taught I have experienced that it is not necessary to include in a model, all the significant factors, nor extended boundaries to be useful. Simplicity and undestandability is much more important than closeness to the reality even if the potential policies found at this stage are not concretely implementable. But it should at least help to get a better overall view of the problem that will help greatly when adding progressively later on more material to the model.
Regards.
JJ
tomfid
Administrator
Posts: 3808
Joined: Wed May 24, 2006 4:54 am

Post by tomfid »

pen.k = pen.j +dt*(Desired Population - Population)^2: pen0 = 0.
You don't need to perform the integration step in Coyle's formula, because Vensim integrates payoffs for you. The equivalent would be:

*C
population|desired population/weight

If you make your weight something like PULSE( target_time, target_width) with target_time = 20, you can evaluate the fit near your desired time. Then you don't have to stop the model at that point.
karankhosla
Senior Member
Posts: 107
Joined: Wed Nov 26, 2008 6:12 am

Post by karankhosla »

Thanks Tom! I'm going to try it out. I presume the logic behind it is that, as the weight is multiplied to the payoff at each time step, the pulse function forces the value of the payoff to be "x" at a particular time and zero elsewhere, which forces the optimizer to (if so desired) to minimize the only non-zero in its calculation.

[Edited on 3-3-2010 by karankhosla]
LAUJJL
Senior Member
Posts: 1426
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

optimize

Post by LAUJJL »

One can do the same with an interval of fitness with a small change on the previous model sent.
With an interval of two months lasting 5 months, one gets a value of nutrition of 13.51 with the interval and 13.58 with no interval.
Regards.
JJ
Attachments
population_optimize_3.mdl
(3.97 KiB) Downloaded 227 times
karankhosla
Senior Member
Posts: 107
Joined: Wed Nov 26, 2008 6:12 am

Post by karankhosla »

JJ That works very well too. Thank you.
LAUJJL
Senior Member
Posts: 1426
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

optimize

Post by LAUJJL »

You can too try to keep the maximum difference within the fitness interval minimal.
It gives the following model that proves that there are many ways to skin a cat giving the same result than the optimize_2 model.
Regards.
JJ
Attachments
population_optimize_4.mdl
(4.3 KiB) Downloaded 228 times
tomfid
Administrator
Posts: 3808
Joined: Wed May 24, 2006 4:54 am

Post by tomfid »

Originally posted by karankhosla
Thanks Tom! I'm going to try it out. I presume the logic behind it is that, as the weight is multiplied to the payoff at each time step, the pulse function forces the value of the payoff to be "x" at a particular time and zero elsewhere, which forces the optimizer to (if so desired) to minimize the only non-zero in its calculation.
That's right. It's also possible to use IF THEN ELSE and SAMPLE IF TRUE for similar purposes.

One caveat: using IF THEN ELSE to test for Time = desired time can fail unexpectedly, because of round off error in the accumulation of time steps. That's why I used PULSE (which has logic to test for whether the next time interval includes the desired time) rather than IF THEN.
karankhosla
Senior Member
Posts: 107
Joined: Wed Nov 26, 2008 6:12 am

Post by karankhosla »

Thanks Tom.
Post Reply