Package cplex :: Package _internal :: Module _subinterfaces :: Class SolnPoolInterface
[frames] | no frames]
 

Class SolnPoolInterface


Methods for accessing the solution pool.
Instance Methods
 
__init__(self, parent)
Creates a new SolnPoolInterface.
 
get_objective_value(self, soln)
Returns the objective value for a member of the solution pool.
 
get_values(self, soln, *args)
Returns the values of a set of variables for a given solution.
 
get_linear_slacks(self, soln, *args)
Returns a set of linear slacks for a given solution.
 
get_quadratic_slacks(self, soln, *args)
Returns a set of quadratic slacks for a given solution.
 
get_integer_quality(self, soln, which)
Returns the integer quality of a given solution.
 
get_float_quality(self, soln, which)
Returns the float quality of a given solution.
 
get_mean_objective_value(self)
Returns the average among the objective values in the solution pool.
 
delete(self, *args)
Deletes solutions from the solution pool.
 
get_names(self, *args)
Returns the names of a set of solutions.
 
get_num_replaced(self)
Returns the number of solution pool members that have been replaced.
 
get_num(self)
Returns the number of solutions in the solution pool.
 
write(self, filename, which=None)
Writes solutions to a file.
 
get_quality_metrics(self, soln)
Returns an object containing measures of the quality of the specified solution.

Inherited from _baseinterface.BaseInterface: get_indices

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables
  incumbent = -1
See _constants.CPX_INCUMBENT_ID
  quality_metric = QualityMetric()
See QualityMetric()
Instance Variables
  filter
See SolnPoolFilterInterface()
Properties

Inherited from object: __class__

Method Details

__init__(self, parent)
(Constructor)

 

Creates a new SolnPoolInterface.

The solution pool interface is exposed by the top-level Cplex class as Cplex.solution.pool. This constructor is not meant to be used externally.

Overrides: object.__init__

get_objective_value(self, soln)

 

Returns the objective value for a member of the solution pool.

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> out = c.set_results_stream(None)
>>> out = c.set_log_stream(None)
>>> c.read("ind.lp")
>>> c.solve()
>>> obj_val = c.solution.pool.get_objective_value(0)
>>> abs(obj_val - 499.0) < 1e-6
True

get_values(self, soln, *args)

 

Returns the values of a set of variables for a given solution.

Can be called by four forms.

>>> import cplex
>>> c = cplex.Cplex()
>>> c.parameters.randomseed.set(1)
>>> out = c.set_results_stream(None)
>>> out = c.set_log_stream(None)
>>> c.read("ind.lp")
>>> c.solve()
>>> c.solution.pool.get_values(1, 2)
244.0
>>> abs(c.solution.pool.get_values(1, "x2"))
0.0
>>> val = c.solution.pool.get_values(1, ["x2", 2])
>>> [x if x else 0.0 for x in val]
[0.0, 244.0]
>>> val = c.solution.pool.get_values(1)
>>> val[2]
244.0

get_linear_slacks(self, soln, *args)

 

Returns a set of linear slacks for a given solution.

Can be called by four forms.

>>> import cplex
>>> c = cplex.Cplex()
>>> out = c.set_results_stream(None)
>>> out = c.set_log_stream(None)
>>> c.read("ind.lp")
>>> c.solve()
>>> c.solution.pool.get_linear_slacks(2, 1)
0.0
>>> c.solution.pool.get_linear_slacks(2, "c2")
0.0
>>> c.solution.pool.get_linear_slacks(2, ["c2", 1])
[0.0, 0.0]
>>> linslack = c.solution.pool.get_linear_slacks(2)
>>> abs(linslack[2]) < 1e-6
True

get_quadratic_slacks(self, soln, *args)

 

Returns a set of quadratic slacks for a given solution.

Can be called by four forms.

>>> import cplex
>>> c = cplex.Cplex()
>>> c.parameters.randomseed.set(1)
>>> out = c.set_results_stream(None)
>>> out = c.set_log_stream(None)
>>> c.read("miqcp.lp")
>>> c.solve()
>>> var = c.solution.pool.get_quadratic_slacks(1, 1)
>>> var = c.solution.pool.get_quadratic_slacks(1, "QC3")
>>> vars = c.solution.pool.get_quadratic_slacks(1, ["QC3", 1])
>>> vars = c.solution.pool.get_quadratic_slacks(1)

get_integer_quality(self, soln, which)

 

Returns the integer quality of a given solution.

The integer quality of a solution can either be a single attribute of solution.pool.quality_metrics or a sequence of such attributes.

Note
This corresponds to the CPLEX callable library function CPXgetsolnpoolintquality.
>>> import cplex
>>> c = cplex.Cplex()
>>> out = c.set_results_stream(None)
>>> out = c.set_log_stream(None)
>>> c.read("ind.lp")
>>> c.solve()
>>> quality_metric = c.solution.pool.quality_metric
>>> misi = quality_metric.max_indicator_slack_infeasibility
>>> c.solution.pool.get_integer_quality(1, misi)
-1

get_float_quality(self, soln, which)

 

