Sunteți pe pagina 1din 14

Introduction

Introduction to Linear Programming


► Outline - brief introduction to…
and Integer Linear Programming
§ Modeling
§ Linear Programming
RMIT, Melbourne, Australia § Integer Linear Programming
§ Solution Methods for LP and ILP

Helena Ramalhinho Lourenço § AMPL

LP & ILP introduction 1 LP & ILP introduction 2

Real
Problem
OR Methodology Linear Programming

Data Analysis ► Linear programming (LP) is a widely used mathematical


Set of Models
Decision-maker

modeling technique designed to help managers in


Optimization Model
planning and decision making relative to resource
Solution Methods
Results & Interpretation allocation.
► Integer Linear Programming (ILP)
Simulation
§ An integer programming model is one where one or more of the
decision variables has to take on an integer or binary values in
Solution & Analysis the final solution.
OR provides many methods

Scenarios
and techniques to analyze ► Combinatorial Optimization (next)
the consequences of decisions
Make a decision before their introduction to
reality.
LP & ILP introduction 3 LP & ILP introduction 4

OR Methodology OR Methodology

► Identify a problem ► Identify the problem


► Get to know the problem context (get Data) § Describe in detail the problem, and identify all the components.
§ Identify the qualitative and quantitative aspects of the problem.
► Build a Model (Mathematical Model)
► Obtain a solution to the model (Algorithm) ► Get to know the problem context
§ Identify the relationships of the problem with the context of the
► Understand the solution the real context organization.
► Take the decision § Obtain the relevant data.
§ Verify the data.

LP & ILP introduction 5 LP & ILP introduction 6

© Helena Ramalhinho-Lourenço, (2019)


1
OR Methodology OR Methodology

► Build a model ► Obtain a solution to the model


§ A Model is an abstract representation of a real world system § Which are the adequate solution methods to be applied to the
§ Simplification is the very essence of Modeling model?
§ Which components should be included in the model? * Exact Methods
§ Types of models: * Heuristics and Metaheuristics
• Linear programming § Which is the best software to be applied?
• Integer Linear Programming * Commercial software
• Combinatorial Optimization
* Algorithm design and code
• Networks
• Non-linear
• Simulation
• Etc.

LP & ILP introduction 7 LP & ILP introduction 8

OR Methodology Linear Programming

► Understand the solution the real context ► Linear programming (LP) is a widely used mathematical
§ Does the solution obtained makes sense in the real life? modeling technique designed to help managers in
§ Did we have considered all relevant components? planning and decision making relative to resource
► Take the decision allocation.
§ Evaluate the impact of the solution
§ Evaluate the decision process (model + method)
§ Review frequently the impact of the decision.

LP & ILP introduction 9 LP & ILP introduction 10

Linear Programming Linear Programming

► The Linear Programming Models have 4 properties in ► Formulating a linear program involves developing a
common: mathematical model to represent the managerial problem.
§ All problems seek to maximize or minimize some quantity (the ► The steps in formulating a linear program are:
objective function). § Completely understand the managerial problem being faced.
§ Restrictions or constraints that limit the degree to which we can
§ Identify the objective and the constraints.
pursue our objective are present.
§ Define the decision variables.
§ There must be alternative courses of action from which to choose.
§ Use the decision variables to write mathematical expressions for
§ The objective and constraints in problems must be expressed in the objective function and the constraints.
terms of linear equations or inequalities.

LP & ILP introduction 11 LP & ILP introduction 12

© Helena Ramalhinho-Lourenço, (2019)


2
Linear Programming Methodology Example 2: Call Center

► Understand well the problem (by words) ► A call center is hiring personnel since it is
§ What is the problem expanding to a 24h working period.
§ What is the decision we have to take? Can we make quantitative?
§ The call center works 24h a day, and needs personnel to
§ What are the constraints on the decisions?
attend the customers every hour.
§ What is the objective or how we are going to evaluate the solution?
§ The human recourses and the operations directors have
► Define the decision variables (math) estimate the number of persons in each interval of time.
► Define the constraints on the variables (math) § There are 6 intervals of time (4 hours each).
► Define the objective function (math) § The contract of the new employees is for 8h in a row.

