Optimization with variables as parameters and varying constraints

Use this forum to post Vensim related questions.
Post Reply
OlivierV
Junior Member
Posts: 13
Joined: Fri Apr 23, 2021 10:51 am
Vensim version: DSS

Optimization with variables as parameters and varying constraints

Post by OlivierV »

Hi,

I would like to optimize a model, in which :
- Some optimization constraints are time varying (exogeneously).
- Optimization parameters should vary over time.
- I would like to constraint stocks, without taking them as optimization parameters.

It is a dynamic system that I would like to optimise.
I saw that Vensim could only take Constants as parameters, that Vensim only returned one value for each parameter and not one value by year (or time unit), and that all optimization constraints must be entered as parameters thus not allowing putting constraints on resulting stocks.

Are there some ways to overpass these issues ? Should I consider using complementary module or software ?
Maybe I can recreate penalties functions for stock constraints, but as there are 5 different constraints, would it perfectly work ? However, that would not solve the other issues.

Thank you
Administrator
Super Administrator
Posts: 4562
Joined: Wed Mar 05, 2003 3:10 am

Re: Optimization with variables as parameters and varying constraints

Post by Administrator »

OlivierV wrote: Fri Apr 23, 2021 11:38 am I saw that Vensim could only take Constants as parameters, that Vensim only returned one value for each parameter and not one value by year (or time unit), and that all optimization constraints must be entered as parameters thus not allowing putting constraints on resulting stocks.
One way you can do this is to use a VECTOR LOOKUP. You can define a vector of values that will be modified by the optimizer, and use these to create a lookup which is used in the model.

I'm always a little concerned when I hear of someone wanting to optimize this way though. Do you actually have control over the things that vary by year? Or are you trying to fit a curve?
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
tomfid
Administrator
Posts: 3800
Joined: Wed May 24, 2006 4:54 am

Re: Optimization with variables as parameters and varying constraints

Post by tomfid »

You can enforce constraints with penalty terms in the payoff. For example:

Penalty = MAX(0, Actual Stock - Max Stock Constraint) * exceedence value

Then make that a (negative) policy payoff term.
OlivierV
Junior Member
Posts: 13
Joined: Fri Apr 23, 2021 10:51 am
Vensim version: DSS

Re: Optimization with variables as parameters and varying constraints

Post by OlivierV »

Thank you for your answers.
Is there documentation about how Vensim mathematicaly compute optimization ?
I have implemented the optimisation using Vector lookup as you suggested, and turned variable constraints into binary penalties (if variable reach limit, then penalty=100). That has allowed me create the model.

For answering you, the system I want to model in the end is complex, has a lot of variables, inputs and relations, and I want to know which are the best parameters for each year.
Here I am just making a small model for testing how I will implement optimization in the real one

Now I still have some questions and concerns with Vensim optimization.
Here is the description of the model :
1) I want to recreate here a model that indicates me what is the optimum Variable mix for each year.
This is a small model that I want to validate before creating a much bigger one, with more variable(~5), more constraints (~3), and much more computations.
2) I am computing Var 1 and Var 2 based on yearly growth rates that are optimized.

And how I optimize :
1) First, I only aim an exogeneous “Var objective” with “Total Var” , with no constraints
I first did it with policy optimization on “objective function”, and found a persistent non-zero payoff (=-3), which surprised me because here I have no constraint thus no reason to have small mismatches. I tried to change optimization configuration, but that did not solve that mismatch, and changing configuration changed the payoff, but chaotically (reducing Frac Tol sometimes gave me lower payoff, but other reduced values gave greater payoff).
Is there a way to solve that mismatch ? (without using calibration)
Tough it is easily solved with calibration between “Total Var” and Aimed total var exogeneous” (nice payoff of 1e-4), I would like to know how I could enhance the optimization precision because I will have a secondary Policy objective.
Do you also know why there is a peak for Var 1 and 2 growth at last year ?

2) Secondly, I add a secondary policy objective
As there are many possibilities for reaching Total Var objective, I would like to minimize cumulated costs
Therefore I add it as policy constraint with weight=-0.0001
It works. But I see there are lots of variations in Var1 and Var2, what we would avoid in reality, thus I added 2 penalty functions for limiting Var1 and Var2 sharp variation. And there I need to put a -1e-10 on that penalty for not loosing my secondary objective. It also seems that there is a gap in result : Or the payoff is around -22 for |weights|>1e-8 and -11 for |weights|<1e-8. Can we explain that ?

