To remove members from a set

542 views
Skip to first unread message

yiz...@lehigh.edu

unread,
Nov 18, 2014, 4:56:03 PM11/18/14
to am...@googlegroups.com
Hello,

I am currently confronted with an algorithm that I have to change the elements of an array often.

But when remove the members from the set, or change the "length" of the set, I am seen the error: 2 invalid subscripts discarded:

Do you have some ideas to fix this?

Thank you very much. Your help mean a lot to me.


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
;

Robert Fourer

unread,
Nov 18, 2014, 10:03:18 PM11/18/14
to am...@googlegroups.com
You should not remove members from a set that indexes a param. In your latest example, you index myData over allSet. But then you reduce endNum; since you defined "set allSet = 1..endNum;" this has the effect of removing members from allSet.

To avoid the errors you are seeing, first set up the complete data like this:

param endNum default 5;
set allSet = 1..endNum;
param allData {allSet};
let {i in allSet} allData[i] := i;

Then define your subset:

param myNum <= endNum;
set mySet = 1..myNum;

Do not index any parameters over mySet. Only use mySet for indexing your model. Then you can change myNum whenever you want, and when you change myNum, it will change the problem that is generated from your model.

Bob Fourer
am...@googlegroups.com

=======

From: am...@googlegroups.com [mailto:am...@googlegroups.com] On Behalf Of yiz...@lehigh.edu
Sent: Tuesday, November 18, 2014 3:56 PM
To: am...@googlegroups.com
Subject: [AMPL 9562] To remove members from a set

I am currently confronted with an algorithm that I have to change the elements of an array often.

But when remove the members from the set, or change the "length" of the set, I am seen the error: 2 invalid subscripts discarded:

Do you have some ideas to fix this?


Ying Zhang

unread,
Nov 18, 2014, 10:12:40 PM11/18/14
to am...@googlegroups.com
Thank you for your attention and consideration.

You said that I should not remove members from a set that indexes a param. But now in my model, I have a loop, and in each iteration, I have to store some values, while we may have different number of values in each iteration.
For example, in the first loop, I will have to store 3 values, but in the second loop, I have to store 5 values (in the branch and bound, I donnot know how many branched I will have).

So how can we achieve this goal?
Reply all
Reply to author
Forward
0 new messages