lemon-project-template-glpk

view deps/glpk/examples/graph.mod @ 9:33de93886c88

Import GLPK 4.47
author Alpar Juttner <alpar@cs.elte.hu>
date Sun, 06 Nov 2011 20:59:10 +0100
parents
children
line source
1 /* graph.mod - graph visualization */
3 /* Written in GNU MathProg by Andrew Makhorin <mao@gnu.org> */
5 /* This model creates a picture in EPS format to visualize a graph. */
7 param file, symbolic, default "graph.eps";
8 /* output file to write the picture */
10 param R, default 2;
11 /* radius to draw vertices, in mm */
13 param n, integer, > 0;
14 /* number of vertices */
16 set V, default 1..n;
17 /* set of vertices */
19 set E, within V cross V;
20 /* set of edges */
22 param x{i in V}, default 50 * cos((i - 1) / card(V) * 8 * atan(1));
23 param y{i in V}, default 50 * sin((i - 1) / card(V) * 8 * atan(1));
24 /* x[i] and y[i] are coordinates of node i, in mm */
26 param x0 := (min{i in V} x[i]) - R - 3.0;
27 param y0 := (min{i in V} y[i]) - R - 3.0;
28 param x1 := (max{i in V} x[i]) + R + 3.0;
29 param y1 := (max{i in V} y[i]) + R + 3.0;
31 printf "%%!PS-Adobe-3.0 EPSF-3.0\n" > file;
32 printf "%%%%BoundingBox: 0 0 %d %d\n",
33 (72 / 25.4) * (x1 - x0), (72 / 25.4) * (y1 - y0) >> file;
34 printf "/Helvetica findfont 6 scalefont setfont\n" >> file;
35 printf "/mm { 72 mul 25.4 div } def\n" >> file;
37 for {(i,j) in E}
38 { printf "newpath\n" >> file;
39 printf "%g mm %g mm moveto\n", x[i] - x0, y[i] - y0 >> file;
40 printf "%g mm %g mm lineto\n", x[j] - x0, y[j] - y0 >> file;
41 printf "closepath\n" >> file;
42 printf "stroke\n" >> file;
43 }
45 for {i in V}
46 { printf "newpath\n" >> file;
47 printf "%g mm %g mm %g mm 0 360 arc\n",
48 x[i] - x0, y[i] - y0, R >> file;
49 printf "closepath\n" >> file;
50 printf "gsave 1 1 1 setrgbcolor fill grestore\n" >> file;
51 printf "stroke\n" >> file;
52 printf "%g mm %g mm moveto\n",
53 x[i] - (if i <= 9 then 1.2 else 1.8) - x0,
54 y[i] - 0.8 - y0 >> file;
55 printf "( %d ) show\n", i >> file;
56 }
58 printf "showpage\n" >> file;
59 printf "%%%%EOF\n" >> file;
61 data;
63 param
64 : V : x y :=
65 1 0 40
66 2 38 12
67 3 24 -32
68 4 -24 -32
69 5 -38 12
70 6 -19 26
71 7 19 26
72 8 31 -10
73 9 0 -32
74 10 -31 -10
75 11 -9 12
76 12 9 12
77 13 14 -5
78 14 0 -15
79 15 -14 -5
80 16 0 0 ;
82 set E :=
83 (1,*) 6 10 16 12 7
84 (2,*) 7 6 16 13 8
85 (3,*) 8 7 16 14 9
86 (4,*) 9 8 16 15 10
87 (5,*) 10 9 16 11 6
88 (6,*) 14
89 (7,*) 15
90 (8,*) 11
91 (9,*) 12
92 (10,*) 13
93 (11,*) 12 15
94 (12,*) 13
95 (13,*) 14
96 (14,*) 15 ;
98 end;