Optimizer isn't finding the optimum I expect

Use this forum to post Vensim related questions.
Post Reply
carmidc
Junior Member
Posts: 10
Joined: Sun Jul 17, 2011 4:10 am

Optimizer isn't finding the optimum I expect

Post by carmidc »

In the attached model, I am trying to use the optimizer to find an optimal mix of Baseload (cheap) and Peaker (expensive) electricity production. However, the optimization doesn’t get very close to the optimal solution. I have set the Baseload Production Cost to be one third of the Peaker Production Cost (cost information is on the second page of the model). In addition, I have set up the model so that all production needs could be met simply by using Baseload production. However, the model is calculating a production mix of 10 from Baseload and 8.2 from Peaker production, even though Peaker production is far more expensive. (Note – the initial value for Baseload production was 10, but this parameter is allowed to vary between 0 and 25 in the Optimization Setup box.) I thought perhaps the optimizer had simply stopped at a local optimum, but it doesn’t seem like the 10-to-8.2 production mix could really be a local optimum given that ANY increase in baseload production will improve the objective function and any increase in peaker production will make the objective worse (regardless of what happens downstream). Note that if I force the optimizer to do Multiple Starts at different starting points, I get a better optimum (with essentially all production needs covered by Baseload and essentially none covered by Peaker). Could someone explain to me why the optimizer appears to get “stuck” at a non-optimal solution when I just do one optimization run? The answer to this is very important because I need to increase the complexity of this model substantially, and if the optimizer is getting stuck on this model I will have serious problems determining whether the more-complex model is actually finding an optimal solution. I am new to using Vensim, so it is likely I have simply made a mistake somewhere. If you have any suggestions, I would greatly appreciate them!

Additional model background: I am using Vensim Pro for Windows v.5.10.e. The model is a simplification of an electrical grid, with two power sources (Baseload and Peaker). Electricity can either go through a storage device (where it loses some electricity) or through a bypass path. Either way, total electricity out of the system has to be equivalent (or nearly equivalent) to Demand at all times. In order to force this equivalence, I created a Demand Differential variable and penalized it in the optimizer if it was nonzero. I also penalized a Storage Out variable if it was below zero. If there is a better way to set this up, please let me know!
Attachments
Model5.zip
Here is the model file, plus the VOC and VPD files.
(3.05 KiB) Downloaded 162 times
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Optimizer isn't finding the optimum I expect

Post by tomfid »

My guess is that your penalties on demand diff and negative storage are somehow distorting the payoff surface.

It might be good to calculate your payoff explicitly in the equations rather than in the .vpd. In other words, in the model, create:

Code: Select all

cost = total cost + diff penalty + neg penalty
diff penalty = ABS( demand - supply)*diff weight
neg penalty = - MIN(0, storage)*neg weight
cum cost = INTEG(cost,0)
Your .vpd would use

Code: Select all

cost/-1
The payoff will be the equivalent of cum cost (payoffs are integrated).

Then you can see what's going on, and also vary the weights interactively (SyntheSim is good for that).

Another issue is that your logic for storage usage doesn't seem to provide maximum storage output coincident with the demand peak.

Hope this helps.
carmidc
Junior Member
Posts: 10
Joined: Sun Jul 17, 2011 4:10 am

Re: Optimizer isn't finding the optimum I expect

Post by carmidc »

Thanks Tom! Based on your suggestions, I have defined penalty variables directly within the simulation and added a Cost Objective Function variable to my model (all on the Cost Function tab). In the Optimization Setup, I am now optimizing only the Cost Objective Function variable within the .vpd. However, I am still getting non-optimal results when I perform optimizations with a single start. (If I use a high enough number of starts, I obtain a much better optimum). I think you are correct that the payoff surface may be distorted by the penalty functions – in the single runs (i.e., no restarts), I end up with a large penalty for Negative Storage Out at the beginning of the simulation, which overwhelms the other costs. Is there a better way for me force Demand Differential to be zero and Storage Out to be non-negative (rather than using penalties with large weightings)? Related to this, is there a good way for me to allow the “Proportion Stored In End User Storage” parameter (which is a “variable” of Type: Constant) to vary on EACH iteration? I need to build this functionality into the model eventually (since sometimes it makes sense to store electricity and other times it would be counterproductive to send electricity through storage because of storage losses). Furthermore, it seems like allowing the “Proportion Stored In End User Storage” parameter to be varied by the optimization engine during each simulation would allow the optimization engine to avoid sending excess electricity to storage early on (thus avoiding the high penalty function values and incorrect “optima”).
Thanks again!!
Attachments
Model7.zip
Here is the current model, including the VPD and VOC files.
(3.71 KiB) Downloaded 165 times
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Optimizer isn't finding the optimum I expect

