the eplex library and hybrid forms involving eplex

97
The EPLEX Library and Hybrid Forms Involving EPLEX

Upload: clinton-hodges

Post on 17-Dec-2015

228 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: The EPLEX Library and Hybrid Forms Involving EPLEX

The EPLEX Libraryand Hybrid Forms Involving EPLEX

Page 2: The EPLEX Library and Hybrid Forms Involving EPLEX

Introduction

lib(eplex)

An interface between ECLiPSe and an external LP/MIP

solver XPRESS-MP, a product by Dash Associates CPLEX, a product by ILOG SA

Motivation to have this link: Use state-of-the-art linear programming tools Use ECLiPSe for modelling Build hybrid solvers

Implementation Tight coupling, using subroutine libraries

Page 3: The EPLEX Library and Hybrid Forms Involving EPLEX

Capabilities of these Solvers

Linear Programming Variables: continuous Constraints: linear (in)equalities Methods: Simplex (primal and dual), Newton Barrier

Quadratic Programming As LP, but quadratic terms in objective Methods: Newton Barrier

(Mixed) Integer Programming As LP, plus integrality constraints Methods: Branch-and-bound, cut generation

Page 4: The EPLEX Library and Hybrid Forms Involving EPLEX

Mathematical Programming

500

300

400

200

100

400

300

10

89

7

5

11

5

35

108

7

Plantcapacity

Clientdemand

Transportationcost

minimize10 A1 + 7 A2 + 11 A3 + 8 B1 + 5 B2 + 10 B3 + 5 C1 + 5 C2 + 8 C3 + 9 D1 + 3 D2 + 7 D3

subject toA1 + A2 + A3 = 200B1 + B2 + B3 = 400C1 + C2 + C3 = 300D1 + D2 + D3 = 100

A1 + B1 + C1 + D1 500A2 + B2 + C2 + D2 300A3 + B3 + C3 + D3 400

A

B

C

D

1

2

3

Objective Function

Constraints

Leads to a matrix:•Each row is one constraint•Each column is one variable

Page 5: The EPLEX Library and Hybrid Forms Involving EPLEX

Possible Uses From Within ECLiPSe

Black-box If problem is suitable for LP/QP/MIP as a whole But: Only one solution, non-incremental, rounding errors

Incrementality and multiple instances Results explicitly retrieved Multiple independent subproblems

Hybrid Solvers work on (possibly overlapping) subproblems Programmed cooperation strategy Data-driven triggering

Low-level interface

Page 6: The EPLEX Library and Hybrid Forms Involving EPLEX

General Usage

Loading: :- lib(eplex). Loads interface with default solver XPRESS-MP 14

Differences between the underlying solvers are largely hidden

Documentation ECLiPSe Library Manual Tutorial chapter on eplex Reference Manual

Page 7: The EPLEX Library and Hybrid Forms Involving EPLEX

Transportation Problem (black box solving)

:- lib(eplex).

main(Cost, Vars) :-Vars = [A1, A2, A3, B1, B2, B3, C1, C2, C3, D1, D2, D3],Vars :: 0.0..1.0Inf,

A1 + A2 + A3 $= 200,B1 + B2 + B3 $= 400,C1 + C2 + C3 $= 300,D1 + D2 + D3 $= 100,

A1 + B1 + C1 + D1 $=< 500,A2 + B2 + C2 + D2 $=< 300,A3 + B3 + C3 + D3 $=< 400,

optimize(min( 10*A1 + 7*A2 + 11*A3 + 8*B1 + 5*B2 + 10*B3 + 5*C1 + 5*C2 + 8*C3 + 9*D1 + 3*D2 + 7*D3), Cost).

Page 8: The EPLEX Library and Hybrid Forms Involving EPLEX

Eplex Constraints

Constraints Vars :: Min..Max Expr1 $= Epxr2 eplex:(Expr1 =:= Epxr2) Expr1 $>= Epxr2 eplex:(Expr1 >= Epxr2) Expr1 $=< Expr2 eplex:(Expr1 =< Epxr2) integers(Vars)

Linear expressions X 123 3.4 +Expr -Expr E1+E2 E1-E2 E1*E2 sum( ListOfExpr ) ListOfExpr1 * ListOfExpr2

Page 9: The EPLEX Library and Hybrid Forms Involving EPLEX

Be Aware of Conventions

In mathematical programming, non-negative variables are usually assumed as default

In ECLiPSe, the default is -1.0Inf .. 1.0Inf

Non-negative variables need to be declared, e.g. X :: 0.0 .. 1.0Inf

Page 10: The EPLEX Library and Hybrid Forms Involving EPLEX

Common Arithmetic Solver Interface

=:=/2

>=/2

=</2

>/2

</2

=\=/2

::/2

$::/2

$=/2

$>=/2

$=</2

#::/2 #\=/2

#= /2 $\=/2

#>=/2, #>/2

#=</2, #</2

$>/2 $</2

