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