# ApCoCoA-1:GLPK.LPSolve

## LPSolve

solve linear programms

### Syntax

```GLPK.LPSolv(Objective_Function:POLYNOM, EQ_Polynomials:LIST, LE_Polynomials:LIST, GE_Polynomials:LIST, Bounds:LIST, Methode:STRING, MinMax:STRING)
```

### Description

The basic idea behind this package is to make the linear optimization program GLPK usable in/with ApCoCoA.

The package GLPK contains various functions that let you make use of the GLPK library, rather the stand-alone LP/MIP Solver glpsol.

Objective_Function: A linear polynomial which is equivalent to the linear objective Function.

EQ_Polynomials: List of linear polynomials, which are equivalent to the equality-part in the list of conditions.

LE_Polynomials: List of linear polynomials, which are equivalent to the lower or equal-part in the list of conditions.

GE_Polynomials: List of linear polynomials, which are equivalent to the greater or equal-part in the list of conditions.

Bounds: List of lists with two elements. Each List contains the lower and upper bounds for each variable.

Methode: You can choose between the inner-point-method (InnerP) or the simplex-algorithm (Simplex).

MinMax: Minimization (Min) or maximization (Max), that's the question.

When you execute the package, you had to specify the path of the LP solver glpsol, i.e. GlpsolPath:="/usr/bin/";

and the working path, i.e. WorkingPath:="/home/user/";

First we want to discuss a rather easy example.

#### Example

```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.

We prename the input of GLPK.LPSol-function.
OF := 1/2x + y;
LE := 3/4x + y - 6;
GE := x + y - 1;
Bounds:=[[0,6], [1/3,4]];

Then we compute the solution with
GLPK.LPSol(OF, LE, GE, Bounds, Simplex, Max);

And we achieve
```

#### Example

```<em>Linear programming example 1996 MBA exam</em>

A cargo plane has three compartments for storing cargo: front, centre and rear.
These compartments have the following limits on both weight and space:

Compartment   Weight capacity (tonnes)   Space capacity (cubic metres)
Front         10                         6800
Centre        16                         8700
Rear          8                          5300

Furthermore, 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.

The following four cargoes are available for shipment on the next flight:

Cargo   Weight (tonnes)   Volume (cubic metres/tonne)  Profit (£/tonne)
C1      18                480                          310
C2      15                650                          380
C3      23                580                          350
C4      12                390                          285

Any proportion of these cargoes can be accepted. The objective is to determine how much
(if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each
among the compartments so that the total profit for the flight is maximised.
```

To solve this problem we had to compose a linear program.