Mathematica solution Planning Model
From: http://blog.csdn.net/yxf/archive/2006/09/22/1266041.aspx
Modified some content.
Mathematica can describe complex planning models from 5.0, mainly using maximize and minimize functions. The previous versions mainly used constrainedmax and constrainedmin to solve the problem. Maximize and minimize functions are more powerful than constrainedmax and constrainedmin.
You can also use linearprogramming, for example:
Constrainedmin [2x-3y, {X + Y <10, x-y> 2, x> 1}, {x, y}] And linearprogramming [{2,-3 }, {-1,-1}, {1,-1}, {}}, {-10, 2, 1}] returns the same answer.
The following examples illustrate how to use these two functions to solve the planning problem:
* Linear Programming
Maximize [{x1 + X2 + X3 + X4,
X5 + X6 + X7 + X8> = 250000,
X1 + X5 <= 380000,
X2 + X6 <= 265200,
X3 + X7 <= 408100,
X4 + X8 <= 130100,
2.85 * x1-1.42 * X2 + 4.27 * X3-18.49 * X4> = 0,
2.85 * X5-1.42 * X6 + 4.27 * X7-18.49 * X8> = 0,
16.5 * X1 + 2 * x2-4 * X3 + 17 * X4> = 0,
7.5 * X5-7 * X6-13.0 * X7 + 8 * X8> = 0,
X1> = 0, X2> = 0, X3> = 0, X4> = 0, X5> = 0, X6> = 0, X7> = 0, x8> = 0 },
{X1, x2, X3, X4, X5, X6, X7, X8}]
Or
Constrainedmax [
X1 + X2 + X3 + X4,
{X5 + X6 + X7 + X8> = 250000,
X1 + X5 <= 380000,
X2 + X6 <= 265200, X3 + X7 <= 408100, X4 + X8 <= 130100,
2.85 * x1-1.42 * X2 + 4.27 * X3-18.49 * X4> = 0,
2.85 * X5-1.42 * X6 + 4.27 * X7-18.49 * X8> = 0,
16.5 * X1 + 2 * x2-4 * X3 + 17 * X4> = 0,
7.5 * X5-7 * X6-13.0 * X7 + 8 * X8> = 0, x1> = 0, X2> = 0, X3> = 0,
X4> = 0, X5> = 0, X6> = 0, X7> = 0, X8> = 0}, {x1, x2, X3, X4, X5,
X6, X7, X8}]
Calculation Result:
{933400., {x1-> 264938., x2-> 135702., X3-> 408100., X4->
124660., X5-> 115062., X6-> 129498., X7-> 0., X8-> 5440.01 }}
933400 is the optimal value of the target function, and the result of the following table is the result when the target function reaches the optimal value.
* Secondary planning
Minimize [{(X-1) ^ 2 + (Y-2) ^ 2, Y-x = 1, x + y <= 2, x> = 0, y> = 0}, {x, y}]
1 1 3
{-, {X->-, Y-> -}}
2 2 2
* 0-1 plan
Maximize [{3x1-2x2 + 5x3, X1 + 2x2-x3 <= 2, X1 + 4x2 + X3 <= 4, x1 + X2 <= 3, 4x2 + X3 <= 6, X1 = 1 | X1 = 0, X2 = 1 | X2 = 0, x3 = 1 | X3 = 0}, {x1, x2, X3}]
{8, {x1-> 1, x2-> 0, X3-> 1 }}
* Integer Planning
Maximize [{40x1-90x2, 9x1 + 7x2 <= 56, 7x1 + 20x2 <= 70, x1> = 0, X2> = 0, x1 \ [element] integers, X2 \ [element] integers}, {x1, x2}]
{240, {x1-> 6, x2-> 0 }}
* Approximate Solution (nmaximize/nminimize)
Nminimize [{8x1 + 10x2 + 7x3 + 6x4 + 11x5 + 9x6,
12x1 + 9x2 + 25x3 + 20x4 + 17x5 + 13x6> = 60,
35x1 + 42X2 + 18x3 + 31X4 + 56x5 + 49x6> = 150,
37X1 + 53x2 + 28x3 + 24x4 + 29x5 + 20x6> = 125, 0 <= X1 <= 1,
0 <= X2 <= 1, 0 <= X3 <= 1, 0 <= X4 <= 1, 0 <= X5 <= 1,
0 <= X6 <= 1}, {x1, x2, X3, X4, X5, X6}]
{32.1546, {x1-> 1., x2-> 0.622697, X3-> 0.343479, X4-> 1 .,
X5-> 0.0475728, X6-> 1 .}}
* Nonlinear planning
Maximize [{13x1-X1 ^ 2 + 3x2-1/3 X1 x2-X2 ^ 2 + 4x3-X3 ^ 2,
3x1 + 4x2 + 6x3 <= 150,
4x1 + 10x2 + 7x3 <= 280,
X1> = 0, X2> = 0, X3> = 0 },
{X1, x2, X3}]
{325/7, {x1-> 45/7, x2-> 3/7, X3-> 2 }}
Maximize [{3X1 + 5x2, X1 <= 4,
9 X1 ^ 2 + 5 X2 ^ 2 <= 216,
X1> = 0, X2> = 0 },
{X1, x2}]
{36, {x1-> 2, x2-> 6 }}
Minimize [{(x1-2) ^ 2 + (x2-3) ^ 2,
-(2-X1) ^ 3 + X2 <= 0,
-2x1 + X2 =-1 },
{X1, x2}]
{5, {x1-> 1, x2-> 1 }}
* Score Planning
Nmaximize [{(0.25*400 A + 0.20*500 B + 0.30*360 c) * 2)/(400 * a * 1.2/
1000 + 500 * B * 1.3/1000 + 360 * C * 1.4/1000) * 2 ),
A + B + C = 90,
A> = 0, B> = 0, C> = 0,
400*2 A <= 40000,
500*2 B <= 48000,
360*2 C <= 30000,
(400 * a * 1.2/1000 + 500 * B * 1.3/1000 + 360 * C * 1.4/1000) * 2 <= 150 },
{A, B, c}]
{211.161, {A-> 48.3333, B-> 0., C-> 41.6667 }}
* Hybrid Planning
Maximize [{120x1 + 10x2 + 100x3-5000 Y1-2000 Y2-1000 Y3,
5x1 + X2 + 4x3 <= 2000, 3X1 <= 300 Y1, 0.5x2 <= 300 Y2,
2x3 <= 300 Y3, x1> = 0, X2> = 0, X3> = 0, X1 \ [element] integers,
X2 \ [element] integers, X3 \ [element] integers, Y1 = 0 | Y1 = 1,
Y2 = 0 | y2 = 1, Y3 = 0 | Y3 = 1}, {x1, x2, X3, Y1, Y2, Y3}]
{25000., {x1-> 100, x2-> 600, X3-> 150, Y1-> 1., Y2-> 1 .,
Y3-> 1 .}}
* A special example (the original usage in help)
Minimize [{(x1-2) ^ 4 + (x1-2x2) ^ 2}, {x1, x2}]
{0, {x1-> 2, x2-> 1 }}