integers/1

reals/1

suspend

ic

eplex

std arith

Page 11: The EPLEX Library and Hybrid Forms Involving EPLEX

Black-box Optimizer

eplex:optimize(+Objective, -Cost)

Objective is min(Expr) or max(Expr) Runs the external solver as a black box Considers all $=, $>=, $=< constraints, their variables, the

variable bounds and the integers/1 constraints Computes an optimal solution for Objective Returns the cost Cost Instantiates the variables to the computed solution values Selects LP/QP/MIP depending on integers and

Objective

Page 12: The EPLEX Library and Hybrid Forms Involving EPLEX

Black-box use of LP and MIP solver A linear problem

?- X+Y $>= 3, X-Y $= 0, optimize(min(X),Cost).

Y=1.5

X=1.5

Cost=1.5

A mixed integer problem?- X+Y $>= 3, X-Y $= 0, integers([X]), optimize(min(X),Cost).

Y=2.0

X=2

Cost=2.0

X

Y

Cost

Page 13: The EPLEX Library and Hybrid Forms Involving EPLEX

Summary: eplex as black-box solver CLP modelling / LP or MIP solving

1. Do modelling and transformations in ECLiPSe 2. Load model into CPLEX/XPRESS/MP and solve using LP or MIP solver 3. Pass cost and solution values back to ECLiPSe

LP / MIP search

ECLiPSe External Solvervariables & bounds

cost

constraints

solution valuesX1 X2 ... Xm

=

=<

>=

= Cost

c1

c2

cn

Obj

Page 14: The EPLEX Library and Hybrid Forms Involving EPLEX

IC-Parc 14

Modelling with CLP Parameterised Constraints

product1(ProdQ,Raw1Q,Raw2Q) :-

ProdQ = 3*Raw1Q + 4*Raw2Q.

Define new constraints from Old Conjunction

conjCons(X) :- cons1(X), cons2(X). Disjunction

disjCons(X) :- cons1(X).

disjCons(X) :- cons2(X). Existential quantification

exqCons(X) :-

zeroOne(B), cons1(X,B),cons2(X,1-B).

Page 15: The EPLEX Library and Hybrid Forms Involving EPLEX

IC-Parc 15

Default Evaluation?- cons1(X,2).

cons1(X,Y) :- X$>=5, cons2(X,Y).

cons1(X,Y) :- X$=<0, cons2(X,Y).

cons2(X,Y) :- Y-X$=<2, X-Y$=<2.

CLP(R) Requirement Highly dynamic constraint solver: Add new variables and new constraints Repeatedly check global consistency Remove variables and constraints on backtracking

Consequence Constraint solving is costly

CLP(R)

Page 16: The EPLEX Library and Hybrid Forms Involving EPLEX

IC-Parc 16

Making CLP(R) Efficient

Fix the number of variables Fix the constraints Only change variable bounds

=>

Mixed Integer Programming

Page 17: The EPLEX Library and Hybrid Forms Involving EPLEX

IC-Parc 17

CLP Modelling, MIP Efficiency

Collect Constraints Parameterised constraint => Unfold Conjunction => Append Existential quantification => Keep variable Disjunction => ???

Pass to MIP Solver

Page 18: The EPLEX Library and Hybrid Forms Involving EPLEX

IC-Parc 18

A CLP(R) Model

solve(W,X,Y,Z) :-imp(X,W), imp(Y,W), two(X,Y,Z).

imp(X,Y) :- X=<Y.

two(X,Y,Z) :- and(X,Y).two(X,Y,Z) :- and(Y,Z).two(X,Y,Z) :- and(Z,X).

and(X,Y) :- X>=1, Y>=1.

?- solve(W,X,Y,Z), W=0.

Page 19: The EPLEX Library and Hybrid Forms Involving EPLEX

IC-Parc 19

Removing Disjunction from a CLP Model

solve(W,X,Y,Z) :-imp(X,W), imp(Y,W), two(X,Y,Z).

imp(X,Y) :- X=<Y.

two(X,Y,Z) :- and(X,Y).two(X,Y,Z) :- and(Y,Z).two(X,Y,Z) :- and(Z,X).

and(X,Y) :- X>=1, Y>=1.

?- solve(W,X,Y,Z), W=0.

solve(W,X,Y,Z, B) :-imp(X,W, B), imp(Y,W, B), two(X,Y,Z, B).

imp(X,Y, B) :- X=<Y+ 2-2*B.

two(X,Y,Z, B) :- [B1,B2,B3] :: 0..1,and(X,Y, B1), and(Y,Z, B2), and(Z,X, B3),B1+B2+B3 >= B.

and(X,Y, B) :- X+ 2-2*B >= 1, Y+ 2-2*B >= 1.

?- solve(W,X,Y,Z, 1), W=0.

Page 20: The EPLEX Library and Hybrid Forms Involving EPLEX

IC-Parc 20

Removing Disjunction from a CLP(R) Model

