Extracting a subset from a set

752 views
Skip to first unread message

Allexandre Fortes S. Reis

unread,
Sep 23, 2014, 8:42:44 AM9/23/14
to am...@googlegroups.com
Hi,

I have an set that is compound by another set, as follows:

n >= 0; #total of nodes
set N ordered := {0..n+1}; #set nodes
set U{0..S} within N; #eachh subset U[u in 0,,S] can have some nodes that coumpouns a path

At a point of my algorithm, I want to remove the subset U[index_u] from the big set U.

How can I do this? After remove U[index_u], the set U will be automatically updated? (U[0] := U[1], U[1] := U[2], ..., U[S-1] := U[S] )?

Thanks!


Robert Fourer

unread,
Sep 23, 2014, 6:18:21 PM9/23/14
to am...@googlegroups.com
When you define "set U {0..S}" you are creating an indexed collection of sets U[0], U[1], ..., U[S], but no "big set U" is created. I am not sure what would like to do in this case, but if you want to just stop using U[index_u] then you could define

set S_used within S;

You could initialize this set with

let S_used := S;

and then your algorithm could remove an element with

let S_used := S_used diff {index_u};

In your objective and constraints, you would index over S_used, so that the model would change as you remove elements from that set.

Bob Fourer
am...@googlegroups.com

=======

Allexandre Fortes S. Reis

unread,
Sep 23, 2014, 9:12:03 PM9/23/14
to am...@googlegroups.com, 4...@ampl.com
Hello Robert, Thanks by the explanations. 

So, the set U, I imagined it as a set where I can store paths (each path compounds by some nodes/indexes). Then, after explore new extensions for the path U[0] (taking its last element), I would like to remove U[0] and add new paths (U[0] extensions) at the last positions in U.

Can you provide me some ideia to how to do this? I1m really lost. I tried to take the last position of U[], but, as the index are not ordered it is not allowed.

Thanks.

Allexandre.

Robert Fourer

unread,
Sep 24, 2014, 6:57:45 PM9/24/14
to am...@googlegroups.com

You can define

 

   set U {0..S} ordered;

 

so that you can reference the last position of any U[i] set.  I suggest defining a set of current paths initialized to 0..S:

 

   set S_curr;

   let S_curr := 0..S;

 

Then to add a new set,

 

   let S := S + 1;

   let S_curr := S_curr union {S};

 

and to remove set i from use,

 

   let S_curr := S_curr diff {i};

 

Bob Fourer

am...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, 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.

Allexandre Fortes S. Reis

unread,
Oct 3, 2014, 9:29:38 AM10/3/14
to am...@googlegroups.com, 4...@ampl.com
Bob,

As I solve an algorithm iteractively, I would like to reset some sets.

 #reseting P paths sets and parameters
        let {p in PI} P[p] := {};
        let {p in PI} node_p[p] := 0;
        let {p in PI} pred_p[p] := 0;
        let {p in PI} Qp[p] := 0;
        let {p in PI} CostP[p] := 0;
        let {i in N, p in PI} Vp[i,p] := 0;
        let PP := 1;
        let PI := {0..PP};
        
        display P;
        display node_p;
        display pred_p;
        display Qp;
        display CostP;
        display Vp;
        display PI;

I tried in this way, but  the following problem occurs, could you help me? I'm trying to reduce the size of all my parameters

error processing set P:
        710 invalid subscripts discarded:
        P[2]
        P[3]
        P[4]
        and 707 more.

error processing param node_p:
        710 invalid subscripts discarded:
        node_p[2]
        node_p[3]
        node_p[4]
        and 707 more.

Thanks,

Allexandre.

Robert Fourer

unread,
Oct 4, 2014, 12:24:46 PM10/4/14
to am...@googlegroups.com
If you index sets and parameters over the set PI, and then you remove members from PI, you will get the "invalid subscripts discarded" error messages that you see. To avoid this situation, define

param PPmax integer > 0;
param PP integer <= PPmax;

set PImax = 1..PPmax;
set PI = 1..PP;

Initialize PPmax to 711, and define set P, param node_p, and the other parameters as being indexed over PImax. But define your model in terms of PI. Then you can assign any value between 1 and 711 to PP, and your optimization problem will be adjusted accordingly.
Reply all
Reply to author
Forward
0 new messages