straindesign.scip_interface =========================== .. py:module:: straindesign.scip_interface .. autoapi-nested-parse:: SCIP and SoPlex solver interface for LP and MILP Module Contents --------------- .. py:class:: SCIP_LP(c, A_ineq, b_ineq, A_eq, b_eq, lb, ub) Bases: :py:obj:`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 .. rubric:: Example scip = SCIP_LP(c, A_ineq, b_ineq, A_eq, b_eq, lb, ub) :param c: (Default: None) The objective vector (Objective sense: minimization). :type c: list of float :param A_ineq: (Default: None) A coefficient matrix of the static inequalities. :type A_ineq: sparse.csr_matrix :param b_ineq: (Default: None) The right hand side of the static inequalities. :type b_ineq: list of float :param A_eq: (Default: None) A coefficient matrix of the static equalities. :type A_eq: sparse.csr_matrix :param b_eq: (Default: None) The right hand side of the static equalities. :type b_eq: list of float :param lb: (Default: None) The lower variable bounds. :type lb: list of float :param ub: (Default: None) The upper variable bounds. :type ub: list of float :param Returns: (SCIP_LP): A SCIP LP interface class. .. py:method:: add_eq_constraints(A_eq, b_eq) 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. :param A_eq: The coefficient matrix :type A_eq: sparse.csr_matrix :param b_eq: The right hand side vector :type b_eq: list of float .. py:method:: add_ineq_constraints(A_ineq, b_ineq) 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. :param A_ineq: The coefficient matrix :type A_ineq: sparse.csr_matrix :param b_ineq: The right hand side vector :type b_ineq: list of float .. py:method:: get_basis() Reconstruct vbasis/cbasis from SoPlex getBasisInds + solution. Uses getBasisInds() to identify basic variables, then checks solution values against bounds to determine non-basic status. :returns: dict with 'vbasis' (list of int) and 'cbasis' (list of int). Status codes: 0=basic, -2=at lower bound, -3=at upper bound. .. py:method:: get_lp_method() Return LP_METHOD_AUTO — SCIP_LP does not expose method selection. .. py:method:: set_basis(basis) No-op — pyscipopt LP does not expose basis loading. .. py:method:: set_lp_method(method) Set the LP solving method (no-op for SCIP_LP — SoPlex manages internally). .. py:method:: set_objective(c) Set the objective function with a vector .. py:method:: set_objective_idx(C) Set the objective function with index-value pairs e.g.: C=[[1, 1.0], [4,-0.2]] .. py:method:: set_time_limit(t) No-op — SCIP_LP does not support time limits. .. py:method:: slim_solve() -> float Solve the LP, but return only the optimal value .. rubric:: Example optim = scip.slim_solve() :returns: (float) Optimum value of the objective function. .. py:method:: solve() -> Tuple[List, float, float] Solve the LP .. rubric:: Example sol_x, optim, status = scip.solve() :returns: (Tuple[List, float, float]) solution_vector, optimal_value, optimization_status .. py:class:: SCIP_MILP(c=None, A_ineq=None, b_ineq=None, A_eq=None, b_eq=None, lb=None, ub=None, vtype=None, indic_constr=None, seed=None, milp_threads=None) Bases: :py:obj:`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 .. rubric:: Example scip = SCIP_MILP(c, A_ineq, b_ineq, A_eq, b_eq, lb, ub, vtype, indic_constr) :param c: (Default: None) The objective vector (Objective sense: minimization). :type c: list of float :param A_ineq: (Default: None) A coefficient matrix of the static inequalities. :type A_ineq: sparse.csr_matrix :param b_ineq: (Default: None) The right hand side of the static inequalities. :type b_ineq: list of float :param A_eq: (Default: None) A coefficient matrix of the static equalities. :type A_eq: sparse.csr_matrix :param b_eq: (Default: None) The right hand side of the static equalities. :type b_eq: list of float :param lb: (Default: None) The lower variable bounds. :type lb: list of float :param ub: (Default: None) The upper variable bounds. :type ub: list of float :param vtype: (Default: None) A character string that specifies the type of each variable: 'c'ontinous, 'b'inary or 'i'nteger :type vtype: str :param indic_constr: (Default: None) A set of indicator constraints stored in an object of IndicatorConstraints (see reference manual or docstring). :type indic_constr: IndicatorConstraints :param seed: (Default: None) An integer value serving as a seed to make MILP solving reproducible. :type seed: int16 :param Returns: (SCIP_MILP): A SCIP MILP interface class. .. py:method:: addExclusionConstraintIneq(x) Function to add exclusion constraint (SCIP compatibility function) .. py:method:: add_eq_constraints(A_eq, b_eq) 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. :param A_eq: The coefficient matrix :type A_eq: sparse.csr_matrix :param b_eq: The right hand side vector :type b_eq: list of float .. py:method:: add_ineq_constraints(A_ineq, b_ineq) 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. :param A_ineq: The coefficient matrix :type A_ineq: sparse.csr_matrix :param b_ineq: The right hand side vector :type b_ineq: list of float .. py:method:: getSolution() -> list Retrieve solution from SCIP backend .. py:method:: get_basis() :abstractmethod: Not available for SCIP MILP — LP basis is discarded after MIP solve. .. py:method:: get_lp_method() Return the current LP method as a solver-neutral string. .. py:method:: set_basis(basis) :abstractmethod: Not available for SCIP MILP — pyscipopt does not expose basis loading. .. py:method:: set_ineq_constraint(idx, a_ineq, b_ineq) Replace a specific inequality constraint Replace the constraint with the index idx with the constraint a_ineq*x ~ b_ineq :param idx: Index of the constraint :type idx: int :param a_ineq: The coefficient vector :type a_ineq: list of float :param b_ineq: The right hand side value :type b_ineq: float .. py:method:: set_lp_method(method) Set the LP solving method. :param method: LP_METHOD_AUTO, LP_METHOD_PRIMAL, LP_METHOD_DUAL, or LP_METHOD_BARRIER .. py:method:: set_objective(c) Set the objective function with a vector .. py:method:: set_objective_idx(C) Set the objective function with index-value pairs e.g.: C=[[1, 1.0], [4,-0.2]] .. py:method:: set_time_limit(t) Set the computation time limit (in seconds) .. py:method:: set_ub(ub) Set the upper bounds to a given vector .. py:method:: slim_solve() -> float Solve the MILP, but return only the optimal value .. rubric:: Example optim = scip.slim_solve() :returns: (float) Optimum value of the objective function. .. py:method:: solve() -> Tuple[List, float, float] Solve the MILP .. rubric:: Example sol_x, optim, status = scip.solve() :returns: (Tuple[List, float, float]) solution_vector, optimal_value, optimization_status