[AMPL 1652] assigning values to parameters

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[AMPL 1652] assigning values to parameters

math_prog

Hi,

I am declaring a one dimensional list of parameters giving it random
values as shown below.

option randseed 105;
set NODES := 1..4;
param x {NODES} default max(Normal(x_mean,x_variance),0);
param y {NODES} default max(Normal(y_mean,y_variance),0);

I have two questions.

1. There are multiple .mod and .run files using the above
declarations. I need all the files to generate the same x and y
values.  The randseed option is set to the same value in all the
files. But for some reason, AMPL generates the same values in the .run
files and the .mod files have the same value but one different from
the .run files. Is there a simple way of fixing this problem?

2. What is the command for setting the values of a one-dimensional
parameter such as x above? For example, when the syntax below is used,

param x {NODES} default 1  10.2327   2  6.56207   3  19.4473   4
9.65429;

AMPL gives the error below

prob.mod, line 22 (offset 662): syntax error
context:  param x {NODES} default 1  >>> 10.2327  <<< 2 6.56207 3
19.4473 4 9.65429;

Thank you for your time and effort.
m_p
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

[AMPL 1653] Re: assigning values to parameters

Robert Fourer-2


> From: [hidden email] [mailto:[hidden email]] On Behalf Of m_p
> Sent: Monday, March 10, 2008 1:26 AM
> To: AMPL Modeling Language
> Subject: [AMPL 1652] assigning values to parameters
>
> I am declaring a one dimensional list of parameters giving it random
> values as shown below.
>
> option randseed 105;
> set NODES := 1..4;
> param x {NODES} default max(Normal(x_mean,x_variance),0);
> param y {NODES} default max(Normal(y_mean,y_variance),0);
>
> I have two questions.
>
> 1. There are multiple .mod and .run files using the above
> declarations. I need all the files to generate the same x and y
> values.  The randseed option is set to the same value in all the
> files. But for some reason, AMPL generates the same values in the .run
> files and the .mod files have the same value but one different from
> the .run files. Is there a simple way of fixing this problem?

A .mod file is just a special case of a .run file, so you are right that they
wouldn't be expected to give rise to different series of random variables.
Perhaps you are using them in different ways.  But without seeing them I can't
be more specific.

> 2. What is the command for setting the values of a one-dimensional
> parameter such as x above? For example, when the syntax below is used,
>
> param x {NODES} default 1  10.2327   2  6.56207   3  19.4473   4
> 9.65429;

You can't set values for this kind of a parameter in a param statement.  To use
a syntax like the one shown above, you can define the parameter in model mode
and then read its values in data mode:

   param x {NODES};
   ...
   data;
   param x := 1  10.2327   2  6.56207  
              3  19.4473   4  9.65429 ;

It is advisable to keep parameter definitions separate from parameter data in
this way.

Bob Fourer
[hidden email]




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

[AMPL 1654] Re: assigning values to parameters

math_prog


> A .mod file is just a special case of a .run file, so you are right that they
> wouldn't be expected to give rise to different series of random variables.
> Perhaps you are using them in different ways.  But without seeing them I can't
> be more specific.

Thank you for giving the command for setting parameter data. I am
pasting the first several lines of the .run file
and the .mod file respectively below. The random values generated are
different although the same 'option randseed 105' is used for both the
files. Changing the name of the .mod file to .run file and adding an
additional 'solve' command doesn't fix the discrepancy in numbers
generated. Please let me know if you need to see the complete files
and I will paste them.

Thanks for your time and effort,
e_m

.run file
______________________________________________________________________________________
option randseed 105;
param N := 6;
param cost_mean := 10;
param cost_variance := cost_mean/2;
param x_mean := 10;
param x_variance := x_mean/2;
param y_mean := 10;
param y_variance := y_mean/2;
set NODES := 1..N;
set PLUS_NODES := 1..(N/2);
set MINUS_NODES := ((N/2)+1)..N;
set PAIRS := setof {i in NODES, j in NODES diff{i}} (i,j);
var arc {PAIRS} binary;
var theta {PAIRS} integer, >=0;
param lambda{PAIRS} default max(Normal(cost_mean, cost_variance),0);
param x {NODES} default max(Normal(x_mean,x_variance),0);
param y {NODES} default max(Normal(y_mean,y_variance),0);
param cost {(i,j) in PAIRS} default ((x[i]-x[j])^2 + (y[i]-
y[j])^2)^0.5;
________________________________________________________________________________________________


