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

Class SolnPoolFilterInterface


Methods for solution pool filters.
Instance Methods
 
__init__(self, parent)
Creates a new SolnPoolFilterInterface.
 
add_diversity_filter(self, lb, ub, expression, weights=None, name='')
Adds a diversity filter to the solution pool.
 
add_range_filter(self, lb, ub, expression, name='')
Adds a range filter to the solution pool.
 
get_diversity_filters(self, *args)
Returns a set of diversity filters.
 
get_range_filters(self, *args)
Returns a set of range filters.
 
get_bounds(self, *args)
Returns (lb, ub) pairs for a set of filters.
 
get_num_nonzeros(self, *args)
Returns the number of variables specified by a set of filters.
 
delete(self, *args)
Deletes filters from the problem.
 
get_types(self, *args)
Returns the types of a set of filters.
 
get_names(self, *args)
Returns the names of filters, given their indices.
 
write(self, filename)
Writes the filters to a file.
 
read(self, filename)
Reads filters from a file.
 
get_num(self)
Returns the number of filters in the problem.

Inherited from _baseinterface.BaseInterface: get_indices

Class Variables
  type = FilterType()
See FilterType()
Method Details

__init__(self, parent)
(Constructor)

 

Creates a new SolnPoolFilterInterface.

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

Overrides: _baseinterface.BaseInterface.__init__

add_diversity_filter(self, lb, ub, expression, weights=None, name='')

 

Adds a diversity filter to the solution pool.

The arguments determine, in order,

the lower bound (float)

the upper bound (float)

the variables and values it takes as either a SparsePair or a list of two lists.

a set of weights (a list of floats with the same length as expression). If an empty list is given, then weights of 1.0 (one) will be used.

name (string)

Returns the index of the added diversity filter.

>>> 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.filter.add_diversity_filter(
...     300, 600, [['x1','x2'], [1,1]], [2,1], "")
0

add_range_filter(self, lb, ub, expression, name='')

 

Adds a range filter to the solution pool.

The arguments determine, in order,

the lower bound (float)

the upper bound (float)

the variables and values it takes as either a SparsePair or a list of two lists.

name (string)

Returns the index of the added range filter.

>>> 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.filter.add_range_filter(
...     300, 600, [['x1','x2'], [1,1]], "")
0

get_diversity_filters(self, *args)

 

Returns a set of diversity filters.

Returns filters as pairs of (SparsePair, weights), where weights is a list of floats.

Can be called by four forms.

>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(names = ['x','y'], types = ["BB"])
>>> f = cplex.SparsePair(ind = ['x'],val = [1.0])
>>> [c.solution.pool.filter.add_diversity_filter(
...      0, 1, f, [1], str(i))
...  for i in range(2)]
[0, 1]
>>> c.solution.pool.filter.get_diversity_filters(0)
(SparsePair(ind = [0], val = [1.0]), [1.0])
>>> c.solution.pool.filter.get_diversity_filters("1")
(SparsePair(ind = [0], val = [1.0]), [1.0])
>>> c.solution.pool.filter.get_diversity_filters([0, "1"])
[(SparsePair(ind = [0], val = [1.0]), [1.0]), (SparsePair(ind = [0], val = [1.0]), [1.0])]
>>> c.solution.pool.filter.get_diversity_filters()
[(SparsePair(ind = [0], val = [1.0]), [1.0]), (SparsePair(ind = [0], val = [1.0]), [1.0])]

get_range_filters(self, *args)

 

Returns a set of range filters.

Returns filters as SparsePair instances.

Can be called by four forms.

>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(names = ['x','y'], types = ["II"])
>>> f = cplex.SparsePair(ind = ['x'],val = [1.0])
>>> [c.solution.pool.filter.add_range_filter(
...      0.0, 1.0, f, str(i)) for i in range(2)]
[0, 1]
>>> c.solution.pool.filter.get_range_filters(0)
SparsePair(ind = [0], val = [1.0])
>>> c.solution.pool.filter.get_range_filters("1")
SparsePair(ind = [0], val = [1.0])
>>> c.solution.pool.filter.get_range_filters([0, "1"])
[SparsePair(ind = [0], val = [1.0]), SparsePair(ind = [0], val = [1.0])]
>>> c.solution.pool.filter.get_range_filters()
[SparsePair(ind = [0], val = [1.0]), SparsePair(ind = [0], val = [1.0])]

get_bounds(self, *args)

 

Returns (lb, ub) pairs for a set of filters.

Can be called by four forms.