Add boolean to all predicates solve(W,X,Y,Z, B) :- imp(X,W, B), imp(Y,W, B), two(X,Y,Z, B).

Call the goal with extra boolean=1 ?- solve(W,X,Y,Z,1).

Add M*(1-B) to inequationsimp(X,Y, B) :- X=<Y+ 2-2*B.

Replace disjunction with boolean inequations two(X,Y,Z, B) :-

[B1,B2,B3] :: 0..1, and(X,Y, B1), and(Y,Z, B2), and(Z,X, B3),

B1+B2+B3 >= B.

Page 21: The EPLEX Library and Hybrid Forms Involving EPLEX

IC-Parc 21

The Small Steps from CLP(R) to MIP

(0) Input CLP(R) Model

(1) Remove DisjunctionsConjunctive CLP(R) Model

(2) UnfoldConjunction of linear constraints

(3) Send to different solversSolution!

Page 22: The EPLEX Library and Hybrid Forms Involving EPLEX

Problems with Black-Box Approach Solvable constraint class severely limited

Pure LP/QP/MIP Numerical problems

The external solvers use floating-point numbers, subject to rounding errors Other ECLiPSe solvers are usually precise (intervals or rational numbers) Instantiating the ECLiPSe variables to inexact values may cause other

implementations of the constraints to fail! Lack of incrementality

Cannot find alternative optima Cannot add constraints or variables

MIP search is a straightjacket A complex search process inside the black box Hard to control (via dozens of parameters) Hard to add problem-specific heuristics

Unsuitable for solver cooperation!

Page 23: The EPLEX Library and Hybrid Forms Involving EPLEX

Opening the Black Box

Code for optimize/2:

optimize(Objective, Cost) :-

eplex_solver_setup(Objective),

eplex_solve(Cost),

eplex_get(vars, VarVector),

eplex_get(typed_solution,SolutionVector),

VarVector = SolutionVector.

Page 24: The EPLEX Library and Hybrid Forms Involving EPLEX

Incrementality Solver setup

eplex_solver_setup(+Objective)

Run solver once eplex_solve(-Cost) Computes a solution with Cost but does not instantiate variables

Access solution information Status, solutions, reduced costs, dual values, slack, statistics, etc. eplex_get(+What, -Value) eplex_var_get(+Var, +What, -Value)

New constraints and variables can now be added and the problem re-solved!

Page 25: The EPLEX Library and Hybrid Forms Involving EPLEX

Traditional MIP branching

simplex solution:X = 4.2

X =< 4 X >= 5

At each node: Solve the continuous relaxation (ignoring integrality) with simplex Select an integer variable with fractional simplex solution Try two alternatives, with bounds forced to integers

Eventually, all variables will be narrowed to integers (if a solution exists)

Page 26: The EPLEX Library and Hybrid Forms Involving EPLEX

Doing MIP in ECLiPSe

:- lib(eplex), lib(branch_and_bound).

main :-<setup constraints>IntVars = <variables that should take integral values>,Objective $= <objective function>,eplex_solver_setup(min(Objective)),eplex_solve(RelaxedCost), % initial simplex solvingObjective $>= RelaxedCost % apply resulting cost boundminimize(mip_search(IntVars, CostVar), CostVar).

mip_search(IntVars, CostVar) :-...% for each X violating the integrality conditioneplex_var_get(X, solution, RelaxedSol),Split is floor(RelaxedSol),( X $=< Split ; X $>= Split+1 ), % choiceeplex_solve(RelaxedCost), % simplex re-solvingCostVar $>= RelaxedCost, % apply new cost bound...

no integrality constraints!

Page 27: The EPLEX Library and Hybrid Forms Involving EPLEX

Ok, but ...

Why run simplex once every time? there might be no significant change There might be more than one change

Solution: data-driven triggering, e.g. on instantiation instantiation far from relaxed solution bounds change bounds exclude relaxed solution

Page 28: The EPLEX Library and Hybrid Forms Involving EPLEX

Triggering the solver automatically eplex_solver_setup(+Objective, ?Cost, +Options, +TriggerModes)

Objective min(Expr) or max(Expr)

Cost variable - it does not get instantiated, but only bounded by the solution cost.

TriggerModes inst - if a variable was instantiated deviating_inst - if a variable was instantiated to a value that differs more

than a tolerance from its LP-solution bounds - if a variable bound was changed deviating_bounds - if a variable bound was changed such that its LP-

solution was excluded by more than a tolerance. new_constraint - when a new constraint appears <module>:<cond> - waking condition defined by other solver, e.g. ic:min trigger(Atom) - explicit triggering

Page 29: The EPLEX Library and Hybrid Forms Involving EPLEX

Using trigger conditions Example

?- X+Y $>= 3, X-Y $= 0, eplex_solver_setup(min(X), X, [], [inst]).

Y = Y{1.5}

X = X{1.5}

Delayed goals:

lp_demon(…)

Yes.

?- X+Y $>= 3, X-Y $= 0, eplex_solver_setup(min(X), X, [], [inst]), X=2.0.

Y = Y{2.0}

X = 2.0

Delayed goals:

lp_demon(…)

Yes.

Page 30: The EPLEX Library and Hybrid Forms Involving EPLEX

Eplex solver as compound constraint

X1 X2 ... Xm

=

=<

>=

= Cost

c1

c2

cn

Obj

solver

setup

ExternalSolver

Solver triggered by events, then:

• new bounds and constraints are sent to the external solver

• external solver is run

• cost bound (or failure) is exported

• solution values are exported and ECLiPSe variables annotated (optional)

Page 31: The EPLEX Library and Hybrid Forms Involving EPLEX

More Elegant Implementation of MIP

main :-<setup constraints>IntVars = <variables that should take integral values>,CostVar = <objective function>,eplex_solver_setup(min(Objective), CostVar, [], [bounds]),minimize(mip_search(IntVars), CostVar).

mip_search(IntVars) :-...% for each X violating the integrality conditioneplex_var_get(X, solution, RelaxedSol),Split is floor(RelaxedSol),( X $=< Split) ; X $>= Split+1 ), % choice...

No explicit simplex calls, no auxiliary parameters to search procedure Standard CLP search scheme - other choices/constraints can be added now

Page 32: The EPLEX Library and Hybrid Forms Involving EPLEX

Control Flow with Constraint Propagation

Search/Choice

Propagation phase

Search/Choice

constraints

Eplex instance demon can be integrated similar to a global constraint

eplex instances

Page 33: The EPLEX Library and Hybrid Forms Involving EPLEX

Hybridisation

Solver Cooperation in ECLiPSe

Page 34: The EPLEX Library and Hybrid Forms Involving EPLEX

Why Use Multiple Solvers?

Real problems comprise different subproblems Different solvers/algorithms suit different subproblems

Global reasoning can be achieved in different ways Linear solvers reason globally on linear constraints Domain solvers support application-specific global constraints

Solvers complement each other Optimisation versus feasibility New and adapted forms of cooperation (e.g. Linear relaxation as a heuristic)

Page 35: The EPLEX Library and Hybrid Forms Involving EPLEX

How to Use Multiple Solvers

Problem Decomposition Send subproblem constraints to subproblem solver e.g. Continuous/discrete circuits; Process scheduling

Redundant Solving Send a constraint to more than one solver e.g. Hoist scheduling; Progressive Party Problem

Page 36: The EPLEX Library and Hybrid Forms Involving EPLEX

Global Constructive Search Hybrid Forms

Root Node

Node1

Node2

Some of these leaf nodes are our solutions

Add constraintand wake solvers

Page 37: The EPLEX Library and Hybrid Forms Involving EPLEX

Cooperating Solvers: Intersecting Subproblems

X

Y

Z

C1

C2

Subproblem1 Subproblem2

Page 38: The EPLEX Library and Hybrid Forms Involving EPLEX

Cooperating Solvers: Copied Variables

X1

Y

Z

C1

C2

Solver1 Solver2

X2

Keep X1 and X2 in stepCommunicate eventsCommunicate information

Page 39: The EPLEX Library and Hybrid Forms Involving EPLEX

Cooperating Solvers: Copied Variables

X1

Y

Z

C1C2

Linear Solver Interval Solver

X2

Info on “X”

X1 >= 10.5

X >= 10.5

X2 >= 10.5X2 >= 11

X1 >= 11

integer(X2)X1 >= 10.5

X2 >= 11

Page 40: The EPLEX Library and Hybrid Forms Involving EPLEX

FD and Linear Solver Cooperation (within a Global Constructive Search)

Motivation Linking through Channeling Constraints Forms of Cooperation

Page 41: The EPLEX Library and Hybrid Forms Involving EPLEX

Motivation for FD Linear Comunication

Performance Behaviour

Page 42: The EPLEX Library and Hybrid Forms Involving EPLEX

IC-Parc 44

Motivation for FD Linear Communication:Performance FD

e.g. interval propagation more general constraints handle integers directly Favourable example:

Variable Bounds: [X1,…,X100] :: 1..100

Previous Constraints: X1 < X2 , … , X98 < X99 Resulting Bounds: X1 :: 1..2, …, X99 :: 99..100

New Constraint: X1 >= 3 Result (1 step): failure!

Linear e.g. Simplex, Gauss restricted class of constraints finds optimum without search Favourable example:

Variable Bounds: [X1,X2] :: 1..100

New Constraints: X1 > X2, X2 > X1 Result (1 step): failure!

Page 43: The EPLEX Library and Hybrid Forms Involving EPLEX

IC-Parc

FD and Linear Constraint Solving Performance

Add N variables and trivial constraints N = 100, 200, 500, 1000, 2000, 5000, 10,000, 20,000, 50,000

