Sie sind auf Seite 1von 2

Dear all:

Here is a GAMS formulation of MST using network techniques:


/// GAMS
START //////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
$title Minimum Spannung Tree Formulation
$ontext
A Node-arc incidence matrix of type (num.of nodes) x (num.of
edges)
an example of a conservation of flow constraint:
Ax = b := (1,0,0,0,0,0,-1)'
where one unit external in-flow at 1st node and one unit out-flow at
last node
and -1 <= x(k) <= +1 for each arc k, flow vector x
* 1st node and last node are connected if and only if Ax = b has a
solution
* network flow theory considers directed arcs. LOWER BOUND[x(k)] =
-1 and
UPPER BOUND[x(k)] = +1 allows to represent an undirected graph,
i.e. from-to
is just a definition of sign.
An n node connected graph has n(n-1)/2 pairs of nodes to be connected,
so:
matrix equation AX = B
where X of type (num.of edges) x (n(n-1)/2)
the h-th column of X is a flow vector and
B of type (num.of nodes) x (n(n-1)/2) provides all
combinations
of external flows.
$offtext
set i Node / n1 * n7 /,
k Edge / e1 * e12 /,
h column index of matrix B / 1 * 21 /;
table A(i,k) 'Node-arc incidence matrix'
e1 e2 e3 e4 e5 e6 e7 e8 e9 e10 e11 e12
n1 1 1
n2 -1 1 1 1
n3 -1 -1 1 -1
n4 -1 -1 1 1 1
n5 -1 -1 1
n6 -1 1 1
n7 -1 -1 -1
parameter c(k) /
e1 = 8, e2 = 5, e3 = 10, e4 = 2, e5 = 18, e6 = 3,
e7 = 12, e8 = 30, e9 = 4, e10 = 14, e11 = 16, e12 = 26 /;
parameter B(i,h) /
n1.(1*6)=1, n2.1=-1, n3.2=-1, n4.3=-1, n5.4=-1, n6.5=-1,
n7.6=-1,
n2.(7*11)=1, n3.7=-1, n4.8=-1, n5.9=-1, n6.10=-1, n7.11=-1,
n3.(12*15)=1, n4.12=-1, n5.13=-1, n6.14=-1, n7.15=-1,
n4.(16*18)=1, n5.16=-1, n6.17=-1, n7.18=-1,
n5.(19,20)=1, n6.19=-1, n7.20=-1,
n6.21=1, n7.21=-1
/;
option decimals=0; display B;
variable z obj.fun.val,
x(k,h) flow variable;
binary variable y(k) edge k in MST;
x.LO(k,h) = -1;
x.UP(k,h) = 1;
equation OBJ objective function,
FLOW conservation of flow constraints,
EDGE1, EDGE2 if flow in arc k then k edge in MST,
NEDGE n-1 edges make up a tree;
OBJ .. z =E= sum(k, c(k) * y(k));
FLOW(i,h) .. sum(k, A(i,k)*x(k,h)) =E= B(i,h);
EDGE1(k,h) .. y(k) =G= x(k,h);
EDGE2(k,h) .. y(k) =G= -x(k,h);
NEDGE .. sum(k, y(k)) =E= 6;
model MSTFORMUL / ALL /;
solve MSTFORMUL using MIP min z;
display y.L;
/// GAMS
END ////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////

Das könnte Ihnen auch gefallen