Param, same value for multiple parameters

9 views
Skip to first unread message

ransomkan

unread,
Jul 13, 2022, 2:44:05 AM7/13/22
to AMPL Modeling Language
Hi,

Suppose I have param b{J,K}, 
param b:
    1 2 3 4 5 :=
1 1 2 3 2 5
2 1 3 4 9 6
3 1 2 8 6 4;

and notice that b[j ,1] =1 for all j in J. is there a way to write it separately,
param b[,1]=1 and 
param b:
    2 3 4 5 :=
1 2 3 2 5
2 3 4 9 6
3 2 8 6 4;
to save some space for large data files?
Thank you so much. 


AMPL Google Group

unread,
Jul 13, 2022, 4:26:03 PM7/13/22
to AMPL Modeling Language
You can specify a default value of 1 for your data statement:

param b default 1:
  2 3 4 5 :=
1 2 3 2 5
2 3 4 9 6
3 2 8 6 4;

Then when b is used (for example when you solve), any missing entries in b will be given the value 1. There can be only one default value for a parameter's data, however. Another approach is to read


param b:
  2 3 4 5 :=
1 2 3 2 5
2 3 4 9 6
3 2 8 6 4;

and then assign the missing entries with AMPL assignment statements like this:

let {j in J} b[j,1] := 1;

This is more general, since you can have any number of assignments of various values. (Note that if your "let" statement appears in the middle of a data file, you should follow it with a "data;" statement to switch AMPL back to "data mode".)


--
Robert Fourer
am...@googlegroups.com
{#HS:1947687322-110960#}
Reply all
Reply to author
Forward
0 new messages