Returns the float quality of a given solution.

The float quality of a solution can either be a single attribute of solution.pool.quality_metrics or a sequence of such attributes.

Note
This corresponds to the CPLEX callable library function CPXgetsolnpooldblquality.
>>> import cplex
>>> c = cplex.Cplex()
>>> out = c.set_results_stream(None)
>>> out = c.set_log_stream(None)
>>> c.read("ind.lp")
>>> c.solve()
>>> qual = c.solution.pool.get_float_quality(1,
                         c.solution.pool.quality_metric.max_indicator_slack_infeasibility)
>>> abs(qual) < 1.e-6
True

get_mean_objective_value(self)

 

Returns the average among the objective values in the solution pool.

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> c.parameters.randomseed.set(1)
>>> out = c.set_results_stream(None)
>>> out = c.set_log_stream(None)
>>> c.read("ind.lp")
>>> c.solve()
>>> mov = c.solution.pool.get_mean_objective_value()

delete(self, *args)

 

Deletes solutions from the solution pool.

There are four forms by which pool.delete may be called.

pool.delete()
deletes all solutions from the problem.
pool.delete(i)
i must be a solution name or index. Deletes the solution whose index or name is i.
pool.delete(s)
s must be a sequence of solution names or indices. Deletes the solutions with names or indices contained within s. Equivalent to [pool.delete(i) for i in s].
pool.delete(begin, end)
begin and end must be solution indices or solution names. Deletes the solutions with indices between begin and end, inclusive of end. Equivalent to pool.delete(range(begin, end + 1)). This will give the best performance when deleting batches of solutions from the solution pool.

See CPXdelsolnpoolsolns in the Callable Library Reference Manual for more detail.

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> out = c.set_results_stream(None)
>>> out = c.set_log_stream(None)
>>> c.read("ind.lp")
>>> c.parameters.randomseed.set(1)
>>> c.parameters.mip.limits.populate.set(5)
>>> c.populate_solution_pool()
>>> names = c.solution.pool.get_names()
>>> c.solution.pool.delete(1)
>>> n = c.solution.pool.get_names()
>>> del names[1]
>>> n == names
True
>>> c.solution.pool.delete(names[1])
>>> n = c.solution.pool.get_names()
>>> names.remove(names[1])
>>> n == names
True
>>> c.solution.pool.delete([names[1], 0])
>>> n = c.solution.pool.get_names()
>>> names.remove(names[1])
>>> del names[0]
>>> n == names
True
>>> c.solution.pool.delete()
>>> c.solution.pool.get_names()
[]

get_names(self, *args)

 

Returns the names of a set of solutions.

There are four forms by which solution.pool.get_names may be called.

solution.pool.get_names()
return the names of all solutions from the problem.
solution.pool.get_names(i)
i must be a solution index. Returns the name of row i.
solution.pool.get_names(s)
s must be a sequence of row indices. Returns the names of the solutions with indices the members of s. Equivalent to [solution.pool.get_names(i) for i in s]
solution.pool.get_names(begin, end)
begin and end must be solution indices. Returns the names of the solutions with indices between begin and end, inclusive of end. Equivalent to solution.pool.get_names(range(begin, end + 1)).
>>> import cplex
>>> c = cplex.Cplex()
>>> out = c.set_results_stream(None)
>>> out = c.set_log_stream(None)
>>> c.read("ind.lp")
>>> c.parameters.randomseed.set(1)
>>> c.parameters.mip.limits.populate.set(10)
>>> c.populate_solution_pool()
>>> names = c.solution.pool.get_names()
>>> names[1] == c.solution.pool.get_names(1)
True
>>> [names[i] for i in [1,2]] == c.solution.pool.get_names([1,2])
True
>>> names[1:5] == c.solution.pool.get_names(1, 4)
True

get_num_replaced(self)

 

Returns the number of solution pool members that have been replaced.

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> out = c.set_results_stream(None)
>>> out = c.set_log_stream(None)
>>> c.read("ind.lp")
>>> c.solve()
>>> c.solution.pool.get_num_replaced()
0

get_num(self)

 

Returns the number of solutions in the solution pool.

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> c.parameters.randomseed.set(1)
>>> out = c.set_results_stream(None)
>>> out = c.set_log_stream(None)
>>> c.read("ind.lp")
>>> c.solve()
>>> num = c.solution.pool.get_num()

write(self, filename, which=None)

 

Writes solutions to a file.

If no second argument is provided, all solutions are written to file.

If a second argument is provided, it is the index of a solution in the solution pool. Only that solution will be written to file.

>>> import cplex
>>> c = cplex.Cplex()
>>> out = c.set_results_stream(None)
>>> out = c.set_log_stream(None)
>>> c.read("ind.lp")
>>> c.parameters.randomseed.set(1)
>>> c.parameters.mip.limits.populate.set(10)
>>> c.populate_solution_pool()
>>> c.solution.pool.write("ind.sol",4)

get_quality_metrics(self, soln)

 

Returns an object containing measures of the quality of the specified solution.

See QualityMetrics