The “invalid subscript discarded” message when change the set

301 views
Skip to first unread message

yiz...@lehigh.edu

unread,
Nov 17, 2014, 9:00:40 PM11/17/14
to am...@googlegroups.com
Hello, I get an “invalid subscript discarded” message when I display an AMPL parameter. 
According to file dietflex.mod, I use the following method, but the error still exists. How can I fix it? Thank you very much. Your help will be greatly appreciated.

param endNum default 5;
set allSet = 1..endNum;
set dropSet within allSet default {};
set mySet := allSet diff dropSet;
param myData {mySet};

let {i in mySet} myData[i] := i;
display myData;

let dropSet := {3,4};
display myData;


error processing param myData:
2 invalid subscripts discarded:
myData[3]
myData[4]
myData [*] :=
1  1
2  2
5  5
;

Robert Fourer

unread,
Nov 18, 2014, 11:35:15 AM11/18/14
to am...@googlegroups.com
To avoid these "invalid subscript discarded" messages, you need to be sure that members are not removed from any set that is used to index a parameter (or another set). In your example, you write

set dropSet within allSet default {};
set mySet := allSet diff dropSet;
param myData {mySet};

When members are added to dropSet, that has the effect of taking members away from mySet, which is the index set for myData -- hence the error messages for myData.

Instead you should index param myData over allSet, which does not change. Then use mySet in defining your variables, objective, and constraints.

Bob Fourer
am...@googlegroups.com

=======

From: am...@googlegroups.com [mailto:am...@googlegroups.com] On Behalf Of yiz...@lehigh.edu
Sent: Monday, November 17, 2014 8:01 PM
To: am...@googlegroups.com
Subject: [AMPL 9550] The “invalid subscript discarded” message when change the set

I get an “invalid subscript discarded” message when I display an AMPL parameter.
According to file dietflex.mod, I use the following method, but the error still exists. How can I fix it?

Ying Zhang

unread,
Nov 18, 2014, 12:38:30 PM11/18/14
to am...@googlegroups.com
Hi, Fourer, Thanks for your detailed explanation.

Actually, I have an array whose elements will change. For example, in one loop, the elements is {1,2,3,4,5}, but in the other loop, it will be {1,2,3}, how could I implement this ?

param endNum default 5;
set allSet = 1..endNum;
param myData {allSet};

let {i in allSet} myData[i] := i;
display myData;

let endNum := 3;
display myData;

error processing param myData:
2 invalid subscripts discarded:
myData[4]
myData[5]
myData [*] :=
1  1
2  2
3  3
;

If I define the parameter inside the repeat loop, then an other error is thrown : Abandoning compound command to accept declaration
So how could I fix this, so that I can go on with my program? Thank you, and I am waiting for your help.


Best
Ying Zhang

--
You received this message because you are subscribed to a topic in the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ampl/wCRzESXgnrA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ampl+uns...@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at http://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.

Ying Zhang

unread,
Nov 18, 2014, 12:40:00 PM11/18/14
to am...@googlegroups.com
Or is there a method that we can remove the members from a set?

Robert Fourer

unread,
Nov 19, 2014, 8:48:22 AM11/19/14
to am...@googlegroups.com
It's not clear why you are trying to define a parameter inside a repeat loop. You should define it outside and then just change its value inside. Perhaps you could give a more complete example.

Bob Fourer
am...@googlegroups.com

=======

From: am...@googlegroups.com [mailto:am...@googlegroups.com] On Behalf Of Ying Zhang
Sent: Tuesday, November 18, 2014 11:38 AM
To: am...@googlegroups.com
Subject: Re: [AMPL 9557] The “invalid subscript discarded” message when change the set

.......

Ying Zhang

unread,
Nov 19, 2014, 9:37:26 AM11/19/14
to am...@googlegroups.com
Dear Fourer,

Thank you for your help with my programming. It may be difficult to show all codes here. My algorithm is a Benders Decomposition embedded some B & B, while in each outer iteration, we don't know how may branches we will have. What if we want to store the upper and lower bounds in each outer iteration?

To be simple, I give the following example:

param endNum default 5;
set allSet = 1..endNum;
param myData {allSet};
let {i in allSet} myData[i] := endNum - i + 1;
display myData; # ={5,4,3,2,1}
for{i in allSet}
{
for{j in 1..myData[i]}
display j;
}

We have two loops: the outer and the inner, while the inner loop depends on the outer i.
In the position "display j", if j is the value we want to store, how can we achieve this? Since defining a parameter inside the outer loop is impossible.

I want to store j in a two dimensional array. In this example, it will be {{1,2,3,4,5},{1,2,3,4},{1,2,3},{1,2},{1}}, and the number of values are decreasing. (So it will come back the problem: how to remove the member from a set, or remove the elements from an array).


I meet this bottleneck in my whole programming, and I am eager to fix it. Thank you and I am waiting for your reply. 

Best

Robert Fourer

unread,
Nov 20, 2014, 11:38:38 AM11/20/14
to am...@googlegroups.com
It is very hard to understand your explanation, but it seems like you just want to define

param p {i in 1..endNum, j in 1..endNum+1-i} = j;

Bob Fourer
am...@googlegroups.com

=======

From: am...@googlegroups.com [mailto:am...@googlegroups.com] On Behalf Of Ying Zhang
Sent: Wednesday, November 19, 2014 8:37 AM
To: am...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages