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 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 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:
:- eplex_instance(instance).
For convenience, the eplex library declares eplex as an eplex instance when the library is loaded.
In exceptional cases, it is possible for a problem variable not to be transferred to the external solver at all. This would happen when the variable occurs only in trivial single-variable constraints, and does not occur in the objective function either.
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. Other instances can be used if they have been declared using eplex_instance/1.
The following arithmetic expression can be used inside the constraints:
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. Generally the solver set up and constraint posting can be done in any order, with one restriction: at set up, eplex must know if the problem is a MIP problem or not. This means that for the above problem, the integers/1 call must be before the eplex_solver_setup/1 call.
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 11.5.