In this chapter, the problem passed to the external solver will be referred to as an eplex problem. An eplex problem consists of a set of linear arithmetic constraints, whose variables have bounds and may possibly have integrality constraints. The external solver will solve such a problem by optimising these constraints with respect to an objective function.
With the eplex library, it is possible to have more than one eplex problem within one program. The simplest way to write such programs with the library is through Eplex Instances. An eplex instance is an instance of the eplex solver, to which an eplex problem can be sent. An external solver state can be associated with each eplex instance, which can be invoked to solve the eplex problem. Declaratively, an eplex instance can be seen as a compound constraint consisting of all the variables, their bounds, and constraints of the eplex problem.
Like other solvers, each eplex instance has its own module. To use an eplex instance, it must first be declared, so that the module can be created. This is done by:
This predicate will initialise an eplex instance Name. Once initialised, a Name module will exist, to which the user can post the constraints for the eplex problem and setup and use the external solver state to solve the eplex problem. Normally, this predicate should be issued as a directive in the user’s program, so that the program code can refer to the instance directly in their code. For example:
For convenience, the eplex library declares eplex as an eplex instance when the library is loaded.
The constraints provided are equalities and inequalities over linear expressions. Their operational behaviour is as follows:
As with all predicates defined for an eplex instance, these constraints should be module-qualified with the name of the eplex instance. In the following they are shown qualified with the eplex instance, and with brackets around the constraints when needed. Other instances can be used if they have been declared using eplex_instance/1.
X is equal to Y. X and Y are linear expressions.
X is greater or equal to Y. X and Y are linear expressions.
X is less or equal to Y. X and Y are linear expressions.
The following arithmetic expression can be used inside the constraints:
Bounds for variables can be given to an eplex instance via the
The difference between using an LP vs. an MIP solver is made by declaring integrality to the solver via the integers/1 constraint:
Note that unless eplex:integers/1 (or lp_add/3, see section 10.4.2) is invoked, any invocation of the eplex external solver (via lp_solve/2, lp_probe/3 or lp_demon_setup/5) will only solve a continuous relaxation, even when problem variables have been declared as integers in other solvers (e.g. ic).
Note that all the above constraints are local to the eplex instance; they do not place any restrictions on the variables for other eplex instances or solvers. Failure will occur only when inconsistency is detected within the same eplex instance, unless the user explicitly try to merge the constraints from different solvers/eplex instance.
A counterpart, reals/1 ‘constraint’ also exists – this simply declares the variables specified are problem variables, and does not actually place any other constraint on the variables.
In order to solve an eplex problem, the eplex instance must be set up for an external solver state. The solver state can then be invoked to solve the problem. The simplest way to do this is to use:
Objective is either min(Expr) or max(Expr) where Expr is a linear expression (or quadratic, if supported by the external solver).
Here is a simple linear program, handled by the predefined eplex instance ’eplex’:
:- lib(eplex). lp_example(Cost) :- eplex: eplex_solver_setup(min(X)), eplex: (X+Y $>= 3), eplex: (X-Y $= 0), eplex: eplex_solve(Cost).
The same example using a user-defined eplex instance:
:- lib(eplex). :- eplex_instance(my_instance). lp_example(Cost) :- my_instance: eplex_solver_setup(min(X)), my_instance: (X+Y $>= 3), my_instance: (X-Y $= 0), my_instance: eplex_solve(Cost).
Running the program gives the optimal value for Cost:
[eclipse 2]: lp_example(Cost). Cost = 1.5
Note that if the eplex eplex instance is used instead of my_instance, then the eplex_instance/1 declaration is not necessary.
By declaring one variable as integer, we obtain a Mixed Integer Problem:
:- lib(eplex). :- eplex_instance(my_instance). mip_example(Cost) :- my_instance: (X+Y $>= 3), my_instance: (X-Y $= 0), my_instance: integers([X]), my_instance: eplex_solver_setup(min(X)), my_instance: eplex_solve(Cost). .... [eclipse 2]: mip_example(Cost). Cost = 2.0
The cost is now higher because X is constrained to be an integer. Note also that in this example, we posted the constraints before setting up the external solver, whereas in the previous example we set up the solver first. The solver set up and constraint posting can be done in any order. If integers/1 constraints are only posted after problem setup, the problem will be automatically converted from an LP to a MIP problem.
This section has introduced the most basic ways to use the eplex library. We will discuss more advanced methods of using the eplex instances in section 10.3.