GurobiPersistent

Methods

GurobiPersistent.add_block(block) Add a single Pyomo Block to the solver’s model.
GurobiPersistent.add_constraint(con) Add a constraint to the solver’s model.
GurobiPersistent.set_objective(obj) Set the solver’s objective.
GurobiPersistent.add_sos_constraint(con) Add an SOS constraint to the solver’s model (if supported).
GurobiPersistent.add_var(var) Add a variable to the solver’s model.
GurobiPersistent.available([exception_flag]) True if the solver is available.
GurobiPersistent.has_capability(cap) Returns a boolean value representing whether a solver supports a specific feature.
GurobiPersistent.has_instance() True if set_instance has been called and this solver interface has a pyomo model and a solver model.
GurobiPersistent.load_vars([vars_to_load]) Load the values from the solver’s variables into the corresponding pyomo variables.
GurobiPersistent.problem_format() Returns the current problem format.
GurobiPersistent.remove_block(block) Remove a single block from the solver’s model.
GurobiPersistent.remove_constraint(con) Remove a single constraint from the solver’s model.
GurobiPersistent.remove_sos_constraint(con) Remove a single SOS constraint from the solver’s model.
GurobiPersistent.remove_var(var) Remove a single variable from the solver’s model.
GurobiPersistent.reset() Reset the state of the solver
GurobiPersistent.results_format() Returns the current results format.
GurobiPersistent.set_callback(name[, …]) Set the callback function for a named callback.
GurobiPersistent.set_instance(model, **kwds) This method is used to translate the Pyomo model provided to an instance of the solver’s Python model.
GurobiPersistent.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.
GurobiPersistent.set_results_format(format) Set the current results format (if it’s valid for the current problem format).
GurobiPersistent.solve(*args, **kwds) Solve the model.
GurobiPersistent.update_var(var) Update a single variable in the solver’s model.
GurobiPersistent.version() Returns a 4-tuple describing the solver executable version.
GurobiPersistent.write(filename) Write the model to a file (e.g., and lp file).
class pyomo.solvers.plugins.solvers.gurobi_persistent.GurobiPersistent(**kwds)[source]

Bases: pyomo.solvers.plugins.solvers.persistent_solver.PersistentSolver, pyomo.solvers.plugins.solvers.gurobi_direct.GurobiDirect

A class that provides a persistent interface to Gurobi. 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_constraint(con)[source]

Add a constraint to the solver’s model. This will keep any existing model components intact.

Parameters:con (Constraint) –
add_sos_constraint(con)[source]

Add an SOS constraint to the solver’s model (if supported). This will keep any existing model components intact.

Parameters:con (SOSConstraint) –
add_var(var)[source]

Add a variable to the solver’s model. This will keep any existing model components intact.

Parameters:var (Var) – The variable to add to the solver’s model.
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
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_format()

Returns the current results format.

set_callback(name, callback_fn=None)

Set the callback function for a named callback.

A call-back 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 non-existent 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 4-tuple describing the solver executable version.

warm_start_capable()

True is the solver can accept a warm-start solution

write(filename)[source]

Write the model to a file (e.g., and lp file).

Parameters:filename (str) – Name of the file to which the model should be written.