param lambda_mach {JOBS, K_mach_RESOURCES};
param lambda_test {JOBS};
then the problem would appear to be that the number 1 is not a member of the
set K_mach_RESOURCES. It would be necessary to look at the set data to
check this.
Note that the members of sets can be either numbers or character strings, so
when 1 is used as a subscript, it refers to the number 1 as a member of the
indexing set, not to the first member of the indexing set. To refer to the
first member of K_mach_RESOURCES (as given by the order that the members
first appear in the data), declare "set K_mach_RESOURCES ordered;" and refer
to lambda_mach[j,first(K_mach_RESOURCES)].
Bob Fourer
4...@ampl.com
You cannot use numbers to refer to the members of a set, unless it is actually a set of numbers. If your set "ingredients" is not a set of numbers, then you can refer to the second member by use of the function
member(2,ingredients)
and similarly for others. Thus one of your constraints could be, for example,
subject to Twice_Peanut:
amount[member(2,ingredients)] >= 2 * amount[member(3,ingredients)];
However if there is nothing special about the fact that these are the second and third ingredients, but you just want to refer to specific individual ingredients in certain constraints, then you would do better to refer to the names of the ingredients explicitly in the constraints. For example, your constraints might be
subject to two_bread: amount["bread"] = 2;
subject to Twice_Peanut: amount["walnut"] >= 2 * amount["peanut"];
subject to One_liquid: amount["water"] + amount["wine"] >= 1;
Bob Fourer
From: am...@googlegroups.com [mailto:am...@googlegroups.com]
On Behalf Of zhen...@gmail.com
Sent: Wednesday, September 19, 2012 12:52 PM
To: am...@googlegroups.com
Subject: [AMPL 6150] Re: Invalid subscript
Dear SIr,
i also tortured by the invalid subscript problem.
there are certain constraints for some specific variables, i have tried the way you taught and changed amount[1] to amount[ first(ingredients)], what should i do to amount[2] and amount[3], etc.
set ingredients ordered;
var amount {j in ingredients} >=0;
subject to two_bread:
amount[first(ingredients)] = 2;
subject to Twice_Peanut:
amount[2] >= 2 * amount[3];
subject to One_liquid:
amount[5] + amount[6] >= 1;
thanks so much!!!
--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To view this discussion on the web visit https://groups.google.com/d/msg/ampl/-/4_V_ydTXD-0J.
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.