1 / 29

The EPLEX Library

The EPLEX Library. Introduction. lib(eplex) An interface between ECLiPSe and an external LP/MIP solver COIN-OR Open Solver Interface: currently to COIN’s CLP/CBC and SYMPHONY/CLP (Open Source) XPRESS-MP, a product by Dash Associates CPLEX, a product by ILOG SA Motivation to have this link:

arlinem
Download Presentation

The EPLEX Library

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The EPLEX Library

  2. Introduction • lib(eplex) • An interface between ECLiPSe and an external LP/MIP solver • COIN-OR Open Solver Interface: currently to COIN’s CLP/CBC and SYMPHONY/CLP (Open Source) • 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

  3. Mathematical Programming • Making optimal decisions with limited resources • ‘Programming’ in the sense of planning • Model problem to optimise as an ‘objective’ function, subject to constraints • Classic example: transportation problem

  4. Objective Function Constraints Mathematical Programming Plant capacity Transportation cost Client demand minimize 10 A1 + 7 A2 + 11 A3 + 8 B1 + 5 B2 + 10 B3 + 5 C1 + 5 C2 + 8 C3 + 9 D1 + 3 D2 + 7 D3 subject to 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 A 200 10 1  500 8 9 5 B 7 400 5 2  300 5 3 C 300 10 11 3 8  400 7 D 100 • Leads to a matrix: • Each row is one constraint • Each column is one variable

  5. LP/MIP – A brief overview • Linear Programming: • Optimisation problem formulated using linear constraints and a linear objective function • An efficient algebraic method developed to solve such problems (Simplex, 1947) • Interior point (barrier) method • Mixed Integer Programming: • LP problems where some of the variables are constrained to be integer • No known ‘optimal’ method: generally use simplex/barrier with branch and bound search for optimal • Quadratic Programming • Quadratic objective function, linear constraints • Barrier method

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

  7. General Usage • Loading: • :- lib(eplex). • Loads interface with default solver (OSI CLP/CBC on most machines) • Differences between the underlying solvers are largely hidden • Documentation • ECLiPSe Library Manual • Tutorial chapter on Eplex • Reference Manual

  8. 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).

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

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

  11. Common Arithmetic Solver Interface

  12. Black-box Optimizer • 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 forObjective • Returns the costCost • Instantiates the variables to the computed solution values • Selects LP/QP/MIP depending on integersand Objective

  13. Y Cost X 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

  14. LP / MIP search 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 External Solver ECLiPSe variables & bounds X1 X2 ... Xm solution values = c1 =< c2 constraints >= cn = Cost Obj cost

  15. 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!

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

  17. 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!

  18. Multiple problems (eplex instances) • Declare an eplex instance, e.g. • :- eplex_instance(prob). • (an instance calledeplexexists by default) • Constraints • prob:(Vars :: Min..Max) • prob:(Expr1 $= Epxr2) prob:(Expr1 =:= Epxr2) • prob:(Expr1 $>= Epxr2) prob:(Expr1 >= Epxr2) • prob:(Expr1 $=< Expr2) prob:(Expr1 =< Epxr2) • prob:(integers(Vars)) • Solver setup • prob:eplex_solver_setup(+Objective) • Run solver once • prob:eplex_solve(-Cost) • Computes a solution with Cost but does not instantiate variables • Access solution information • prob:eplex_get(+What, -Value) • prob:epelx_var_get(+Var, +What, -Value)

  19. Transportation Problem (with Instance API) :- lib(eplex). :- eplex_instance(prob). main(Cost, Vars) :- Vars = [A1, A2, A3, B1, B2, B3, C1, C2, C3, D1, D2, D3], prob:(Vars :: 0.0..1.0Inf), prob:(A1 + A2 + A3 $= 200), prob:(B1 + B2 + B3 $= 400), prob:(C1 + C2 + C3 $= 300), prob:(D1 + D2 + D3 $= 100), prob:(A1 + B1 + C1 + D1 $=< 500), prob:(A2 + B2 + C2 + D2 $=< 300), prob:(A3 + B3 + C3 + D3 $=< 400), prob:eplex_solver_setup(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)), prob:eplex_solve(Cost), ( foreach(Var,Vars) do prob:eplex_var_get(Var, typed_solution, Var) ).

  20. Traditional MIP branching simplex solution: X = 4.2 • 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) X >= 5 X =< 4

  21. Doing MIP in ECLiPSe :- lib(eplex), lib(branch_and_bound). main :- ... <setup constraints> IntVars = <variables that should take integral values>, Objective = <objective function>, ... Objective $= CostVar, eplex_solver_setup(min(Objective)), eplex_solve(RelaxedCost), % initial simplex solving CostVar $>= RelaxedCost) % apply resulting cost bound ... minimize(mip_search(IntVars, CostVar), CostVar). mip_search(IntVars, CostVar) :- ... % for each X violating the integrality condition eplex_var_get(X, solution, RelaxedSol), Split is floor(RelaxedSol), ( X $=< Split ; X $>= Split+1 ), % choice eplex_solve(RelaxedCost), % simplex re-solving CostVar $>= RelaxedCost, % apply new cost bound ... no integrality constraints!

  22. Ok, but ... • The search procedure became messy • extra argument (CostVar) • explicit simplex calls • modularity lost (choices/propagation) • Do we really need to run simplex every time? • there might be no significant change • Solution: data-driven triggering, e.g. on • instantiation • instantiation far from relaxed solution • bounds change • bounds exclude relaxed solution

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

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

  25. Eplex solver as compound constraint setup solver • 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) X1 X2 ... Xm c1 = External Solver c2 =< cn >= Obj = Cost

  26. More Elegant Implementation of MIP :- lib(eplex), lib(branch_and_bound). main :- ... <setup constraints> IntVars = <variables that should take integral values>, Objective = <objective function>, ... Objective $= CostVar, eplex_solver_setup(min(Objective), CostVar, [], [bounds]), ... minimize(mip_search(IntVars), CostVar). mip_search(IntVars) :- ... % for each X violating the integrality condition eplex_var_get(X, solution, RelaxedSol), Split is floor(RelaxedSol), ( X $=< Split) ; X $>= Split+1 ), % choice ... % simplex re-solving triggered by bounds change % cost bound automatically applied ... • No explicit simplex calls, no auxiliary parameters to search procedure • Standard CLP search scheme - other choices/constraints can be added now

  27. Control Flow in Classical MIP Solver Choice Simplex step Solve continuous relaxation Choice

  28. Control Flow with Constraint Propagation Search/Choice constraints Propagation phase Search/Choice

  29. Control Flow with Constraint Propagation Eplex instance demon can be integrated similar to a global constraint Search/Choice Propagation phase constraints eplex instances Search/Choice

More Related