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.

94 lines
3.0 KiB

  1. /* Any Wolfram elementary CA in 6D eucl. Neumann CA grid emulator generator */
  2. /* Implemented, inspected, written and converted to GNU MathProg
  3. by NASZVADI, Peter, 2016-2017 <vuk@cs.elte.hu> */
  4. /* see background info and more details in wolfra6d.lp */
  5. /* each axis has this two endpoints */
  6. set V := 0..1;
  7. /* this model processes a hypercube in 6d, so 6+1 parallel planes intersect */
  8. set H := 0..6;
  9. /* denoting all vertices in the 6d unit hypercube */
  10. set Cells := V cross V cross V cross V cross V cross V;
  11. /* input parameters, bup/bdn = number of upper/lower neighbour 6d cells of a (cyclic) segment */
  12. param bup{i in H}, default 1;
  13. param bdn{i in H}, default 2;
  14. /* boolean meaning if a vertex is chosen */
  15. var x{Cells}, binary;
  16. /* temporary calculations to enforce bup/bdn */
  17. var up{Cells}, >=0;
  18. var dn{Cells}, >=0;
  19. /* the total weight of selected cells near the main diagonal */
  20. var obj;
  21. /* up/dn vars denote the number of selected upper/lower neighbours */
  22. s.t. cup{(v1,v2,v3,v4,v5,v6) in Cells: v1+v2+v3+v4+v5+v6<6}:
  23. sum{(w1,w2,w3,w4,w5,w6) in Cells: max(v1-w1,v2-w2,v3-w3,v4-w4,v5-w5,v6-w6)<=0}
  24. if (w1+w2+w3+w4+w5+w6) = (1+v1+v2+v3+v4+v5+v6) then x[w1,w2,w3,w4,w5,w6] else 0 =
  25. up[v1,v2,v3,v4,v5,v6];
  26. s.t. cdn{(v1,v2,v3,v4,v5,v6) in Cells: v1+v2+v3+v4+v5+v6>0}:
  27. sum{(w1,w2,w3,w4,w5,w6) in Cells: min(v1-w1,v2-w2,v3-w3,v4-w4,v5-w5,v6-w6)>=0}
  28. if (w1+w2+w3+w4+w5+w6) = (-1+v1+v2+v3+v4+v5+v6) then x[w1,w2,w3,w4,w5,w6] else 0 =
  29. dn[v1,v2,v3,v4,v5,v6];
  30. /* 4 helper constraints, hences the leading "c" */
  31. s.t. cbup1{(v1,v2,v3,v4,v5,v6) in Cells: v1+v2+v3+v4+v5+v6<6}:
  32. up[v1,v2,v3,v4,v5,v6] >= bup[v1+v2+v3+v4+v5+v6] * x[v1,v2,v3,v4,v5,v6];
  33. s.t. cbup2{(v1,v2,v3,v4,v5,v6) in Cells: v1+v2+v3+v4+v5+v6<6}:
  34. up[v1,v2,v3,v4,v5,v6] + (2**6) * x[v1,v2,v3,v4,v5,v6] <= (2**6) + bup[v1+v2+v3+v4+v5+v6];
  35. s.t. cbdn1{(v1,v2,v3,v4,v5,v6) in Cells: v1+v2+v3+v4+v5+v6>0}:
  36. dn[v1,v2,v3,v4,v5,v6] >= bdn[v1+v2+v3+v4+v5+v6] * x[v1,v2,v3,v4,v5,v6];
  37. s.t. cbdn2{(v1,v2,v3,v4,v5,v6) in Cells: v1+v2+v3+v4+v5+v6>0}:
  38. dn[v1,v2,v3,v4,v5,v6] + (2**6) * x[v1,v2,v3,v4,v5,v6] <= (2**6) + bdn[v1+v2+v3+v4+v5+v6];
  39. /* these two promoted points should be selected */
  40. s.t. initdiag: x[0,0,0,0,0,0] + x[1,1,1,1,1,1] = 2;
  41. /* obvious */
  42. s.t. sumx: sum{(v1,v2,v3,v4,v5,v6) in Cells} x[v1,v2,v3,v4,v5,v6] = obj;
  43. minimize cobj: obj;
  44. solve;
  45. /* pretty-printing hopefully nontrivial solution */
  46. printf "\nChosen vertex subset:\n";
  47. for{i in H}: {
  48. printf "Weight=%s\n", i;
  49. printf{(v1,v2,v3,v4,v5,v6) in Cells: v1+v2+v3+v4+v5+v6 = i+(8-8*x[v1,v2,v3,v4,v5,v6])}
  50. " %s%s%s%s%s%s\n",v1,v2,v3,v4,v5,v6;
  51. }
  52. printf "\nTotal number of selected cells in the hypercube: %g\n\n", obj;
  53. data;
  54. /* these parameters were chosen in the first run that yielded a solution */
  55. param bup := 0 6
  56. 1 2
  57. 2 3
  58. 3 2
  59. 4 1
  60. 5 1
  61. 6 6;
  62. param bdn := 0 3
  63. 1 1
  64. 2 2
  65. 3 1
  66. 4 4
  67. 5 3
  68. 6 3;
  69. end;