Re: [AIMMS] Index of a two-dimensional subset

426 views
Skip to first unread message

Sergio Bruno

unread,
May 13, 2013, 2:56:01 PM5/13/13
to ai...@googlegroups.com

Why don't you declare 'HomePlayingTeams(d)' has a parameter? Working with indexed sets is usually unnecessary and problematic

Em 13/05/2013 12:05, "Robin Weber" <robinw...@gmail.com> escreveu:
Dear all,
 
I have been trying to model a MILP for a scheduling problem in AIMMS. Now, the situation is as follows, I am trying to model the assignment of referees to matches for a certain sports club. The referees are delivered from another team that plays at home that same fixture day at the sports club.
 
Now, when I design a set 'Teams' (say there are 8 teams) and a create a subset 'HomePlayingTeams(d)', where I can fill in which four teams will play at home that fixture day and which teams play away. However, there is no option for me to fill in an index anymore. When I fill in the index in the set 'Teams', the program is not solved correctly, since it tries to select referees from teams that do not play at home. When I manually create an index and try to set the Range to 'HomePlayingTeams(d)' I get the error :
 
The range of an index must be a one-dimensional set, however the indexed set "HomePlayingTeams" has dimension two.
 
Is there any way around this error? Can I create an index which will only account for the values that I have set to 'true' in the data section of the subset some other way?
 
Thanks much in advance.
Kind regards,
Robin Weber

--
You received this message because you are subscribed to the Google Groups "AIMMS - The Modeling System" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aimms+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Robin Weber

unread,
May 14, 2013, 7:44:35 AM5/14/13
to ai...@googlegroups.com
Dear Sergio,
 
I had not considered declaring this set as a parameter as a possibility, however I still believe it would be far less troublesome for me if I would be able to declare the index of the subset. It would be a possibility to declare 'HomePlayingTeams(d) as a parameter, yet I have about 10 constraints that should hold for all elements of that set. Now, it would be an option to multiply both sides of these constraints with a binary parameter 'HomePlayingTeams(d)' (and if a team does not play at home these constraints would trivially hold).
 
However, then I would have to rewrite a lot of constraints and it would be an easier way out for me, if the indexing would simply be possible. And the constraints can simply hold for all elements in 'HomePlayingTeams(d)'
 
Thanks anyway for your answer.
 
Robin

Luis Pinto

unread,
May 14, 2013, 9:13:52 AM5/14/13
to AIMMS GoogleGroups
Hello,

You cannot set an index to an indexed set (or subset for the matter).
You can use this kind of concept to, for instance:

Procedure:
For d do
LocalSet := IndexedSet(d);

/* do something with set */

Endfor;


In this case I suggest you do as Sergio mentioned, create a HomeTeamVsDays(TEAM,d) and simply use it in your sums / domains..

Cheers

Luis Pinto

www.unisoma.com.br


--

Sergio Bruno

unread,
May 14, 2013, 9:20:25 AM5/14/13
to ai...@googlegroups.com
OKay, lets do it your way. Let's say the index from the root set Teams is t.

then, what you should do is, use the index t, but filtering like this:

t in HomePlayingTeams(d)

for instance, say you want to multiple a variable to a cost in the homeplaying teams for constraint MyConstraint(d):

sum[ t | t in HomePlayingTeams(d), variable(t)*cost(t)] <= maxcost(d)

let me know how it goes

 


--

Robin Weber

unread,
May 15, 2013, 5:30:21 AM5/15/13
to ai...@googlegroups.com
Dear Sergio and Luis,
 
I have tried to do it my way, without success. The rebuilding of my mathematical model require some work and a few altered and one additional constraint(s), however i got it out to work flawlessly thanks to your tip of making 'HomePlayingTeams(i,d)' as a parameter.
Then I made sure that the schedule does not assign a match to be played or refereed on day d by team i when the entry of 'HomePlayingTeams(i,d)' was equal to 0.
 
Thanks for the help and tips!
 
Cheers,
 
Robin

Ricardo Mateus

