Package cplex :: Package _internal :: Module _subinterfaces :: Class MIPStartsInterface
 

Class MIPStartsInterface


Contains methods pertaining to MIP starts.
Instance Methods
 
__init__(self, cplex)
Creates a new MIPStartsInterface.
 
get_num(self)
Returns the number of MIP starts currently stored.
 
read(self, filename)
Reads MIP starts from a file.
 
write(self, filename, begin=-1, end=-1)
Writes a set of MIP starts to a file.
 
add(self, *args)
Adds MIP starts to the problem.
 
change(self, *args)
Changes a MIP start or set of MIP starts.
 
delete(self, *args)
Deletes MIP starts from the problem.
 
get_starts(self, *args)
Returns a set of MIP starts.
 
get_effort_levels(self, *args)
Returns the effort levels for a set of MIP starts.
 
get_num_entries(self, *args)
Returns the number of variables specified by a set of MIP starts.
 
get_names(self, *args)
Returns the names of a set of MIP starts.

Inherited from _baseinterface.BaseInterface: get_indices

Class Variables
  effort_level = EffortLevel()
See EffortLevel()
Method Details

__init__(self, cplex)
(Constructor)

 

Creates a new MIPStartsInterface.

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

Overrides: _baseinterface.BaseInterface.__init__

get_num(self)

 

Returns the number of MIP starts currently stored.

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(
...     names = [str(i) for i in range(11)],
...     types = "I" * 11)
>>> indices = c.MIP_starts.add(
...     [(cplex.SparsePair(ind = [i], val = [0.0]),
...       c.MIP_starts.effort_level.auto) for i in range(5)])
>>> c.MIP_starts.get_num()
5

read(self, filename)

 

Reads MIP starts from a file.

This method reads a file in the format MST and copies the information of all the MIP starts contained in that file into a CPLEX problem object. The parameter cplex.parameters.advance must be set to cplex.parameters.advance.values.standard, its default value, or cplex.parameters.advance.values.alternate in order for the MIP starts to be used.

Note
If the MIP start file is successfully read, then any previously existing MIP starts will be deleted.

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.MIP_starts.write("test_all.mst")
>>> c.MIP_starts.read("test_all.mst")

write(self, filename, begin=-1, end=-1)

 

Writes a set of MIP starts to a file.

If called with only a filename, writes all MIP starts to that file.

If called with a filename and one index or name of a MIP start, writes only that MIP start to the file.

If called with a filename and two indices or names of MIP starts, writes all MIP starts between the first and second index or name, inclusive of begin and end, to the file.

>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(
...     names = [str(i) for i in range(11)], types = "I" * 11)
>>> indices = c.MIP_starts.add(
...     [(cplex.SparsePair(ind = [i], val = [0.0]),
...       c.MIP_starts.effort_level.auto) for i in range(5)])
>>> c.MIP_starts.write("test_all.mst")
>>> c.MIP_starts.write("test_one.mst", 1)
>>> c.MIP_starts.write("test_four.mst", 1, 4)

add(self, *args)

 

Adds MIP starts to the problem.

To add a single MIP start, call this method as

cpx.MIP_starts.add(start, effort_level, name)

The first argument, start, must be either a SparsePair instance or a list of two lists, the first of which contains variable indices or names, the second of which contains the values that those variables take.

The second argument, effort_level, must be an attribute of MIP_starts.effort_level.

The third optional argument is the name of the MIP start.

To add a set of MIP starts, call this method as

cpx.MIP_starts.add(sequence)

where sequence is a list or tuple of pairs (start, effort_level) or triples (start, effort_level, name) as described above.

>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(names = [str(i) for i in range(11)],
...                           types = "I" * 11)
>>> indices = c.MIP_starts.add(
...     cplex.SparsePair(ind = [0], val = [0.0]),
...     c.MIP_starts.effort_level.repair, "first")
>>> indices = c.MIP_starts.add(
...     cplex.SparsePair(ind = [1], val = [0.0]),
...     c.MIP_starts.effort_level.solve_MIP)
>>> indices = c.MIP_starts.add(
...     [([[2, 4], [0.0, 1.0]],
...       c.MIP_starts.effort_level.auto, "third"),
...      ([[3, 4], [1.0, 3.0]],
...       c.MIP_starts.effort_level.check_feasibility)])
>>> c.MIP_starts.get_num()
4
>>> c.MIP_starts.get_names()
['first', 'm2', 'third', 'm4']

change(self, *args)

 

Changes a MIP start or set of MIP starts.

To change a single MIP start, call this method as

cpx.MIP_starts.change(ID, start, effort_level)

The first argument, ID, must be an index or name of an existing MIP start.

The second argument, start, must be either a SparsePair instance or a list of two lists, the first of which contains variable indices or names, the second of which contains the values that those variables take. If the MIP start identified by ID already has a value for a variable specified by start, that value is replaced.

The third argument, effort_level, must be an attribute of MIP_starts.effort_level.

To change multiple MIP starts, call this method as

cpx.MIP_starts.change(sequence)