The Constraints for each variable X[J] do

X[J]::1..N, X[J] >= X[J-1].

The Solvers FD CLPQ CPLEX (run once, after posting ALL constraints) CPLEX (incremental)

Page 44: The EPLEX Library and Hybrid Forms Involving EPLEX

IC-Parc

Performance Figures (FD) - X i+1>=Xi

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

0.5

2 2.3 2.7 3 3.3 3.7 4 4.3 4.7

Log. # Constraints Added (100 - 50000)

CLPQ

Inc-CPLEX

CPLEX

FD

Log.Time perConstraint

Page 45: The EPLEX Library and Hybrid Forms Involving EPLEX

IC-Parc

The Less Trivial Case - N Propagation Steps per Constraint

Add N variables and constraints N = 100, 200, 500, 1000, 2000, 5000, 10,000, 20,000, 50,000

The Constraints for each variable X[J] do

X[J]::1..N, X[J]-1 >= X[J-1].

The Solvers FD CPLEX (run once, after posting ALL constraints) CPLEX (incremental)

Page 46: The EPLEX Library and Hybrid Forms Involving EPLEX

IC-Parc

Performance Figures (FD) - X i+1>Xi

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0

2 2.3 2.7 3 3.3 3.7 4 4.3 4.7

Log. # Constraints Added (100 - 50000)

FD - Xi+1>Xi

Inc-CPLEX

CPLEX

Log.Time perConstraint

Page 47: The EPLEX Library and Hybrid Forms Involving EPLEX

Motivation for FD Linear Comunication

Performance Behaviour

Page 48: The EPLEX Library and Hybrid Forms Involving EPLEX

IC-Parc 50

One-machine SchedulingTask 1 = Start-time 0..15, Duration 5Task 2 = Start-time 0..15, Duration 15,

Either Task1 must precede Task2:

0 5 10

15

20

Or Task2 must precede Task1:

0 5 10 15 20

Constraint: no_overlap(S1,5,S2,15).

25

Page 49: The EPLEX Library and Hybrid Forms Involving EPLEX

IC-Parc 51

Representing Disjunction with Auxiliary Boolean Variables

no_overlap(S1,D1,S2,D2) :- S1 >= S2+D2.no_overlap(S1,D1,S2,D2) :- S2 >= S1+D1.

Choose a “large” number MIntroduce variables [B1,B2] :: 0..1Replace disjuction with conjunction:

no_overlap(S1,D1,S2,D2,B1,B2) :- S1+M-B1*M >= S2+D2,S2+M-B2*M >= S1+D1,B1+B2>=1.

Example:[S1,S2] :: 0..4, no_overlap(S1,3,S2,5,B1,B2), B1=1

=> fail!

Page 50: The EPLEX Library and Hybrid Forms Involving EPLEX

Communicating Linear and FD Solvers

Optimisation Integer Feasibility

X,Y::0..10Y>= 2*XX+Y >= 5Cost = min(X+2*Y)

FD

Linear

Cost = min(S1)

Cost >= 0

Cost ::0..30

Cost >= 25/3

S1,S2::0..4, B1,B2::0..1S1 + 10 - B1*10 >= S2 + 3S2 + 10 - B2*10 >= S1 + 5B1 + B2 >= 1

B2=0, B1=1S1 :: 3..4, S2 ::0..1

Page 51: The EPLEX Library and Hybrid Forms Involving EPLEX

IC-Parc 53

Hoist Scheduling

Each product must be dipped in a sequence of tanks.

Page 52: The EPLEX Library and Hybrid Forms Involving EPLEX

IC-Parc 54

Disjunctive Constraint in Hoist Scheduling

Period = P1 Hoist

0T1 T2

PP+T1 P+T2

Disjunctive Constraint on actions a and b :T2 >= P+T1+timefull12 + timeempty23

or P+T1 >= T2+timefull34 + timeempty41

action a

action b

1 2 3 4

1 2 3 4

Page 53: The EPLEX Library and Hybrid Forms Involving EPLEX

IC-Parc 55

Disjunctive Constraint in Hoist Scheduling

Period = P2 Hoists

0 T1 T2

P P+T1 P+T2

Disjunctive Constraint on actions a and b :T2 >= P+T1+timefull12 + timeempty23

or P+T1 >= T2+timefull34 + timeempty41or H1 < H2

action a: hoist H1

action b: hoist H2

1 2 3 4

1 2 3 4

Page 54: The EPLEX Library and Hybrid Forms Involving EPLEX

IC-Parc 56

Hoist Performance

CP solver MIPsolver

CP/MPsolver

1 hoist1 track

96 s 10 s 51 s

2 hoists1track

> 10 min 34 s 96 s

2 hoists2 tracks

> 10 min > 10 min 152 s

Page 55: The EPLEX Library and Hybrid Forms Involving EPLEX

Hoist Robustness -Algorithm

100 Randomly Generated 2-hoist 2-track Problems

