Subsets In Gams

318 views
Skip to first unread message

/\ l_ !

unread,
Oct 7, 2011, 5:19:14 AM10/7/11
to gamsworld
Hello Everybody
Thank You For Reading My Question
I Have A Set Of Cities In My Model And The Cities Are Denoted By "i"
and "j"
My Model Outcome Is A Parameter x(i,,j) Which Is A Binary Variable And
For Some "i' and "j"s It Is 1.
How Can I Define A Subset Of The Original Set That Contains The "i"
and "j"s That Their x(i,j) Is Equal To 1.
To Make It More Clear Suppose I Have A Set Of Cities From 1 to 20.
The Model Answers x(i,j) Are x(1,2)=1 x(3,4)=1 And The Rest Are Equal
To 0.
How Can I Define A Subset Of The Original Set Which Becomes {1,2,3,4}
When The Answers Are Like Above?

Muhajir

unread,
Oct 7, 2011, 7:13:19 AM10/7/11
to gams...@googlegroups.com
Hi Ali,

I would suggest you use only one set for the cities and create a subset to use in the parameter

**Define set of cities as:
set i  /1*20/
**Define subsets on set i as:
set j(i)/1*20)
set k(i) /1*4/
**Now you can define whatever parameter you want over the subsets like
Parameter x(k,j)
Parameter y(k)


--
You received this message because you are subscribed to the Google Groups "gamsworld" group.
To post to this group, send email to gams...@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.


Arne Stolbjerg Drud

unread,
Oct 7, 2011, 8:47:28 AM10/7/11
to gams...@googlegroups.com
Hi Ali

Try something like

Set i / 1*20/;
Alias (i,j);
Binary variable x(i,j);
Set k(i)
..solve model...

k(i)$sum(j,x.l(i,j)) = yes;
k(j)$sum(i,x.l(i,j)) = yes;

The first assignment finds the elements where there is something in the
column of x(I,j) and the second finds the elements where there is something
in the row.

Good luck

Arne

-------------------------------------------
Arne Stolbjerg Drud
ARKI Consulting & Development A/S
Bagsvaerdvej 246A, DK-2880 Bagsvaerd, Denmark
Phone: (+45) 44 49 03 23, Fax: (+45) 44 49 03 33, email: ad...@arki.dk

-----Oprindelig meddelelse-----
Fra: gams...@googlegroups.com [mailto:gams...@googlegroups.com] På vegne
af /\ l_ !
Sendt: 7. oktober 2011 11:19
Til: gamsworld
Emne: Subsets In Gams

--

Matthes

unread,
Oct 7, 2011, 8:55:26 AM10/7/11
to gamsworld
if you want a one dimensional set, you could try this:

set
z(i)
;
loop((i,j)$(x.l(i,j)=1),
z(i) = yes;
z(j) = yes;
);

Matthes

unread,
Oct 7, 2011, 8:51:07 AM10/7/11
to gamsworld
set
z(i,j)
;
z(i,j)$(x.l(i,j)=1) = yes;


On 7 Okt., 05:19, "/\\ l_ !" <ali.ghafoori...@gmail.com> wrote:

/\ l_ !

unread,
Oct 9, 2011, 3:34:22 PM10/9/11
to gamsworld
Thanks To Everybody
Reply all
Reply to author
Forward
0 new messages