eml.backend package

Submodules

eml.backend.base module

class eml.backend.base.Backend[source]

Bases: object

CP Solver Wrapper

const_eps()[source]
cst_eq(mdl, left, right, name=None)[source]
cst_geq(mdl, left, right, name=None)[source]
cst_indicator(mdl, trigger, cst, name=None)[source]
cst_leq(mdl, left, right, name=None)[source]
get_obj(mdl)[source]
new_model(name=None)[source]
set_obj(mdl, sense, xpr)[source]
solve(mdl, timelimit)[source]
var_bin(mdl, name=None)[source]
var_cont(mdl, lb, ub, name=None)[source]
xpr_eq(mdl, left, right)[source]
xpr_scalprod(mdl, coefs, terms)[source]
xpr_sum(mdl, terms)[source]

eml.backend.cplex_backend module

class eml.backend.cplex_backend.CplexBackend(ml_tol=0.0001)[source]

Bases: eml.backend.base.Backend

Backend for CPLEX solver

_ml_tol

Tollerance

Type:float
Parameters:ml_tol (float)) – Tollerance
const_eps(mdl)[source]

Get tollerance

Parameters:mdl (docplex.mp.model.Model) – Cplex model
Returns:Tollerance – Tollerance
Return type:float
cst_eq(mdl, left, right, name=None)[source]

Add to the model equality constraint between two variables

Parameters:
  • mdl (docplex.mp.model.Model) – Cplex model
  • left (:obj:docplex.mp.linear.Var) – Variable
  • right (:obj:docplex.mp.linear.Var) – Variable
  • name (string) – Name of the constraint
Returns:

Equality constraint – Equality contraint between the two variables in input

Return type:

docplex.mp.constr.LinearConstraint

cst_indicator(mdl, trigger, val, cst, name=None)[source]

Add an indicator to the model

An indicator constraint links (one-way) the value of a binary variable to the satisfaction of a linear constraint

Parameters:
  • mdl (docplex.mp.model.Model) – Cplex model
  • trigger (docplex.mp.Var) – Binary Variable
  • val (int) – Active value, used to trigger the satisfaction of the constraint
  • cst (docplex.mp.constr.LinearConstraint) – Linear constraint
  • name (string) – Name of the constraint
Returns:

Indicator constraint – Indicator constraint between the trigger and the linear constraint in input

Return type:

docplex.mp.constr.IndicatorConstraint

cst_leq(mdl, left, right, name=None)[source]

Add to the model a lowe or equal constraint between two variables

Parameters:
  • mdl (docplex.mp.model.Model) – Cplex model
  • left (:obj:docplex.mp.linear.Var) – Variable
  • right (:obj:docplex.mp.linear.Var) – Variable
  • name (string) – Name of the constraint
Returns:

Lower or equal constraint – Lowe or equal contraint between the two variables in input

Return type:

docplex.mp.constr.LinearConstraint

get_obj(mdl)[source]

Returns objextive expression

Parameters:mdl (docplex.mp.model.Model) – Cplex model
Returns:Objective and expression – ‘min’ if the objective function is to be minimized, ‘max otherwise. The expression repesenting the objective function
Return type:(string, )
new_model(mdl=None, name=None)[source]

Creates a new model

Parameters:
  • mdl (docplex.mp.model.Model) – Cplex model (default None)
  • name (string) – Name of the model (default None)
Returns:

Model – Cplex model

Return type:

docplex.mp.model.Model

set_obj(mdl, sense, xpr)[source]

Sets the objective function

Parameters:
  • mdl (docplex.mp.model.Model) – Cplex model
  • sense (string) – Represents the objective, ‘min’ or ‘max’
  • xpr – Expression representing the objective function
Returns:

Return type:

None

solve(mdl, timelimit)[source]

Solves the problem

Parameters:
  • mdl (docplex.mp.model.Model) – Cplex model
  • timelimit (int) – time limit in seconds for the solver
Returns:

Solution – A solution if the problem is feasible, the status of the of the solver otherwise

Return type:

docplex.mp.solution.SolveSolution

var_bin(mdl, name=None)[source]

Creates continuous variable in the model

Parameters:
  • mdl (docplex.mp.model.Model) – Cplex model
  • name (string)) – Name of the variable (default None)
Returns:

Binary Variable – Binary Variable

Return type:

docplex.mp.linear.Var`

var_cont(mdl, lb, ub, name=None)[source]

Creates continuous variable in the model

Parameters:
  • mdl (docplex.mp.model.Model) – Cplex model
  • lb (float)) – Lower bound of the variable
  • ub (float) – Upper bound of the variable
  • name (string) – Name of the variable (default None)
Returns:

Continuos Variable – Continuos variable with specified bounds and name

Return type:

docplex.mp.linear.Var`

xpr_eq(mdl, left, right)[source]

Creates an equality constraint between two variables

Parameters:
  • mdl (docplex.mp.model.Model) – Cplex model
  • left (:obj:docplex.mp.linear.Var) – Variable
  • right (:obj:docplex.mp.linear.Var) – Variable
Returns:

Equality constraint – Equality contraint between the two variables in input

Return type:

docplex.mp.constr.LinearConstraint

xpr_scalprod(mdl, coefs, terms)[source]

Scalar product of varibles and coefficients

Parameters:
  • mdl (docplex.mp.model.Model) – Cplex model
  • coefs (list(float)) – List of coefficients
  • terms (list(:obj:docplex.mp.linear.Var]):) – List of variables
Returns:

Linear Expression – Linear expression representing the linear combination of terms and coefficients or 0

Return type:

docplex.mp.LinearExpr()

xpr_sum(mld, terms)[source]

Sum of variables

Parameters:
  • mdl (docplex.mp.model.Model) – Cplex model
  • terms (list(:obj:docplex.mp.linear.Var)) – List of variables
Returns:

Linear Expression – Linear expression representing the sum of all the term in input

Return type:

docplex.mp.LinearExpr()

eml.backend.cplex_backend.model_to_string(mdl)[source]

Returns a string representing the model

Parameters:mdl (docplex.mp.model.Model) – Cplex model
Returns:Representation – String representig the cplex model
Return type:string

Module contents