Solution

class flopt.Solution(variables, sort=True, *args, **kwargs)[source]

Solution Class

Parameters

variables (list of VarElement family) – variables which has no duplicate

name

name of solution

Type

str

type
Type

str

_variables

variable array

Type

list of varElement

_var_dict

key is name of variable, key is variable

Type

dict

Examples

Create a Solution which has Integer, Continuous and Binary Variables

>>> a = Variable(name="a", lowBound=0, upBound=1, cat="Integer")
>>> b = Variable(name="b", lowBound=1, upBound=2, cat="Continuous")
>>> c = Variable(name="c", cat="Binary")
>>> sol = Solution([a, b, c])

Four arithmetic operations are supported between Solutions or between a Solution and a constant.

>>> sol1 = Solution([a, b])
>>> sol2 = Solution([a, c])
>>> sol_plus = sol1 + sol2  # (Solution + Solution or Solution + list)
>>> sol_minus = sol1 - sol2  # (Solution - Solution or Solution - list)
>>> sol_product = sol1 * 2  # (Solution * constant)
>>> sol_divide = sol1 / 2  # (Solution / constant)
clip()[source]

Guarantee feasibility of the solution

clone()[source]
Returns

Copy of the Solution (call by value)

Return type

Solution

copy(other)[source]

Copy the values of a Solution to itself (call by value)

dot(other)[source]
Returns

Inner product between the Solution and another Solution

Return type

float

feasible()[source]
Returns

Whether the solution is feasible or not

Return type

bool

getVariables()[source]
Returns

Variable instances which belong to the Solution

Return type

list

norm()[source]
Returns

2-norm of the solution as a vector in Euclid space

Return type

float

setRandom()[source]

Set the solution values uniformly random

setValue(name, value)[source]
Parameters
  • name (str) –

  • value (int or float) –

setValuesFromArray(array)[source]
Parameters

array (iterator) – array of variable values

squaredNorm()[source]
Returns

Squared 2-norm of the solution as a vector in Euclid space

Return type

float

toDict()[source]
Returns

key is name of variable, value is VarElement family or Expression or Const

Return type

dict

value(solution=None)[source]
Parameters

solution (None or Solution) –

Returns

values of the variables in the Solution

Return type

list