Package cplex :: Package _internal :: Module _multiobj :: Class MultiObjInterface
[frames] | no frames]
 

Class MultiObjInterface


Methods for adding, querying, and modifying multiple objectives.

The methods in this interface can be used to add, query, and modify objectives in a specified problem. These objectives are used when multi-objective optimization is initiated.

For more details see the section on multi-objective optimization in the CPLEX User's Manual.

Instance Methods
 
__init__(self, cpx)
Creates a new MultiObjInterface.
 
get_abstol(self, objidx)
Returns the absolute tolerance of an objective function.
 
get_definition(self, objidx, begin=None, end=None)
Returns the definition of an objective.
 
get_linear(self, objidx, *args)
Returns the linear coefficients of a set of variables.
 
get_names(self, *args)
Returns the names of a set of objectives.
 
get_num(self)
Returns the number of objectives in the problem.
 
get_offset(self, objidx)
Returns the constant offset of an objective function.
 
get_priority(self, objidx)
Returns the priority of an objective function.
 
get_reltol(self, objidx)
Returns the relative tolerance of an objective function.
 
get_sense(self)
Returns the sense of all objective functions.
 
get_weight(self, objidx)
Returns the weight of an objective function.
 
set_abstol(self, objidx, abstol)
Sets the absolute tolerance of an objective function.
 
set_definition(self, objidx, obj=None, offset=0.0, weight=1.0, priority=0, abstol=None, reltol=None, name=None)
Sets the definition of an objective.
 
set_linear(self, objidx, *args)
Changes the linear part of an objective function.
 
set_name(self, objidx, name)
Sets the name of an objective function.
 
set_num(self, numobj)
Sets the number of objectives in the problem instance.
 
set_offset(self, objidx, offset)
Sets the constant offset of an objective function.
 
set_priority(self, objidx, priority)
Sets the priority of an objective function.
 
set_reltol(self, objidx, reltol)
Sets the relative tolerance of an objective function.
 
set_sense(self, sense)
Sets the sense of all objective functions.
 
set_weight(self, objidx, weight)
Sets the weight of an objective function.

Inherited from _baseinterface.BaseInterface: get_indices

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

Class Variables
  sense = <cplex._internal._subinterfaces.ObjSense object at 0x7ff53e959510>
Properties

Inherited from object: __class__

Method Details

__init__(self, cpx)
(Constructor)

 

Creates a new MultiObjInterface.

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

Overrides: object.__init__

get_abstol(self, objidx)

 

Returns the absolute tolerance of an objective function.

objidx must be an objective name or index.

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(obj=[1.0 for i in range(3)])
>>> c.multiobj.get_abstol(0)
0.0

get_definition(self, objidx, begin=None, end=None)

 

Returns the definition of an objective.

Returns an objective definitions, where the definition is a list containing the following components: obj (a list containing the linear objective coefficients), offset, weight, priority, abstol, reltol (see set_definition).

objidx is the name or index of the objective to be accessed.

The optional begin and end arguments must be variable indices or names. Together, begin and end specify the range of objective function coefficients to be returned. By default, the linear objective coefficients of all variables from the problem will be returned (i.e., begin will default to the first variable index and end will default to the last variable index).

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

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> varind = list(c.variables.add(obj=[1.0, 2.0]))
>>> c.multiobj.get_definition(0)
[[1.0, 2.0], 0.0, 1.0, 0, 0.0, 0.0]

get_linear(self, objidx, *args)

 

Returns the linear coefficients of a set of variables.

Can be called by four forms each of which requires an objidx argument. objidx must be an objective name or index.

multiobj.get_linear(objidx)
return the linear objective coefficients of all variables from the problem.
multiobj.get_linear(objidx, i)
i must be a variable name or index. Returns the linear objective coefficient of the variable whose index or name is i.
multiobj.get_linear(objidx, s)
s must be a sequence of variable names or indices. Returns the linear objective coefficient of the variables with indices the members of s. Equivalent to [multiobj.get_linear(objidx, i) for i in s]
multiobj.get_linear(objidx, begin, end)
begin and end must be variable indices or variable names. Returns the linear objective coefficient of the variables with indices between begin and end, inclusive of end. Equivalent to multiobj.get_linear(objidx, range(begin, end + 1)).

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(
...     obj=[1.5 * i for i in range(10)],
...     names=[str(i) for i in range(10)])
>>> c.variables.get_num()
10
>>> c.multiobj.get_linear(0, 8)
12.0
>>> c.multiobj.get_linear(0, '1', 3)
[1.5, 3.0, 4.5]
>>> c.multiobj.get_linear(0, [2, '0', 5])
[3.0, 0.0, 7.5]
>>> c.multiobj.get_linear(0)
[0.0, 1.5, 3.0, 4.5, 6.0, 7.5, 9.0, 10.5, 12.0, 13.5]

get_names(self, *args)

 

Returns the names of a set of objectives.

There are four forms by which multiobj.get_names may be called.

multiobj.get_names()
return the names of all objectives from the problem.
multiobj.get_names(i)
i must be an objective index. Returns the name of row i.
multiobj.get_names(s)
s must be a sequence of objective indices. Returns the names of the objectives with indices the members of s. Equivalent to [multiobj.get_names(i) for i in s]
multiobj.get_names(begin, end)
begin and end must be objective indices. Returns the names of the objectives with indices between begin and end, inclusive of end. Equivalent to multiobj.get_names(range(begin, end + 1)).

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

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> c.multiobj.set_definition(0, name='mo1')
>>> c.multiobj.get_names(0)
'mo1'

get_num(self)

 

Returns the number of objectives in the problem.

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> c.multiobj.get_num()
1
>>> indices = c.multiobj.set_num(2)
>>> c.multiobj.get_num()
2

get_offset(self, objidx)

 

Returns the constant offset of an objective function.

objidx must be an objective name or index.

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(obj=[1.0 for i in range(3)])
>>> c.multiobj.get_offset(0)
0.0

get_priority(self, objidx)

 

Returns the priority of an objective function.

objidx must be an objective name or index.

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(obj=[1.0 for i in range(3)])
>>> c.multiobj.get_priority(0)
0

get_reltol(self, objidx)

 

Returns the relative tolerance of an objective function.

objidx must be an objective name or index.

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(obj=[1.0 for i in range(3)])
>>> c.multiobj.get_reltol(0)
0.0

get_sense(self)

 

Returns the sense of all objective functions.

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> c.multiobj.sense[c.multiobj.get_sense()]
'minimize'
>>> c.multiobj.set_sense(c.multiobj.sense.maximize)
>>> c.multiobj.sense[c.multiobj.get_sense()]
'maximize'
>>> c.multiobj.set_sense(c.multiobj.sense.minimize)
>>> c.multiobj.sense[c.multiobj.get_sense()]
'minimize'

get_weight(self, objidx)

 

Returns the weight of an objective function.

objidx must be an objective name or index.

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(obj=[1.0 for i in range(3)])
>>> c.multiobj.get_weight(0)
1.0

set_abstol(self, objidx, abstol)

 

Sets the absolute tolerance of an objective function.

objidx must be an objective name or index.

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(obj=[1.0 for i in range(3)])
>>> c.multiobj.set_abstol(0, 1e-6)
>>> c.multiobj.get_abstol(0)
1e-06

set_definition(self, objidx, obj=None, offset=0.0, weight=1.0, priority=0, abstol=None, reltol=None, name=None)

 

Sets the definition of an objective.

multiobj.set_definition accepts the keyword arguments objidx, obj, offset, weight, priority, abstol, reltol, and name.

objidx is the name or index of the objective to be set. The objective index must be in the interval [0, Cplex.multiobj.get_num() - 1].

obj can be either a SparsePair or a list of two lists specifying the linear component of the objective. If not specified, the coefficients of every variable are set to 0.0.

Note
obj must not contain duplicate indices. If obj references a variable more than once, either by index, name, or a combination of index and name, an exception will be raised.

offset is the offset of the objective to be set. If not specififed, the offset is set to 0.0.

weight is the weight of the objective to be set. For the definition of the weight see the description of blended objective in the multi-objective optimization section of the CPLEX User's Manual. If not specified, the weight is set to 1.0.

priority is the priority of the objective to be set. It must be a nonnegative integer. For the definition of the priority see the description of lexicographic objective in the multi-objective optimization section of the CPLEX User's Manual. If not specified, the priority is set to 0.

abstol is the absolute tolerance of the objective to be set. If not specified, the absolute tolerance is set to 0.0.

reltol is the relative tolerance of the objective to be set. If not specified, the relative tolerance is set to 0.0.

name is a string representing the name of the objective to be set. If not specified, the objective name will default to None.

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

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> varind = list(c.variables.add(names=['x1', 'x2']))
>>> c.multiobj.set_definition(
...     objidx=0,
...     obj=cplex.SparsePair(ind=varind, val=[1.0, 2.0]),
...     offset=0.0,
...     weight=1.0,
...     priority=0,
...     abstol=1e-06,
...     reltol=1e-04,
...     name='obj1')
>>> c.multiobj.get_definition('obj1')
[[1.0, 2.0], 0.0, 1.0, 0, 1e-06, 0.0001]
>>> c.multiobj.get_names(0)
'obj1'

set_linear(self, objidx, *args)

 

Changes the linear part of an objective function.

Can be called by two forms each of which requires an objidx argument. objidx must be an objective name or index.

multiobj.set_linear(objidx, var, value)
var must be a variable index or name and value must be a float. Changes the coefficient of the variable identified by var to value.
multiobj.set_linear(objidx, sequence)
sequence is a sequence of pairs (var, value) as described above. Changes the coefficients for the specified variables to the given values.

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(names=[str(i) for i in range(4)])
>>> c.multiobj.get_linear(0)
[0.0, 0.0, 0.0, 0.0]
>>> c.multiobj.set_linear(0, 0, 1.0)
>>> c.multiobj.get_linear(0)
[1.0, 0.0, 0.0, 0.0]
>>> c.multiobj.set_linear(0, '3', -1.0)
>>> c.multiobj.get_linear(0)
[1.0, 0.0, 0.0, -1.0]
>>> c.multiobj.set_linear(0, [('2', 2.0), (1, 0.5)])
>>> c.multiobj.get_linear(0)
[1.0, 0.5, 2.0, -1.0]

set_name(self, objidx, name)

 

Sets the name of an objective function.

objidx must be an objective name or index.

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> c.multiobj.set_num(3)
>>> for i in range(3):
...     c.multiobj.set_name(i, str(i))
>>> c.multiobj.get_names()
['0', '1', '2']

set_num(self, numobj)

 

Sets the number of objectives in the problem instance.

There is always at least one objective in the problem instance (indexed 0) thus numobj must be at least 1. If before calling this function there were more objectives in the instance than the specified numobj then the objectives whose index is >= numobj are removed from the instance. If before calling this function the number of objectives was <= numobj then new objectives are created, all with all-zero coefficients and default settings (like priority, weight, etc).

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> c.multiobj.set_num(2)
>>> c.multiobj.get_num()
2

set_offset(self, objidx, offset)

 

Sets the constant offset of an objective function.

objidx must be an objective name or index.

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(obj=[1.0 for i in range(3)])
>>> c.objective.set_offset(3.14)
>>> c.objective.get_offset()
3.14

set_priority(self, objidx, priority)

 

Sets the priority of an objective function.

objidx must be an objective name or index.

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(obj=[1.0 for i in range(3)])
>>> c.multiobj.set_priority(0, 2)
>>> c.multiobj.get_priority(0)
2

set_reltol(self, objidx, reltol)

 

Sets the relative tolerance of an objective function.

objidx must be an objective name or index.

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(obj=[1.0 for i in range(3)])
>>> c.multiobj.set_reltol(0, 1e-4)
>>> c.multiobj.get_reltol(0)
0.0001

set_sense(self, sense)

 

Sets the sense of all objective functions.

Note
All objective functions share the same sense. To model an objective with a different sense use a negative value for the weight attribute. See set_weight.

The argument to this method must be either multiobj.sense.minimize or multiobj.sense.maximize.

>>> import cplex
>>> c = cplex.Cplex()
>>> c.multiobj.sense[c.multiobj.get_sense()]
'minimize'
>>> c.multiobj.set_sense(c.multiobj.sense.maximize)
>>> c.multiobj.sense[c.multiobj.get_sense()]
'maximize'
>>> c.multiobj.set_sense(c.multiobj.sense.minimize)
>>> c.multiobj.sense[c.multiobj.get_sense()]
'minimize'

set_weight(self, objidx, weight)

 

Sets the weight of an objective function.

objidx must be an objective name or index.

Note
All objective functions share the same sense. To model an objective with a different sense use a negative value for the weight attribute. See set_sense.

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(obj=[1.0 for i in range(3)])
>>> c.multiobj.set_weight(0, -2.0)
>>> c.multiobj.get_weight(0)
-2.0