`straindesign.scip_interface`

SCIP and SoPlex solver interface for LP and MILP

Module Contents

class straindesign.scip_interface.SCIP_LP(c, A_ineq, b_ineq, A_eq, b_eq, lb, ub)[source]

Bases: `pyscipopt.LP`

SoPlex interface for LP

This class is a wrapper for the SoPlex-Python API to offer bindings and namings for functions for the construction and manipulation of LPs in an vector-matrix-based manner that are consistent with those of the other solver interfaces in the StrainDesign package. The purpose is to unify the instructions for operating with MILPs and LPs throughout StrainDesign.

Constructor of the SCIP (SoPlex) LP interface class

Accepts a (mixed integer) linear problem in the form:

minimize(c) subject to: A_ineq * x <= b_ineq

A_eq * x = b_eq lb <= x <= ub forall(i) type(x_i) = vtype(i) (continous, binary, integer) indicator constraints: x(j) = [0|1] -> a_indic * x [<=|=|>=] b_indic

Please ensure that the number of variables and (in)equalities is consistent

Example

scip = SCIP_LP(c, A_ineq, b_ineq, A_eq, b_eq, lb, ub)

Parameters:
• c (list of float) – (Default: None) The objective vector (Objective sense: minimization).

• A_ineq (sparse.csr_matrix) – (Default: None) A coefficient matrix of the static inequalities.

• b_ineq (list of float) – (Default: None) The right hand side of the static inequalities.

• A_eq (sparse.csr_matrix) – (Default: None) A coefficient matrix of the static equalities.

• b_eq (list of float) – (Default: None) The right hand side of the static equalities.

• lb (list of float) – (Default: None) The lower variable bounds.

• ub (list of float) – (Default: None) The upper variable bounds.

• Returns

(SCIP_LP):

A SCIP LP interface class.

Add equality constraints to the model

Additional equality constraints have the form A_eq * x = b_eq. The number of columns in A_eq must match with the number of variables x in the problem.

Parameters:
• A_eq (sparse.csr_matrix) – The coefficient matrix

• b_eq (list of float) – The right hand side vector

Add inequality constraints to the model

Additional inequality constraints have the form A_ineq * x <= b_ineq. The number of columns in A_ineq must match with the number of variables x in the problem.

Parameters:
• A_ineq (sparse.csr_matrix) – The coefficient matrix

• b_ineq (list of float) – The right hand side vector

set_objective(c)[source]

Set the objective function with a vector

set_objective_idx(C)[source]

Set the objective function with index-value pairs

e.g.: C=[[1, 1.0], [4,-0.2]]

slim_solve() [source]

Solve the LP, but return only the optimal value

Example

optim = scip.slim_solve()

Returns:

(float)

Optimum value of the objective function.

solve() Tuple[List, float, float][source]

Solve the LP

Example

sol_x, optim, status = scip.solve()

Returns:

(Tuple[List, float, float])

solution_vector, optimal_value, optimization_status

class straindesign.scip_interface.SCIP_MILP(c, A_ineq, b_ineq, A_eq, b_eq, lb, ub, vtype, indic_constr)[source]

Bases: `pyscipopt.Model`

SCIP interface for MILP

This class is a wrapper for the SCIP-Python API to offer bindings and namings for functions for the construction and manipulation of MILPs in an vector-matrix-based manner that are consistent with those of the other solver interfaces in the StrainDesign package. The purpose is to unify the instructions for operating with MILPs and LPs throughout StrainDesign.

The SCIP interface provides support for indicator constraints as well as for the populate function. The SCIP interface does not natively support the populate function. A high level implementation emulates the behavior of populate.

Accepts a (mixed integer) linear problem in the form:

minimize(c), subject to: A_ineq * x <= b_ineq, A_eq * x = b_eq, lb <= x <= ub, forall(i) type(x_i) = vtype(i) (continous, binary, integer), indicator constraints: x(j) = [0|1] -> a_indic * x [<=|=|>=] b_indic

Please ensure that the number of variables and (in)equalities is consistent

Example

scip = SCIP_MILP(c, A_ineq, b_ineq, A_eq, b_eq, lb, ub, vtype, indic_constr)

Parameters:
• c (list of float) – (Default: None) The objective vector (Objective sense: minimization).

• A_ineq (sparse.csr_matrix) – (Default: None) A coefficient matrix of the static inequalities.

• b_ineq (list of float) – (Default: None) The right hand side of the static inequalities.

• A_eq (sparse.csr_matrix) – (Default: None) A coefficient matrix of the static equalities.

• b_eq (list of float) – (Default: None) The right hand side of the static equalities.

• lb (list of float) – (Default: None) The lower variable bounds.

• ub (list of float) – (Default: None) The upper variable bounds.

• vtype (str) – (Default: None) A character string that specifies the type of each variable: ‘c’ontinous, ‘b’inary or ‘i’nteger

• indic_constr (IndicatorConstraints) – (Default: None) A set of indicator constraints stored in an object of IndicatorConstraints (see reference manual or docstring).

• Returns

(SCIP_MILP):

A SCIP MILP interface class.

Function to add exclusion constraint (SCIP compatibility function)

Add equality constraints to the model

Additional equality constraints have the form A_eq * x = b_eq. The number of columns in A_eq must match with the number of variables x in the problem.

Parameters:
• A_eq (sparse.csr_matrix) – The coefficient matrix

• b_eq (list of float) – The right hand side vector

Add inequality constraints to the model

Additional inequality constraints have the form A_ineq * x <= b_ineq. The number of columns in A_ineq must match with the number of variables x in the problem.

Parameters:
• A_ineq (sparse.csr_matrix) – The coefficient matrix

• b_ineq (list of float) – The right hand side vector

getSolution() list[source]

Retrieve solution from SCIP backend

set_ineq_constraint(idx, a_ineq, b_ineq)[source]

Replace a specific inequality constraint

Replace the constraint with the index idx with the constraint a_ineq*x ~ b_ineq

Parameters:
• idx (int) – Index of the constraint

• a_ineq (list of float) – The coefficient vector

• b_ineq (float) – The right hand side value

set_objective(c)[source]

Set the objective function with a vector

set_objective_idx(C)[source]

Set the objective function with index-value pairs

e.g.: C=[[1, 1.0], [4,-0.2]]

set_time_limit(t)[source]

Set the computation time limit (in seconds)

set_ub(ub)[source]

Set the upper bounds to a given vector

slim_solve() [source]

Solve the MILP, but return only the optimal value

Example

optim = scip.slim_solve()

Returns:

(float)

Optimum value of the objective function.

solve() Tuple[List, float, float][source]

Solve the MILP

Example

sol_x, optim, status = scip.solve()

Returns:

(Tuple[List, float, float])

solution_vector, optimal_value, optimization_status