Post by tomfid »

Hi - It does look like your payoff has multiple optima. I'm not sure I have special insight into why this is, but it seems like the best thing would be to focus on your decision rules. For example, you have base and peaker calculated separately, but it might be better to switch to a different basis, e.g. total generation and share of peaker. Also, I'd rewrite your decision rule for storage so that it does more to make use of storage coincide with peak demand. Finally, balancing your units might shed some light on the needed solution.

This is a fundamentally hard problem, so don't be discouraged. A look into the literature for other solutions might be useful.
carmidc
Junior Member
Posts: 10
Joined: Sun Jul 17, 2011 4:10 am

Re: Optimizer isn't finding the optimum I expect

Post by carmidc »

Thanks again Tom! As you suggested, I changed the decision logic so that instead of two input power sources, I have only the Total Electricity (and a new “Proportion Peaker” variable). This allowed the optimization to find (what appears to be) the best solution in a single pass. I’m not sure why that change in structure made a difference, but it worked nevertheless. I now have another question: How can I allow the “Total Electricity” and “Proportion Stored In End User Storage” parameters to vary during EACH iteration of an optimization run? For example, the proportion of electricity that is sent to storage should be varied throughout the day (it should be high when excess production capacity is available, and it should fall to zero when demand exceeds production capacity). I see that Vensim can do sensitivity analyses in which model parameters are changed for each simulation. However, I am trying to do something different - I want a given parameter to take on different values at different times during an optimization run, in order to deliver a single optimal overall solution. I can't find advice for this in the Manuals or the users' Forum. FYI, I tried using subscripting, but when I added a time subscript to the “Total Electricity” and “Proportion Stored In End User Storage” parameters, they became variables rather than constants (and thus they could not be used as optimization parameters). Is there a way to allow a subscripted element be an optimization parameter? Or is there some other way that I can get the optimization engine to determine a (different) optimal value of a given parameter during EACH individual iteration of an optimization run? If you would like an example of what I am trying to accomplish, I can upload a “brute force” proof-of-concept example where I have created different “Proportion Stored In End User Storage” parameters for each individual time step. This method seems to work, but it is not scaleable to thousands of time steps (which is what we would like).
Thanks again!
Doug
Attachments
Model7.zip
Here's the latest file.
(3.85 KiB) Downloaded 157 times
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Optimizer isn't finding the optimum I expect

Post by tomfid »