► Solve it!!!

LP & ILP introduction 13 LP & ILP introduction 14

Example 2: Call Center Example 2: Call Center

► Need of additional employees for ofinterval


Interval times of time: ► Describe the problem by words.
§ What is the problem?
Period 1 2 3 4 5 6
§ What is the decision we have to take? Can we make quantitative?
0:00 – 4:00 – 8:00 – 12:00 – 16:00 – 20:00 –
4:00 h 8:00 h 12:00 h 16:00 h 20:00 h 24:00 h § What are the constraints on the decisions?
Employees § What is the objective or how we are going to evaluate the
needed
9 8 3 7 5 4 solution?

► Which is the minimal number of employees that should be


hired?

LP & ILP introduction 15 LP & ILP introduction 16

Example 2: Call Center Ejemplo 1: Personal laboratorio

► Define the decision variables: ► Define the constraints


§ Number of employees to be hired to start at the beginning of § In period 1, there is the need of 9 employees…
period 1 (x1) § In period 2, there is the need of 8 employees…
§ Number of employees to be hired to start at the beginning of § In period 3, there is the need of 3 employees…
period 2 (x2) § …
Periods
1 2 3 4 5 6
§ Number of employees to be hired to start at the beginning of 0:00-4:00 4:00-8:00 8:00-12:00 12:00-16:00 16:00-20:00 20:00-24:00

period 3 (x3) 0:00 X1 X1


4:00 X2 X2
§ Number of employees to be hired to start at the beginning of 8:00 X3 X3
12:00 X4 X4
period 4 (x4)
16:00 X5 X5
§ … 20:00 X6 X6
Personnel ≥ ≥ ≥ ≥ ≥ ≥
9 8 3 7 5 4

LP & ILP introduction 17 LP & ILP introduction 18

© Helena Ramalhinho-Lourenço, (2019)


3
Example 2: Call Center Example 2: Call Center

► The constraints… ► Define the constraints:


§ The number of persons that start at beginning of period 1 + the § X6 + X1 ≥ 9
ones that continue from period 6 must be greater or equal to 9: § X1 + X2 ≥ 8
* X6 + X1 ≥ 9 § X2 + X3 ≥ 3
§ The number of persons that start at beginning of period 2 + the § X3 + X4 ≥ 7
ones that continue from period 1 must be greater or equal to 8.
§ X4 + X5 ≥ 5
* X1 + X2 ≥ 8
§ X5 + X6 ≥ 4
§ …
§ Xj ≥ 0, j= 1,...,6.

LP & ILP introduction 19 LP & ILP introduction 20

Example 2: Call Center Example 2: Call Center

► Define the objective function ► The complete model


► Min Z= X1 + X2 + X3 + X4 + X5 + X6 ► Min Z= X1 + X2 + X3 + X4 + X5 + X6
§ Subject to:
* X6 + X1 ≥ 9
* X1 + X2 ≥ 8
* X2 + X3 ≥ 3
* X3 + X4 ≥ 7
* X4 + X5 ≥ 5
* X5 + X6 ≥ 4
* Xj ≥ 0, j= 1,...,6.

LP & ILP introduction 21 LP & ILP introduction 22

Solution Methods Solution Methods

► Obtain the optimal solution of the LP Model ► LINEAR PROGRAMMING SOFTWARE SURVEY
► Exact Method § https://www.informs.org/ORMS-Today/Public-Articles/June-
Volume-44-Number-3/Linear-Programming-Software-Survey
§ The PL models are “easy” to be solved
§ June 2017
§ Simplex Method (Dantzig 1947)
* https://www.informs.org/ORMS-Today/OR-MS-Today-Software-
* Primal simplex
Surveys/Linear-Programming-Software-Survey
* Dual simplex
§ Vendors
§ Interior Point Method (Karmarkar 1984)
* GLPK (GNU Linear Programming Kit), Gurobi Optimizer, IBM ILOG
§ ALGORITMS / SOFTWARE CPLEX Optimization Studio, LINDO & LINGO, Premium Solver Pro,
* Excel Solver etc
* Commercial Software § Prices
* Open Software * Free to $4000/licence
LP & ILP introduction 23 LP & ILP introduction 24

