linineq.log 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. REDUCE 3.4, 15-Jul-91 ...
  2. 1:
  3. (LININEQ)
  4. % Examples taken from G.B. Dantzig.
  5. lll := {x1 >= 0,
  6. x1+2x2 <= 6,
  7. x1 + x2 >= 2,
  8. x1 - x2 >= 3,
  9. x2 >= 0,
  10. -2 x1 -x2 <= z };
  11. LLL := {X1>=0,
  12. X1 + 2*X2<=6,
  13. X1 + X2>=2,
  14. X1 - X2>=3,
  15. X2>=0,
  16. - 2*X1 - X2<=Z}
  17. sol := linineq(lll,{x1,x2,z=min});
  18. SOL := {X1=6,X2=0,Z=-12}
  19. sol := linineq(lll,{x1,x2,z=min},record=t);
  20. - X2 - Z
  21. SOL := {{X1=6,MAX(-----------,X2 + 3, - X2 + 2,0), - 2*X2 + 6},
  22. 2
  23. Z + 12
  24. {X2=0,0,MIN(--------,1)},
  25. 3
  26. {Z=-12,-12,INF}}
  27. linineq({z = x1 + 2 x2 + 3 x3 + 4 x4,
  28. 4 = x1 + x2 + x3 + x4,
  29. -2 = x1 - 2 x2 + 3 x3 - 4 x4,
  30. x1>=0, x2>=0, x3>=0,x4>=0}, {z=min});
  31. {X4=0,X3=0,X2=2,X1=2,Z=6}
  32. linineq({z = x1 + 2 x2 + 3 x3 + 4 x4,
  33. 4 = x1 + x2 + x3 + x4,
  34. -2 = x1 - 2 x2 + 3 x3 - 4 x4,
  35. x1>=0, x2>=0, x3>=0,x4>=0}, {z=max});
  36. {X4=2,X3=2,X2=0,X1=0,Z=14}
  37. linineq({ x1 + x2 >= 1,
  38. x1 + x2 <= 2,
  39. x1 - x2 <= 1,
  40. x1 - x2 >=-1,
  41. -x2 =z } , {z=min});
  42. 3 1 - 3
  43. {X2=---,X1=---,Z=------}
  44. 2 2 2
  45. linineq({ 5x1 - 4x2 + 13x3 - 2x4 + x5 = 20,
  46. x1 - x2 + 5x3 - x4 + x5 = 8,
  47. x1 + 6x2 - 7x3 + x4 + 5x5 = z,
  48. x1>=0,x2>=0,x3>=0,x4>=0,x5>=0}, {z=min});
  49. 12 4 - 60
  50. {X5=0,X4=0,X3=----,X2=---,X1=0,Z=-------}
  51. 7 7 7
  52. % Examples for integer and mixed integer linear programming
  53. % (Beightler, Phillips, Wilde, pp. 142 ff)
  54. linineq({z= 3x1 + 2x2,
  55. 5x1 + 4x2 <= 23.7,
  56. x1 >= 0,
  57. x2 >= 0},
  58. {z=max},
  59. int={x1,x2});
  60. {X2=2,X1=3,Z=13}
  61. linineq({z= x1 + x2,
  62. -2x1 + 5x2 <= 8,
  63. 6x1 + x2 <= 30,
  64. x1 >= 0,
  65. x2 >= 0},
  66. {z=max},
  67. int={x1,x2});
  68. {X2=3,X1=4,Z=7}
  69. linineq({z=-7x1 + 106x2,
  70. -x1 + 15x2 <= 90,
  71. x1 + 2x2 <= 35,
  72. -3x1 + 4x2 <= 12,
  73. x1 >= 0,
  74. x2 >= 0},
  75. {z=max},
  76. int={x1,x2});
  77. {X2=7,X1=15,Z=637}
  78. linineq({z=9x1 + 6x2 + 5x3,
  79. 2x1 + 3x2 + 7x3 <= 35/2,
  80. 4x1 + 9x3 <= 15,
  81. x1 >= 0,
  82. x2 >= 0,
  83. x3 >= 0},
  84. {z=max},
  85. int={x1});
  86. 23
  87. {X3=0,X2=----,X1=3,Z=50}
  88. 6
  89. % a case where the extremum requirement cannot be resolved
  90. sol := linineq(lll,{x1,x2,z=max});
  91. SOL := {}
  92. % print the selection from the intervals:
  93. on prlinineq;
  94. sol := linineq(lll,{x1,x2,z=min});
  95. variables:(X1 X2 Z)
  96. - 12 <= Z <= INF; minimum: Z=-12
  97. 0 <= X2 <= 0; zero length interval: X2=0
  98. 6 <= X1 <= 6; zero length interval: X1=6
  99. SOL := {X1=6,X2=0,Z=-12}
  100. sol := linineq(lll,{x1,x2,z=max});
  101. variables:(X1 X2 Z)
  102. - 12 <= Z <= INF; max/min cannot be resolved
  103. SOL := {}
  104. % print the full elimination process
  105. on trlinineq;
  106. sol := linineq(lll,{x1,x2,z=min});
  107. variables:(X1 X2 Z)
  108. --------------------------------
  109. next variable:X1; initial system:
  110. {Z>= - 2*X1 - X2,
  111. X2>=0,
  112. X1 - X2>=3,
  113. X1 + X2>=2,
  114. 6>=X1 + 2*X2,
  115. X1>=0}
  116. --------------------------------
  117. normalized and reduced:
  118. {X1>=0,
  119. - X1 - 2*X2>=-6,
  120. X1 + X2>=2,
  121. X1 - X2>=3,
  122. X2>=0,
  123. 2*X1 + X2 + Z>=0}
  124. --------------------------------
  125. class 1:
  126. - X2 - Z
  127. {X1>=-----------,X1>=X2 + 3,X1>= - X2 + 2,X1>=0}
  128. 2
  129. --------------------------------
  130. class 2:
  131. { - 2*X2 + 6>=X1}
  132. --------------------------------
  133. class 3:
  134. {X2>=0}
  135. --------------------------------
  136. class 4:
  137. {}
  138. --------------------------------
  139. next variable:X2; initial system:
  140. {X2>=0,
  141. - X2 - Z
  142. - 2*X2 + 6>=-----------,
  143. 2
  144. - 2*X2 + 6>=X2 + 3,
  145. - 2*X2 + 6>= - X2 + 2,
  146. - 2*X2 + 6>=0}
  147. --------------------------------
  148. normalized and reduced:
  149. { - X2>=-1, - 3*X2 + Z>=-12,X2>=0}
  150. --------------------------------
  151. class 1:
  152. {X2>=0}
  153. --------------------------------
  154. class 2:
  155. Z + 12
  156. {-------->=X2,1>=X2}
  157. 3
  158. --------------------------------
  159. class 3:
  160. {}
  161. --------------------------------
  162. class 4:
  163. {}
  164. --------------------------------
  165. next variable:Z; initial system:
  166. Z + 12
  167. {-------->=0,1>=0}
  168. 3
  169. --------------------------------
  170. normalized and reduced:
  171. {0>=-1,Z>=-12}
  172. --------------------------------
  173. class 1:
  174. {Z>=-12}
  175. --------------------------------
  176. class 2:
  177. {}
  178. --------------------------------
  179. class 3:
  180. {}
  181. --------------------------------
  182. class 4:
  183. {0>=-1}
  184. - 12 <= Z <= INF; minimum: Z=-12
  185. 0 <= X2 <= 0; zero length interval: X2=0
  186. 6 <= X1 <= 6; zero length interval: X1=6
  187. SOL := {X1=6,X2=0,Z=-12}
  188. end;
  189. Quitting