COIN-OR::LEMON - Graph Library

source: glpk-cmake/examples/graph.mod @ 1:c445c931472f

Last change on this file since 1:c445c931472f was 1:c445c931472f, checked in by Alpar Juttner <alpar@…>, 10 years ago

Import glpk-4.45

  • Generated files and doc/notes are removed
File size: 2.3 KB
Line 
1/* graph.mod - graph visualization */
2
3/* Written in GNU MathProg by Andrew Makhorin <mao@gnu.org> */
4
5/* This model creates a picture in EPS format to visualize a graph. */
6
7param file, symbolic, default "graph.eps";
8/* output file to write the picture */
9
10param R, default 2;
11/* radius to draw vertices, in mm */
12
13param n, integer, > 0;
14/* number of vertices */
15
16set V, default 1..n;
17/* set of vertices */
18
19set E, within V cross V;
20/* set of edges */
21
22param x{i in V}, default 50 * cos((i - 1) / card(V) * 8 * atan(1));
23param 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 */
25
26param x0 := (min{i in V} x[i]) - R - 3.0;
27param y0 := (min{i in V} y[i]) - R - 3.0;
28param x1 := (max{i in V} x[i]) + R + 3.0;
29param y1 := (max{i in V} y[i]) + R + 3.0;
30
31printf "%%!PS-Adobe-3.0 EPSF-3.0\n" > file;
32printf "%%%%BoundingBox: 0 0 %d %d\n",
33      (72 / 25.4) * (x1 - x0), (72 / 25.4) * (y1 - y0) >> file;
34printf "/Helvetica findfont 6 scalefont setfont\n" >> file;
35printf "/mm { 72 mul 25.4 div } def\n" >> file;
36
37for {(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}
44
45for {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}
57
58printf "showpage\n" >> file;
59printf "%%%%EOF\n" >> file;
60
61data;
62
63param
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 ;
81
82set 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 ;
97
98end;
Note: See TracBrowser for help on using the repository browser.