http://apcocoa.uni-passau.de/wiki/api.php?action=feedcontributions&user=StK&feedformat=atomApCoCoAWiki - User contributions [en]2021-06-13T14:36:40ZUser contributionsMediaWiki 1.35.0http://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7981ApCoCoA-1:GLPK.LPSolve2008-12-08T20:43:04Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolve(Objective_f:POLYNOM, EQ_Poly:LIST, LE_Poly:LIST, GE_Poly:LIST, Bounds:LIST, Method:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
<em>Objective_f</em>: A linear polynomial which is equivalent to the linear objective function.<br />
<br />
<em>EQ_Poly</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Poly</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Poly</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>Method</em>: You can choose between the interior-point-method ("InterP") or the simplex-algorithm ("Simplex"). Usually you should use the simplex-algorithm.<br />
<br />
<em>MinMax</em>: Minimization ("Min") or maximization ("Max"), that's the question.<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
Use S::=Q[x,y];<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
$GLPK.LPSolve(OF, [], LE, GE, Bounds, "Simplex", "Max");<br />
<br />
And we achieve: <br />
Solution Status: OPTIMAL<br />
Value of objective function: 5333333333/1000000000<br />
[x[1] - 266667/100000, x[2] - 4]<br />
</example><br />
<br />
[[Image:LinOpt.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""]];<br />
<br />
$GLPK.LPSolve(Objective, Balance, LessEq, [], Bounds, "Simplex", "Max");<br />
<br />
<br />
And we receive:<br />
Solution Status: OPTIMAL<br />
Value of objective function: 11460<br />
[x[1,1], x[1,2] - 29/5, x[1,3] - 26/5, x[2,1], x[2,2], x[2,3], x[3,1] - 10, x[3,2] - 51/5, x[3,3] - 14/5, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo two (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,1] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 29/5 tons of cargo one (x[1,2] = 29/5)<br />
- 0 of cargo two (x[2,2] = 0)<br />
- 51/5 tons of cargo three (x[3,2] = 51/5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 26/5 tons of cargo one (x[1,3] = 26/5)<br />
- 0 of cargo two (x[2,3] = 0)<br />
- 14/5 tons of cargo three (x[3,3] = 14/5)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.MIPSolve&diff=7980ApCoCoA-1:GLPK.MIPSolve2008-12-08T20:41:34Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.MIPSolve(Objective_f:POLYNOM, EQ_Poly:LIST, LE_Poly:LIST, GE_Poly:LIST, Bounds:LIST, IntNum:LIST, Binaries:LIST, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
<em>Objective_f</em>: A linear polynomial which is equivalent to the linear objective function.<br />
<br />
<em>EQ_Poly</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Poly</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Poly</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>IntNum</em>: List of variables, which should be integer. <em>Note</em>: For each variable in this list, the borders get rounded (lower bound: up and upper bound: down). In the case that the lower rounded bound becomes greater then the upper rounded bound, glpk returns: Solution Status: INTEGER UNDEFINED - Value of objective function: 0.<br />
<br />
<em>Binaries</em>: List of variables, which should be binaries (0 or 1).<br />
<br />
<em>MinMax</em>: Minimization ("Min") or maximization ("Max"), that's the question.<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.MIPSolve-function.<br />
Use S::=Q[x,y];<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
IntNum:=[x,y]<br />
<br />
Then we compute the solution with<br />
$GLPK.MIPSolve(OF, [], LE, GE, Bounds, IntNum, [], "Max");<br />
<br />
<br />
And we achieve:<br />
Solution Status: INTEGER OPTIMAL<br />
Value of objective function: 5<br />
[x[1] - 2, x[2] - 4]<br />
</example><br />
<br />
[[Image:LinOpt_2.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""]];<br />
<br />
IntNum:=[x[1,2], x[1,3]];<br />
<br />
$GLPK.MIPSolve(Objective, Balance, LessEq, [], Bounds, IntNum, [], "Max");<br />
<br />
<br />
And we receive:<br />
Solution Status: INTEGER OPTIMAL<br />
Value of objective function: 11460<br />
[x[1,1], x[1,2] - 8, x[1,3], x[2,1], x[2,2] - 3, x[2,3], x[3,1] - 10, x[3,2] - 5, x[3,3] - 8, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo two (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,1] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 8 tons of cargo one (x[1,2] = 8)<br />
- 3 of cargo two (x[2,2] = 3)<br />
- 5 tons of cargo three (x[3,2] = 5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 0 tons of cargo one (x[1,3] = 0)<br />
- 0 of cargo two (x[2,3] = 0)<br />
- 8 tons of cargo three (x[3,3] = 8)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7979ApCoCoA-1:GLPK.LPSolve2008-12-08T20:38:40Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolve(Objective_f:POLYNOM, EQ_Poly:LIST, LE_Poly:LIST, GE_Poly:LIST, Bounds:LIST, Method:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
<em>Objective_f</em>: A linear polynomial which is equivalent to the linear objective function.<br />
<br />
<em>EQ_Poly</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Poly</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Poly</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>Method</em>: You can choose between the interior-point-method ("InterP") or the simplex-algorithm ("Simplex"). Usually you should use the simplex-algorithm.<br />
<br />
<em>MinMax</em>: Minimization ("Min") or maximization ("Max"), that's the question.<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
Use S::=Q[x,y];<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
$GLPK.LPSolve(OF, [], LE, GE, Bounds, "Simplex", "Max");<br />
<br />
And we achieve: <br />
Solution Status: OPTIMAL<br />
Value of objective function: 5333333333/1000000000<br />
[x[1] - 266667/100000, x[2] - 4]<br />
</example><br />
<br />
[[Image:LinOpt.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""]];<br />
<br />
$GLPK.LPSolve(Objective, Balance, LessEq, [], Bounds, "Simplex", "Max");<br />
<br />
<br />
And we receive<br />
Solution Status: OPTIMAL<br />
Value of objective function: 11460<br />
[x[1,1], x[1,2] - 29/5, x[1,3] - 26/5, x[2,1], x[2,2], x[2,3], x[3,1] - 10, x[3,2] - 51/5, x[3,3] - 14/5, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo two (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,1] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 29/5 tons of cargo one (x[1,2] = 29/5)<br />
- 0 of cargo two (x[2,2] = 0)<br />
- 51/5 tons of cargo three (x[3,2] = 51/5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 26/5 tons of cargo one (x[1,3] = 26/5)<br />
- 0 of cargo two (x[2,3] = 0)<br />
- 14/5 tons of cargo three (x[3,3] = 14/5)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7978ApCoCoA-1:GLPK.LPSolve2008-12-08T20:36:47Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolve(Objective_f:POLYNOM, EQ_Poly:LIST, LE_Poly:LIST, GE_Poly:LIST, Bounds:LIST, Method:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
<em>Objective_f</em>: A linear polynomial which is equivalent to the linear objective function.<br />
<br />
<em>EQ_Poly</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Poly</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Poly</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>Method</em>: You can choose between the interior-point-method ("InterP") or the simplex-algorithm ("Simplex"). Usually you should use the simplex-algorithm.<br />
<br />
<em>MinMax</em>: Minimization ("Min") or maximization ("Max"), that's the question.<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
Use S::=Q[x,y];<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
$GLPK.LPSolve(OF, [], LE, GE, Bounds, "Simplex", "Max");<br />
<br />
And we achieve: <br />
Solution Status: OPTIMAL<br />
Value of objective function: 5333333333/1000000000<br />
[x[1] - 266667/100000, x[2] - 4]<br />
</example><br />
<br />
[[Image:LinOpt.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""]];<br />
<br />
$GLPK.LPSolve(Objective, Balance, LessEq, [], Bounds, "Simplex", "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 29/5, x[1,3] - 26/5, x[2,1], x[2,2], x[2,3], x[3,1] - 10, x[3,2] - 51/5, x[3,3] - 14/5, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo two (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,1] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 29/5 tons of cargo one (x[1,2] = 29/5)<br />
- 0 of cargo two (x[2,2] = 0)<br />
- 51/5 tons of cargo three (x[3,2] = 51/5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 26/5 tons of cargo one (x[1,3] = 26/5)<br />
- 0 of cargo two (x[2,3] = 0)<br />
- 14/5 tons of cargo three (x[3,3] = 14/5)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.MIPSolve&diff=7969ApCoCoA-1:GLPK.MIPSolve2008-12-08T13:38:25Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.MIPSolve(Objective_f:POLYNOM, EQ_Poly:LIST, LE_Poly:LIST, GE_Poly:LIST, Bounds:LIST, IntNum:LIST, Binaries:LIST, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
<em>Objective_f</em>: A linear polynomial which is equivalent to the linear objective function.<br />
<br />
<em>EQ_Poly</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Poly</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Poly</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>IntNum</em>: List of variables, which should be integer. <em>Note</em>: For each variable in this list, the borders get rounded (lower bound: up and upper bound: down). In the case that the lower rounded bound becomes greater then the upper rounded bound, glpk returns: Solution Status: INTEGER UNDEFINED - Value of objective function: 0.<br />
<br />
<em>Binaries</em>: List of variables, which should be binaries (0 or 1).<br />
<br />
<em>MinMax</em>: Minimization ("Min") or maximization ("Max"), that's the question.<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.MIPSolve-function.<br />
Use S::=Q[x,y];<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
IntNum:=[x,y]<br />
<br />
Then we compute the solution with<br />
$GLPK.MIPSolve(OF, [], LE, GE, Bounds, IntNum, [], "Max");<br />
<br />
And we achieve x = 2 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt_2.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""]];<br />
<br />
IntNum:=[x[1,2], x[1,3]];<br />
<br />
$GLPK.MIPSolve(Objective, Balance, LessEq, [], Bounds, IntNum, [], "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 8, x[1,3], x[2,1], x[2,2] - 3, x[2,3], x[3,1] - 10, x[3,2] - 5, x[3,3] - 8, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo two (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,1] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 8 tons of cargo one (x[1,2] = 8)<br />
- 3 of cargo two (x[2,2] = 3)<br />
- 5 tons of cargo three (x[3,2] = 5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 0 tons of cargo one (x[1,3] = 0)<br />
- 0 of cargo two (x[2,3] = 0)<br />
- 8 tons of cargo three (x[3,3] = 8)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.MIPSolve&diff=7951ApCoCoA-1:GLPK.MIPSolve2008-12-04T23:32:27Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.MIPSolve(Objective_f:POLYNOM, EQ_Poly:LIST, LE_Poly:LIST, GE_Poly:LIST, Bounds:LIST, IntNum:LIST, Binaries:LIST, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
<em>Objective_f</em>: A linear polynomial which is equivalent to the linear objective function.<br />
<br />
<em>EQ_Poly</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Poly</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Poly</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>IntNum</em>: List of variables, which should be integer.<br />
<br />
<em>Binaries</em>: List of variables, which should be binaries (0 or 1).<br />
<br />
<em>MinMax</em>: Minimization ("Min") or maximization ("Max"), that's the question.<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.MIPSolve-function.<br />
Use S::=Q[x,y];<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
IntNum:=[x,y]<br />
<br />
Then we compute the solution with<br />
$GLPK.MIPSolve(OF, [], LE, GE, Bounds, IntNum, [], "Max");<br />
<br />
And we achieve x = 2 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt_2.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""]];<br />
<br />
IntNum:=[x[1,2], x[1,3]];<br />
<br />
$GLPK.MIPSolve(Objective, Balance, LessEq, [], Bounds, IntNum, [], "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 8, x[1,3], x[2,1], x[2,2] - 3, x[2,3], x[3,1] - 10, x[3,2] - 5, x[3,3] - 8, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo two (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,1] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 8 tons of cargo one (x[1,2] = 8)<br />
- 3 of cargo two (x[2,2] = 3)<br />
- 5 tons of cargo three (x[3,2] = 5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 0 tons of cargo one (x[1,3] = 0)<br />
- 0 of cargo two (x[2,3] = 0)<br />
- 8 tons of cargo three (x[3,3] = 8)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7950ApCoCoA-1:GLPK.LPSolve2008-12-04T23:28:33Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolve(Objective_f:POLYNOM, EQ_Poly:LIST, LE_Poly:LIST, GE_Poly:LIST, Bounds:LIST, Method:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
<em>Objective_f</em>: A linear polynomial which is equivalent to the linear objective function.<br />
<br />
<em>EQ_Poly</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Poly</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Poly</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>Method</em>: You can choose between the interior-point-method ("InterP") or the simplex-algorithm ("Simplex"). Usually you should use the simplex-algorithm.<br />
<br />
<em>MinMax</em>: Minimization ("Min") or maximization ("Max"), that's the question.<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
Use S::=Q[x,y];<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
$GLPK.LPSolve(OF, [], LE, GE, Bounds, "Simplex", "Max");<br />
<br />
And we achieve x = 266667/100000 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""]];<br />
<br />
$GLPK.LPSolve(Objective, Balance, LessEq, [], Bounds, "Simplex", "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 29/5, x[1,3] - 26/5, x[2,1], x[2,2], x[2,3], x[3,1] - 10, x[3,2] - 51/5, x[3,3] - 14/5, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo two (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,1] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 29/5 tons of cargo one (x[1,2] = 29/5)<br />
- 0 of cargo two (x[2,2] = 0)<br />
- 51/5 tons of cargo three (x[3,2] = 51/5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 26/5 tons of cargo one (x[1,3] = 26/5)<br />
- 0 of cargo two (x[2,3] = 0)<br />
- 14/5 tons of cargo three (x[3,3] = 14/5)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7948ApCoCoA-1:GLPK.LPSolve2008-12-04T23:22:05Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolve(Objective_f:POLYNOM, EQ_Poly:LIST, LE_Poly:LIST, GE_Poly:LIST, Bounds:LIST, Method:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
<em>Objective_f</em>: A linear polynomial which is equivalent to the linear objective function.<br />
<br />
<em>EQ_Poly</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Poly</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Poly</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>Method</em>: You can choose between the interior-point-method ("InterP") or the simplex-algorithm ("Simplex"). Usually you should use the simplex-algorithm.<br />
<br />
<em>MinMax</em>: Minimization ("Min") or maximization ("Max"), that's the question.<br />
<br />
<br />
<em>Specification of the paths</em>: When you execute the GLPK.LPSolve-command, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
Use S::=Q[x,y];<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
$GLPK.LPSolve(OF, [], LE, GE, Bounds, "Simplex", "Max");<br />
<br />
And we achieve x = 266667/100000 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""]];<br />
<br />
$GLPK.LPSolve(Objective, Balance, LessEq, [], Bounds, "Simplex", "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 29/5, x[1,3] - 26/5, x[2,1], x[2,2], x[2,3], x[3,1] - 10, x[3,2] - 51/5, x[3,3] - 14/5, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo two (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,1] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 29/5 tons of cargo one (x[1,2] = 29/5)<br />
- 0 of cargo two (x[2,2] = 0)<br />
- 51/5 tons of cargo three (x[3,2] = 51/5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 26/5 tons of cargo one (x[1,3] = 26/5)<br />
- 0 of cargo two (x[2,3] = 0)<br />
- 14/5 tons of cargo three (x[3,3] = 14/5)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.MIPSolve&diff=7944ApCoCoA-1:GLPK.MIPSolve2008-11-30T20:42:41Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.MIPSolve(Objective_f:POLYNOM, EQ_Poly:LIST, LE_Poly:LIST, GE_Poly:LIST, Bounds:LIST, IntNum:LIST, Binaries:LIST, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
<em>Objective_f</em>: A linear polynomial which is equivalent to the linear objective function.<br />
<br />
<em>EQ_Poly</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Poly</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Poly</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>IntNum</em>: List of variables, which should be integer.<br />
<br />
<em>Binaries</em>: List of variables, which should be binaries (0 or 1).<br />
<br />
<em>MinMax</em>: Minimization ("Min") or maximization ("Max"), that's the question.<br />
<br />
<br />
<em>Specification of the paths</em>: When you execute the GLPK.MIPSolve-command, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.MIPSolve-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
IntNum:=[x,y]<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.MIPSolve(OF, LE, GE, Bounds, IntNum, [], "Max");<br />
<br />
And we achieve x = 2 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt_2.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""]];<br />
<br />
IntNum:=[x[1,2], x[1,3]];<br />
<br />
$GLPK.MIPSolve(Objective, Balance, LessEq, [], Bounds, IntNum, [], "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 8, x[1,3], x[2,1], x[2,2] - 3, x[2,3], x[3,1] - 10, x[3,2] - 5, x[3,3] - 8, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo two (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,1] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 8 tons of cargo one (x[1,2] = 8)<br />
- 3 of cargo two (x[2,2] = 3)<br />
- 5 tons of cargo three (x[3,2] = 5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 0 tons of cargo one (x[1,3] = 0)<br />
- 0 of cargo two (x[2,3] = 0)<br />
- 8 tons of cargo three (x[3,3] = 8)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.MIPSolve&diff=7943ApCoCoA-1:GLPK.MIPSolve2008-11-30T20:41:06Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.MIPSolve(Objective_f:POLYNOM, EQ_Poly:LIST, LE_Poly:LIST, GE_Poly:LIST, Bounds:LIST, IntNum:LIST, Binaries:LIST, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
<em>Objective_f</em>: A linear polynomial which is equivalent to the linear objective function.<br />
<br />
<em>EQ_Poly</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Poly</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Poly</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>IntNum</em>: List of variables, which should be integer.<br />
<br />
<em>Binaries</em>: List of variables, which should be binaries (0 or 1).<br />
<br />
<em>MinMax</em>: Minimization ("Min") or maximization ("Max"), that's the question.<br />
<br />
<br />
<em>Specification of the paths</em>: When you execute the GLPK.LPSolve-command, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.MIPSolve-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
IntNum:=[x,y]<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.MIPSolve(OF, LE, GE, Bounds, IntNum, [], "Max");<br />
<br />
And we achieve x = 2 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt_2.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""]];<br />
<br />
IntNum:=[x[1,2], x[1,3]];<br />
<br />
$GLPK.MIPSolve(Objective, Balance, LessEq, [], Bounds, IntNum, [], "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 8, x[1,3], x[2,1], x[2,2] - 3, x[2,3], x[3,1] - 10, x[3,2] - 5, x[3,3] - 8, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo two (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,1] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 8 tons of cargo one (x[1,2] = 8)<br />
- 3 of cargo two (x[2,2] = 3)<br />
- 5 tons of cargo three (x[3,2] = 5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 0 tons of cargo one (x[1,3] = 0)<br />
- 0 of cargo two (x[2,3] = 0)<br />
- 8 tons of cargo three (x[3,3] = 8)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=File:LinOpt_2.jpg&diff=7942File:LinOpt 2.jpg2008-11-30T20:38:28Z<p>StK: uploaded a new version of "Image:LinOpt 2.jpg"</p>
<hr />
<div></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.MIPSolve&diff=7937ApCoCoA-1:GLPK.MIPSolve2008-11-30T20:29:03Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.MIPSolve(Objective_f:POLYNOM, EQ_Poly:LIST, LE_Poly:LIST, GE_Poly:LIST, Bounds:LIST, IntNum:LIST, Binaries:LIST, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
<em>Objective_f</em>: A linear polynomial which is equivalent to the linear objective function.<br />
<br />
<em>EQ_Poly</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Poly</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Poly</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>IntNum</em>: List of variables, which should be integer.<br />
<br />
<em>Binaries</em>: List of variables, which are binaries (0 or 1).<br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
<em>Specification of the paths</em>: When you execute the GLPK.LPSolve-command, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
IntNum:=[x,y]<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.MIPSolve(OF, LE, GE, Bounds, IntNum, [], "Max");<br />
<br />
And we achieve x = 2 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt_2.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""]];<br />
<br />
IntNum:=[x[1,2], x[1,3]];<br />
<br />
$GLPK.MIPSolve(Objective, Balance, LessEq, [], Bounds, IntNum, [], "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 8, x[1,3], x[2,1], x[2,2] - 3, x[2,3], x[3,1] - 10, x[3,2] - 5, x[3,3] - 8, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo two (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,1] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 8 tons of cargo one (x[1,2] = 8)<br />
- 3 of cargo two (x[2,2] = 3)<br />
- 5 tons of cargo three (x[3,2] = 5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 0 tons of cargo one (x[1,3] = 0)<br />
- 0 of cargo two (x[2,3] = 0)<br />
- 8 tons of cargo three (x[3,3] = 8)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7935ApCoCoA-1:GLPK.LPSolve2008-11-30T20:27:20Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolve(Objective_f:POLYNOM, EQ_Poly:LIST, LE_Poly:LIST, GE_Poly:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
<em>Objective_f</em>: A linear polynomial which is equivalent to the linear objective function.<br />
<br />
<em>EQ_Poly</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Poly</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Poly</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>Methode</em>: You can choose between the inner-point-method (InnerP) or the simplex-algorithm (Simplex). Usually you should use the simplex-algorithm.<br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
<em>Specification of the paths</em>: When you execute the GLPK.LPSolve-command, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.LPSolve(OF, LE, GE, Bounds, "Simplex", "Max");<br />
<br />
And we achieve x = 8/3 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""]];<br />
<br />
$GLPK.LPSolve(Objective, Balance, LessEq, [], Bounds, "Simplex", "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 29/5, x[1,3] - 26/5, x[2,1], x[2,2], x[2,3], x[3,1] - 10, x[3,2] - 51/5, x[3,3] - 14/5, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo two (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,1] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 29/5 tons of cargo one (x[1,2] = 29/5)<br />
- 0 of cargo two (x[2,2] = 0)<br />
- 51/5 tons of cargo three (x[3,2] = 51/5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 26/5 tons of cargo one (x[1,3] = 26/5)<br />
- 0 of cargo two (x[2,3] = 0)<br />
- 14/5 tons of cargo three (x[3,3] = 14/5)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7933ApCoCoA-1:GLPK.LPSolve2008-11-30T20:25:53Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolve(Objective_f:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
<em>Objective_f</em>: A linear polynomial which is equivalent to the linear objective function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>Methode</em>: You can choose between the inner-point-method (InnerP) or the simplex-algorithm (Simplex). Usually you should use the simplex-algorithm.<br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
<em>Specification of the paths</em>: When you execute the GLPK.LPSolve-command, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.LPSolve(OF, LE, GE, Bounds, "Simplex", "Max");<br />
<br />
And we achieve x = 8/3 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""]];<br />
<br />
$GLPK.LPSolve(Objective, Balance, LessEq, [], Bounds, "Simplex", "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 29/5, x[1,3] - 26/5, x[2,1], x[2,2], x[2,3], x[3,1] - 10, x[3,2] - 51/5, x[3,3] - 14/5, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo two (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,1] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 29/5 tons of cargo one (x[1,2] = 29/5)<br />
- 0 of cargo two (x[2,2] = 0)<br />
- 51/5 tons of cargo three (x[3,2] = 51/5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 26/5 tons of cargo one (x[1,3] = 26/5)<br />
- 0 of cargo two (x[2,3] = 0)<br />
- 14/5 tons of cargo three (x[3,3] = 14/5)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7930ApCoCoA-1:GLPK.LPSolve2008-11-30T20:22:10Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolve(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>Methode</em>: You can choose between the inner-point-method (InnerP) or the simplex-algorithm (Simplex). Usually you should use the simplex-algorithm.<br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
<em>Specification of the paths</em>: When you execute the GLPK.LPSolve-command, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.LPSolve(OF, LE, GE, Bounds, "Simplex", "Max");<br />
<br />
And we achieve x = 8/3 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""]];<br />
<br />
$GLPK.LPSolve(Objective, Balance, LessEq, [], Bounds, "Simplex", "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 29/5, x[1,3] - 26/5, x[2,1], x[2,2], x[2,3], x[3,1] - 10, x[3,2] - 51/5, x[3,3] - 14/5, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo two (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,1] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 29/5 tons of cargo one (x[1,2] = 29/5)<br />
- 0 of cargo two (x[2,2] = 0)<br />
- 51/5 tons of cargo three (x[3,2] = 51/5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 26/5 tons of cargo one (x[1,3] = 26/5)<br />
- 0 of cargo two (x[2,3] = 0)<br />
- 14/5 tons of cargo three (x[3,3] = 14/5)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.MIPSolve&diff=7929ApCoCoA-1:GLPK.MIPSolve2008-11-30T20:20:51Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.MIPSolve(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, IntNum:LIST, Binaries:LIST, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>IntNum</em>: List of variables, which should be integer.<br />
<br />
<em>Binaries</em>: List of variables, which are binaries (0 or 1).<br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
<em>Specification of the paths</em>: When you execute the GLPK.LPSolve-command, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
IntNum:=[x,y]<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.MIPSolve(OF, LE, GE, Bounds, IntNum, [], "Max");<br />
<br />
And we achieve x = 2 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt_2.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""],[0,""]];<br />
<br />
IntNum:=[x[1,2], x[1,3]];<br />
<br />
$GLPK.MIPSolve(Objective, Balance, LessEq, [], Bounds, IntNum, [], "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 8, x[1,3], x[2,1], x[2,2] - 3, x[2,3], x[3,1] - 10, x[3,2] - 5, x[3,3] - 8, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo two (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,1] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 8 tons of cargo one (x[1,2] = 8)<br />
- 3 of cargo two (x[2,2] = 3)<br />
- 5 tons of cargo three (x[3,2] = 5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 0 tons of cargo one (x[1,3] = 0)<br />
- 0 of cargo two (x[2,3] = 0)<br />
- 8 tons of cargo three (x[3,3] = 8)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.MIPSolve&diff=7927ApCoCoA-1:GLPK.MIPSolve2008-11-30T20:19:18Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.MIPSolve(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, IntNum:LIST, Binaries:LIST, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>IntNum</em>: List of variables, which should be integer.<br />
<br />
<em>Binaries</em>: List of variables, which are binaries (0 or 1).<br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
<em>Specification of the paths</em>: When you execute the GLPK.LPSolve-command, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
IntNum:=[x,y]<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.MIPSolve(OF, LE, GE, Bounds, IntNum, [], "Max");<br />
<br />
And we achieve x = 2 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt_2.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"]];<br />
<br />
IntNum:=[x[1,2], x[1,3]];<br />
<br />
$GLPK.MIPSolve(Objective, Balance, LessEq, [], Bounds, IntNum, [], "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 8, x[1,3], x[2,1], x[2,2] - 3, x[2,3], x[3,1] - 10, x[3,2] - 5, x[3,3] - 8, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo two (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,1] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 8 tons of cargo one (x[1,2] = 8)<br />
- 3 of cargo two (x[2,2] = 3)<br />
- 5 tons of cargo three (x[3,2] = 5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 0 tons of cargo one (x[1,3] = 0)<br />
- 0 of cargo two (x[2,3] = 0)<br />
- 8 tons of cargo three (x[3,3] = 8)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.MIPSolve&diff=7925ApCoCoA-1:GLPK.MIPSolve2008-11-30T20:17:24Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.MIPSolve(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, IntNum:LIST, Binaries:LIST, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>IntNum</em>: List of variables, which should be integer.<br />
<br />
<em>Binaries</em>: List of variables, which are binaries (0 or 1).<br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
<em>Specification of the paths</em>: When you execute the GLPK.LPSolve-command, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
IntNum:=[x,y]<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.MIPSolve(OF, LE, GE, Bounds, IntNum, [], "Max");<br />
<br />
And we achieve x = 2 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt_2.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"]];<br />
<br />
IntNum:=[x[1,2], x[1,3]];<br />
<br />
$GLPK.MIPSolve(Objective, Balance, LessEq, [], Bounds, IntNum, [], "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 8, x[1,3], x[2,1], x[2,2] - 3, x[2,3], x[3,1] - 10, x[3,2] - 5, x[3,3] - 8, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo one (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,1] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 8 tons of cargo one (x[1,2] = 8)<br />
- 3 of cargo one (x[2,2] = 3)<br />
- 5 tons of cargo three (x[3,2] = 5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 0 tons of cargo one (x[1,3] = 0)<br />
- 0 of cargo one (x[2,3] = 0)<br />
- 8 tons of cargo three (x[3,3] = 8)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7924ApCoCoA-1:GLPK.LPSolve2008-11-30T20:12:10Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolve(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>Methode</em>: You can choose between the inner-point-method (InnerP) or the simplex-algorithm (Simplex). Usually you should use the simplex-algorithm.<br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
<em>Specification of the paths</em>: When you execute the GLPK.LPSolve-command, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.LPSolve(OF, LE, GE, Bounds, "Simplex", "Max");<br />
<br />
And we achieve x = 8/3 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"]];<br />
<br />
$GLPK.LPSolve(Objective, Balance, LessEq, [], Bounds, "Simplex", "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 29/5, x[1,3] - 26/5, x[2,1], x[2,2], x[2,3], x[3,1] - 10, x[3,2] - 51/5, x[3,3] - 14/5, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo one (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,1] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 29/5 tons of cargo one (x[1,2] = 29/5)<br />
- 0 of cargo one (x[2,2] = 0)<br />
- 51/5 tons of cargo three (x[3,2] = 51/5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 26/5 tons of cargo one (x[1,3] = 26/5)<br />
- 0 of cargo one (x[2,3] = 0)<br />
- 14/5 tons of cargo three (x[3,3] = 14/5)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.MIPSolve&diff=7923ApCoCoA-1:GLPK.MIPSolve2008-11-30T20:10:26Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.MIPSolve(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, IntNum:LIST, Binaries:LIST, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>IntNum</em>: List of variables, which should be integer.<br />
<br />
<em>Binaries</em>: List of variables, which are binaries (0 or 1).<br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
<em>Specification of the paths</em>: When you execute the GLPK.LPSolve-command, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
IntNum:=[x,y]<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.MIPSolve(OF, LE, GE, Bounds, IntNum, [], "Max");<br />
<br />
And we achieve x = 2 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt_2.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"]];<br />
<br />
IntNum:=[x[1,2], x[1,3]];<br />
<br />
$GLPK.MIPSolve(Objective, Balance, LessEq, [], Bounds, IntNum, [], "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 8, x[1,3], x[2,1], x[2,2] - 3, x[2,3], x[3,1] - 10, x[3,2] - 5, x[3,3] - 8, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo one (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,1] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 8 tons of cargo one (x[1,2] = 8)<br />
- 3 of cargo one (x[2,2] = 3)<br />
- 5 tons of cargo three (x[3,2] = 5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 0 tons of cargo one (x[1,3] = 0)<br />
- 0 of cargo one (x[2,3] = 0)<br />
- 8 tons of cargo three (x[3,3] = 8)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.MIPSolve&diff=7922ApCoCoA-1:GLPK.MIPSolve2008-11-30T20:09:27Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.MIPSolve(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Integral_Numbers:LIST, Binaries:LIST, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>Integral_Numbers</em>: List of variables, which should be integer.<br />
<br />
<em>Binaries</em>: List of variables, which are binaries (0 or 1).<br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
<em>Specification of the paths</em>: When you execute the GLPK.LPSolve-command, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
IntNum:=[x,y]<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.MIPSolve(OF, LE, GE, Bounds, IntNum, [], "Max");<br />
<br />
And we achieve x = 2 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt_2.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"]];<br />
<br />
IntNum:=[x[1,2], x[1,3]];<br />
<br />
$GLPK.MIPSolve(Objective, Balance, LessEq, [], Bounds, IntNum, [], "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 8, x[1,3], x[2,1], x[2,2] - 3, x[2,3], x[3,1] - 10, x[3,2] - 5, x[3,3] - 8, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo one (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,1] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 8 tons of cargo one (x[1,2] = 8)<br />
- 3 of cargo one (x[2,2] = 3)<br />
- 5 tons of cargo three (x[3,2] = 5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 0 tons of cargo one (x[1,3] = 0)<br />
- 0 of cargo one (x[2,3] = 0)<br />
- 8 tons of cargo three (x[3,3] = 8)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.MIPSolve&diff=7921ApCoCoA-1:GLPK.MIPSolve2008-11-30T20:01:50Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.MIPSolve(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Integral_Numberss:LIST, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>Integral_Numbers</em>: List of variables, which should be integer.<br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
<em>Specification of the paths</em>: When you execute the GLPK.LPSolve-command, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
IntNum:=[x,y]<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.MIPSolve(OF, LE, GE, Bounds, IntNum, "Max");<br />
<br />
And we achieve x = 2 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt_2.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"]];<br />
<br />
IntNum:=[x[1,1]];<br />
<br />
$GLPK.MIPSolve(Objective, Balance, LessEq, [], Bounds, IntNum, "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 29/5, x[1,3] - 26/5, x[2,1], x[2,2], x[2,3], x[3,1] - 10, x[3,2] - 51/5, x[3,3] - 14/5, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo one (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,3] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 29/5 tons of cargo one (x[1,2] = 29/5)<br />
- 0 of cargo one (x[2,2] = 0)<br />
- 51/5 tons of cargo three (x[3,2] = 51/5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 26/5 tons of cargo one (x[1,3] = 26/5)<br />
- 0 of cargo one (x[2,3] = 0)<br />
- 14/5 tons of cargo three (x[3,3] = 14/5)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7920ApCoCoA-1:GLPK.LPSolve2008-11-30T20:00:50Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolve(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>Methode</em>: You can choose between the inner-point-method (InnerP) or the simplex-algorithm (Simplex). Usually you should use the simplex-algorithm.<br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
<em>Specification of the paths</em>: When you execute the GLPK.LPSolve-command, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.LPSolve(OF, LE, GE, Bounds, "Simplex", "Max");<br />
<br />
And we achieve x = 8/3 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"]];<br />
<br />
$GLPK.LPSolve(Objective, Balance, LessEq, [], Bounds, "Simplex", "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 29/5, x[1,3] - 26/5, x[2,1], x[2,2], x[2,3], x[3,1] - 10, x[3,2] - 51/5, x[3,3] - 14/5, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo one (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,3] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 29/5 tons of cargo one (x[1,2] = 29/5)<br />
- 0 of cargo one (x[2,2] = 0)<br />
- 51/5 tons of cargo three (x[3,2] = 51/5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 26/5 tons of cargo one (x[1,3] = 26/5)<br />
- 0 of cargo one (x[2,3] = 0)<br />
- 14/5 tons of cargo three (x[3,3] = 14/5)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7919ApCoCoA-1:GLPK.LPSolve2008-11-30T19:31:32Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>Methode</em>: You can choose between the inner-point-method (InnerP) or the simplex-algorithm (Simplex). Usually you should use the simplex-algorithm.<br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
<em>Specification of the paths</em>: When you execute the GLPK.LPSolve-command, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.LPSolv(OF, LE, GE, Bounds, "Simplex", "Max");<br />
<br />
And we achieve x = 8/3 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"]];<br />
<br />
$GLPK.LPSolv(Objective, Balance, LessEq, [], Bounds, "Simplex", "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 29/5, x[1,3] - 26/5, x[2,1], x[2,2], x[2,3], x[3,1] - 10, x[3,2] - 51/5, x[3,3] - 14/5, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo one (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,3] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 29/5 tons of cargo one (x[1,2] = 29/5)<br />
- 0 of cargo one (x[2,2] = 0)<br />
- 51/5 tons of cargo three (x[3,2] = 51/5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 26/5 tons of cargo one (x[1,3] = 26/5)<br />
- 0 of cargo one (x[2,3] = 0)<br />
- 14/5 tons of cargo three (x[3,3] = 14/5)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.MIPSolve&diff=7918ApCoCoA-1:GLPK.MIPSolve2008-11-30T19:30:20Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.MIPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Integral_Numberss:LIST, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>Integral_Numbers</em>: List of variables, which should be integer.<br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
<em>Specification of the paths</em>: When you execute the GLPK.LPSolve-command, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
IntNum:=[x,y]<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.MIPSolv(OF, LE, GE, Bounds, IntNum, "Max");<br />
<br />
And we achieve x = 2 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt_2.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"]];<br />
<br />
IntNum:=[x[1,1]];<br />
<br />
$GLPK.MIPSolv(Objective, Balance, LessEq, [], Bounds, IntNum, "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 29/5, x[1,3] - 26/5, x[2,1], x[2,2], x[2,3], x[3,1] - 10, x[3,2] - 51/5, x[3,3] - 14/5, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo one (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,3] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 29/5 tons of cargo one (x[1,2] = 29/5)<br />
- 0 of cargo one (x[2,2] = 0)<br />
- 51/5 tons of cargo three (x[3,2] = 51/5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 26/5 tons of cargo one (x[1,3] = 26/5)<br />
- 0 of cargo one (x[2,3] = 0)<br />
- 14/5 tons of cargo three (x[3,3] = 14/5)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.MIPSolve&diff=7917ApCoCoA-1:GLPK.MIPSolve2008-11-30T19:18:04Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.MIPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Integral_Numberss:LIST, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>Integral_Numbers</em>: List of variables, which should be integer.<br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
<em>Specification of the paths</em>: When you execute the GLPK.LPSolve-command, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
IntNum:=[x,y]<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.MIPSol(OF, LE, GE, Bounds, IntNum, "Max");<br />
<br />
And we achieve x = 2 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt_2.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"]];<br />
<br />
$GLPK.LPSolv(Objective, Balance, LessEq, [], Bounds, "Simplex", "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 29/5, x[1,3] - 26/5, x[2,1], x[2,2], x[2,3], x[3,1] - 10, x[3,2] - 51/5, x[3,3] - 14/5, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo one (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,3] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 29/5 tons of cargo one (x[1,2] = 29/5)<br />
- 0 of cargo one (x[2,2] = 0)<br />
- 51/5 tons of cargo three (x[3,2] = 51/5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 26/5 tons of cargo one (x[1,3] = 26/5)<br />
- 0 of cargo one (x[2,3] = 0)<br />
- 14/5 tons of cargo three (x[3,3] = 14/5)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=File:LinOpt_2.jpg&diff=7916File:LinOpt 2.jpg2008-11-30T19:17:07Z<p>StK: </p>
<hr />
<div></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.MIPSolve&diff=7912ApCoCoA-1:GLPK.MIPSolve2008-11-28T23:10:01Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.MIPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Integral_Numberss:LIST, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>Integral_Numbers</em>: List of variables, which should be integer.<br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
<em>Specification of the paths</em>: When you execute the GLPK.LPSolve-command, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
IntNum:=[x,y]<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.MIPSol(OF, LE, GE, Bounds, IntNum, "Max");<br />
<br />
And we achieve x = 2 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"]];<br />
<br />
$GLPK.LPSolv(Objective, Balance, LessEq, [], Bounds, "Simplex", "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 29/5, x[1,3] - 26/5, x[2,1], x[2,2], x[2,3], x[3,1] - 10, x[3,2] - 51/5, x[3,3] - 14/5, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo one (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,3] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 29/5 tons of cargo one (x[1,2] = 29/5)<br />
- 0 of cargo one (x[2,2] = 0)<br />
- 51/5 tons of cargo three (x[3,2] = 51/5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 26/5 tons of cargo one (x[1,3] = 26/5)<br />
- 0 of cargo one (x[2,3] = 0)<br />
- 14/5 tons of cargo three (x[3,3] = 14/5)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.MIPSolve&diff=7911ApCoCoA-1:GLPK.MIPSolve2008-11-28T23:05:33Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.MIPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Integral_Numberss:LIST, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>Integral_Numbers</em>: List of variables, which should be integer.<br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
<em>Specification of the paths</em>: When you execute the GLPK.LPSolve-command, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.LPSol(OF, LE, GE, Bounds, "Simplex", "Max");<br />
<br />
And we achieve x = 8/3 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"]];<br />
<br />
$GLPK.LPSolv(Objective, Balance, LessEq, [], Bounds, "Simplex", "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 29/5, x[1,3] - 26/5, x[2,1], x[2,2], x[2,3], x[3,1] - 10, x[3,2] - 51/5, x[3,3] - 14/5, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo one (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,3] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 29/5 tons of cargo one (x[1,2] = 29/5)<br />
- 0 of cargo one (x[2,2] = 0)<br />
- 51/5 tons of cargo three (x[3,2] = 51/5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 26/5 tons of cargo one (x[1,3] = 26/5)<br />
- 0 of cargo one (x[2,3] = 0)<br />
- 14/5 tons of cargo three (x[3,3] = 14/5)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.MIPSolve&diff=7910ApCoCoA-1:GLPK.MIPSolve2008-11-28T22:57:01Z<p>StK: New page: <command> <title>LPSolve</title> <short_description>solve linear programms</short_description> <syntax> GLPK.MIPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, G...</p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.MIPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>Methode</em>: You can choose between the inner-point-method (InnerP) or the simplex-algorithm (Simplex). Usually you should use the simplex-algorithm.<br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
<em>Specification of the paths</em>: When you execute the GLPK.LPSolve-command, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.LPSol(OF, LE, GE, Bounds, "Simplex", "Max");<br />
<br />
And we achieve x = 8/3 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"]];<br />
<br />
$GLPK.LPSolv(Objective, Balance, LessEq, [], Bounds, "Simplex", "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 29/5, x[1,3] - 26/5, x[2,1], x[2,2], x[2,3], x[3,1] - 10, x[3,2] - 51/5, x[3,3] - 14/5, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo one (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,3] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 29/5 tons of cargo one (x[1,2] = 29/5)<br />
- 0 of cargo one (x[2,2] = 0)<br />
- 51/5 tons of cargo three (x[3,2] = 51/5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 26/5 tons of cargo one (x[1,3] = 26/5)<br />
- 0 of cargo one (x[2,3] = 0)<br />
- 14/5 tons of cargo three (x[3,3] = 14/5)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7907ApCoCoA-1:GLPK.LPSolve2008-11-28T21:30:13Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>Methode</em>: You can choose between the inner-point-method (InnerP) or the simplex-algorithm (Simplex). Usually you should use the simplex-algorithm.<br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
<em>Specification of the paths</em>: When you execute the GLPK.LPSolve-command, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.LPSol(OF, LE, GE, Bounds, "Simplex", "Max");<br />
<br />
And we achieve x = 8/3 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"]];<br />
<br />
$GLPK.LPSolv(Objective, Balance, LessEq, [], Bounds, "Simplex", "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 29/5, x[1,3] - 26/5, x[2,1], x[2,2], x[2,3], x[3,1] - 10, x[3,2] - 51/5, x[3,3] - 14/5, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo one (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,3] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 29/5 tons of cargo one (x[1,2] = 29/5)<br />
- 0 of cargo one (x[2,2] = 0)<br />
- 51/5 tons of cargo three (x[3,2] = 51/5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 26/5 tons of cargo one (x[1,3] = 26/5)<br />
- 0 of cargo one (x[2,3] = 0)<br />
- 14/5 tons of cargo three (x[3,3] = 14/5)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7906ApCoCoA-1:GLPK.LPSolve2008-11-28T21:26:45Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>Methode</em>: You can choose between the inner-point-method (InnerP) or the simplex-algorithm (Simplex). Usually you should use the simplex-algorithm.<br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
<em>Specification of the paths</em>: When you execute the package, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.LPSol(OF, LE, GE, Bounds, "Simplex", "Max");<br />
<br />
And we achieve x = 8/3 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"]];<br />
<br />
$GLPK.LPSolv(Objective, Balance, LessEq, [], Bounds, "Simplex", "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 29/5, x[1,3] - 26/5, x[2,1], x[2,2], x[2,3], x[3,1] - 10, x[3,2] - 51/5, x[3,3] - 14/5, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo one (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,3] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 29/5 tons of cargo one (x[1,2] = 29/5)<br />
- 0 of cargo one (x[2,2] = 0)<br />
- 51/5 tons of cargo three (x[3,2] = 51/5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 26/5 tons of cargo one (x[1,3] = 26/5)<br />
- 0 of cargo one (x[2,3] = 0)<br />
- 14/5 tons of cargo three (x[3,3] = 14/5)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7905ApCoCoA-1:GLPK.LPSolve2008-11-28T21:24:13Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>Methode</em>: You can choose between the inner-point-method (InnerP) or the simplex-algorithm (Simplex). Usually you should use the simplex-algorithm.<br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
When you execute the package, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.LPSol(OF, LE, GE, Bounds, Simplex, Max);<br />
<br />
And we achieve x = 8/3 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"]];<br />
<br />
$GLPK.LPSolv(Objective, Balance, LessEq, [], Bounds, "Simplex", "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 29/5, x[1,3] - 26/5, x[2,1], x[2,2], x[2,3], x[3,1] - 10, x[3,2] - 51/5, x[3,3] - 14/5, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of cargo one (x[1,1] = 0)<br />
- 0 of cargo one (x[2,1] = 0)<br />
- 10 tons of cargo three (x[3,3] = 10)<br />
- 0 of cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 29/5 tons of cargo one (x[1,2] = 29/5)<br />
- 0 of cargo one (x[2,2] = 0)<br />
- 51/5 tons of cargo three (x[3,2] = 51/5)<br />
- 0 of cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 26/5 tons of cargo one (x[1,3] = 26/5)<br />
- 0 of cargo one (x[2,3] = 0)<br />
- 14/5 tons of cargo three (x[3,3] = 14/5)<br />
- 0 of cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7904ApCoCoA-1:GLPK.LPSolve2008-11-28T21:21:42Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. <br />
You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) <br />
or plus infinity (second place).<br />
<br />
<em>Methode</em>: You can choose between the inner-point-method (InnerP) or the simplex-algorithm (Simplex). <br />
Usually you should use the simplex-algorithm.<br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
When you execute the package, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.LPSol(OF, LE, GE, Bounds, Simplex, Max);<br />
<br />
And we achieve x = 8/3 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
Balance := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LessEq := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"]];<br />
<br />
$GLPK.LPSolv(Objective, Balance, LessEq, [], Bounds, "Simplex", "Max");<br />
<br />
<br />
And we receive<br />
[x[1,1], x[1,2] - 29/5, x[1,3] - 26/5, x[2,1], x[2,2], x[2,3], x[3,1] - 10, x[3,2] - 51/5, x[3,3] - 14/5, x[4,1], x[4,2], x[4,3]]<br />
<br />
This means <br />
* in the front we put<br />
- 0 of Cargo one (x[1,1] = 0)<br />
- 0 of Cargo one (x[2,1] = 0)<br />
- 10 tons of Cargo three (x[3,3] = 10)<br />
- 0 of Cargo four (x[4,1] = 0)<br />
* in the middle we put<br />
- 29/5 tons of Cargo one (x[1,2] = 29/5)<br />
- 0 of Cargo one (x[2,2] = 0)<br />
- 51/5 tons of Cargo three (x[3,2] = 51/5)<br />
- 0 of Cargo four (x[4,2] = 0)<br />
* in the rear we put<br />
- 26/5 tons of Cargo one (x[1,3] = 26/5)<br />
- 0 of Cargo one (x[2,3] = 0)<br />
- 14/5 tons of Cargo three (x[3,3] = 14/5)<br />
- 0 of Cargo four (x[4,3] = 0)<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7903ApCoCoA-1:GLPK.LPSolve2008-11-28T21:02:26Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>Methode</em>: You can choose between the inner-point-method (InnerP) or the simplex-algorithm (Simplex). Usually you should use the simplex-algorithm.<br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
When you execute the package, you had to <em>specify the path of the LP solver glpsol</em>, i.e. GlpsolPath:="/usr/bin/";<br />
and the <em>working path</em>, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.LPSol(OF, LE, GE, Bounds, Simplex, Max);<br />
<br />
And we achieve x = 8/3 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective_Function := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
EQ_Polynomials := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LE_Polynomials := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"]];<br />
<br />
$GLPK.LPSolv(Objective_Function, EQ_Polynomials, LE_Polynomials, [],Bounds, "Simplex", "Max");<br />
<br />
And we receive<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7902ApCoCoA-1:GLPK.LPSolve2008-11-28T20:59:05Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
{{ApCoCoAServer}}<br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable. You can choose between INT or RAT for the type of each bound, if you type in a (empty) string, then it means minus infinity (first place) or plus infinity (second place).<br />
<br />
<em>Methode</em>: You can choose between the inner-point-method (InnerP) or the simplex-algorithm (Simplex). Usually you should use the simplex-algorithm.<br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
When you execute the package, you had to specify the path of the LP solver glpsol, i.e. GlpsolPath:="/usr/bin/";<br />
and the working path, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.LPSol(OF, LE, GE, Bounds, Simplex, Max);<br />
<br />
And we achieve x = 8/3 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
<br />
In ApCoCoa you can solve this LP like this:<br />
<br />
Use S::= Q[x[1..4,1..3]];<br />
<br />
Objective_Function := 310*(x[1,1]+x[1,2]+x[1,3])+310*(x[2,1]+x[2,2]+x[2,3])+350*(x[3,1]+x[3,2]+x[3,3])+285*(x[4,1]+x[4,2]+x[4,3]);<br />
EQ_Polynomials := [16(x[1,1]+x[2,1]+x[3,1]+x[4,1])-10(x[1,2]+x[2,2]+x[3,2]+x[4,2]), 8(x[1,2]+x[2,2]+x[3,2]+x[4,2])-16(x[1,3]+x[2,3]+x[3,3]+x[4,3])];<br />
<br />
Available := [x[1,1]+x[1,2]+x[1,3]-18, x[2,1]+x[2,2]+x[2,3]-15, x[3,1]+x[3,2]+x[3,3]-23, x[4,1]+x[4,2]+x[4,3]-12];<br />
Weight := [x[1,1]+x[2,1]+x[3,1]+x[4,1]-10, x[1,2]+x[2,2]+x[3,2]+x[4,2]-16, x[1,3]+x[2,3]+x[3,3]+x[4,3]-8];<br />
Volume := [480x[1,1]+650x[2,1]+580x[3,1]+390x[4,1]-6800, 480x[1,2]+650x[2,2]+580x[3,2]+390x[4,2]-8700, 480x[1,3]+650x[2,3]+580x[3,3]+390x[4,3]-5300];<br />
LE_Polynomials := Flatten([Available, Weight, Volume]);<br />
<br />
Bounds := [[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"],[0,"Infty"]];<br />
<br />
$GLPK.LPSolv(Objective_Function, EQ_Polynomials, LE_Polynomials, [],Bounds, "Simplex", "Max");<br />
</example><br />
<br />
</description><br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7823ApCoCoA-1:GLPK.LPSolve2008-11-13T17:03:22Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable.<br />
<br />
<em>Methode</em>: You can choose between the inner-point-method (InnerP) or the simplex-algorithm (Simplex). <br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
When you execute the package, you had to specify the path of the LP solver glpsol, i.e. GlpsolPath:="/usr/bin/";<br />
and the working path, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, <br />
with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.LPSol(OF, LE, GE, Bounds, Simplex, Max);<br />
<br />
And we achieve x = 8/3 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt.jpg]]<br />
<br />
<br />
<br />
<example><br />
''Linear programming example 1996 MBA exam''<br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. <br />
Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into <br />
compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 ≤ 18<br />
x21 + x22 + x23 ≤ 15<br />
x31 + x32 + x33 ≤ 23<br />
x41 + x42 + x43 ≤ 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 ≤ 10<br />
x12 + x22 + x32 + x42 ≤ 16<br />
x13 + x23 + x33 + x43 ≤ 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 ≤ 6800<br />
480x12 + 650x22 + 580x32 + 390x42 ≤ 8700<br />
480x13 + 650x23 + 580x33 + 390x43 ≤ 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion <br />
of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would <br />
not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
The advantages of using a software package to solve the above linear program, rather than a judgemental <br />
approach are:<br />
<br />
* actually maximise profit, rather than just believing that our judgemental solution maximises profit <br />
(we may have bad judgement, even if we have an MBA!)<br />
* makes the cargo loading the decision one that we can solve in a routine operational manner on a computer, <br />
rather than having to exercise judgement each and every time we want to solve it<br />
* problems that can be appropriately formulated as linear programs are almost always better solved by computers <br />
than by people<br />
* can perform sensitivity analysis very easily using a computer<br />
<br />
</example><br />
<br />
<br />
</description><br />
<br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7822ApCoCoA-1:GLPK.LPSolve2008-11-13T16:57:14Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable.<br />
<br />
<em>Methode</em>: You can choose between the inner-point-method (InnerP) or the simplex-algorithm (Simplex). <br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
When you execute the package, you had to specify the path of the LP solver glpsol, i.e. GlpsolPath:="/usr/bin/";<br />
and the working path, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.LPSol(OF, LE, GE, Bounds, Simplex, Max);<br />
<br />
And we achieve x = 8/3 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt.jpg]]<br />
<br />
<br />
<br />
<example><br />
<em>Linear programming example 1996 MBA exam</em><br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
Variables<br />
<br />
We need to decide how much of each of the four cargoes to put in each of the three compartments. Hence let:<br />
<br />
xij be the number of tonnes of cargo i (i=1,2,3,4 for C1, C2, C3 and C4 respectively) that is put into compartment j (j=1 for Front, j=2 for Centre and j=3 for Rear) where xij >=0 i=1,2,3,4; j=1,2,3<br />
<br />
Note here that we are explicitly told we can split the cargoes into any proportions (fractions) that we like.<br />
Constraints<br />
<br />
* cannot pack more of each of the four cargoes than we have available<br />
<br />
x11 + x12 + x13 <= 18<br />
x21 + x22 + x23 <= 15<br />
x31 + x32 + x33 <= 23<br />
x41 + x42 + x43 <= 12<br />
<br />
* the weight capacity of each compartment must be respected<br />
<br />
x11 + x21 + x31 + x41 <= 10<br />
x12 + x22 + x32 + x42 <= 16<br />
x13 + x23 + x33 + x43 <= 8<br />
<br />
* the volume (space) capacity of each compartment must be respected<br />
<br />
480x11 + 650x21 + 580x31 + 390x41 <= 6800<br />
480x12 + 650x22 + 580x32 + 390x42 <= 8700<br />
480x13 + 650x23 + 580x33 + 390x43 <= 5300<br />
<br />
* the weight of the cargo in the respective compartments must be the same proportion of that compartment's weight capacity to maintain the balance of the plane<br />
<br />
[x11 + x21 + x31 + x41]/10 = [x12 + x22 + x32 + x42]/16 = [x13 + x23 + x33 + x43]/8<br />
Objective<br />
<br />
The objective is to maximise total profit, i.e.<br />
<br />
maximise 310[x11+ x12+x13] + 380[x21+ x22+x23] + 350[x31+ x32+x33] + 285[x41+ x42+x43]<br />
<br />
The basic assumptions are:<br />
<br />
* that each cargo can be split into whatever proportions/fractions we desire<br />
* that each cargo can be split between two or more compartments if we so desire<br />
* that the cargo can be packed into each compartment (for example if the cargo was spherical it would not be possible to pack a compartment to volume capacity, some free space is inevitable in sphere packing)<br />
* all the data/numbers given are accurate<br />
<br />
The advantages of using a software package to solve the above linear program, rather than a judgemental approach are:<br />
<br />
* actually maximise profit, rather than just believing that our judgemental solution maximises profit (we may have bad judgement, even if we have an MBA!)<br />
* makes the cargo loading the decision one that we can solve in a routine operational manner on a computer, rather than having to exercise judgement each and every time we want to solve it<br />
* problems that can be appropriately formulated as linear programs are almost always better solved by computers than by people<br />
* can perform sensitivity analysis very easily using a computer<br />
<br />
</example><br />
<br />
<br />
</description><br />
<br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7813ApCoCoA-1:GLPK.LPSolve2008-11-13T12:41:42Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable.<br />
<br />
<em>Methode</em>: You can choose between the inner-point-method (InnerP) or the simplex-algorithm (Simplex). <br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
When you execute the package, you had to specify the path of the LP solver glpsol, i.e. GlpsolPath:="/usr/bin/";<br />
and the working path, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.LPSol(OF, LE, GE, Bounds, Simplex, Max);<br />
<br />
And we achieve x = 8/3 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt.jpg]]<br />
<br />
<br />
<br />
<example><br />
<em>Linear programming example 1996 MBA exam</em><br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
</example><br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
</description><br />
<br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7812ApCoCoA-1:GLPK.LPSolve2008-11-13T12:39:16Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable.<br />
<br />
<em>Methode</em>: You can choose between the inner-point-method (InnerP) or the simplex-algorithm (Simplex). <br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
When you execute the package, you had to specify the path of the LP solver glpsol, i.e. GlpsolPath:="/usr/bin/";<br />
and the working path, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.LPSol(OF, LE, GE, Bounds, Simplex, Max);<br />
<br />
And we achieve x = 8/3 and y = 4.<br />
</example><br />
<br />
[[Image:LinOpt,jpg]]<br />
<br />
<br />
<br />
<example><br />
<em>Linear programming example 1996 MBA exam</em><br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
</example><br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
</description><br />
<br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7810ApCoCoA-1:GLPK.LPSolve2008-11-12T21:30:01Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable.<br />
<br />
<em>Methode</em>: You can choose between the inner-point-method (InnerP) or the simplex-algorithm (Simplex). <br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
When you execute the package, you had to specify the path of the LP solver glpsol, i.e. GlpsolPath:="/usr/bin/";<br />
and the working path, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
Use S::=Q[x,y];<br />
$GLPK.LPSol(OF, LE, GE, Bounds, Simplex, Max);<br />
<br />
And we achieve x = 8/3 and y = 4.<br />
</example><br />
<br />
<br />
<br />
<example><br />
<em>Linear programming example 1996 MBA exam</em><br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
</example><br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
</description><br />
<br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7809ApCoCoA-1:GLPK.LPSolve2008-11-12T21:21:45Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable.<br />
<br />
<em>Methode</em>: You can choose between the inner-point-method (InnerP) or the simplex-algorithm (Simplex). <br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
When you execute the package, you had to specify the path of the LP solver glpsol, i.e. GlpsolPath:="/usr/bin/";<br />
and the working path, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
GLPK.LPSol(OF, LE, GE, Bounds, Simplex, Max);<br />
<br />
And we achieve x = 8/3 and y = 4.<br />
</example><br />
<br />
<br />
<br />
<example><br />
<em>Linear programming example 1996 MBA exam</em><br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
</example><br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
</description><br />
<br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7808ApCoCoA-1:GLPK.LPSolve2008-11-12T21:19:03Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable.<br />
<br />
<em>Methode</em>: You can choose between the inner-point-method (InnerP) or the simplex-algorithm (Simplex). <br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
When you execute the package, you had to specify the path of the LP solver glpsol, i.e. GlpsolPath:="/usr/bin/";<br />
and the working path, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss a rather easy example. <br />
<example><br />
We want to maximize the Function y = - 1/2x, with the two conditions y ≤ 6 - 3/4x and y ≥ 1 - x and the bounds 0 ≤ x ≤ 6 and 1/3 ≤ y ≤ 4.<br />
<br />
We prename the input of GLPK.LPSol-function.<br />
OF := 1/2x + y;<br />
LE := 3/4x + y - 6;<br />
GE := x + y - 1;<br />
Bounds:=[[0,6], [1/3,4]];<br />
<br />
Then we compute the solution with<br />
GLPK.LPSol(OF, LE, GE, Bounds, Simplex, Max);<br />
<br />
And we achieve <br />
</example><br />
<br />
<br />
<br />
<example><br />
<em>Linear programming example 1996 MBA exam</em><br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
</example><br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
</description><br />
<br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7807ApCoCoA-1:GLPK.LPSolve2008-11-12T17:23:27Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable.<br />
<br />
<em>Methode</em>: You can choose between the inner-point-method (InnerP) or the simplex-algorithm (Simplex). <br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
When you execute the package, you had to specify the path of the LP solver glpsol, i.e. GlpsolPath:="/usr/bin/";<br />
and the working path, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
First we want to discuss rather easy example. <br />
<example><br />
<br />
</example><br />
<br />
<br />
<br />
<example><br />
<em>Linear programming example 1996 MBA exam</em><br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
</example><br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
</description><br />
<br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7806ApCoCoA-1:GLPK.LPSolve2008-11-12T17:18:13Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable.<br />
<br />
<em>Methode</em>: You can choose between the inner-point-method (InnerP) or the simplex-algorithm (Simplex). <br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
When you execute the package, you had to specify the path of the LP solver glpsol, i.e. GlpsolPath:="/usr/bin/";<br />
and the working path, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
<br />
<br />
<br />
<example><br />
<em>Linear programming example 1996 MBA exam</em><br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
</example><br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
</description><br />
<br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7805ApCoCoA-1:GLPK.LPSolve2008-11-12T17:17:22Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable.<br />
<br />
<em>Methode</em>: You can choose between the inner-point-method (InnerP) or the simplex-algorithm (Simplex). <br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
When you execute the package, you had to specify the path of the LP solver "glpsol", i.e. GlpsolPath:="/usr/bin/";<br />
and the working path, i.e. WorkingPath:="/home/user/";<br />
<br />
<br />
<br />
<br />
<br />
<example><br />
<em>Linear programming example 1996 MBA exam</em><br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
</example><br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
</description><br />
<br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7799ApCoCoA-1:GLPK.LPSolve2008-11-12T16:42:06Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>: List of lists with two elements. Each List contains the lower and upper bounds for each variable.<br />
<br />
<em>Methode</em>: You can choose between the inner-point-method (InnerP) or the simplex-algorithm (Simplex). <br />
<br />
<em>MinMax</em>: Minimization (Min) or maximization (Max), that's the question.<br />
<br />
<br />
<example><br />
<em>Linear programming example 1996 MBA exam</em><br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
</example><br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
</description><br />
<br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7795ApCoCoA-1:GLPK.LPSolve2008-11-12T16:09:06Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A linear polynomial which is equivalent to the linear objective Function.<br />
<br />
<em>EQ_Polynomials</em>: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<em>LE_Polynomials</em>: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.<br />
<br />
<em>GE_Polynomials</em>: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.<br />
<br />
<em>Bounds</em>:<br />
<br />
<em>Methode</em>:<br />
<br />
<em>MinMax</em>:<br />
<br />
<br />
<example><br />
<em>Linear programming example 1996 MBA exam</em><br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
</example><br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
</description><br />
<br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7792ApCoCoA-1:GLPK.LPSolve2008-11-12T15:13:38Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolv(Objective_Function:POLYNOM, EQ_Polynoms:LIST, LE_Polynoms:LIST, GE_Polynoms:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A polynomial which is equivalent to the linear objective Function.<br />
<em>EQ_Polynoms</em>: List of Polinomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<br />
<example><br />
<em>Linear programming example 1996 MBA exam</em><br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
</example><br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
</description><br />
<br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Package_GLPK</wiki-category><br />
</command></div>StKhttp://apcocoa.uni-passau.de/wiki/index.php?title=ApCoCoA-1:GLPK.LPSolve&diff=7791ApCoCoA-1:GLPK.LPSolve2008-11-12T15:04:54Z<p>StK: </p>
<hr />
<div><command><br />
<title>LPSolve</title><br />
<short_description>solve linear programms</short_description><br />
<syntax><br />
GLPK.LPSolv(Objective_Function:POLYNOM, EQ_Polynoms:LIST, LE_Polynoms:LIST, GE_Polynoms:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)<br />
</syntax><br />
<description><br />
<br />
The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.<br />
The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.<br />
<br />
<em>Objective_Function</em>: A polynomial which is equivalent to the linear objective Function.<br />
<em>EQ_Polynoms</em>: List of Polinomials, which are equivalent to the equality-part in the list of conditions.<br />
<br />
<br />
<example><br />
<em>Linear programming example 1996 MBA exam</em><br />
<br />
A cargo plane has three compartments for storing cargo: front, centre and rear. <br />
These compartments have the following limits on both weight and space:<br />
<br />
Compartment Weight capacity (tonnes) Space capacity (cubic metres)<br />
Front 10 6800<br />
Centre 16 8700<br />
Rear 8 5300<br />
<br />
Furthermore, the weight of the cargo in the respective compartments must be the same <br />
proportion of that compartment's weight capacity to maintain the balance of the plane.<br />
<br />
The following four cargoes are available for shipment on the next flight:<br />
<br />
Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)<br />
C1 18 480 310<br />
C2 15 650 380<br />
C3 23 580 350<br />
C4 12 390 285<br />
<br />
Any proportion of these cargoes can be accepted. The objective is to determine how much <br />
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each <br />
among the compartments so that the total profit for the flight is maximised. <br />
</example><br />
<br />
To solve this problem we had to compose a linear program.<br />
<br />
</description><br />
<br />
<types><br />
<type>cocoaserver</type><br />
</types><br />
<key>lpsolve</key><br />
<key>solve linear programm</key><br />
<key>solve lp</key><br />
<key>jbrandt</key><br />
<key>skuehling</key><br />
<wiki-category>Optimization_Problems</wiki-category><br />
</command></div>StK