Optimization variables are represented by variable objects.
variable([size[, name]])
A vector variable. The first argument is the dimension of the vector (a positive integer with default value 1). The second argument is a string with a name for the variable. The name is optional and has default value "". It is only used when displaying variables (or objects that depend on variables, such as functions or constraints) using print statements, when calling the built-in functions repr() or str(), or when writing linear programs to MPS files.
The function len() returns the length of a variable. A variable x has two attributes.
name
The name of the variable.
value
Either None or a dense ’d’ matrix of size len(x) by 1.
The attribute x.value is set to None when the variable x is created. It can be given a numerical value later, typically by solving an LP that has x as one of its variables. One can also make an explicit assignment x.value = y. The assigned value y must be an integer or float, or a dense ’d’ matrix of size (len(x),1). If y is an integer or float all the elements of x.value are set to the value of y.
>>> from cvxopt import matrix
>>> from cvxopt.modeling import variable >>> x = variable(3,’a’) >>> len(x) 3 >>> print x.name a >>> print x.value None >>> x.value = matrix([1.,2.,3.]) >>> print x.value [ 1.00e+00] [ 2.00e+00] [ 3.00e+00] >>> x.value = 1 >>> print x.value [ 1.00e+00] [ 1.00e+00] [ 1.00e+00] |