Skip to main content

compiled_model

class CompiledInstance

CompiledInstance: object return compile_model method.

Attributes

  • sense(jijmodeling.ProblemSense) : problem sense minimize or maximize.
  • objective(SubstitutedExpression) : objective expression.
  • constraint(dict[str, dict[tuple[int, ...], SubstitutedExpression]]) : constraints. str key represents name of constraint. tuple[int,...] is values of forall index.
  • penalty : dict[str, dict[tuple[int, ...], SubstitutedExpression]]
  • var_map : VariableMap
  • data : InstanceData
  • problem : jijmodeling.InstanceData

Examples

import jijmodeling as jm
import jijmodeling_transpiler as jmt
n = jm.Placeholder("n")
x = jm.Binary("x", (n, n))
i = jm.Element("i", n)
problem = jm.Problem("sample")
problem += x[:, :]
problem += jm.Constraint("onehot", x[:, i], forall=i)
compiled_instance = jmt.core.compile_model(problem, {"n": 2}, {})
compiled_instance
CompiledInstance(
objective=SubstitutedExpression(
linear=LinearSubstitutedExpr(coeff={0: 1.0, 1: 1.0, 2: 1.0, 3: 1.0}, constant=0.0),
nonlinear=None),
constraint={
'onehot': {
(0,): SubstitutedExpression(
linear=LinearSubstitutedExpr(coeff={0: 1.0, 1: 1.0}, constant=0.0),
nonlinear=None),
(1,): SubstitutedExpression(
linear=LinearSubstitutedExpr(coeff={2: 1.0, 3: 1.0}, constant=0.0),
nonlinear=None)}
},
penalty={},
var_map=VariableMap(var_map={'x': {(0, 0): 0, (0, 1): 2, (1, 0): 1, (1, 1): 3}},
var_num=4,
integer_bound={}),
...
)

add (self, source) -> -


class InstanceData

Instance Data class

The constructor provides type validation and conversion from user's input to valid instance data type.

Attributes

  • tensor_data(dict[str, numpy.ndarray]) : tensor value of Placheolder. The key is uuid of the corresponding Placheolder.
  • jagged_data(dict[str, list]) : jagged array value of JaggedArray. The key is uuid of the corresponding JaggedArray.
  • fixed_variables(dict[str, dict[tuple[int, ...], float]]) : fixed variable values.
  • indices(dict[str, int]) : value of Element. The attribute is changing in compile process.

__init__ (self, instance_data, fixed_vars, ph_names, indices) -> -

Parameters

  • instance_data(dict) : user input instance_data.
  • fixed_vars(dict) : user input fixed_variables.
  • ph_vars(list[name]) : Placeholder list include user defined model. This is used for validation.
  • indices(typ.Optional[dict]) : value of each Elements. Defaults to None.

Raises

  • ValueError: user's input is invalid.

get_length (self, name, subscripts, axis) -> -

get_value (self, uuid, subscripts) -> -


class Problem

Problem(name: 'str', sense: 'ProblemSense', objective: 'subs_expr.SubstitutableExpr', constraints: 'dict[str, Constraint]', penalties: 'dict[str, CustomPenalty]')


class ProblemSense

An enumeration.


class SubstitutedExpression

SubstitutedExpression(coeff: 'dict[tuple[int, ...], float]', constant: 'float', order: 'int')

add (self, other) -> -

from_serializable (data) -> -

is_constant (self) -> -

mul (self, other) -> -

power (self, exponent) -> -

to_serializable (self) -> -


class VariableMap

VarialeMap

This class is used to manage the mapping between the label and the index of the decision variable.

Attributes

  • var_map(dict[str, dict[tuple[int, ...], int]]) : label, subscripts -> index (int)
  • var_num(int) : number of variables
  • integer_bound(dict[str, dict[tuple[int, ...], IntegerBound]]) : bounds of integer decision variables.

add_cont_variable (self, label, subscripts, lower, upper) -> -

Add an integer variable to the variable map.

add_int_variable (self, label, subscripts, lower, upper) -> -

Add an integer variable to the variable map.

add_variable (self, label, subscripts) -> int

Add a variable to the variable map.

Parameters

  • label(str) : label of the variable
  • subscripts(tuple[int, ...]) : subscripts of the variable

Returns

  • int : index of the variable in the variable map

from_serializable (data) -> -

to_serializable (self) -> dict

Convert to a serializable object.

Returns

  • dict : serializable object

Examples

varmap = VariableMap()
varmap.add_variable("x", (0, 0))
varmap.add_variable("x", (0, 1))
varmap.to_serializable()
# {
# "class": "VariableMap",
# "var_map": {
# "x": {
# "subscripts": [
# [0, 0],
# [0, 1]
# ],
# "index": [0, 1]
# }
# },
# "var_num": 2,
# "integer_bound": {}
# }