One way to have time-varying decisions is to use the VECTOR LOOKUP function (see examples in the new release's help system). Usually it's better to come up with some kind of feedback rule with a few parameters that can be varied though.

Tom
carmidc
Junior Member
Posts: 10
Joined: Sun Jul 17, 2011 4:10 am

Re: Optimizer isn't finding the optimum I expect

Post by carmidc »

Thanks Tom. I was able to get the Vector Lookup Function to vary the Proportion Stored In End User Storage for each time period, so that's good. However, the optimization results don't give the globally optimal answer. For instance, there are times when the End User Storage Bypass flow is zero. This doesn't make sense because there is always demand for at least 4 kW of electricity, and if none of the electricity in a given time period is sent through the Bypass, then it all must go through storage (thus incurring costly and unnecessary storage losses). In addition, there are some strange peaks/valleys in the various End User Storage Bypass/Storage In/Storage Out graphs that don't make sense to me.

I wondered if there was something about the model structure that could result in a global optimum associated with the strange peaks/valleys that I just described. To check this, I decided to see if I could get better optimization results with a "brute force" model (with the Proportions Stored In End User Storage for each time period explicitly specified as P1 through P24). That model gave a much better optimization result than the Vector Lookup model, with a much better objective function and smoother graphs for End User Storage In and End User Storage Bypass. However, this model is obviously not scaleable to thousands of time units, and even this model does not give globally optimal results.

Do you have any suggestions regarding Optimization Control settings or changes to the model structure that could produce better results for the optimization of the Vector Lookup Function model? Also - In a different version of this model, I created some parameters associated with the Proportion Stored In End User Storage that could be varied by the optimization engine. I tried 4 or 5 different equations for the Proportion Stored In End User Storage, but the results were poor. If you have suggestions on this, please let me know.

Thanks,
Doug
Attachments
Model10.zip
This model has 4 adjustable parameters that define the Proportion Stored
(7.06 KiB) Downloaded 153 times
Model9.zip
This model uses the Vector Lookup function
(7.09 KiB) Downloaded 151 times
Model8.zip
This is the "brute force" model, with different parameters specified for each individual time period.
(17.92 KiB) Downloaded 136 times
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Optimizer isn't finding the optimum I expect

Post by Administrator »

I've only had a quick look at model10. But this sentence got me thinking.
For instance, there are times when the End User Storage Bypass flow is zero. This doesn't make sense because there is always demand for at least 4 kW of electricity, and if none of the electricity in a given time period is sent through the Bypass, then it all must go through storag
If this is wrong, is your model behaving how you think it should? When I optimised, the "Proportion Stored in End User Storage" was over 1 (which does not make sense to me), resulting in "End User Storage Bypass" going negative.
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
carmidc
Junior Member
Posts: 10
Joined: Sun Jul 17, 2011 4:10 am

Re: Optimizer isn't finding the optimum I expect

Post by carmidc »

Hi Tony,
I was referring to the Vector Lookup Function model (model9) when I made that comment. However, the comment certainly applies to the other models as well - the End User Storage Bypass flow should never be zero (and in a real-world physical sense, it certainly could not be negative and similarly the Proportion Stored certainly could not be more than one). I tried various equations within the Proportion Stored In End User Storage variable, but none of them gave me good results. It doesn't seem like it's possible to get good results with just 4 parameters, given that there are 24 time periods and the Proportion Stored In End User Storage needs to be optimized for each individual period. But if you have any suggestions on how to get better results for the Proportion Stored using a small number of parameters, I would love to hear them!
Thanks,
Doug
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Optimizer isn't finding the optimum I expect

Post by Administrator »

The optimizer will never find a correct answer unless the model is correct. When I optimized, the results were nonsense due to the value of "Proportion stored in end user" calculation. I'd suggest working some more on the model and making sure the proportion cannot go above 1. Then optimize. Check the results are ok, and then figure out why the results are not optimal (if they are not).

If you really can modify the proportion daily (or for each time step) then build that into the model.If you can only change it once every month, build that into the model.
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
carmidc
Junior Member
Posts: 10
Joined: Sun Jul 17, 2011 4:10 am

Re: Optimizer isn't finding the optimum I expect

Post by carmidc »

Please look at Model 9, which I uploaded yesterday. Model 9 was the model that I really wanted feedback on (in Model 10, I was playing around with some parameters, but as I noted in my post yesterday, that model didn't work well). Model 9 only allows the Proportion Stored In End User Storage to vary between 0 and 1, so it does not have the issue with proportions above 1 or negative flows.
Thank you!
carmidc
Junior Member
Posts: 10
Joined: Sun Jul 17, 2011 4:10 am

Re: Optimizer isn't finding the optimum I expect

Post by carmidc »

I may have figured out a way to solve the problem with the optimization, so you can hold off on looking at Model 9. I will work on the next version of the model tomorrow.
Cheers,
Doug
carmidc
Junior Member
Posts: 10
Joined: Sun Jul 17, 2011 4:10 am

Re: Optimizer isn't finding the optimum I expect

Post by carmidc »

Hello,

I’m still having problems getting the optimizer to arrive at good results in a reasonable period of time. One reason for the slow convergence is probably the number of parameters that are being varied – three different parameters are being varied for each of 24 time periods. I have tried setting up the model in various ways, and I have tried various optimization settings, but I still get poor optimization performance. For instance, if I run the attached file and stop the optimizer after about 100,000 simulations, I get a value for Max End User Storage (the variable in red on the Cost Function tab) of roughly 24.2 kWh. If I stop the optimizer after roughly 5 million simulations, the Max End User Storage is about 20.2. If I let the optimization engine go through many millions of simulation, it eventually gets down to a Max End User Storage of about 4.4, but it takes a very long time to do this.

Do you have any advice on how to speed up the policy optimization of the attached file? Are there any changes to the model structure that you would suggest (i.e. a better way to set up the “Demand Differential” penalty or the “Negative Storage Out Penalty” on the Demand tab)? Do you have any suggestions regarding Optimization Control settings that could produce better results for the optimization of the Vector Lookup Function model?

Thanks,
Doug
Attachments
Model14.zip
(10.23 KiB) Downloaded 152 times
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Optimizer isn't finding the optimum I expect

Post by Administrator »

I think the problem is with the objective function.

The only thing actually changing it is "production and storage cost per time period", so work on that and figure out why it's not giving you the optimal result you want. "Incremental storage required" goes to zero pretty quickly, maybe this is the problem, I cannot figure out what you are trying to do here though so cannot comment any further.

One other tip, delete the "TIME UNITS" variable, there is no point cheating on the units check as it just hides errors in your models (the first unit error that crops up can be solved by changing the units for "STORAGE COST PER KWH" to $/KwH/hour).
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
carmidc
Junior Member
Posts: 10
Joined: Sun Jul 17, 2011 4:10 am

Re: Optimizer isn't finding the optimum I expect

Post by carmidc »

The "Production and Storage Cost Per Time Period” is actually the only cost that should change significantly from time period to time period. The Penalty functions should always be zero (or close to zero) in order to ensure that “Total Out” is identical to “Total Demand”, and “End User Storage Out” is non-negative. If there is a better way to set this up, please let me know.

The “Incremental Storage Required” is performing the way I expect. Basically it determines whether the storage required at a given point in time is greater than at any previous point in time. If so, the size of the storage device (i.e. the battery) is increased in order to meet this maximum capacity. Since “Storage At End User” peaks at hour 4, “Incremental Storage Required” also peaks at hour 4. In other words, if a battery is sized the meet the required capacity at hour 4, that same battery will be sufficient to meet the capacity requirement at any other point in the day.

Regarding the optimal result that I expect, the “Baseload Production Profile” on the Check tab should be at its maximum output of 18 at any time that Peaker Production is used. Instead, depending on the Optimization Setup options that I use and the number of simulations, Baseload Production is sometimes well below capacity even though additional electricity is needed. This necessitates the use of additional (expensive) Peaker Production in order to meet “Total Demand”. Furthermore, excessive electricity is sent through “End User Storage In” during the middle and end of the day, despite the fact that the storage unit could be bypassed at this time with no ill effects. Bypassing this electricity would lower production costs because it would eliminate unnecessary storage losses. Ideally, “Max End User Storage” should be roughly equivalent to “End User Storage In”.

I have tried using every possible Multiple Start option in the Optimization Setup, and I have tried various other options on that tab. Some options give better results than others, but none actually produces a truly optimal result for this model. (I know this because if I manually tweak the initial values for certain parameters that are varied by the optimizer, and then run the optimization, I can obtain better results – for example, see the attached file which uses different initial conditions for various parameters - this model produces better results than the previous model even though the only things that changed were the initial values of parameters that the optimizer will vary). In addition, as noted previously, it takes a very long time and numerous simulations in order to even get near a true optimum (as noted previously, if I run the file and stop the optimizer after about 100,000 simulations, I get a value for “Max End User Storage” (the variable in red on the Cost Function tab) of roughly 24.2 kWh. If I stop the optimizer after roughly 5 million simulations, the “Max End User Storage” is about 20.2. If I let the optimization engine go through many millions of simulation, it eventually gets down to a “Max End User Storage” of about 4.4, but it takes a very long time to do this.) Please let me know if there are specific combinations of Optimization Setup options that I should try, or if there is some better way to ensure non-negativity of “End User Storage Out” (other than the Penalty function that I created), or if there are other tips related to model structure that I should be aware of in order to facilitate global optimization.

Thanks,
Doug
Attachments
Model14_v2.zip
(5.22 KiB) Downloaded 158 times
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Optimizer isn't finding the optimum I expect

Post by tomfid »

It still seems to me that more could be done to improve the robustness of the decision rules before turning to the optimizer. For example, negative storage out could be ruled out by the physics of the model rather than by a penalty.

Can you create something more like the attached, in which storage utilization is driven by a decision rule with tunable parameters? (It's probably possible to do much better than what I whipped up here, especially if you use an array dimension to represent the 24hr cycle so that expectations about demand can be more sophisticated.)
AltStorage.mdl
(5.31 KiB) Downloaded 157 times
Tom
carmidc
Junior Member
Posts: 10
Joined: Sun Jul 17, 2011 4:10 am

Re: Optimizer isn't finding the optimum I expect

Post by carmidc »

Thanks for sending that example Tom! I will see if I get better results using this type of structure.
Post Reply