© Helena Ramalhinho-Lourenço, (2019)


4
Simplex Method Simplex Method

► Dantzig (1947) ► In Euclidean space, an object is convex if for every pair of


§ The set of solutions is a convex set. points within the object, every point on the straight
§ If there is a optimal solution, there exist an optimal solution in a line segment that joins them is also within the object.
corner point (or extreme point)
§ An extreme point always have at least two adjacent extreme
points.
§ If a extreme point has no adjacent extreme points with better value
for the objective function, then it is the optimal solution.

LP & ILP introduction 25 LP & ILP introduction 26

Simplex Method Simplex Method

► Basic theorem ► Example of Linear Programming


Maximizar Z = 60x1 + 40x2
► If exist a optimal solution there exist one in a extreme
sa
point. x1 + x2 £ 8
► Simplex method 2 x2 £12
§ Look only in the extreme point (or corner points of the polytope) 4 x1 + 2 x2 £ 22
§ There are a finite number of extreme points x1 ³ 0, x2 ³ 0

LP & ILP introduction 27 LP & ILP introduction 28

Only five extreme


Infinite number of points
feasible solutions

LP & ILP introduction 29 LP & ILP introduction 30

© Helena Ramalhinho-Lourenço, (2019)


5
Simplex Method Initialization
Find initial feasible
extreme-point solution

Look for the optimal ► An iterative procedure


solution in the 5 § Move from extreme
extreme/corner
point to extreme point Is the current Yes
points feasible extreme- Stop
§ Optimality test in the point solution
the actual
optimal? solution is
Simplex Method: optimal
* If a extreme-corner No
solution has no
adjacent solutions that
Move to a better
are better, then it must adjacent feasible extreme-point
be an optimal solution solution

LP & ILP introduction 31 LP & ILP introduction 32

step 1. Solution (0,0) step 2. Adjacent


with z=0. solution(0,6) with
z=240.

LP & ILP introduction 33 LP & ILP introduction 34

Step 3. Adjacent
solution(2,6) with Step 4. Adjacent
z=360 solution (3,5) with
z=380

LP & ILP introduction 35 LP & ILP introduction 36

© Helena Ramalhinho-Lourenço, (2019)


6
z=360

Step 5. Adjacent z=380


solution (5.5,0) with
z=330 z=330

LP & ILP introduction 37 LP & ILP introduction 38

Excel Solver

Objective function cell


So, (3,5) is the Variables (changing cells)
optimal solution with
Paso 4. Solución
z=380!! Constraints
adyacente (0,5.5)
entonces z=330

LP & ILP introduction 39 LP & ILP introduction 40

Example 2: Call Center Example 2: Call Center

► Need of additional employees for ofinterval


Interval times of time: ► The complete model
Period 1 2 3 4 5 6 ► Min Z= X1 + X2 + X3 + X4 + X5 + X6
§ Subject to:
0:00 – 4:00 – 8:00 – 12:00 – 16:00 – 20:00 –
4:00 h 8:00 h 12:00 h 16:00 h 20:00 h 24:00 h * X6 + X1 ≥ 9
Employees * X1 + X2 ≥ 8
needed
9 8 3 7 5 4 * X2 + X3 ≥ 3
* X3 + X4 ≥ 7
* X4 + X5 ≥ 5
► Which is the minimal number of employees that should be
* X5 + X6 ≥ 4
hired?
* Xj ≥ 0, j= 1,...,6.

LP & ILP introduction 41 LP & ILP introduction 42

© Helena Ramalhinho-Lourenço, (2019)


7
Excel Solver Excel Solver Objective function
Z= X1 + X2 + X3 + X4 +
Objective function X5 + X6
► Min Z= X1 + X2 + X3 + X4 + X5
Función
► Excel file Objetivo min ∑ X
Variables
min 0
+ X6 Función
Variables:
Objetivo min ∑ X
► Specify where to X1 0
X 1,X 2 ,X 3 ,X 4 , X 5 ,X 6 min 0

