You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.3 KiB

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