Using Results of a problem in a new problem

15 views
Skip to first unread message

Matts Davids

unread,
Jul 31, 2022, 12:29:08 PM7/31/22
to am...@googlegroups.com
Hello sir, I am running a stochastic problem that has the intention to obtain the optimal profit of a factory. The data is given as three scenarios.

After running the problem, to make it easy, I first obtain the best objective, best_c, best_r, best_N_HC, best_r_HV and set them as parameters and solve manually to obtain the other variables associated with the best objective. However, among the other variables, one is uncertain. To consider this uncertainty, I set it as: P_umuriro_unc{w in WW, t in TT} = P_umuriro[w,t] + P_umuriro_error[w,t]; Where I expect to obtain the uncertain P_umuriro_unc from P_umuriro[w,t] + P_umuriro_error[w,t] which are both variables. 

To obtain the new objective I wrote a new .mod file which I called Foodversion_RP2. In this file I want to use the  best_c, best_r, best_N_HC, best_r_HV, umuriro_cap, Psalsa_cap, Ivomo_cap, ububiko_cap, Isooko_cap and the  P_umuriro[w,t] as parameters. 

My questions are:
1: is it possible to edit the run file and solve this problem by running one time?
2. If running the problem at one time is difficult, could you help me with how I can import the excel saved results of P_umuriro[w,t], load it to AMPL and use it as a parameter in Foodversion_RP2?

I have shared all my resources.
Foodversion.dat
Foodversion_RP2.dat
Foodversion.run
Foodversion.mod
Foodversion.xlsx
Foodversion_RP2.mod

AMPL Google Group

unread,
Aug 1, 2022, 3:53:56 PM8/1/22
to AMPL Modeling Language
To make a variable act like a parameter, use AMPL's fix command to make the variable take one particular value. For example, at the place in your script where you want to make "var umuriro_cap >= 0" act like "param umuriro_cap = 5.57308", you do not need any param statement; just give the command

fix umuriro_cap := 5.57308;

If no value is given in the fix command, then the variable is fixed at its current value. So as another example, if you want to fix all of the variables P_umuriro[w,t] at their current values, you can do it with the command

fix {w in WW, t in TT} P_umuriro[w,t];

After you have executed all of the needed fix commands, you can execute "solve" again to get the optimal solution to the modified problem where all of those variables have been fixed.


--
Robert Fourer
am...@googlegroups.com
{#HS:1964885161-111263#}

Matts Davids

unread,
Aug 2, 2022, 6:22:01 AM8/2/22
to am...@googlegroups.com
Hello Sir,

Thank you so much for guiding me. But I still have a problem, I have finished executing all the fix commands but one of the fix commands will appear in a constraint of the modified problem Foodversion_RP2. For example the fixed value for all the variables P_umuriro[w,t] will replace the variable P_umuriro_unc[w,t] in the constraint balance in Foodversion_RP2. How can I do this? I guess I don't need to declare Foodversion_RP2.mod after the fix command.

Attached is the original problem Foodversion and the modified problem Foodversion_RP2

--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ampl/reply-77152-1964885161-5828702871-1659383632-1062373930%40helpscout.net.
Foodversion.dat
Foodversion_RP2.dat
Foodversion_RP2.mod
Foodversion.run
Foodversion.mod

AMPL Google Group

unread,
Aug 3, 2022, 1:17:05 PM8/3/22
to AMPL Modeling Language
It is not possible to fix the value of variable P_umuriro_unc, because it is defined in terms of other variables. Instead, you can add another constraint to your model, which has P_umuriro[w,t] in place of P_umuriro_unc[w,t]:

subject to balance2{w in WW, t in TT}: 
  c*P_n[t] + P_Ivomo[w,t] = 
    P_umuyoboro[w,t] + P_umuriro[w,t] + P_Isooko[w,t] - P_ch[w,t] + P_d[w,t];

At the start of your run file, you should temporarily drop this constraint:

drop balance2;

Then later in the run file, you should drop the constraint "balance" and restore "balance2":

drop balance;
restore balance2;



--
Robert Fourer
am...@googlegroups.com
{#HS:1964885161-111263#}
On Tue, Aug 2, 2022 at 10:22 AM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Hello Sir,

Thank you so much for guiding me. But I still have a problem, I have finished executing all the fix commands but one of the fix commands will appear in a constraint of the modified problem Foodversion_RP2. For example the fixed value for all the variables P_umuriro[w,t] will replace the variable P_umuriro_unc[w,t] in the constraint balance in Foodversion_RP2. How can I do this? I guess I don't need to declare Foodversion_RP2.mod after the fix command.

Attached is the original problem Foodversion and the modified problem Foodversion_RP2

On Mon, Aug 1, 2022 at 7:53 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
To make a variable act like a parameter, use AMPL's fix command to make the variable take one particular value. For example, at the place in your script where you want to make "var umuriro_cap >= 0" act like "param umuriro_cap = 5.57308", you do not need any param statement; just give the command

fix umuriro_cap := 5.57308;

If no value is given in the fix command, then the variable is fixed at its current value. So as another example, if you want to fix all of the variables P_umuriro[w,t] at their current values, you can do it with the command

fix {w in WW, t in TT} P_umuriro[w,t];

After you have executed all of the needed fix commands, you can execute "solve" again to get the optimal solution to the modified problem where all of those variables have been fixed.


--
Robert Fourer
am...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages