Package cplex :: Package _internal :: Module _anno :: Class DoubleAnnotationInterface
 

Class DoubleAnnotationInterface


Methods for adding, querying, and modifying double annotations.
Instance Methods
 
__init__(self, cpx)
Creates a new DoubleAnnotationInterface.
 
get_num(self)
Returns the number of double annotations in the problem.
 
add(self, name, defval)
Adds an annotation to the problem.
 
delete(self, *args)
Deletes double annotations from the problem.
 
get_names(self, *args)
Returns the names of a set of double annotations.
 
get_default_values(self, *args)
Returns the default value of a set of double annotations.
 
set_values(self, idx, objtype, *args)
Sets the values for objects in the specified double annotation.
 
get_values(self, idx, objtype, *args)
Returns the double annotation values for the specified objects.

Inherited from _baseinterface.BaseInterface: get_indices

Class Variables

Inherited from AnnotationInterface: object_type

Method Details

__init__(self, cpx)
(Constructor)

 

Creates a new DoubleAnnotationInterface.

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

Overrides: _baseinterface.BaseInterface.__init__

get_num(self)

 

Returns the number of double annotations in the problem.

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> c.double_annotations.get_num()
0
>>> idx = c.double_annotations.add('ann1', 0.0)
>>> c.double_annotations.get_num()
1

add(self, name, defval)

 

Adds an annotation to the problem.

name: the name of the annotation.

defval: the default value for annotation objects.

Returns the index of the added annotation.

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> idx = c.double_annotations.add(name='ann1', defval=0.0)
>>> c.double_annotations.get_num()
1

delete(self, *args)

 

Deletes double annotations from the problem.

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

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

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

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> idx = c.double_annotations.add('ann1', 0.0)
>>> c.double_annotations.get_num()
1
>>> c.double_annotations.delete(idx)
>>> c.double_annotations.get_num()
0

get_names(self, *args)

 

Returns the names of a set of double annotations.

May be called by four forms.

double_annotations.get_names()
return the names of all double annotations in the problem.
double_annotations.get_names(i)
i must be an annotation name or index. Returns the name of double annotation i.
double_annotations.get_names(seq)
seq must be a sequence of annotation names or indices. Returns the names of double annotations with names or indices in s. Equivalent to [double_annotations.get_names(i) for i in s]
double_annotations.get_names(begin, end)
begin and end must be annotation indices or annotation names. Returns the names of double annotations with indices between begin and end, inclusive of end. Equivalent to double_annotations.get_names(range(begin, end + 1))

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> [c.double_annotations.add('ann{0}'.format(i), i)
...  for i in range(1, 6)]
[0, 1, 2, 3, 4]
>>> c.double_annotations.get_names()
['ann1', 'ann2', 'ann3', 'ann4', 'ann5']
>>> c.double_annotations.get_names(0)
'ann1'
>>> c.double_annotations.get_names([0, 2, 4])
['ann1', 'ann3', 'ann5']
>>> c.double_annotations.get_names(1, 3)
['ann2', 'ann3', 'ann4']

get_default_values(self, *args)

 

Returns the default value of a set of double annotations.

May be called by four forms.

double_annotations.get_default_values()
return the default values of all double annotations in the problem.
double_annotations.get_default_values(i)
i must be an annotation name or index. Returns the default value of double annotation i.
double_annotations.get_default_values(seq)
seq must be a sequence of annotation names or indices. Returns the default values of double annotations with names or indices in s. Equivalent to [double_annotations.get_default_values(i) for i in s]
double_annotations.get_default_values(begin, end)
begin and end must be annotation indices or annotation names. Returns the default values of double annotations with indices between begin and end, inclusive of end. Equivalent to double_annotations.get_default_values(list(range(begin, end + 1)))

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> idx1 = c.double_annotations.add(name='ann1', defval=0.0)
>>> idx2 = c.double_annotations.add(name='ann2', defval=1.0)
>>> c.double_annotations.get_default_values()
[0.0, 1.0]

set_values(self, idx, objtype, *args)

 

Sets the values for objects in the specified double annotation.

idx: the double annotation index or name.

objtype: the annotation object type.

Can be called by two forms:

double_annotations.set_values(idx, objtype, i, val)
i must be a name or index. Changes the double annotation value of the object identified by i.
double_annotations.set_values(idx, objtype, seq)
seq is a sequence of pairs (i, val) as described above. Changes the double annotation values for the specified objects.

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> idx = c.double_annotations.add('ann1', 0.0)
>>> objtype = c.double_annotations.object_type.objective
>>> c.double_annotations.set_values(idx, objtype, 0, 1.0)
>>> c.double_annotations.get_values(idx, objtype, 0)
1.0
>>> indices = c.variables.add(names=['v1', 'v2', 'v3'])
>>> objtype = c.double_annotations.object_type.variable
>>> c.double_annotations.set_values(idx, objtype,
...                                 [(i, 1.0) for i in indices])
>>> c.double_annotations.get_values(idx, objtype)
[1.0, 1.0, 1.0]

get_values(self, idx, objtype, *args)

 

Returns the double annotation values for the specified objects.

idx: the double annotation index or name.

objtype: the annotation object type.

Can be called by four forms:

double_annotations.get_values(idx, objtype)
return the values of all objects for a given annotation.
double_annotations.get_values(idx, objtype, i)
i must be a name or index. Returns the double annotation value of the object identified by i.
double_annotations.get_values(idx, objtype, seq)
seq is a sequence of object names or indices. Returns the double annotation values for the specified objects. Equivalent to [double_annotations.get_values(idx, objtype, i) for i in seq]
double_annotations.get_values(idx, objtype, begin, end)
begin and end must be object indices or object names. Returns the double annotation values of objects with indices between begin and end, inclusive of end. Equivalent to double_annotations.get_values(range(begin, end + 1))

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> idx = c.double_annotations.add('ann1', 0.0)
>>> objtype = c.double_annotations.object_type.objective
>>> c.double_annotations.set_values(idx, objtype, 0, 1.0)
>>> c.double_annotations.get_values(idx, objtype, 0)
1.0
>>> indices = c.variables.add(names=['v1', 'v2', 'v3'])
>>> objtype = c.double_annotations.object_type.variable
>>> c.double_annotations.set_values(idx, objtype,
...                                 [(i, 1.0) for i in indices])
>>> c.double_annotations.get_values(idx, objtype, list(indices))
[1.0, 1.0, 1.0]