► Sujeto a:
X2 0
X3 0
locate …
X1 0
X4 0 X2 0
X5 Constraints
0 X6 + X1 ≥ 9 X3 0
X6 0
§ parameters Parameters
X1 + X2 ≥ 8
X4
X5
0
0
Restricciones
Constraints X6 0
Parameters
§ variables X6 + X1 ≥ 9
X1 + X2 ≥ 8
0 >=
0 >=
9
8 X2 + X3 ≥ 3 Restricciones
X2 + X3 ≥ 3 0 >= 3 X6 + X1 ≥ 9 0 >= 9
§ constraints X3 + X4 ≥ 7 0 >= 7 X3 + X4 ≥ 7 X1 + X2 ≥ 8 0 >= 8
X4 + X5 ≥ 5 0 >= 5 X2 + X3 ≥ 3 0 >= 3
X5 + X6 ≥ 4 0 >= 4
X4 + X5 ≥ 5 X3 + X4 ≥ 7 0 >= 7
§ Objective function X4 + X5 ≥ 5 0 >= 5
X5 + X6 ≥ 4 X5 + X6 ≥ 4 0 >= 4

X j ≥ 0, j= 1,...,6.
=B4+B5

LP & ILP introduction 43 LP & ILP introduction 44

Excel Solver Example 2: Call Center


Objective Function min ∑ X
Función
min 19

► Excel file
Objetivo min ∑ X
min 0 X1 8
X2 0
X1
X2
0
0 § callcenter.xlsx X3 5
X3 0 X4 2
X4 0 X5 3
X5 0
X6 1
X6 0

Restricciones Constraints
X6 + X1 ≥ 9 0 >= 9 X6 + X1 ≥ 9 9 >= 9
X1 + X2 ≥ 8 0 >= 8
X1 + X2 ≥ 8 8 >= 8
X2 + X3 ≥ 3 0 >= 3
X3 + X4 ≥ 7 0 >= 7
X2 + X3 ≥ 3 5 >= 3
X4 + X5 ≥ 5 0 >= 5
Minimize X3 + X4 ≥ 7 7 >= 7
X5 + X6 ≥ 4 0 >= 4 X4 + X5 ≥ 5 5 >= 5
X5 + X6 ≥ 4 4 >= 4

LP & ILP introduction 45 LP & ILP introduction 46

Example 2: Call Center Integer Linear Programming

► We need to hired 19 employees


Interval of times ► Not every problem faced by businesses can easily be
modeled as linear programming model…
Period 1 2 3 4 5 6

0:00 – 4:00 – 8:00 – 12:00 – 16:00 – 20:00 –


► A large number of decision problems can be solved only if
4:00 h 8:00 h 12:00 h 16:00 h 20:00 h 24:00 h variables have integer values.
Employees
needed
9 8 3 7 5 4
► Examples?

Empoyees
working
8+1 0+8 5+0 2+5 3+2 1+3

LP & ILP introduction 47 LP & ILP introduction 48

© Helena Ramalhinho-Lourenço, (2019)


8
Integer Programming Example:
Integer Programming
Car rental Flipcar
► An integer programming model is one where one or more ► Flipcar, a car rental company, is planning to offer
of the decision variables has to take on an integer value in electrical cars to its clients.
the final solution. ► The choice is limited to two models, and the manager
► An integer variable that can only take a value equal to 0 or wishes to decide on how many cars of each type to buy, if
to 1 is called binary variable § There is limited parking space for charging the cars
§ Pure integer programming where all variables have integer values. § There is a budget limit
§ Mixed-integer programming where some but not all of the § The maintenance services of the company has limited capacity
variables will have integer values. ► The goal is to maximize profits.
§ Zero-one integer programming are special cases in which all the
decision variables must have integer solution values of 0 or 1.

LP & ILP introduction 49 LP & ILP introduction 50

Integer programming Approaches for solving the problem

