MOSEKPersistent
(class from pyomo.solvers.plugins.solvers.mosek_persistent
)
- class pyomo.solvers.plugins.solvers.mosek_persistent.MOSEKPersistent(**kwds)[source]
Bases:
PersistentSolver
,MOSEKDirect
This class provides a persistent interface between pyomo and MOSEK’s Optimizer API. As a child to the MOSEKDirect class, this interface does not need any file IO. Furthermore, the persistent interface preserves the MOSEK task object, allowing users to make incremental changes (such as removing variables/constraints, modifying variables, adding columns etc.) to their models. Note that users are responsible for informing the persistent interface of any incremental change. For instance, if a new variable is defined, then it would need to be added explicitly by calling the add_var method, before the solver knows of its existence. :keyword type: String indicating the class type of the solver instance. :kwtype type: str :keyword name: String representing either the class type of the solver instance or an assigned name. :kwtype name: str :keyword doc: Documentation for the solver :kwtype doc: str :keyword options: Dictionary of solver options :kwtype options: dict
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_constraints
(con_seq)Add multiple constraints to the MOSEK task object in one method call.
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.
add_vars
(var_seq)Add multiple variables to the MOSEK task object in one method call.
available
([exception_flag])True if the solver is available.
config_block
([init])default_variable_value
()has_capability
(cap)Returns a boolean value representing whether a solver supports a specific feature.
True if set_instance has been called and this solver interface has a pyomo model and a solver model.
Runs a check for a valid MOSEK license.
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.
Returns the current problem format.
remove_block
(block)Remove a single block from the solver's model.
remove_constraint
(solver_con)Remove a single constraint from the model as well as the MOSEK task.
remove_constraints
(*solver_cons)Remove multiple constraints from the model as well as the MOSEK task in one method call.
Remove a single SOS constraint from the solver's model.
remove_var
(solver_var)Remove a single variable from the model as well as the MOSEK task.
remove_vars
(*solver_vars)Remove multiple scalar variables from the model as well as the MOSEK task.
reset
()Reset the state of the solver
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).
solve
(*args, **kwds)Solve the model.
update_var
(solver_var)Update a single variable in solver model.
update_vars
(*solver_vars)Update multiple scalar variables in solver model.
version
()Returns a 4-tuple describing the solver executable version.
True is the solver can accept a warm-start solution
write
(filename)Write the model to a file.
Attributes
keepfiles
log_file
soln_file
suffixes
symbolic_solver_labels
tee
warm_start_file_name
warm_start_solve
A results object return from the solve method.
Member Documentation
- 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.
- 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_constraints(con_seq)[source]
Add multiple constraints to the MOSEK task object in one method call.
This will keep any existing model components intact.
NOTE: If this method is used to add cones, then the cones should be passed as constraints. Use the add_block method for conic_domains.
- Parameters:
con_seq (tuple/list of 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)
- add_vars(var_seq)[source]
Add multiple variables to the MOSEK task object in one method call.
This will keep any existing model components intact.
- Parameters:
var_seq (tuple/list of 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’)
- 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:
- license_is_valid()
Runs a check for a valid MOSEK license. Returns False if MOSEK fails to run on a trivial test case.
- 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.
- 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.
- 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(solver_con)[source]
Remove a single constraint from the model as well as the MOSEK task.
This will keep any other model components intact.
To remove a conic-domain, you should use the remove_block method. :param solver_con: :type solver_con: Constraint (scalar Constraint or single ConstraintData)
- remove_constraints(*solver_cons)[source]
Remove multiple constraints from the model as well as the MOSEK task in one method call.
This will keep any other model components intact. To remove conic-domains, use the remove_block method.
- Parameters:
*solver_cons (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(solver_var)[source]
Remove a single variable from the model as well as the MOSEK task. This will keep any other model components intact. :param solver_var: :type solver_var: Var (scalar Var or single VarData)
- remove_vars(*solver_vars)[source]
Remove multiple scalar variables from the model as well as the MOSEK task. The user can pass an unpacked list of scalar variables. This will keep any other model components intact. :param *solver_var: :type *solver_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 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(solver_var)[source]
Update a single variable in solver model. This method allows fixing/unfixing, changing variable type and bounds. :param solver_var: :type solver_var: Var
- update_vars(*solver_vars)[source]
Update multiple scalar variables in solver model. This method allows fixing/unfixing, changing variable types and bounds. :param *solver_var: :type *solver_var: Constraint (scalar Constraint or single ConstraintData)
- 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. MOSEK can write files in various popular formats such as: lp, mps, ptf, cbf etc. In addition to the file formats mentioned above, MOSEK can also write files to native formats such as : opf, task and jtask. The task format is binary, and is the preferred format for sharing with the MOSEK staff in case of queries, since it saves the status of the problem and the solver down the smallest detail. Parameters: filename: str (Name of the output file, including the desired extension)
- results
A results object return from the solve method.