[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-glpk] Subset
From: |
glpk xypron |
Subject: |
Re: [Help-glpk] Subset |
Date: |
Mon, 17 Oct 2011 22:23:43 +0200 |
Hello Kasper,
> I'm having problems with creating a subset.
> What I want to be able to do is this:
> sum for s in S', forall S' where S' is a subset of Sc such that the size
> of
> S' = mc[c]
>
> set S; /* The set of servers */
> set C; /* The set of Cluster */
> set Sc {c in C}; /* The set of servers in cluster c */
> param mc {c in C}, integer, > 0;
>
> Is there a way to do this with GMPL?
The code below shows how to determine all subsets of size m of a set S.
Best regards
Xypron
/*********************************************
*
* For a set of servers S determine all subsets
* of size m
*
*********************************************/
# The set of servers
set S;
# Number of servers in subset
param m;
# Number of servers available
param n := card(S);
# Set of subset sizes less or equal m
set I := {1 .. m};
# Set of indices for a subset of size i of set S
set J{i in I} := { 1 .. round((prod{a in {1..n}}a) /
(prod{a in {1..i}}a) / (prod{a in {1..n-i}}a)) };
# Set of indices for S
set K := {1 .. n};
# Set containing the kth member of S
set L{k in K} := setof{s in S : k == sum{t in S : t <= s} 1} s;
# Set of integers in [i, n]
set M{i in I} := {i .. n};
# Number of subsets of size i of a set of size j - 1
param ji{i in I, j in M[i]} := if i==j then 0
else round((prod{a in {1..j-1}}a) /
(prod{a in {1..i}}a) / (prod{a in {1..j-1-i}}a)) ;
# Subsets j of size i
set N{i in I, j in J[i]} :=
if i == 1
then L[j]
else N[i-1,j - ji[i,max{k in M[i] : ji[i,k] < j} k]]
union L[max{k in M[i] : ji[i,k] < j} k];
# Set of subsets of size m
set C := J[m];
# Servers in subset c
set Sc{c in C} := N[m, c];
solve;
printf "Last 100 subsets\n";
for {c in C: c > card(C) - 100} {
printf "[%d]: ", c;
printf {s in Sc[c]} "%s ", s;
printf "\n";
}
printf "\nChecking cardinality\n";
printf {c in C}
"%s", if card(Sc[c]) != m then "Wrong cadinality! " else "";
printf "\n";
printf "Checking disjunctness\n";
for {c in C}
printf {d in C: d > c} "%s",
if card(Sc[c] union Sc[d]) <= m then "Two subsets are the same!" else "";
printf "\n";
printf "Number of subsets = %d\n\n", card(C);
data;
param m:= 4;
set S := A B C D E F G H I J K L;
end;
--
Follow me at http://twitter.com/#!/xypron
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
Jetzt informieren: http://www.gmx.net/de/go/freephone