Max Z =X1+ 1.4X2 ► Solve the LP relaxation


s.a. § Forget about the integer constraints
X1 + 0.5X2 £ 6 Max Z =X1+ 1.4X2
0,5X1 + X2 £ 5.5 s.a.
X1 + X2 £ 6.8 X1 + 0.5X2 £ 6
0,5X1 + X2 £ 5.5
X1, X2 >= 0 and integer X1 + X2 £ 6.8
X1, X2 ≥ 0
Being
§ What is the solution?
X1 = Number of electrical cars of type 1 to buy § Can you round the solution?
X2 = Number of electrical cars of type 2 to buy
LP & ILP introduction 51 LP & ILP introduction 52

Approaches for solving the problem Branch and Bound algorithm X2


4,2
P0

P0
Z = 8,5; 2,6 X1
► Solve the LP relaxation and round-off values X1 = 2,6 X2 = 4,2

X2 P1 X2 P2
§ Rounding may provide with a non-optimal solution. P1 P2 4,5
3,8
P0 + X 1 £ 2 P0 + X 1 ³ 3
§ Rounding may provide non-feasible solutions. Z1 = 8,3 Z2 = 8,3
X1 = 2 X2 = 4,5 X1 = 3 X2 = 3,8

► Enumerate all possible solutions 2 X1 3 X1

§ Enumeration is generally not possible for large problems. P11 P12 P21 P22
X2 P11 X2
5
P12 X2 P21 X2 P22

P1 + X 2 £ 4 P1 + X2 ³ 5 P2 + X 2 £ 3 P1 + X 2 ³ 4 4 No
► Use Branch-and-bound algorithm Z11 = 7,6
X1 = 2 X2 = 4
Z12 = 8,0
X1 = 1 X2 = 5
Z21 = 8,0
X1 = 3,8 X2 = 3
3 factible

Discarded Discarded Discarded

… Z12 < Z11 Optimal Infeasible solution 2 X1 1 X1 3,8 X1 X1


LP & ILP introduction 53 LP & ILP introduction 54

© Helena Ramalhinho-Lourenço, (2019)


9
Product-mix planning in an Airplane Plant Product-mix planning in an Airplane Plant

► You’re the manager of an airplane plant and you want to ► The profit and fixed costs are given in the following table:
determine the best product-mix of your six models to
Plane Profit Setup
produce. The six models currently under production are
Rocket 30 35
the Rocket, Meteor, Streak, Comet, Jet, and Biplane.
Meteor 45 20
Each plane has a known profit contribution. There is also
Streak 24 60
a fixed cost associated with the production of any plane in
Comet 26 70
a period.
Jet 24 75
Biplane 30 30

Source: Optimization Modeling with Lingo. LP & ILP introduction 55 Source: Optimization Modeling with Lingo. LP & ILP introduction 56

Product-mix planning in an Airplane Plant Product-mix planning in an Airplane Plant

► Each plane is produced using six raw materials—steel, ► The problem is to determine the final mix of products that
copper, plastic, rubber, glass, and paint. maximizes net profit (gross profit – setup costs) without
► The units of these raw materials required by the planes as exceeding the availability of any raw material.
well as the total availability of the raw materials are: ► Your brand new Meteor model has the highest profit per
Rocket Meteor Streak Comet Jet Biplane Available unit of anything you’ve ever manufactured and the lowest
Steel 1 4 0 4 2 1 800 setup cost.
Copper 4 5 3 0 1 0 1160
► Maybe you should build nothing but Meteors? Then again,
Plastic 0 3 8 0 1 0 1780
Rubber 2 0 1 2 1 5 1050
maybe not.
Glass 2 4 2 2 2 4 1360
Paint 1 4 1 4 3 4 1240

LP & ILP introduction 57 LP & ILP introduction 58

Product-mix planning in an Airplane Plant Binary variables


