friendlysam.opt.Variable¶
-
class
friendlysam.opt.
Variable
(name=None, lb=None, ub=None, domain=<Domain.real: 0>)¶ A variable to build expressions with.
Parameters: - name (str, optional) – A name of the variable. It has no relation to the identity of the variable. Just a name used in string representations.
- lb (number, optional) – If supplied, a lower bound on the variable in optimization problems. If not supplied, the variable is unbounded downwards.
- ub (number, optional) – If supplied, an upper bound on the variable in optimization problems. If not supplied, the variable is unbounded upwards.
- domain (any of the
Domain
values) – The domain of the variable, enforced in optimization problems.
Note
The
name
,lb
,ub
anddomain
can also be set as attributes after creation.>>> a = Variable('a') >>> a.lb = 10 >>> a.Domain = Domain.integer
is equivalent to
>>> a = Variable('a', lb=10, domain=Domain.integer)
Examples
The
namespace()
context manager can be used to conveniently name groups of variables.>>> with namespace('dimensions'): ... w = Variable('width') ... h = Variable('height') ... >>> w.name, h.name ('dimensions.width', 'dimensions.height')
Variable.evaluate ([replace, evaluators]) |
Evaluate a variable. |
Variable.take_value (solution) |
Try setting the value of this variable from a dictionary. |
Variable.value |
Value property. |
Variable.variables |