>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(names=['x', 'y'], types=["BB"])
>>> f = cplex.SparsePair(ind=['x'], val=[1.0])
>>> [c.solution.pool.filter.add_diversity_filter(
...      0, 1, f, [1], "div{0}".format(i)) for i in range(2)]
[0, 1]
>>> [c.solution.pool.filter.add_range_filter(
...      0, 1, f, "rng{0}".format(i)) for i in range(2)]
[2, 3]
>>> c.solution.pool.filter.get_bounds(0)
(0.0, 1.0)
>>> c.solution.pool.filter.get_bounds("rng0")
(0.0, 1.0)
>>> c.solution.pool.filter.get_bounds(["div0", 2])
[(0.0, 1.0), (0.0, 1.0)]
>>> c.solution.pool.filter.get_bounds()
[(0.0, 1.0), (0.0, 1.0), (0.0, 1.0), (0.0, 1.0)]

get_num_nonzeros(self, *args)

 

Returns the number of variables specified by a set of filters.

Can be called by four forms.

>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(names=['x', 'y'], types=["BB"])
>>> f = cplex.SparsePair(ind=['x'], val=[1.0])
>>> [c.solution.pool.filter.add_diversity_filter(
...      0, 1, f, [1], "div{0}".format(i)) for i in range(2)]
[0, 1]
>>> [c.solution.pool.filter.add_range_filter(
...      0, 1, f, "rng{0}".format(i)) for i in range(2)]
[2, 3]
>>> c.solution.pool.filter.get_num_nonzeros(0)
1
>>> c.solution.pool.filter.get_num_nonzeros("rng0")
1
>>> c.solution.pool.filter.get_num_nonzeros(["div0", 2])
[1, 1]
>>> c.solution.pool.filter.get_num_nonzeros()
[1, 1, 1, 1]

delete(self, *args)

 

Deletes filters from the problem.

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

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

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

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(names=['x', 'y'], types=['II'])
>>> f = cplex.SparsePair(ind=['x'], val=[1.0])
>>> [c.solution.pool.filter.add_range_filter(
...      0.0, 1.0, f, str(i)) for i in range(10)]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> c.solution.pool.filter.get_num()
10
>>> c.solution.pool.filter.delete(8)
>>> c.solution.pool.filter.get_names()
['0', '1', '2', '3', '4', '5', '6', '7', '9']
>>> c.solution.pool.filter.delete('1', 3)
>>> c.solution.pool.filter.get_names()
['0', '4', '5', '6', '7', '9']
>>> c.solution.pool.filter.delete([2, '0', 5])
>>> c.solution.pool.filter.get_names()
['4', '6', '7']
>>> c.solution.pool.filter.delete()
>>> c.solution.pool.filter.get_names()
[]

get_types(self, *args)

 

Returns the types of a set of filters.

Can be called by four forms.

>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(names = ['x','y'], types = ["II"])
>>> f = cplex.SparsePair(ind = ['x'],val = [1.0])
>>> [c.solution.pool.filter.add_range_filter(
...      0.0, 1.0, f, str(i)) for i in range(10)]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> c.solution.pool.filter.get_types(3)
2
>>> c.solution.pool.filter.get_types("5")
2
>>> c.solution.pool.filter.get_types([2, "8"])
[2, 2]
>>> c.solution.pool.filter.get_types()
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2]

get_names(self, *args)

 

Returns the names of filters, given their indices.

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

solution.pool.filter.get_names()
return the names of all solution pool filters from the problem.
solution.pool.filter.get_names(i)
i must be a solution filter index. Returns the name of row i.
solution.pool.filter.get_names(s)
s must be a sequence of row indices. Returns the names of the solution pool filters with indices the members of s. Equivalent to [solution.pool.filter.get_names(i) for i in s]
solution.pool.filter.get_names(begin, end)
begin and end must be solution filter indices. Returns the names of the solution pool filter with indices between begin and end, inclusive of end. Equivalent to solution.pool.filter.get_names(range(begin, end + 1)).
>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(names = ['x','y'], types = ["II"])
>>> f = cplex.SparsePair(ind = ['x'],val = [1.0])
>>> [c.solution.pool.filter.add_range_filter(
...      0.0, 1.0, f, str(i)) for i in range(10)]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> c.solution.pool.filter.get_names()
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
>>> c.solution.pool.filter.get_names(6)
'6'
>>> c.solution.pool.filter.get_names([5, 3])
['5', '3']
>>> c.solution.pool.filter.get_names(3, 5)
['3', '4', '5']

write(self, filename)

 

Writes the filters to a file.

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.filter.add_range_filter(
...     300, 600, [['x1','x2'], [1,1]], "")
0
>>> c.solution.pool.filter.write("ind.flt")

read(self, filename)

 

Reads filters from a file.

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.filter.add_range_filter(
...     300, 600, [['x1','x2'], [1,1]], "")
0
>>> c.solution.pool.filter.write("ind.flt")
>>> c.solution.pool.filter.read("ind.flt")

get_num(self)

 

Returns the number of filters in the problem.

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.filter.add_range_filter(
...     300, 600, [['x1','x2'], [1,1]], "")
0
>>> c.solution.pool.filter.get_num()
1