where sequence is a list of tuple of triples (ID, start, effort_level) as described above.

>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(
...     names = ["x{0}".format(i) for i in range(4)],
...     types = "I" * 4
... )
>>> indices = c.MIP_starts.add(
...     [(cplex.SparsePair(ind = [i], val = [0.0]),
...       c.MIP_starts.effort_level.auto) for i in range(3)])
>>> for s in c.MIP_starts.get_starts():
...     print(s)
(SparsePair(ind = [0], val = [0.0]), 0)
(SparsePair(ind = [1], val = [0.0]), 0)
(SparsePair(ind = [2], val = [0.0]), 0)
>>> c.MIP_starts.get_names()
['m1', 'm2', 'm3']
>>> check = c.MIP_starts.effort_level.check_feasibility
>>> repair = c.MIP_starts.effort_level.repair
>>> c.MIP_starts.change("m1", [["x0", "x1"], [1.0, 2.0]], check)
>>> c.MIP_starts.get_starts("m1")
(SparsePair(ind = [0, 1], val = [1.0, 2.0]), 1)
>>> c.MIP_starts.change(1, [[1, 2], [-1.0, -2.0]], repair)
>>> c.MIP_starts.get_starts("m2")
(SparsePair(ind = [1, 2], val = [-1.0, -2.0]), 4)
>>> c.MIP_starts.change([(1, [[0, 2], [-1.0, 2.0]], check),
...                      ("m3", [["x0", 2], [3.0, 2.0]], repair)])
>>> for s in c.MIP_starts.get_starts(["m2", "m3"]):
...     print(s)
(SparsePair(ind = [0, 1, 2], val = [-1.0, -1.0, 2.0]), 1)
(SparsePair(ind = [0, 2], val = [3.0, 2.0]), 4)

delete(self, *args)

 

Deletes MIP starts from the problem.

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

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

See CPXdelmipstarts 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"])
>>> indices = c.MIP_starts.add(
...     [(cplex.SparsePair(ind=['x'], val=[1.0]),
...       c.MIP_starts.effort_level.auto, str(i))
...      for i in range(10)])
>>> c.MIP_starts.get_num()
10
>>> c.MIP_starts.delete(8)
>>> c.MIP_starts.get_names()
['0', '1', '2', '3', '4', '5', '6', '7', '9']
>>> c.MIP_starts.delete("1", 3)
>>> c.MIP_starts.get_names()
['0', '4', '5', '6', '7', '9']
>>> c.MIP_starts.delete([2, "0", 5])
>>> c.MIP_starts.get_names()
['4', '6', '7']
>>> c.MIP_starts.delete()
>>> c.MIP_starts.get_names()
[]

get_starts(self, *args)

 

Returns a set of MIP starts.

Returns a SparsePair instance or a list of SparsePair instances.

Can be called by four forms.

MIP_starts.get_starts()
return the starting vector for all MIP starts from the problem.
MIP_starts.get_starts(i)
i must be a MIP start name or index. Returns the starting vector for the MIP start whose index or name is i.
MIP_starts.get_starts(s)
s must be a sequence of MIP start names or indices. Returns the starting vector for the MIP starts with indices the members of s. Equivalent to [MIP_starts.get_starts(i) for i in s]
MIP_starts.get_starts(begin, end)
begin and end must be MIP start indices or MIP start names. Returns the starting vector for the MIP starts with indices between begin and end, inclusive of end. Equivalent to MIP_starts.get_starts(range(begin, end + 1)).
>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(
...     names=[str(i) for i in range(11)],
...     types="B" * 11)
>>> indices =c.MIP_starts.add(
...     [(cplex.SparsePair(ind=[i], val=[1.0 * i]),
...       c.MIP_starts.effort_level.auto, str(i))
...      for i in range(10)])
>>> c.MIP_starts.get_num()
10
>>> c.MIP_starts.get_starts(7)
(SparsePair(ind = [7], val = [7.0]), 0)
>>> for s in c.MIP_starts.get_starts("0", 2):
...     print(s)
(SparsePair(ind = [0], val = [0.0]), 0)
(SparsePair(ind = [1], val = [1.0]), 0)
(SparsePair(ind = [2], val = [2.0]), 0)
>>> for s in c.MIP_starts.get_starts([2, "0", 5]):
...     print(s)
(SparsePair(ind = [2], val = [2.0]), 0)
(SparsePair(ind = [0], val = [0.0]), 0)
(SparsePair(ind = [5], val = [5.0]), 0)
>>> c.MIP_starts.delete(3,9)
>>> for s in c.MIP_starts.get_starts():
...     print(s)
(SparsePair(ind = [0], val = [0.0]), 0)
(SparsePair(ind = [1], val = [1.0]), 0)
(SparsePair(ind = [2], val = [2.0]), 0)
>>> c.MIP_starts.effort_level[0]
'auto'

get_effort_levels(self, *args)

 

Returns the effort levels for a set of MIP starts.

Can be called by four forms.

