[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-glpk] Ordered sets in GMPL

From: xypron
Subject: [Help-glpk] Ordered sets in GMPL
Date: Sat, 20 Dec 2008 00:17:59 -0800 (PST)

Hello Andrew,

often in my scheduling models I need ordered sets. Currently I need a lot of
coding and O(n^2) time and memory:

# let's build an unordered set
set R := { "a", "quick", "brown", "fox", "jumps", "over", "the", "lazy",
# create an index set
set T := {1..card(R)};
# create a set of sets
set tr{i in T} := (if i == 1 then {} else tr[i-1]) union
  setof{ r in R : sum{q in R : q <= r} 1 = i } r;
# create an ordered set
set Q := tr[card(R)];
# display the result
display Q;

I would appreciate if a function to sort sets could be provided in GMPL.
Then I could simply write:
set Q := sort({ "a", "quick", "brown", "fox", "jumps", "over", "the",
"lazy", "dog"});

Furthermore it would be useful to be able retrieve a single element of a
set. Currently there is no expression in GMPL that can take a set as an
argument and return a symbol which is element of the set.

I suggest to define a statement with the following syntax:
set R;
index q :=S;
index q, symbolic := S;
index q <- R := S;
index q <- R, symbolic := S;
S is any set expression, it should be replaceable by an appropriate
definition in the data section
R is a set and will be initialized with {1..card(S)}. R is optional
q will be created as parameter indexed by {1..card(S)}

Best regards


View this message in context:
Sent from the Gnu - GLPK - Help mailing list archive at

reply via email to

[Prev in Thread] Current Thread [Next in Thread]