Qi = Quantity to be produced of airplane i; (i = 1(Rocket),...,6 (Biplane))
► Model ì1 if plane i is build.
Bi = íï for (i = 1(Rocket),...,6 (Biplane))
► Binary variables add a new layer of flexibility in modeling
ïî0 if plane is not build.
6
real situations where appears selections, choices or other
MAX Z = ∑ ( profiti *Qi − setupi * B i )
i=1
conditions.
s.t.
6
► There are several prototype problems such as:
∑ usage ij *Qi ≤ available j for j = 1,..., 6 (raw materials) § Location problems
i=1

Qi ≤ M * Bi for i = 1,..., 6 (planes) § Routing problems


Qi ≥ 0 and integer; Bi binary
Rocket Meteor Streak Comet Jet Biplane Available § Set covering problems
Steel 800 200 10000 200 400 800 800
Copper 290 232 386.6667 10000 1160 10000 1160 § Scheduling problems
Plastic 10000 593.3333 222.5 10000 1780 10000 1780
Rubber 525 10000 1050 525 1050 210 1050 § and many, many more …
What is the value of M? Glass
Paint
680
1240
340
310
680
1240
680
310 413.3333
680 340
310
1360
1240
400 290 200 222.5 200 400 210

LP & ILP introduction 59 LP & ILP introduction 60

© Helena Ramalhinho-Lourenço, (2019)


10
Algebraic Modeling Languages Mathematical Programming Languages

► High-level computer programming languages for ► AIMMS


describing and solving mathematical optimization ► AMPL
problems.
► GAMS
► Advantages ► LINGO
§ Computer model resembles mathematical notation
► OPL ide (CPLEX)
§ Faster modeling cycles
§ Modeling and future maintenance becomes easier and more
► MOSEL-XPRESS
reliable. ► CMPL COIN-OR (open source)
§ Direct change of solver ► …
§ No need to know specifics from each solver
§ Easy deployment for real-sized large-scale problems
LP & ILP introduction 61 LP & ILP introduction 62

AMPL AMPL workflow

► www.ampl.com
Symbolic model file Data file
§ http://ampl.com/products/ampl/ampl-for-students/
(.mod) (.dat)
§ Student version is limited to 300 variables and 300 constraints and
objectives
► Download the student version (amplcml.zip)
AMPL Solution
§ AMPL program (ampl.exe)
(.run) Report
§ Solver Gurobi (gurobi.exe) LP & MIP
§ Solver CPLEX (cplex.exe) LP & MIP & QP
§ Solver MINOS (minos.exe) NLP
SOLVER
(Cplex, Gurobi, Minos, …)
LP & ILP introduction 63 LP & ILP introduction 64

Example: Call Center Example: Call Center

► A call center is hiring personnel since it is ► Need of additional employees for ofinterval
Interval times of time:
expanding to a 24h working period.
Period 1 2 3 4 5 6
§ The call center works 24h a day, and needs personnel to
0:00 – 4:00 – 8:00 – 12:00 – 16:00 – 20:00 –
attend the customers every hour. 4:00 h 8:00 h 12:00 h 16:00 h 20:00 h 24:00 h
§ The human recourses and the operations directors have Employees
estimate the number of persons in each interval of time. needed
9 8 3 7 5 4
§ There are 6 intervals of time (4 hours each).
§ The contract of the new employees is for 8h in a row.
► Which is the minimal number of employees that should be
hired?

LP & ILP introduction 65 LP & ILP introduction 66

© Helena Ramalhinho-Lourenço, (2019)


11
Example: Call Center Example: Call Center

► The complete model ► Model callcenter.mod


► Min Z= X1 + X2 + X3 + X4 + X5 + X6 § set EMPL := 1 .. 6;
§ Subject to: § var X {j in EMPL} >= 0;
* X6 + X1 ≥ 9 § minimize Total: sum {j in EMPL} X[j];
* X1 + X2 ≥ 8 § subject to Cap:X[6] + X[1] >= 9;
* X2 + X3 ≥ 3 § subject to Cap1:X[1] + X[2] >= 8;
* X3 + X4 ≥ 7 § subject to Cap2:X[2] + X[3] >= 3;
* X4 + X5 ≥ 5 § subject to Cap3:X[3] + X[4] >= 7;
* X5 + X6 ≥ 4
§ subject to Cap4:X[4] + X[5] >= 5;
* Xj ≥ 0, j= 1,...,6.
§ subject to Cap5:X[5] + X[6] >= 4;

