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 */
11 /* radius to draw vertices, in mm */
13 param n, integer, > 0;
14 /* number of vertices */
19 set E, within V cross V;
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;
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;
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;
58 printf "showpage\n" >> file;
59 printf "%%%%EOF\n" >> file;