summaryrefslogtreecommitdiff
path: root/glpk-5.0/examples/mfvsp.mod
diff options
context:
space:
mode:
authorPasha <pasha@member.fsf.org>2023-01-27 00:54:07 +0000
committerPasha <pasha@member.fsf.org>2023-01-27 00:54:07 +0000
commitef800d4ffafdbde7d7a172ad73bd984b1695c138 (patch)
tree920cc189130f1e98f252283fce94851443641a6d /glpk-5.0/examples/mfvsp.mod
parentec4ae3c2b5cb0e83fb667f14f832ea94f68ef075 (diff)
downloadoneapi-master.tar.gz
oneapi-master.tar.bz2
simplex-glpk with modified glpk for fpgaHEADmaster
Diffstat (limited to 'glpk-5.0/examples/mfvsp.mod')
-rw-r--r--glpk-5.0/examples/mfvsp.mod62
1 files changed, 62 insertions, 0 deletions
diff --git a/glpk-5.0/examples/mfvsp.mod b/glpk-5.0/examples/mfvsp.mod
new file mode 100644
index 0000000..a03009d
--- /dev/null
+++ b/glpk-5.0/examples/mfvsp.mod
@@ -0,0 +1,62 @@
+/* MFVSP, Minimum Feedback Vertex Set Problem */
+
+/* Written in GNU MathProg by Andrew Makhorin <mao@gnu.org> */
+
+/* The Minimum Feedback Vertex Set Problem for a given directed graph
+ G = (V, E), where V is a set of vertices and E is a set of arcs, is
+ to find a minimal subset of vertices, which being removed from the
+ graph make it acyclic.
+
+ Reference:
+ Garey, M.R., and Johnson, D.S. (1979), Computers and Intractability:
+ A guide to the theory of NP-completeness [Graph Theory, Covering and
+ Partitioning, Minimum Feedback Vertex Set, GT8]. */
+
+param n, integer, >= 0;
+/* number of vertices */
+
+set V, default 1..n;
+/* set of vertices */
+
+set E, within V cross V,
+default setof{i in V, j in V: i <> j and Uniform(0,1) <= 0.15} (i,j);
+/* set of arcs */
+
+printf "Graph has %d vertices and %d arcs\n", card(V), card(E);
+
+var x{i in V}, binary;
+/* x[i] = 1 means that i is a feedback vertex */
+
+/* It is known that a digraph G = (V, E) is acyclic if and only if its
+ vertices can be assigned numbers from 1 to |V| in such a way that
+ k[i] + 1 <= k[j] for every arc (i->j) in E, where k[i] is a number
+ assigned to vertex i. We may use this condition to require that the
+ digraph G = (V, E \ E'), where E' is a subset of feedback arcs, is
+ acyclic. */
+
+var k{i in V}, >= 1, <= card(V);
+/* k[i] is a number assigned to vertex i */
+
+s.t. r{(i,j) in E}: k[j] - k[i] >= 1 - card(V) * (x[i] + x[j]);
+/* note that x[i] = 1 or x[j] = 1 leads to a redundant constraint */
+
+minimize obj: sum{i in V} x[i];
+/* the objective is to minimize the cardinality of a subset of feedback
+ vertices */
+
+solve;
+
+printf "Minimum feedback vertex set:\n";
+printf{i in V: x[i]} "%d\n", i;
+
+data;
+
+/* The optimal solution is 3 */
+
+param n := 15;
+
+set E := 1 2, 2 3, 3 4, 3 8, 4 9, 5 1, 6 5, 7 5, 8 6, 8 7, 8 9, 9 10,
+ 10 11, 10 14, 11 15, 12 7, 12 8, 12 13, 13 8, 13 12, 13 14,
+ 14 9, 15 14;
+
+end;