utils
ext_vars_from (problem) -> list[Variable]
Extract variables from jijmodeling.Problem.
Parameters
- problem(jm.Problem) : target problem
Returns
- list[Variable] : list of variables
Examples
import jijmodeling as jm
import jijmodeling_transpiler.utils import ext_vars_from
d = jm.Placeholder("d", dim=1)
n = d.shape[0]
k = jm.Placeholder("k")
i, j = jm.Element("i", n), jm.Element("j", k)
x, y = jm.Binary("x", shape=n), jm.Binary("y", shape=(n, k))
problem = jm.Problem("test")
problem += jm.Sum(i, x[i])
problem += jm.Constraint("sample", jm.Sum(j, y[i, j]) == 1, forall=i)
variables = ext_vars_from(problem)
print(variables)
# [x, y, d, n, k, i, j]
is_roughly_correct_type (obj, type_) -> bool
Check if obj is roughly correct type.
The roughly correct type means that the first element of the sequence and mapping only checked.
Parameters
- obj(Any) : target object
- type_(Any) : target type
Returns
- bool : True if obj is roughly correct type, otherwise False
ph_value_type_convert (ph_value, variables) -> tuple[PLACEHOLDER_VALUES, dict[jm.Placeholder, list]]
Separate the input to ph_value into two types of data: data that can be.
converted to numpy associated with a Placeholder and data that should be managed in a list associated with a JaggedArray.
Parameters
- ph_value(jijmodeling.type_annotations.PH_VALUES_INTERFACE) : input ph_value data
- variables(list[Variable]) : variable object list for the reference.
Returns
- tuple[PLACEHOLDER_VALUES, dict[jm.Placeholder, list]] : placeholder's value and jagged array's value.
Raises
- TypeError: When the key of ph_value is not str or Variable.
- ValueError: When the data corresponding to the Placeholder or JaggedArray contained in the variable is not in ph_value.
Examples
import jijmodeling as jm
d = jm.Placeholder("d", dim=1)
n = d.shape[0]
k = jm.Placeholder("k")
i = jm.Element("i", n)
J = jm.JaggedArray("J", dim=2)
ph_value = {"d": [1, 2, 3], "k": 3, "J": [[1, 2], [3, 4, 5]]}
_ph_value, _jagged = ph_value_type_convert(ph_value, [J, d, i, k])
print(_ph_value)
# {d: array([1, 2, 3]), k: array(3)}
print(_jagged)
# {J: [[1, 2], [3, 4, 5]]}
raise_type_error (varname, obj, type) -> -
Raise TypeError.
Parameters
- obj(Any) : target object
- type_(Any) : target type