MIP_starts.get_effort_levels()
return the effort level for all MIP starts from the problem.
MIP_starts.get_effort_levels(i)
i must be a MIP start name or index. Returns the effort level for the MIP start whose index or name is i.
MIP_starts.get_effort_levels(s)
s must be a sequence of MIP start names or indices. Returns the effort level for the MIP starts with indices the members of s. Equivalent to [MIP_starts.get_effort_levels(i) for i in s]
MIP_starts.get_effort_levels(begin, end)
begin and end must be MIP start indices or MIP start names. Returns the effort level for the MIP starts with indices between begin and end, inclusive of end. Equivalent to MIP_starts.get_effort_levels(range(begin, end + 1)).
>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(
...     names = [str(i) for i in range(10)],
...     types = "B" * 10)
>>> indices = c.MIP_starts.add(
...     [(cplex.SparsePair(ind = [i], val = [1.0 * i]),
...       c.MIP_starts.effort_level.auto, str(i))
...      for i in range(10)])
>>> c.MIP_starts.change([(1, [[0], [0.0]], c.MIP_starts.effort_level.check_feasibility),
                         (2, [[0], [0.0]], c.MIP_starts.effort_level.solve_fixed),
                         (3, [[0], [0.0]], c.MIP_starts.effort_level.solve_MIP),
                         (4, [[0], [0.0]], c.MIP_starts.effort_level.repair),
                         (5, [[0], [0.0]], c.MIP_starts.effort_level.no_check)])
>>> c.MIP_starts.get_num()
10
>>> c.MIP_starts.effort_level[c.MIP_starts.get_effort_levels(3)]
'solve_MIP'
>>> [c.MIP_starts.effort_level[i] for i in c.MIP_starts.get_effort_levels("0",2)]
['auto', 'check_feasibility', 'solve_fixed']
>>> [c.MIP_starts.effort_level[i] for i in c.MIP_starts.get_effort_levels([2,"0",5])]
['solve_fixed', 'auto', 'no_check']
>>> c.MIP_starts.get_effort_levels()
[0, 1, 2, 3, 4, 5, 0, 0, 0, 0]

get_num_entries(self, *args)

 

Returns the number of variables specified by a set of MIP starts.

Can be called by four forms.

MIP_starts.get_num_entries()
return the length of the starting vector for all MIP starts from the problem.
MIP_starts.get_num_entries(i)
i must be a MIP start name or index. Returns the length of the starting vector for the MIP start whose index or name is i.
MIP_starts.get_num_entries(s)
s must be a sequence of MIP start names or indices. Returns the length of the starting vector for the MIP starts with indices the members of s. Equivalent to [MIP_starts.get_num_entries(i) for i in s]
MIP_starts.get_num_entries(begin, end)
begin and end must be MIP start indices or MIP start names. Returns the length of the starting vector for the MIP starts with indices between begin and end, inclusive of end. Equivalent to MIP_starts.get_num_entries(range(begin, end + 1)).
>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(
...     names = [str(i) for i in range(11)],
...     types = "B" * 11)
>>> indices = c.MIP_starts.add(
...     [(cplex.SparsePair(ind = range(i), val = [0.0] * i),
...       c.MIP_starts.effort_level.auto, str(i - 1))
...      for i in range(1, 11)])
>>> c.MIP_starts.get_num()
10
>>> c.MIP_starts.get_num_entries(3)
4
>>> c.MIP_starts.get_num_entries("0",2)
[1, 2, 3]
>>> c.MIP_starts.get_num_entries([2,"0",5])
[3, 1, 6]
>>> c.MIP_starts.get_num_entries()
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

get_names(self, *args)

 

Returns the names of a set of MIP starts.

Can be called by four forms.

MIP_starts.get_names()
return the names of all MIP starts from the problem.
MIP_starts.get_names(i)
i must be a MIP start index. Returns the name of MIP start i.
MIP_starts.get_names(s)
s must be a sequence of MIP start indices. Returns the names of the MIP starts with indices the members of s. Equivalent to [MIP_starts.get_names(i) for i in s]
MIP_starts.get_names(begin, end)
begin and end must be MIP start indices. Returns the names of the MIP starts with indices between begin and end, inclusive of end. Equivalent to MIP_starts.get_names(range(begin, end + 1)).
>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(
...     names = [str(i) for i in range(11)],
...     types = "B" * 11)
>>> indices = c.MIP_starts.add(
...     [(cplex.SparsePair(ind = range(i), val = [0.0] * i),
...       c.MIP_starts.effort_level.auto, "mst" + str(i - 1))
...      for i in range(1, 11)])
>>> c.MIP_starts.get_num()
10
>>> c.MIP_starts.get_names(8)
'mst8'
>>> c.MIP_starts.get_names(1, 3)
['mst1', 'mst2', 'mst3']
>>> c.MIP_starts.get_names([2, 0, 5])
['mst2', 'mst0', 'mst5']
>>> c.MIP_starts.get_names()
['mst0', 'mst1', 'mst2', 'mst3', 'mst4', 'mst5', 'mst6', 'mst7', 'mst8', 'mst9']