XpressPersistent

(class from pyomo.solvers.plugins.solvers.xpress_persistent)

class pyomo.solvers.plugins.solvers.xpress_persistent.XpressPersistent(**kwds)[source]

Bases: PersistentSolver, XpressDirect

A class that provides a persistent interface to Xpress. 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 method.

  • 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

__init__(**kwds)[source]

Constructor

Methods

__init__(**kwds)

Constructor

add_block(block)

Add a single Pyomo Block to the solver's model.

add_column(model, var, obj_coef, ...)

Add a column to the solver's and Pyomo model

add_constraint(con)

Add a single constraint to the solver's model.

add_sos_constraint(con)

Add a single SOS constraint to the solver's model (if supported).

add_var(var)

Add a single variable to the solver's model.

available([exception_flag])

True if the solver is available.

config_block([init])

default_variable_value()

get_xpress_attribute(*args)

Get xpress attributes.

get_xpress_control(*args)

Get xpress controls.

has_capability(cap)

Returns a boolean value representing whether a solver supports a specific feature.

has_instance()

True if set_instance has been called and this solver interface has a pyomo model and a solver model.

license_is_valid()

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

load_duals([cons_to_load])

Load the duals into the 'dual' suffix.

load_rc([vars_to_load])

Load the reduced costs into the 'rc' suffix.

load_slacks([cons_to_load])

Load the values of the slack variables into the 'slack' suffix.

load_vars([vars_to_load])

Load the values from the solver's variables into the corresponding pyomo variables.

problem_format()

Returns the current problem format.

remove_block(block)

Remove a single block from the solver's model.

remove_constraint(con)

Remove a single constraint from the solver's model.

remove_sos_constraint(con)

Remove a single SOS constraint from the solver's model.

remove_var(var)

Remove a single variable from the solver's model.

reset()

Reset the state of the solver

results_format()

Returns the current results format.

set_callback(name[, callback_fn])

Set the callback function for a named callback.

set_instance(model, **kwds)

This method is used to translate the Pyomo model provided to an instance of the solver's Python model.

set_objective(obj)

Set the solver's objective.

set_options(istr)

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).

set_xpress_control(*args)

Set xpress controls.

solve(*args, **kwds)

Solve the model.

update_var(var)

Update a single variable in the solver's model.

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[, flags])

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

Attributes

keepfiles

log_file

soln_file

suffixes

symbolic_solver_labels

tee

warm_start_file_name

warm_start_solve

results

A results object return from the solve method.

Member Documentation

XpressException

alias of RuntimeError

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:
  • model (pyomo ConcreteModel to which the column will be added)

  • var (Var (scalar Var or single VarData))

  • obj_coef (float, pyo.Param)

  • constraints (list of scalar Constraints of single ConstraintDatas)

  • coefficients (list of the coefficient to put on var in the associated constraint)

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.

get_xpress_attribute(*args)[source]

Get xpress attributes.

Parameters:
  • control(s) (str, strs, list, None) – The xpress attribute to get. Options include any xpress attribute. Can also be list of xpress controls or None for every attribute Please see the Xpress documentation for options.

  • other (See the Xpress documentation for xpress.problem.getAttrib for)

  • function (uses of this)

Return type:

control value or dictionary of control values

get_xpress_control(*args)[source]

Get xpress controls.

Parameters:
  • control(s) (str, strs, list, None) – The xpress control to get. Options include any xpress control. Can also be list of xpress controls or None for every control Please see the Xpress documentation for options.

  • other (See the Xpress documentation for xpress.problem.getControl for)

  • function (uses of this)

Return type:

control value or dictionary of control values

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=None)

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).

set_xpress_control(*args)[source]

Set xpress controls.

Parameters:
  • control (str) – The xpress control to set. Options include any xpree control. Please see the Xpress documentation for options.

  • val (any) – The value to set the control to. See Xpress documentation for possible values.

  • argument (If one)

  • values (it must be a dictionary with control keys and control)

solve(*args, **kwds)

Solve the model.

Keyword Arguments:
  • suffixes (list of str) – The strings should represent 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, flags='')[source]

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

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

  • flags (str) – Flags for xpress.problem.write

results

A results object return from the solve method.