Optimal Solutions Found 100

Minimum Time 167 secs

Maximum Time 1146 secs

Average Time 314 secs

Page 56: The EPLEX Library and Hybrid Forms Involving EPLEX

Hoist Robustnes - Model Benchmark Hoist Scheduling Problem Tank Capacities Two hoists on one track Multiple hoists on multiple tracks

FD/Linear Hybrid Previous approaches

Same basic model for each problem class

Completely different models

Page 57: The EPLEX Library and Hybrid Forms Involving EPLEX

FD and Linear Solver Cooperation (within a Global Constructive Search)

Motivation Linking through Channeling Constraints Forms of Cooperation

Page 58: The EPLEX Library and Hybrid Forms Involving EPLEX

Different Models in FD and Linear

X1

X2

X3

X4X5

X6

0 5 2 4 1 7

5 0 4 7 2 5

2 4 0 4 6 1

4 7 4 0 3 5

1 2 6 3 0 2

7 5 1 5 2 0

Distances Table: Data

X1

X2

X3

X4

X5

X6

X1 X2 X3 X4 X5 X6

TSP Problem: Find shortest route

Page 59: The EPLEX Library and Hybrid Forms Involving EPLEX

ECLiPSe Syntax

Iterationforeach(El,[a,b,c,d]) do write(El),write(‘ ‘).

for(K,1,4) do write(K), write(‘ ‘).

for(K,1,4),foreach(El,List) do El=K

Const=a, (foreach(El,List), for(_,1,4), param(Const) do El=Const)

Const=a, (foreach(El,List), for(_,1,4) do El=Const)

for(K,1,4),for(J,1,4) do write(K-J),write(‘ ‘).

multifor([K,J],[1,1],[3,3]) do write(K-J),write(‘ ‘)

a b c d

1 2 3 4

List = [1,2,3,4]

List = [a,a,a,a]

1-1 2-2 3-3 4-4

1-1 1-2 1-3 2-1 2-2 2-3 3-1 3-2 3-3

List = [_,_,_,_]

Page 60: The EPLEX Library and Hybrid Forms Involving EPLEX

ECLiPSe Syntax

ArraysStruct = f(a,b,c,d), X is Struct[2].X=bMatrix = m(f(11,12),f(21,22),f(31,32)), X is Matrix[3,2]X=32Matrix = m(f(11,12),f(21,22),f(31,32)), X is Matrix[1..3,2]X=[12,22,32]dim(M,[2,2]), A is M[1,2] M = []([](_,A),[](_,_))dim(M,[2,3]),( multifor([K,J],[1,1],[2,3]), param(M) do X is M[K,J], X=K-J)M = []([](1-1, 1-2, 1-3), [](2-1, 2-2, 2-3))

Page 61: The EPLEX Library and Hybrid Forms Involving EPLEX

TSP Problem – ECLiPSe FD Design Model

length(Vars,6), ic:(Vars :: 1..6), ic:alldifferent(Vars),

length(Dists,6), ic:(Dists :: 1..10),

( for(J,1,6),

foreach(SJ,Vars),

foreach(DJ,Dists),

param(Data)

do

ListJ is Data[J,1..6]), ic:element(SJ,ListJ,DJ) ),

ic: (Cost =:= sum(Dists))

For example:ic:element(S3,[2,4,0,4,6,1],D3)

Page 62: The EPLEX Library and Hybrid Forms Involving EPLEX

TSP Problem – ECLiPSe Linear Design Model

dim(Bools,[6,6]), Bools::0..1,( for(J,1,6), param(Bools) do eplex: (Bools::0..1), eplex: (sum(Bools[J,1..6]) =:= 1), eplex: (sum(Bools[1..6,J]) =:= 1) ),( multifor([I,J],[1,1],[6,6]), foreach(C,Costs), param(Bools,Data) do C = Bools[I,J]*Data[I,J] ),eplex:(Cost =:= sum(Costs)).

Page 63: The EPLEX Library and Hybrid Forms Involving EPLEX

Mapping FD Variables to Booleans

[ic,eplex]: (Var :: 1..N),

length(Bools,N), eplex: (Bools::0..1), eplex: (sum(Bools) =:= 1),

(foreach(B,Bools), for(Val,1,N), for(E,Exprs) do E = B*Val),

eplex: (Var =:= sum(Exprs)).

Channeling constraint in linear solver

Page 64: The EPLEX Library and Hybrid Forms Involving EPLEX

Cooperating Solvers: Copied Variables

Var

Bk

Z

C1C2

Linear Solver FD Solver

Var

Info on “Var”

Bk=1

Var=kVar=k

Channeling constraint in linear solver

Page 65: The EPLEX Library and Hybrid Forms Involving EPLEX

Cooperating Solvers: Copied Variables

Var

Bk

Z

C1C2

Linear Solver FD Solver

Var

Info on “Var”

Bk=1

Var=kVar=k

Channeling constraint in linear solver

Page 66: The EPLEX Library and Hybrid Forms Involving EPLEX

Mapping FD Variables to Booleans

ic: (Var :: 1..N),

length(Bools,N), [ic,eplex]: (Bools::0..1), eplex:(sum(Bools) =:= 1),

( foreach(B,Bools), for(Val,1,N), param(Var) do ic: =:=(Var, Val, B)).

Channeling constraint in FD solver

Page 67: The EPLEX Library and Hybrid Forms Involving EPLEX

FD and Linear Solver Cooperation (within a Global Constructive Search)

Motivation Linking through Channeling Constraints Forms of Cooperation

Page 68: The EPLEX Library and Hybrid Forms Involving EPLEX

Information Communicated from FD to Linear Solvers

Variable Bounds Variable instantiation

Variable remains in linear solver, with identical bounds

Linear Constraints Delay MLLP

Page 69: The EPLEX Library and Hybrid Forms Involving EPLEX

Communicating FD to LP: Delay

X*B >= Y As soon as B is instantiated to 1, send X>=Y to linear solver As soon as B is instantiated to 0, send 0>=Y to linear solver As soon as X is instantiated, send X*B >=Y to linear solver

ECLiPSe Syntax suspend(eplex: (X*B>=Y), 3, [X,B] -> inst)

Page 70: The EPLEX Library and Hybrid Forms Involving EPLEX

Information Communicated from Linear to FD Solvers

Directly Cost Bounds

Indirectly Reduced costs => Var ≠Val often by fixing Bval=0

Page 71: The EPLEX Library and Hybrid Forms Involving EPLEX

Reduced Cost Pruning

Best solution so far

Relaxed OptimumReduced Cost

Infe

asib

leR

egio

n

Val

ues

ru

led

ou

tb

y re

du

ced

co

st

Cost

Value of boolean

0 0.2 0.4 0.6 0.8 1

Page 72: The EPLEX Library and Hybrid Forms Involving EPLEX

Communicating Linear and FD Solvers

Optimisation

X,Y::0..10Y>= 2*XX+Y >= 5Cost = min(X+2*Y)

FD

Linear

Cost ::0..30

Cost >= 25/3

Page 73: The EPLEX Library and Hybrid Forms Involving EPLEX

IC-Parc 75

Branch-and-bound (incremental)

Lower bound(relaxed solution)

Cost

1

First solution

Better solution

2Iterations:

Solu-tions

3

Optimal solution

4

No solution(Proof of optimality)

Page 74: The EPLEX Library and Hybrid Forms Involving EPLEX

Global Constructive Search – FD and Linear Solvers

Root Node

Node1

Node2

Some of these leaf nodes are our solutions

Add constraintand wake FD and linear solvers

Reasoning at each node:RepeatReduce FD domainsTighten linear relaxed cost boundUntil fixpoint

Page 75: The EPLEX Library and Hybrid Forms Involving EPLEX

Linear and FD Constraints as Fixpoint Operators

Information

FD fixpoints

Linear Fixpoints

FD&Linear

Page 76: The EPLEX Library and Hybrid Forms Involving EPLEX

Information Communicated from FD and Linear to Search Engine

FD Domain size Number of active constraints

Linear Relaxed solution Reduced costs => “regret”

Page 77: The EPLEX Library and Hybrid Forms Involving EPLEX

Combining Linear and FD – Horses for Courses

Problem Progressive Party

Cabinet Assignment

Set Partitioning

CP > 5 mins 9.27 secs 64.68 secs

LP > 5 mins > 5 mins 0.18 secs

CP & LP 91.5 secs 13.2 secs 0.71 secs

Page 78: The EPLEX Library and Hybrid Forms Involving EPLEX

Hybridising ic and eplex

ic ?- ic:(X=\=Y)

eplex ?- eplex:(X>=3)

Redundant ?- [ic,eplex]:(X>=3), ic:(X=\=Y)

Page 79: The EPLEX Library and Hybrid Forms Involving EPLEX

Control Flow with Multiple Solvers

Search/Choice

Solver phase withcommunication

Solver1

Solver2

Search/Choice

Page 80: The EPLEX Library and Hybrid Forms Involving EPLEX

A Hybrid Algorithm Set up constraints

Make choices in ECLiPSe code programmer specified variable/value choices

Apply interval propagation, e.g. lib(ic) Narrowed Bounds Empty intervals Instantiated integers

Solve the continuous relaxation with Simplex Global Consistency (of continuous relaxation) Lower bound on cost “Suggested values” (optimising continuous relaxation)

Page 81: The EPLEX Library and Hybrid Forms Involving EPLEX

Flight Schedule Retimer

Page 82: The EPLEX Library and Hybrid Forms Involving EPLEX

Activity Overlaps ~ Fixed TimesS1

S2S3

E1E2

E3

No. ofResourcesRequired

Time

321

Activities

321

S1 S2S3

