One of the problem’s variables
Change or retrieve variable bounds
Parameters: | |
---|---|
Returns: | the variable’s bounds |
Return type: | length-2 tuple of float (or False) |
Raises: |
|
>>> p = MILProgram()
>>> x = p.add_variable()
>>> x.bounds()
(False, False)
>>> x.bounds(lower=0, upper=5.5)
(0.0, 5.5)
>>> x.bounds(upper=False)
(0.0, False)
Change or retrieve variable coefficients (constraint matrix column)
Parameters: | coeffs (Mapping of Constraint to Real) – the mapping with coefficients to change ({} to set all coefficients to 0; omit for retrieval only) |
---|---|
Returns: | the coefficient mapping, which only contains nonzero coefficients |
Return type: | dict of Constraint to float |
Raises: |
>>> p = MILProgram()
>>> c = p.add_constraint()
>>> d = p.add_constraint()
>>> x = p.add_variable()
>>> x.coeffs()
{}
>>> x.coeffs({c: 10/9, d: 0})
{<epyglpki.Constraint object at 0x...>: 1.1111...}
>>> x.coeffs({})
{}
Change or retrieve variable kind
Parameters: | kind (str, either 'continuous', 'integer', or 'binary') – the new variable kind (omit for retrieval only) |
---|---|
Returns: | the variable kind |
Return type: | str |
Raises ValueError: | |
if kind is not 'continuous', 'integer', or 'binary' |
>>> p = MILProgram()
>>> x = p.add_variable()
>>> x.kind()
'continuous'
>>> x.kind('integer')
'integer'
Note
A variable has 'binary' kind if and only if it is an integer variable with lower bound zero and upper bound one:
>>> x.kind()
'integer'
>>> x.bounds(lower=0, upper=1)
(0.0, 1.0)
>>> x.kind()
'binary'
>>> x.bounds(upper=3)
(0.0, 3.0)
>>> x.kind()
'integer'
>>> x.kind('binary')
'binary'
>>> x.bounds()
(0.0, 1.0)
Change or retrieve variable name
Parameters: | name (str) – the new variable name (omit for retrieval only) |
---|---|
Returns: | the variable name |
Return type: | |
Raises: |
|
>>> p = MILProgram()
>>> x = p.add_variable()
>>> x.name()
''
>>> x.name('Stake')
'Stake'
>>> x.name()
'Stake'
Remove the variable from the problem
>>> p = MILProgram()
>>> x = p.add_variable()
>>> p.variables()
[<epyglpki.Variable object at 0x...>]
>>> x.remove()
>>> p.variables()
[]
Note
Removing a variable from a problem object does not delete the referencing Variable objects, which in some sense become ‘zombie’ objects; they should best be deleted manually:
>>> p.variables()
[]
>>> x
<epyglpki.Variable object at 0x...>
>>> x.name()
Traceback (most recent call last):
...
ValueError: <epyglpki.Variable object at 0x...> is not in list
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
...
IndexError: This is possibly a zombie; kill it using 'del'.
>>> del x
>>> x
Traceback (most recent call last):
...
NameError: name 'x' is not defined
One of the problem’s constraints
Change or retrieve constraint bounds
Parameters: | |
---|---|
Returns: | the constraint’s bounds |
Return type: | length-2 tuple of float (or False) |
Raises: |
|
>>> p = MILProgram()
>>> c = p.add_constraint()
>>> c.bounds()
(False, False)
>>> c.bounds(lower=-1/2, upper=1/2)
(-0.5, 0.5)
>>> c.bounds(lower=False)
(False, 0.5)
Change or retrieve constraint coefficients (constraint matrix row)
Parameters: | coeffs (Mapping of Variable to Real) – the mapping with coefficients to change ({} to set all coefficients to 0; omit for retrieval only) |
---|---|
Returns: | the coefficient mapping, which only contains nonzero coefficients |
Return type: | |
Raises: |
>>> p = MILProgram()
>>> x = p.add_variable()
>>> y = p.add_variable()
>>> c = p.add_constraint()
>>> c.coeffs()
{}
>>> c.coeffs({x: .5, y: 0})
{<epyglpki.Variable object at 0x...>: 0.5}
>>> c.coeffs({})
{}
Change or retrieve constraint name
Parameters: | name (str) – the new constraint name (omit for retrieval only) |
---|---|
Returns: | the constraint name |
Return type: | |
Raises: |
|
>>> p = MILProgram()
>>> c = p.add_constraint()
>>> c.name()
''
>>> c.name('Budget')
'Budget'
>>> c.name()
'Budget'
Remove the constraint from the problem
>>> p = MILProgram()
>>> c = p.add_constraint()
>>> p.constraints()
[<epyglpki.Constraint object at 0x...>]
>>> c.remove()
>>> p.constraints()
[]
Note
Removing a constraint from a problem object does not delete the referencing Constraint objects, which in some sense become ‘zombie’ objects; they should best be deleted manually:
>>> p.constraints()
[]
>>> c
<epyglpki.Constraint object at 0x...>
>>> c.name()
Traceback (most recent call last):
...
ValueError: <epyglpki.Constraint object at 0x...> is not in list
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
...
IndexError: This is possibly a zombie; kill it using 'del'.
>>> del c
>>> c
Traceback (most recent call last):
...
NameError: name 'c' is not defined
The problem’s objective function
Change or retrieve objective function coefficients
Parameters: | coeffs (Mapping of Variable to Real) – the mapping with coefficients to change ({} to set all coefficients to 0 ; omit for retrieval only) |
---|---|
Returns: | the coefficient mapping, which only contains nonzero coefficients |
Return type: | |
Raises: |
>>> p = MILProgram()
>>> x = p.add_variable()
>>> y = p.add_variable()
>>> o = p.objective()
>>> o.coeffs()
{}
>>> o.coeffs({x: 3, y: 0})
{<epyglpki.Variable object at 0x...>: 3.0}
>>> o.coeffs({})
{}
Change or retrieve objective function constant
Parameters: | constant (Real) – the new objective function constant (omit for retrieval only) |
---|---|
Returns: | the objective function constant |
Return type: | float |
Raises TypeError: | |
if constant is not Real |
>>> p = MILProgram()
>>> o = p.objective()
>>> o.constant()
0.0
>>> o.constant(3)
3.0
Change or retrieve objective direction
Parameters: | direction (str, either 'minimize' or 'maximize') – the new objective direction (omit for retrieval only) |
---|---|
Returns: | the objective direction |
Return type: | str |
Raises ValueError: | |
if direction is not 'minimize' or 'maximize' |
>>> p = MILProgram()
>>> o = p.objective()
>>> o.direction()
'minimize'
>>> o.direction('maximize')
'maximize'
Change or retrieve objective function name
Parameters: | name (str) – the new objective function name (omit for retrieval only) |
---|---|
Returns: | the objective function name |
Return type: | |
Raises: |
|
>>> p = MILProgram()
>>> o = p.objective()
>>> o.name()
''
>>> o.name('σκοπός')
'σκοπός'
>>> o.name()
'σκοπός'