Optimising using constraint
Optimising using constraint
Simple problem: to optimise a model using a constant "Percentage" which has a subscript "State". State can be or "A" or "B" and the Percentage[State] can vary from 0 to 1. This is easy.
Now the constraint: Percentage[A]+Percentage must be equals to 1. I tried to create a new variable "Total" = SUM(Percentage[State!]) and put it in the "currently active parameters" at the Optimization Setup dialog box as "Total=1".
Then I got an error: "No usable constant name. Total=1"
Can anyone help me here?
Tks
Now the constraint: Percentage[A]+Percentage must be equals to 1. I tried to create a new variable "Total" = SUM(Percentage[State!]) and put it in the "currently active parameters" at the Optimization Setup dialog box as "Total=1".
Then I got an error: "No usable constant name. Total=1"
Can anyone help me here?
Tks
-
- Super Administrator
- Posts: 4838
- Joined: Wed Mar 05, 2003 3:10 am
optimizing using constraints
HI
You cannot put variables in the parameters to be optimized.
These must be constants. If you have constraints on variables it must be added to the objective to be maximized.
For instance with your problem you want sum(percentage[state!] to be equal to 1. You must create a variable penalty = if then else (sum (percenrage|state!] = 1,-100000,0) and add this variable to your objective to be maximized. It will force the constraint to be respected otherwise the objective will become very negative. If your model is more or less continuous you can allow the constraint to be less strict for intance ABS(percentage[state!]) < 0.001.
Regards.
You cannot put variables in the parameters to be optimized.
These must be constants. If you have constraints on variables it must be added to the objective to be maximized.
For instance with your problem you want sum(percentage[state!] to be equal to 1. You must create a variable penalty = if then else (sum (percenrage|state!] = 1,-100000,0) and add this variable to your objective to be maximized. It will force the constraint to be respected otherwise the objective will become very negative. If your model is more or less continuous you can allow the constraint to be less strict for intance ABS(percentage[state!]) < 0.001.
Regards.
-
- Super Administrator
- Posts: 4838
- Joined: Wed Mar 05, 2003 3:10 am
If there are more than one state, maybe use something like the following.
TOTAL PERCENTAGE = SUM ( PERCENTAGE[STATE!] )
PROPORTIONAL PERCENTAGE[STATE] = PERCENTAGE[STATE] / TOTAL PERCENTAGE
The sum of "PROPORTIONAL PERCENTAGE" will be 1. So you can vary the nine PERCENTAGE[STATE] constants, but use PROPORTIONAL PERCENTAGE in the model where you would have used PERCENTAGE before.
Once optimised, look at the values for "PROPORTIONAL PERCENTAGE[STATE]". These can then be used in place of PERCENTAGE[STATE].
Does this make sense?
Tony.
TOTAL PERCENTAGE = SUM ( PERCENTAGE[STATE!] )
PROPORTIONAL PERCENTAGE[STATE] = PERCENTAGE[STATE] / TOTAL PERCENTAGE
The sum of "PROPORTIONAL PERCENTAGE" will be 1. So you can vary the nine PERCENTAGE[STATE] constants, but use PROPORTIONAL PERCENTAGE in the model where you would have used PERCENTAGE before.
Once optimised, look at the values for "PROPORTIONAL PERCENTAGE[STATE]". These can then be used in place of PERCENTAGE[STATE].
Does this make sense?
Tony.
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
One caveat to Tony's note - fix one of the percentage[state] values and optimize over the remaining 8. Might also want different terminology as in
percentage[state] = weight[state] / total weight
weight[state] = 0.1
then optimize over states 2 to 9 letting weight vary from 0 to 1. This should work but will always give state 1 at least 0.1/9 or about 0.01 so you might need to adjust the range upward (et 0 to 100).
percentage[state] = weight[state] / total weight
weight[state] = 0.1
then optimize over states 2 to 9 letting weight vary from 0 to 1. This should work but will always give state 1 at least 0.1/9 or about 0.01 so you might need to adjust the range upward (et 0 to 100).
optimizing with constraints
The approach I explained above works indepedantly from the number of states
JJ
JJ
Tony, Bob and LAUJJL Tks for the help.
Using Tony idea it would not work since the system would give me as best result all the State having 100%, which would then give me the "proportional percentage" = 1/9 for every single one.
Using Bob idea, it would be me as you said at least one State would have a value .1/9. And this thing of fixing one State it's really not ideal.
I tried LAUJJ's idea and it didn't work as well. For me it makes more sense to have a constraint IF THEN ELSE (sum(percentage[State!]=1,1,0). Then I could multiply my result for this constraint. It would change all results for those interations that the sum isn't = 1 to zero and it would keep the results that are good. Anyway, I couldn't do it.
To make it as simple as possible to understand my problem, I'm picturing a very simplified model as the one above:
VAR1=1
VAR2=1
CONSTRAINT=IF THEN ELSE(VAR1=VAR2+1, 1, 0)
TOTAL=(VAR1+VAR2)*CONSTRAINT
1) VAR1 and VAR2 varies from 0 to 10
2) "CONSTRAINT" LIMITS THE RESULTS FOR THOSE WHERE VAR1=VAR2+1. FOR ALL OTHER VAR1 AND VAR2 VALUES IT MAKES TOTAL RESULT = 0
3) AN OPTIMIZATION SHOULD GIVE AS RESULT VAR1=10 AND VAR2=9, SINCE IT IS THE HIGHEST VALUE FOR TOTAL (=19)
4) CAN YOU MAKE THIS OPTIMIZATION WORK? IF YOU CAN I COULD USE THE SAME RATIONALE TO MY MODEL.
5) IN THE REAL MODEL THERE ARE MORE THAN 2 VAR, REMEMBER THAT!
6) I'M GETTING VAR1=1 and VAR2=2.309, WHICH DOES NOT MAKE ANY SENSE FOR ME.
Tks guys!
Felipe
Using Tony idea it would not work since the system would give me as best result all the State having 100%, which would then give me the "proportional percentage" = 1/9 for every single one.
Using Bob idea, it would be me as you said at least one State would have a value .1/9. And this thing of fixing one State it's really not ideal.
I tried LAUJJ's idea and it didn't work as well. For me it makes more sense to have a constraint IF THEN ELSE (sum(percentage[State!]=1,1,0). Then I could multiply my result for this constraint. It would change all results for those interations that the sum isn't = 1 to zero and it would keep the results that are good. Anyway, I couldn't do it.
To make it as simple as possible to understand my problem, I'm picturing a very simplified model as the one above:
VAR1=1
VAR2=1
CONSTRAINT=IF THEN ELSE(VAR1=VAR2+1, 1, 0)
TOTAL=(VAR1+VAR2)*CONSTRAINT
1) VAR1 and VAR2 varies from 0 to 10
2) "CONSTRAINT" LIMITS THE RESULTS FOR THOSE WHERE VAR1=VAR2+1. FOR ALL OTHER VAR1 AND VAR2 VALUES IT MAKES TOTAL RESULT = 0
3) AN OPTIMIZATION SHOULD GIVE AS RESULT VAR1=10 AND VAR2=9, SINCE IT IS THE HIGHEST VALUE FOR TOTAL (=19)
4) CAN YOU MAKE THIS OPTIMIZATION WORK? IF YOU CAN I COULD USE THE SAME RATIONALE TO MY MODEL.
5) IN THE REAL MODEL THERE ARE MORE THAN 2 VAR, REMEMBER THAT!
6) I'M GETTING VAR1=1 and VAR2=2.309, WHICH DOES NOT MAKE ANY SENSE FOR ME.
Tks guys!
Felipe
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
Generally optimization will not work with a completely discontinuous function such as the one you have above. You do not seem to have understood my suggestion. I simply pointed out that one state would have a minimum value of 0.1/9 if you used a range of 0-1 for every other state. If this is too big a minimum than use a range of 0-100 and the minimum would be 0.001/9.
The penalty method suggested by JJ will also work and does not have any issue with minima but penalty methods tend to be lest robust numerically.
Again, if your payoff is discontinuous as your example is the optimizer will not work.
The penalty method suggested by JJ will also work and does not have any issue with minima but penalty methods tend to be lest robust numerically.
Again, if your payoff is discontinuous as your example is the optimizer will not work.
optimizing
Hi
I do not find any difficulty in your problem. It is static optimization problem and one only need to use two periods. One does not need to do anytning special and it founds the two optimal value and the value to be optimized * 2 because there are two periods. I join the voc and vpd optimizing files, the vpd for the objective and the voc for the parameters.
Regards.
[Edited on 10-7-2009 by LAUJJL]
I do not find any difficulty in your problem. It is static optimization problem and one only need to use two periods. One does not need to do anytning special and it founds the two optimal value and the value to be optimized * 2 because there are two periods. I join the voc and vpd optimizing files, the vpd for the objective and the voc for the parameters.
Regards.
[Edited on 10-7-2009 by LAUJJL]
- Attachments
-
- optimizing.zip
- (1.34 KiB) Downloaded 1026 times
BOB and TONY, I finally got what you said and now it's working fine. I didn't even had to fix a value for one State. I just run it varying from 0 to 1 for all of them and the result is good! Tks
TONY, I just got the book by mail. Tks again guys!
LAUJJL, I opened your files and it's exactly the same as I had. I get the same result (var1=10 and var2=9) after optimization. But that's because we set these values to the variables in the beginning. If you just try to change let's say var2=1 and run the Optimization. The result should not change, since the optimization is varying VAR2 from 1 to 10. But you will see that it doesn't work. As Bob said, probably it's because it's a discontinuous function.
TONY, I just got the book by mail. Tks again guys!
LAUJJL, I opened your files and it's exactly the same as I had. I get the same result (var1=10 and var2=9) after optimization. But that's because we set these values to the variables in the beginning. If you just try to change let's say var2=1 and run the Optimization. The result should not change, since the optimization is varying VAR2 from 1 to 10. But you will see that it doesn't work. As Bob said, probably it's because it's a discontinuous function.
optipizing using constraints
Hi
I did not realize that the initial values where set at the optimum already. I was in fact surprised by the result.
Gererally I solve the problem of continuity by setting a penalty equation that is both continuous and has a left and right derivative. One must too make the optimizer restart a minimum times. See the model joined that now works. The method is very general and I have used it already.
Regards.
JJ
I did not realize that the initial values where set at the optimum already. I was in fact surprised by the result.
Gererally I solve the problem of continuity by setting a penalty equation that is both continuous and has a left and right derivative. One must too make the optimizer restart a minimum times. See the model joined that now works. The method is very general and I have used it already.
Regards.
JJ
- Attachments
-
- optimizing2.zip
- (1.4 KiB) Downloaded 1011 times
For those who are following:
To make a variable 0<="Percentage"<=1 vary with a 1% increment in a optimization processes you should set:
Multiple Start = Vector
Vector Points = 101.
If you have "Percentage" with subscript it will vary each one with a 1% increment. The only thing I don't know yet is what to do if there is another variable together with "Percentage" in the currently active parameters and we want it to vary with a different increment.
To make a variable 0<="Percentage"<=1 vary with a 1% increment in a optimization processes you should set:
Multiple Start = Vector
Vector Points = 101.
If you have "Percentage" with subscript it will vary each one with a 1% increment. The only thing I don't know yet is what to do if there is another variable together with "Percentage" in the currently active parameters and we want it to vary with a different increment.
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
In general to get more ganular variation in a parameter you should specify an absolute tolerance for that parameter. For example the absolute tolerance for Percentage could be set to 0.01. This will not actually guarantee that percentage only takes on value like 0.14, but it will prevent the optimizer from trying to distinguish 0.141 from 0.142.
-
- Senior Member
- Posts: 107
- Joined: Wed Nov 26, 2008 6:12 am
Hi Karan
You can formulate a penalty function :
Penalty = if then else (constraint <= 0, 0,100000) or
Penalty = if then else (constraint <= 0,0,100000 * constraint) or
Penalty = if then else (constraint <= 0,0,100000 * power(constraint,2))
The first is not continuous at the value of constraint = 0, the second is but has a left and right derivative not equal: 0 and 100000 and the third is continuous and has a left and right derivative equal to 0. The continuity and derivatives are relative to the constraint, and one must still verify that the constraint is continuous and has continuous derivatives relative to the parameters to be optimized. I do not pretend that it works always nor that it is necessary. Most of the time it works without any trick like this.
Best regards.
JJ
[Edited on 12-8-2009 by LAUJJL]
You can formulate a penalty function :
Penalty = if then else (constraint <= 0, 0,100000) or
Penalty = if then else (constraint <= 0,0,100000 * constraint) or
Penalty = if then else (constraint <= 0,0,100000 * power(constraint,2))
The first is not continuous at the value of constraint = 0, the second is but has a left and right derivative not equal: 0 and 100000 and the third is continuous and has a left and right derivative equal to 0. The continuity and derivatives are relative to the constraint, and one must still verify that the constraint is continuous and has continuous derivatives relative to the parameters to be optimized. I do not pretend that it works always nor that it is necessary. Most of the time it works without any trick like this.
Best regards.
JJ
[Edited on 12-8-2009 by LAUJJL]
-
- Senior Member
- Posts: 107
- Joined: Wed Nov 26, 2008 6:12 am
optimization
Hello,
Could you help me to build optimization model in vensim. I tried it a lot but I couldn't. (I started learning vensim 3 weeks ago).
Mavimize utility U=x+y to constraint 2x^2+y^2=54. It is easy to solve using Lagrangian multiplier in paper, but I need to build model using vensim.
I will be grateful if you can help me by giving some idea.
Thanks.
P.S. I've attached problem
[Edited on 10-10-2009 by Anvar]
Could you help me to build optimization model in vensim. I tried it a lot but I couldn't. (I started learning vensim 3 weeks ago).
Mavimize utility U=x+y to constraint 2x^2+y^2=54. It is easy to solve using Lagrangian multiplier in paper, but I need to build model using vensim.
I will be grateful if you can help me by giving some idea.
Thanks.
P.S. I've attached problem
[Edited on 10-10-2009 by Anvar]
- Attachments
-
- problem.JPG (56.08 KiB) Viewed 18407 times
-
- Super Administrator
- Posts: 4838
- Joined: Wed Mar 05, 2003 3:10 am
utility
Hi
Here is joined a simplistic model with two vpd file for the function to be optimized and the constraint and a voc file for the parameters to be optimized.
It works but does not provide the exact value that gives an analytic and more elegant method like lagrangian.
Regards.
Here is joined a simplistic model with two vpd file for the function to be optimized and the constraint and a voc file for the parameters to be optimized.
It works but does not provide the exact value that gives an analytic and more elegant method like lagrangian.
Regards.
- Attachments
-
- utility.zip
- (1.66 KiB) Downloaded 891 times
If you have constraints on variables it must be added to the objective to be maximized.
For instance with your problem you want sum(percentage[state!] to be equal to 1. You must create a variable penalty = if then else (sum(percenrage|state!] = 1,-100000,0) and add this variable to your objective to be maximized.
Regards
Green
____
[Edited on 10-15-2009 by Green12]
For instance with your problem you want sum(percentage[state!] to be equal to 1. You must create a variable penalty = if then else (sum(percenrage|state!] = 1,-100000,0) and add this variable to your objective to be maximized.
Regards
Green
____
[Edited on 10-15-2009 by Green12]