Potentialresourcebottleneckpoints

Page 83: The EPLEX Library and Hybrid Forms Involving EPLEX

Activity Overlaps ~ Variable Times

S1S2

S3

E1E2

E3

PossibleNo. ofResourcesRequired

321

S1 S2S3

Unknown start times

Page 84: The EPLEX Library and Hybrid Forms Involving EPLEX
Page 85: The EPLEX Library and Hybrid Forms Involving EPLEX
Page 86: The EPLEX Library and Hybrid Forms Involving EPLEX

Constraints on Departure Times(linear)

Precedence Dep1 + time =< Dep2

Maximal delay Dep1 + time >= Dep2

Minimize Perturbation

Change >= Old – New,

Change >= New – Old,

minimize(Change)

Page 87: The EPLEX Library and Hybrid Forms Involving EPLEX

Aircraft Constraints

Start End

Flights

T1

T2

T3

T4

T5

S1 = start of T1

Resources used at S1:B1j = 1 if (S1>=Sj and S1=<Sj+Dj)B1j = 0 otherwise.

Resource constraint at start of T1:

1+B12+B13+B14+B15 = T1R =< 2

Resource Limit = 2

Page 88: The EPLEX Library and Hybrid Forms Involving EPLEX

Tentative Values

:- lib(repair).

X tent_set 2

X tent_get Tent

X tent_is Y+1.

Load the “repair” library

Set the tentative value of X

Get the tentative value of X

Propagate from the tentative value of Y to the tentativeValue of X

Page 89: The EPLEX Library and Hybrid Forms Involving EPLEX

Resource Constraints

Start End

Machine

Tasks

T1

T2

T3

T4

T5

Start of T1

overlap(S1,S2,D2,B12) :- B12 tent_is (S1>=S2 and S1=<S2+D2).

Resource usage at start of T1:

R1 tent_is1 + B12 + B13 + B14 + B15

Resource Limit

Page 90: The EPLEX Library and Hybrid Forms Involving EPLEX

eplex Setting Tentative Values

set_ans_to_tent :- eplex_get(vars,Vars), eplex_get(typed_solution,Solution), Vars tent_set Solution.

Page 91: The EPLEX Library and Hybrid Forms Involving EPLEX

Tentative Values as Heuristic

label_heur(List) :-choose_worst(List,res(RN,S1,S2,D2)),(S2 $>= S1 ; S1 $>= S2+D2),label_heur(List).

choose_worst(List,Resource) :-member(res(RN,_,_,_),List),RN tent_get Load,( foreach(res(RM,_,_,_),List), param(Load)

do RM tent_get Load2, Load2=<Load

).

Page 92: The EPLEX Library and Hybrid Forms Involving EPLEX

Probing

1. Send temporal constraints to linear solver

2. Set tentative values to linear optimum S1 = 10, S2 = 8, S3 = 12, S4 = 13, S5 = 7

3. Propagate tentative values B12 = 1, B13 = 0, B14 = 0, B15 = 1 => T1R = 3 B21 = 0, … => T2R = 2

4. Identify bottleneck (maximum excess overlap) T3R = 4

5. Add precedence constraint on two bottleneck tasks S3 >= S2+D2

Page 93: The EPLEX Library and Hybrid Forms Involving EPLEX

Comparison with Integer/Linear Programming

Encode this using linear constraints B1j = 1 if (S1>=Sj and S1=<Sj+Dj) B1j = 0 otherwise

Impose integrality constraints on the Bij Solve linear constraints Set tentative values to linear optimum Choose a non-integer Bij Add precedence constraint:

Si >= Sj+Dj

Page 94: The EPLEX Library and Hybrid Forms Involving EPLEX

Results – Integer/Linear vs Combined Algorithm: LP Nodes

0

2000

4000

6000

8000

10000

12000

14000

16000

18000

20000

10 20 50

Number of Activities

LP N

odes

Integer/Linear Programming

Unimodular Probing

Page 95: The EPLEX Library and Hybrid Forms Involving EPLEX

Results: Commercial Aircraft UtilisationProblems

Aircraft Utilisation up to 1000 activities, total of over 70 resources, 6 types

Saved a plane in each of two fleets Used by BA for IATA negotiations

Page 96: The EPLEX Library and Hybrid Forms Involving EPLEX

The Future

A Platform for Three Communities Operations Research Metaheuristics Computational Intelligence

Research Issues Algorithm Encapsulation and Hybridisation User Languages

Modelling Search Programming Constraint Behaviours

System Building Research Community Industrial Applications

Page 97: The EPLEX Library and Hybrid Forms Involving EPLEX

The Near Future!

HAL/Mercury User languages Algorithm Encapsulation and Hybridisation System Building

Applications Supply Chain Optimisation

Patrick Corp., Bluescope Steel, Berri,… Inventory and Transport Optimisation

IBM/Qantas NAB/Chubb

Construction Scheduling BLL

NICTA Constraint Technology