Skip to main content

compile

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) -> -


compile_model (problem, instance, fixed_variables) -> CompiledInstance

Compile a problem and an instance into a compiled model.

Parameters

  • problem(jm.Problem) : a problem to be compiled
  • instance(dict[str, np.ndarray | list | int | float]) : an instance to be compiled
  • fixed_variables(dict[dict, dict[tuple[int, ...], float]]) : fixed variables. Defaults to None.

Returns

  • CompiledInstance : a compiled model

partial_compile (expr, instance_data, fixed_variables, var_map) -> CompiledInstance

Partial compile. compile from expression, constraint or penalty not problem.

Parameters

  • expr(jm.Expression | jm.Constraint | jm.Penalty) : Expression to compile.
  • instance_data(dict) : Instance data.
  • fixed_variables(dict) : Fixed variables.
  • var_map(VariableMap) : Variable map.

Returns

  • CompiledInstance : Compiled instance.