unread,
Nov 2, 2013, 6:44:36 PM11/2/13
to ai...@googlegroups.com
I have to agree with Robin!

It is a matter of good modelling.

I do not understand why AIMMS do not support it. Any sound explanation about why is it so?

Ricardo Mateus

Sergio Bruno

unread,
Nov 2, 2013, 7:01:00 PM11/2/13
to ai...@googlegroups.com
AIMMS just released a new feature in version 3.14  that will handle those kind of questions. it involves allowing indexed ranges for element parameters and variables. check it out.

Nevertheless, some expressions will just be inefficient according to the mathematical programming engine you are using, others, could be written just as well in another way. 


--

Ricardo Mateus

unread,
Nov 2, 2013, 7:21:02 PM11/2/13
to ai...@googlegroups.com
Thank you very much for your quick response, Sergio!

I've read it before but it seems not address this problem yet.

My problem is that I have a set of coordinates (x,y) and I want to create an indexed set with the adjacent coordinates (N,S,E,W) for each coordinate (x,y).

The reference manual (at the end of p. 38) explicitly states that the subset domain of an indexed set cannot be a relation, so I guess it is just impossible to model the aforementioned problem with AIMMS, but it should be simple...

Any specific help on this?

Thank you in advance,

Ricardo Mateus

Sergio Bruno

unread,
Nov 2, 2013, 7:36:34 PM11/2/13
to ai...@googlegroups.com
Ricardo,

I guess the indexed set is the way you trying to accomplish something. Could you tell us what are you trying to accomplish? It will make easier to understand if there is a way to do it, using indexed sets or another thing.

best,
Sergio

Ricardo Mateus

unread,
Nov 2, 2013, 7:58:23 PM11/2/13
to ai...@googlegroups.com
Thank you again for your support!

For the sake of simplicity, I will state my problem as simply as I can:

I have a space composed of 4x4 cells, each one defined as a coordinate (x,y).
In that space I must allocate 2 shapes, a first one (A) summing up 10 cells and a second one (B) summing up 6 cells.

So, I created 16 binary variable for shape A and 16 other binary variables for shape B (i.e. Shape(x,y) for any Shape=A,B).

The sum of A(x,y)=10 and the sum of B(x,y)=6.

One of the constraints I must enforce in my model is that all cells=1 of a given shape must be adjacent.

Ideally, I would like to define an indexed set such as:
Type: Set
Identifier: AdjacentShapes
Index domain: (x,y)
Subset of: (x,y)
Definition: {(x+1,y),(x-1,y),(x,y+1),(x,y-1)}

Such that then I could add a constraint such that:
Set: Constraint
Identifier: AdjacencyCells
Index Domain: (Shape,x,y)
Definition: sum( (Shape,x,y) | (x,y) in AdjacentShapes, Variable(Shape,x,y) )>=Variable(Shape,x,y)

I hope this helps...

Kindly,

Ricardo Mateis

Sergio Bruno

unread,
Nov 2, 2013, 9:25:02 PM11/2/13
to ai...@googlegroups.com
OK, there are a lot of x and y here that don`t mean the same thing.
I guess you have a set Xset with index x for the coordinates x and a set Yset with index y for the coordinates y, or something similar.
You can begin defining more than an index for a set. mathematicians are lazy and would define x and x'. Here we will say x and xa for Xset, y and ya for Yset. 'a' stands for adjacent, but we can use anyway we want.

Instead of defining a set, you might define a parameter:
IsAdjacent
domain: (xa,ya,x,y)
text: equals to one if (xa,ya) is adjacent to (x,y)
range: binary
definition:
if xa=x+1 and ya=y then 1 
elseif xa=x and ya=y+1 then 1
elseif xa=x and ya=y-1 then 1
elseif xa=x-1 and ya=y then 1
endif

Now, in your constraint definition, use
sum( (Shape,xa,ya) | IsAdjacent(xa,ya), Variable(Shape,xa,ya) )>=Variable(Shape,x,y)

this is probably not the most efficient way to make it, but should work.

Best,
Sergio
Reply all
Reply to author
Forward
0 new messages