How to update model when parameters are given new value?

756 views
Skip to first unread message

arr...@gmail.com

unread,
Aug 19, 2013, 6:37:09 PM8/19/13
to am...@googlegroups.com
Hi folks, 
          I'm trying to run a model for different values of certain parameters, e.g., epsilon (to see what parameter settings can give me a good solution.) There are other parameters and sets that depend on the value of epsilon. I tried for 5 hours but I found it is not possible to do it in .run file. The major problem is that I couldn't find a way to reset data and update parameters in an order that works. 

I have a parameter, epsilon, to test.      epsilon can change the value of 
param Num_Violation=floor(epsilon*Num_Scenario);
and 
set S := 1..Num_Violation; 

I also have param coef_risk{S};

In .dat file, I process data and fill out values for coef_risk; In .run file, I use a for loop to test different values for epsilon:

for{i in 1..10}
{
    epsilon = epsilon +0.01;
}

No matter how I write the code, I always have problems.  Can someone let me know if I should try another way? 

Thanks a lot!

Robert Fourer

unread,
Aug 23, 2013, 3:40:28 PM8/23/13
to am...@googlegroups.com

I can see that your set S gets larger as you increase epsilon, and that param coef_risk is indexed over S.  But it's not clear to me where the values for coef_risk are supposed to come from.  You might have a different file of coef_risk values for each epsilon value, or there might be one data file that has all of the coef_risk values corresponding to the largest possible epsilon, or there might be some formula for computing the coef_risk values.

 

Without this information, I can't say how to update coef_risk inside the "for" loop.  In general however you should use "update data" followed by a "data" command, or else "let" statements to assign new values to coef_risk.  It should not be necessary to reset the data.

 

Bob Fourer

am...@googlegroups.com

 

 

From: am...@googlegroups.com [mailto:am...@googlegroups.com]

On Behalf Of arr...@gmail.com
Sent: Monday, August 19, 2013 5:37 PM
To: am...@googlegroups.com
Subject: [AMPL 7381] How to update model when parameters are given new value?

arr...@gmail.com

unread,
Aug 23, 2013, 6:22:03 PM8/23/13
to am...@googlegroups.com, 4...@ampl.com

Hi Bob, Thanks for your reply.  

The coef_risk are calculated in .data file. I have formula to calculate the coef_risk, which depends on the value of epsilon.

Here is the structure of my program. 
the main .run file looks as follows

reset; 
model TSW.mod;                          
for{i1 in 1..30}
{
          data TSW_data.dat;
let epsilon := epsilon - 0.01*i1;
include process.run;# this is file to calculate and fill out the values for coef_risk
solve;
reset data;
}

it still does not work.

I was comparing with a C++ program. For a C++ code, after compile, you can run this code multiple times by passing different parameter values.  Now I already have a AMPL code that can run, I'm wondering why I can't do the same thing as in C++. Can .run file take arguments from shell script program? 

Thanks!

Robert Fourer

unread,
Aug 28, 2013, 6:50:01 PM8/28/13
to am...@googlegroups.com

I do not see anything that is obviously wrong here, though perhaps the script could be written so that you don't have to read the file TSW_data.dat in every pass through the "for" loop.  (There is a command "reset data coef_risk;" that resets just the param coef_risk and not all the other sets and params.)

 

To get more help I suggest posting the contents of the file process.run, and also the complete text of the error message that appears when it "does not work."

On Behalf Of arr...@gmail.com
Sent: Friday, August 23, 2013 5:22 PM
To: am...@googlegroups.com
Cc: 4...@ampl.com
Subject: Re: [AMPL 7395] How to update model when parameters are given new value?

Reply all
Reply to author
Forward
0 new messages