3) Now I would like to add constraints
I will try to implement a constraint on Var1 maximum value. I choose Var1 limit=110 as I see it is reaching this value.
It works, but we see a counter intuitive behaviour : after reaching the limit, Var1 decreases although it would better stay at the limit because it is cheaper than Var2 regarding Cost secondary objective.

I would like to implement other constraints, but there are already things I don’t fully understand and I would like to enhance in the simulation for making the final model optimization consitstent and reliable.

Final observation :
I have here a first objective (aim Var exogeneous), a secondary objective (minimize Cumulated costs), and 3 limits (2 for Var growth variations and 1 for Var 1 value).
And as the model give a lower cost for Var1, we could expect it behaviour as this : Var1 increases the faster it can regarding Var1 and Var2 growth, Aimed total Var. Var2 will decrease, lowering cost.
Then Var 1 would reach it limit and stay at this value minimizing costs. Var2 will then evolve for respecting Aimed total Var.
But we don’t really see that perfect behaviour on Var1, why is that ?

Thank you for your answers
I link the model and data
Attachments
Optimization model.mdl
(13.67 KiB) Downloaded 165 times
Optimization exogeneous data.xlsx
(10.02 KiB) Downloaded 152 times
Administrator
Super Administrator
Posts: 4562
Joined: Wed Mar 05, 2003 3:10 am

Re: Optimization with variables as parameters and varying constraints

Post by Administrator »

You haven't provided us with the files necessary to perform the optimization, the payoff definition and optimization control files are missing.
I have here a first objective (aim Var exogeneous), a secondary objective (minimize Cumulated costs), and 3 limits (2 for Var growth variations and 1 for Var 1 value).
And as the model give a lower cost for Var1, we could expect it behaviour as this : Var1 increases the faster it can regarding Var1 and Var2 growth, Aimed total Var. Var2 will decrease, lowering cost.
Then Var 1 would reach it limit and stay at this value minimizing costs. Var2 will then evolve for respecting Aimed total Var.
But we don’t really see that perfect behaviour on Var1, why is that ?
I'd start with just one objective, and make sure that it being met before adding additional objectives. If the two objectives you have interact in any way, it could easily describe what you are seeing. You may need to adjust the weighting of the objectives to give more priority to one.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
OlivierV
Junior Member
Posts: 13
Joined: Fri Apr 23, 2021 10:51 am
Vensim version: DSS

Re: Optimization with variables as parameters and varying constraints

Post by OlivierV »

Sorry, Voc and VPD file attached.
A first issue is precisely that even with only “Objective Function” in policy mode, I find a -3 payoff
Attachments
OptModel.vpd
(211 Bytes) Downloaded 154 times
Test2.voc
(590 Bytes) Downloaded 150 times
tomfid
Administrator
Posts: 3800
Joined: Wed May 24, 2006 4:54 am

Re: Optimization with variables as parameters and varying constraints

Post by tomfid »

By default, Vensim uses a modified Powell search. See http://www.it.uom.gr/teaching/linearalg ... /c10-5.pdf for a good explanation. For complex surfaces, doing lots of random multistart simulations is highly recommended.

You can also use the Markov Chain Monte Carlo algorithm for Simulated Annealing, though I don't think that's needed here.
tomfid
Administrator
Posts: 3800
Joined: Wed May 24, 2006 4:54 am

Re: Optimization with variables as parameters and varying constraints

Post by tomfid »

Some observations on the setup:

- The model has no units, which is not best practice.
- Payoffs are normally flows, so when you include Cumulated Costs in your payoff, you're using not only the final value, but all the earlier values, which means that the early part of the simulation is heavily weighted. Use the "Final" timing option or switch to "Costs".
- Penalty functions that use IF THEN ELSE or similar create a payoff surface with discrete steps that is extremely difficult to search, because it's a mix of zero (flat) and infinite gradients. Much better to use something smooth, like coeff*MAX(0,value-target)^2, or coeff*ABS(value-target).
- You could compute the growth variation directly from the optimization control parameters with subscript math, rather than using delay functions.
- In general, it's much better to specify a feedback control decision rule and optimize the parameters defining that, rather than searching for a vector of points over time. The vector approach is ballistic, which means it is not robust to noise or parameter variation. I can't suggest anything specific without knowing what this model is about.
- The search space is already large (50 parameters) but the model is small, so it will probably work anyway. A feedback decision rule would have far fewer parameters, but you could also use something like Legendre polynomials, which would also be smooth automatically. https://metasd.com/2018/02/polynomials- ... ion-rules/
- Since the payoff is somewhat complex, debugging might be easier if you compute the whole payoff explicitly, so that the vpd has only one term. For example:
payoff = data fit payoff contrib + cost contrib + ...
data fit payoff contrib = ((model - data)/data sd)^2
cost contrib = -cost
etc.
This way, you could also define units for payoff elements, to ensure that everything is in the same terms.
OlivierV
Junior Member
Posts: 13
Joined: Fri Apr 23, 2021 10:51 am
Vensim version: DSS

Re: Optimization with variables as parameters and varying constraints

Post by OlivierV »

Thank you for your answers and advices

I could have tried different optimization methods and found that only Multiple start Vector gave different (and better) results.
However, I have not been able to generate good output even with few objectives. As explained in a previous message, «we could expect it behaviour as this : Var1 increases the faster it can regarding Var1 and Var2 growth limit and Aimed total Var. Var2 will decrease, lowering cost». I could not see that clean behaviour (I also added a low limit=0 for Var2).
For penalty computation, I tried smoothing with an adapted Logistic curve, but it gave me overflow errors.
Finally, it seems to me that this work is too difficult for the way Vensim optimization work, as I also experimented unstable or erratic results.

With all that issues for this small model I will try another approach. I think it would give less relevant results than those a clean optimization could have done, but for that kind of model (and thinking about the bigger one I would optimize) this optimization now seems unreliable to me.
tomfid
Administrator
Posts: 3800
Joined: Wed May 24, 2006 4:54 am

Re: Optimization with variables as parameters and varying constraints

Post by tomfid »

I think the optimizer is perfectly capable of handling a situation like this with appropriate inputs.

The logistic penalty probably causes floating point errors because EXP(x) overflows for x greater than about 300 (or 30 in single precision). x^2 or ABS(x) is usually a better choice.
tomfid
Administrator
Posts: 3800
Joined: Wed May 24, 2006 4:54 am

Re: Optimization with variables as parameters and varying constraints

Post by tomfid »

A good test would be to manually set the parameters to what you think is a good solution, and see if that yields a payoff that is actually better. That would be tedious with the annual decision points, but you could reduce the size of the vector so that decisions are made at 5-year intervals and interpolated.

With abstract variable names and no units, it's hard to know enough about the problem to suggest another approach.
tomfid
Administrator
Posts: 3800
Joined: Wed May 24, 2006 4:54 am

Re: Optimization with variables as parameters and varying constraints

Post by tomfid »

I notice that the computation of growth variation uses DELAY FIXED initialized to 0. This means that any growing scenario will be penalized initially, because the growth rate starts at a nonzero value in year2020.
OlivierV
Junior Member
Posts: 13
Joined: Fri Apr 23, 2021 10:51 am
Vensim version: DSS

Re: Optimization with variables as parameters and varying constraints

Post by OlivierV »

You are right about exp penalty overflow. What bothers me for penalties is that the limits I want to represent are tough limits, meaning that I can’t overpass them but I can be just at their edge without problems (that is why I thought about logistic curves allowing me model a continous penalty switching 0 to 100 quickly at the limit I implemented). I will think about a more continuous-but-fast penalty function based on simple function as you suggested.
I forgot about the definition of first growth limit value, it is therefore impactful on next year evolution.

I will later try beginning optimization closer from expected solution. And don’t worry, finding another approach is even harder studying the real problem !
tomfid
Administrator
Posts: 3800
Joined: Wed May 24, 2006 4:54 am

Re: Optimization with variables as parameters and varying constraints

Post by tomfid »

One option for preserving the logistic is to put a ceiling on the input to the exponential. For example, instead of EXP(x) use EXP(MIN(100,x)).
Post Reply