.mod file
_______________________________________________________________________________________________
option randseed 105;

param N := 6;
param cost_mean := 10;
param cost_variance := cost_mean/2;
param x_mean := 10;
param x_variance := x_mean/2;
param y_mean := 10;
param y_variance := y_mean/2;
set NODES := 1..N;
set PLUS_NODES := 1..(N/2);
set MINUS_NODES := ((N/2)+1)..N;
set PAIRS := setof {i in NODES, j in NODES diff{i}} (i,j);
var arc {PAIRS} binary;
var theta {PAIRS} integer, >=0;
param lambda{PAIRS} default max(Normal(cost_mean, cost_variance),0);
param x {NODES};
param y {NODES};
#param x {NODES} default max(Normal(x_mean,x_variance),0);
#param y {NODES} default max(Normal(y_mean,y_variance),0);
_________________________________________________________________________________
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

[AMPL 1656] Re: assigning values to parameters

Robert Fourer-2


Can you explain why you expect these two files to give identical results?  The
".run file" has

  param x {NODES} default max(Normal(x_mean,x_variance),0);
  param y {NODES} default max(Normal(y_mean,y_variance),0);

but the ".mod file" has these two lines commented out, and instead has

  param x {NODES};
  param y {NODES};

which sets no random values at all.  So it would make sense that you are
getting different results for these parameters.

Are you also getting different results for parameter lambda?  Because lambda is
only assigned a default value, it will have no values at all until it is used
somewhere later in the file.

-- Bob


> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On Behalf Of m_p
> Sent: Tuesday, March 11, 2008 12:32 AM
> To: AMPL Modeling Language
> Subject: [AMPL 1654] Re: assigning values to parameters
>
>
>
> > A .mod file is just a special case of a .run file, so you are right that
> they
> > wouldn't be expected to give rise to different series of random variables.
> > Perhaps you are using them in different ways.  But without seeing them I
> can't
> > be more specific.
>
> Thank you for giving the command for setting parameter data. I am
> pasting the first several lines of the .run file
> and the .mod file respectively below. The random values generated are
> different although the same 'option randseed 105' is used for both the
> files. Changing the name of the .mod file to .run file and adding an
> additional 'solve' command doesn't fix the discrepancy in numbers
> generated. Please let me know if you need to see the complete files
> and I will paste them.
>
> Thanks for your time and effort,
> e_m
>
> .run file
> _____________________________________________________________________________
> _________
> option randseed 105;
> param N := 6;
> param cost_mean := 10;
> param cost_variance := cost_mean/2;
> param x_mean := 10;
> param x_variance := x_mean/2;
> param y_mean := 10;
> param y_variance := y_mean/2;
> set NODES := 1..N;
> set PLUS_NODES := 1..(N/2);
> set MINUS_NODES := ((N/2)+1)..N;
> set PAIRS := setof {i in NODES, j in NODES diff{i}} (i,j);
> var arc {PAIRS} binary;
> var theta {PAIRS} integer, >=0;
> param lambda{PAIRS} default max(Normal(cost_mean, cost_variance),0);
> param x {NODES} default max(Normal(x_mean,x_variance),0);
> param y {NODES} default max(Normal(y_mean,y_variance),0);
> param cost {(i,j) in PAIRS} default ((x[i]-x[j])^2 + (y[i]-
> y[j])^2)^0.5;
> _____________________________________________________________________________
> ___________________
>
>
> .mod file
> _____________________________________________________________________________
> __________________
> option randseed 105;
>
> param N := 6;
> param cost_mean := 10;
> param cost_variance := cost_mean/2;
> param x_mean := 10;
> param x_variance := x_mean/2;
> param y_mean := 10;
> param y_variance := y_mean/2;
> set NODES := 1..N;
> set PLUS_NODES := 1..(N/2);
> set MINUS_NODES := ((N/2)+1)..N;
> set PAIRS := setof {i in NODES, j in NODES diff{i}} (i,j);
> var arc {PAIRS} binary;
> var theta {PAIRS} integer, >=0;
> param lambda{PAIRS} default max(Normal(cost_mean, cost_variance),0);
> param x {NODES};
> param y {NODES};
> #param x {NODES} default max(Normal(x_mean,x_variance),0);
> #param y {NODES} default max(Normal(y_mean,y_variance),0);
> _____________________________________________________________________________
> ____
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---