writing Parameters

23 views
Skip to first unread message

Sachin Argade

unread,
May 14, 2012, 3:31:30 PM5/14/12
to AMPL Modeling Language, Esra.Buyu...@wichita.edu
Hello,

I have defined parameter in mod file. Now I am using that parameter to
write one more parameter.
for example.

param q{1..5};# this is the parameter I want to use in the parameter x
which is defined below
param d{1..5};
param x{1..5,1..q};# here I used parameter q which is defined earlier
param alpha{1..5};
.
.
.
.
subject to constr1{i in 1..5}:alpha[i]>=(1/d[i])*(sum{k in 1..q[i]}
(x[i,k]));# here I am using both x and q

it gives me error saying syntax error. what can I do to avoid this,
please let me know,

waiting for reply,

Thank You,
Sachin.

Robert Fourer

unread,
May 14, 2012, 9:16:35 PM5/14/12
to am...@googlegroups.com
I think what you're looking for is

param x {i in 1..5, 1..q[i]};

Since q is a parameter indexed over a set, you will always get a syntax
error if you write q without a [...] expression following it.

Bob Fourer
4...@ampl.com

Sachin Argade

unread,
May 14, 2012, 9:35:19 PM5/14/12
to am...@googlegroups.com, 4...@ampl.com
Bob,

as you mentioned I tried putting [i] in front of q...then it looks like this

param q{1..5}; # this is the parameter I want to use in the parameter x which is defined below

param d{1..5};

param x{1..5,1..q[i]}; # here I used parameter q which is defined earlier


param alpha{1..5};
.
.
.
subject to constr1{i in 1..5}:alpha[i]>=(1/d[i])*(sum{k in 1..q[i]}(x[i,k]));  # here I am using both x and q

then it gives me error that i is not defined.......and I do not want define i before, because as you can see it is defined in the constraint below

please let me know how to avoid this.

Thank you,
Sachin.


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




--
Sachin Argade

Robert Fourer

unread,
May 15, 2012, 9:56:05 AM5/15/12
to am...@googlegroups.com

You can use "i" in both statements:

 

   param x{i in 1..5, 1..q[i]};

   ...

   subject to constr1{i in 1..5}: alpha[i]>=(1/d[i])*(sum{k in 1..q[i]}(x[i,k]));

 

It is just a dummy index whose definition is active only in the statement that uses it.

 

Bob Fourer

4...@ampl.com

 

 

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

On Behalf Of Sachin Argade
Sent: Monday, May 14, 2012 8:35 PM
To: am...@googlegroups.com
Cc: 4...@ampl.com
Subject: Re: [AMPL 5800] writing Parameters

 

Bob,

as you mentioned I tried putting [i] in front of q...then it looks like this

param q{1..5}; # this is the parameter I want to use in the parameter x which is defined below

param d{1..5};

param x{1..5,1..q[i]}; # here I used parameter q which is defined earlier

param alpha{1..5};
.
.
.
subject to constr1{i in 1..5}:alpha[i]>=(1/d[i])*(sum{k in 1..q[i]}(x[i,k]));  # here I am using both x and q

then it gives me error that i is not defined.......and I do not want define i before, because as you can see it is defined in the constraint below

please let me know how to avoid this.

Thank you,
Sachin.

 

.

Sachin Argade

unread,
May 15, 2012, 10:13:58 AM5/15/12
to am...@googlegroups.com, 4...@ampl.com
Still it gives error as ' i ' is not defined.......

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



--
Sachin Argade

Robert Fourer

unread,
May 16, 2012, 12:17:14 AM5/16/12
to am...@googlegroups.com

Perhaps the error is now coming from some other statement.  Or maybe the indexing of x was accidentally written "I in 1..5", which would result in that error.  Can you post the entire error message, so that the context is clear?  Also it might help to attach the model file.

On Behalf Of Sachin Argade
Sent: Tuesday, May 15, 2012 9:14 AM
To: am...@googlegroups.com
Cc: 4...@ampl.com
Subject: Re: [AMPL 5805] writing Parameters

 

Still it gives error as ' i ' is not defined.......

On Tue, May 15, 2012 at 8:56 AM, Robert Fourer <4...@ampl.com> wrote:

 

You can use "i" in both statements:

 

   param x{i in 1..5, 1..q[i]};

   ...

   subject to constr1{i in 1..5}: alpha[i]>=(1/d[i])*(sum{k in 1..q[i]}(x[i,k]));

 

It is just a dummy index whose definition is active only in the statement that uses it.

 

Bob Fourer

4...@ampl.com

 

 

.

Luke Li

unread,
May 16, 2012, 10:21:50 AM5/16/12
to am...@googlegroups.com, 4...@ampl.com
Hi Sachin,

You might want to check which line is the error is coming from.

Cheers
luke
To unsubscribe from this group, send email to ampl+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/ampl?hl=en.



--
Sachin Argade

Reply all
Reply to author
Forward
0 new messages