CPLEXPersistent

class
pyomo.solvers.plugins.solvers.cplex_persistent.
CPLEXPersistent
(**kwds)[source] Bases:
PersistentSolver
,CPLEXDirect
A class that provides a persistent interface to Cplex. Direct solver interfaces do not use any file io. Rather, they interface directly with the python bindings for the specific solver. Persistent solver interfaces are similar except that they “remember” their model. Thus, persistent solver interfaces allow incremental changes to the solver model (e.g., the gurobi python model or the cplex python model). Note that users are responsible for notifying the persistent solver interfaces when changes are made to the corresponding pyomo model.
Keyword Arguments:  model (ConcreteModel) – Passing a model to the constructor is equivalent to calling the set_instance mehtod.
 type (str) – String indicating the class type of the solver instance.
 name (str) – String representing either the class type of the solver instance or an assigned name.
 doc (str) – Documentation for the solver
 options (dict) – Dictionary of solver options

add_block
(block) Add a single Pyomo Block to the solver’s model.
This will keep any existing model components intact.
Parameters: block (Block (scalar Block or single _BlockData)) –

add_column
(model, var, obj_coef, constraints, coefficients) Add a column to the solver’s and Pyomo model
This will add the Pyomo variable var to the solver’s model, and put the coefficients on the associated constraints in the solver model. If the obj_coef is not zero, it will add obj_coef*var to the objective of both the Pyomo and solver’s model.
Parameters:

add_constraint
(con) Add a single constraint to the solver’s model.
This will keep any existing model components intact.
Parameters: con (Constraint (scalar Constraint or single _ConstraintData)) –

add_sos_constraint
(con) Add a single SOS constraint to the solver’s model (if supported).
This will keep any existing model components intact.
Parameters: con (SOSConstraint) –

add_var
(var) Add a single variable to the solver’s model.
This will keep any existing model components intact.
Parameters: var (Var) –

available
(exception_flag=True) True if the solver is available.

has_capability
(cap) Returns a boolean value representing whether a solver supports a specific feature. Defaults to ‘False’ if the solver is unaware of an option. Expects a string.
Example: # prints True if solver supports sos1 constraints, and False otherwise print(solver.has_capability(‘sos1’)
# prints True is solver supports ‘feature’, and False otherwise print(solver.has_capability(‘feature’)
Parameters: cap (str) – The feature Returns: val – Whether or not the solver has the specified capability. Return type: bool

has_instance
() True if set_instance has been called and this solver interface has a pyomo model and a solver model.
Returns: tmp Return type: bool

license_is_valid
() True if the solver is present and has a valid license (if applicable)

load_duals
(cons_to_load=None) Load the duals into the ‘dual’ suffix. The ‘dual’ suffix must live on the parent model.
Parameters: cons_to_load (list of Constraint) –

load_rc
(vars_to_load) Load the reduced costs into the ‘rc’ suffix. The ‘rc’ suffix must live on the parent model.
Parameters: vars_to_load (list of Var) –

load_slacks
(cons_to_load=None) Load the values of the slack variables into the ‘slack’ suffix. The ‘slack’ suffix must live on the parent model.
Parameters: cons_to_load (list of Constraint) –

load_vars
(vars_to_load=None) Load the values from the solver’s variables into the corresponding pyomo variables.
Parameters: vars_to_load (list of Var) –

problem_format
() Returns the current problem format.

remove_block
(block) Remove a single block from the solver’s model.
This will keep any other model components intact.
WARNING: Users must call remove_block BEFORE modifying the block.
Parameters: block (Block (scalar Block or a single _BlockData)) –

remove_constraint
(con) Remove a single constraint from the solver’s model.
This will keep any other model components intact.
Parameters: con (Constraint (scalar Constraint or single _ConstraintData)) –

remove_sos_constraint
(con) Remove a single SOS constraint from the solver’s model.
This will keep any other model components intact.
Parameters: con (SOSConstraint) –

remove_var
(var) Remove a single variable from the solver’s model.
This will keep any other model components intact.
Parameters: var (Var (scalar Var or single _VarData)) –

reset
() Reset the state of the solver

results
A results object return from the solve method.

results_format
() Returns the current results format.

set_callback
(name, callback_fn=None) Set the callback function for a named callback.
A callback function has the form:
 def fn(solver, model):
 pass
where ‘solver’ is the native solver interface object and ‘model’ is a Pyomo model instance object.

set_instance
(model, **kwds) This method is used to translate the Pyomo model provided to an instance of the solver’s Python model. This discards any existing model and starts from scratch.
Parameters: model (ConcreteModel) – The pyomo model to be used with the solver.
Keyword Arguments:  symbolic_solver_labels (bool) – If True, the solver’s components (e.g., variables, constraints) will be given names that correspond to the Pyomo component names.
 skip_trivial_constraints (bool) – If True, then any constraints with a constant body will not be added to the solver model. Be careful with this. If a trivial constraint is skipped then that constraint cannot be removed from a persistent solver (an error will be raised if a user tries to remove a nonexistent constraint).
 output_fixed_variable_bounds (bool) – If False then an error will be raised if a fixed variable is used in one of the solver constraints. This is useful for catching bugs. Ordinarily a fixed variable should appear as a constant value in the solver constraints. If True, then the error will not be raised.

set_objective
(obj) Set the solver’s objective. Note that, at least for now, any existing objective will be discarded. Other than that, any existing model components will remain intact.
Parameters: obj (Objective) –

set_problem_format
(format) Set the current problem format (if it’s valid) and update the results format to something valid for this problem format.

set_results_format
(format) Set the current results format (if it’s valid for the current problem format).

solve
(*args, **kwds) Solve the model.
Keyword Arguments:  suffixes (list of str) – The strings should represnt suffixes support by the solver. Examples include ‘dual’, ‘slack’, and ‘rc’.
 options (dict) – Dictionary of solver options. See the solver documentation for possible solver options.
 warmstart (bool) – If True, the solver will be warmstarted.
 keepfiles (bool) – If True, the solver log file will be saved.
 logfile (str) – Name to use for the solver log file.
 load_solutions (bool) – If True and a solution exists, the solution will be loaded into the Pyomo model.
 report_timing (bool) – If True, then timing information will be printed.
 tee (bool) – If True, then the solver log will be printed.

update_var
(var)[source] Update a single variable in the solver’s model.
This will update bounds, fix/unfix the variable as needed, and update the variable type.
Parameters: var (Var (scalar Var or single _VarData)) –

version
() Returns a 4tuple describing the solver executable version.

warm_start_capable
() True is the solver can accept a warmstart solution