LP & ILP introduction 67 LP & ILP introduction 68

Example: Call Center High Note Sound Company

► AMPL console ► .mod file (highnote.mod)


§ ampl: reset; var x1 >= 0; # Number of CD players to
§ ampl: model callcenter.mod; produce
§ option solver cplex; var x2 >= 0; # Number of stereo receivers
§ ampl: solve; to produce
§ CPLEX 12.8.0.0: optimal solution; objective 19
maximize Profit: 50*x1 + 120*x2;
6 dual simplex iterations (0 in phase I)

subject to Electrician: 2*x1 + 4*x2 <= 80;


subject to Technician: 3*x1 + x2 <= 60;

LP & ILP introduction 69 LP & ILP introduction 70

AMPL commands file AMPL

► .run file (highnote.run) ► AMPL console


§ ampl: include highnote.run;
reset;
§ CPLEX 12.6.1.0: sensitivity
option solver cplex;
§ CPLEX 12.6.1.0: optimal solution; objective 2400
option cplex_options 'sensitivity';
§ 1 dual simplex iterations (1 in phase I)
§ suffix up OUT;
model highnote.mod; § suffix down OUT;
solve; § suffix current OUT;
§ x1 = 0
display x1,x2; § x2 = 20
display Profit; § Profit = 2400
§ ampl:
LP & ILP introduction 71 LP & ILP introduction 72

© Helena Ramalhinho-Lourenço, (2019)


12
Good modeling practices High Note Sound Company

► Use meaningful names («production» not «x») ► highnote2.mod


# Symbolic data
► Use comments to describe any declaration set PRODUCT;
set PROCESS;
► Organize programs in a clear flow
param profit{i in PRODUCT};
param hours{j in PROCESS, i in PRODUCT};
param maxHours{j in PROCESS};

# Symbolic model
# Variables
var production{i in PRODUCT} >= 0;
# Objective
maximize Profit: sum{i in PRODUCT} profit[i]*production[i];

# Constraints
subject to ResourcesAvailable{j in PROCESS}:
sum{i in PRODUCT} hours[j,i]*production[i] <= maxHours[j];
LP & ILP introduction 73 LP & ILP introduction 74

High Note Sound Company High Note Sound Company

► highnote2.dat ► highnote2.run
data;
set PRODUCT:= CDplayer stereoRecv; # High Note Sound Company - Example 2
set PROCESS:= Electrician Technician; # Commands file ----------------------------------

param profit:= reset;


CDplayer 50 option solver cplex;
stereoRecv 120;
model highnote2.mod;
data highnote2.dat;
param hours: expand;
CDplayer stereoRecv:=
Electrician 2 4 solve;
Technician 3 1;
display production;
display Profit;
param maxHours:=
Electrician 80
Technician 60; LP & ILP introduction 75 LP & ILP introduction 76

Some AMPL keywords AMPL commands


display <value>;
► Declarations: ►

§ <value> is any set, parameter or variable of the model


§ set
§ Arranges the information into lists and tables.
§ param ► expand;
§ var § Displays the current instantiated model.

► Objectives: ► show;
§ Displays the names of the sets, parameters, variables, constraints, and
§ maximize objective function of current LP model.
§ minimize ► reset;

► Constraints: § Cleans the current working LP problem.


§ reset data; Keeps the models but cleans the data information.
§ subject to

LP & ILP introduction 77 LP & ILP introduction 78

© Helena Ramalhinho-Lourenço, (2019)


13
Real Problems..

► Many real problems do not have this property…


► Many real problems have a large-scale dimension
§ Large number of variables
§ Large number of constraints
§ Need to be solved in very short time…
► Metaheuristics need to be applied!
► Examples
* Location problems
* Routing problems
* Set covering problems
* Scheduling problems
LP & ILP introduction 79

© Helena Ramalhinho-Lourenço, (2019)


14

S-ar putea să vă placă și