Skip to main content

binary_decode

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


binary_decode (results, binary_encoder, inverse_varmap) -> list[dict[int, int | float]]

binary decode using binary_encoder

Parameters

  • results(typ.Iterable[dict[int, int | float]]) : binary results
  • binary_encoder(dict[str, IntegerEncoder]) : encoder provide decode method.
  • inverse_varmap(dict[int, tuple[str, tuple[int, ...]]]) : variable map

Returns

  • list[dict[int, int | float]] : decoded results

decode_from_dict_binary_result (samples, binary_encoder, compiled_model) -> -


dict_to_record (results, compiled_model) -> jm.Record

convert to jm.Record from dict result

Parameters

  • results(typ.Iterable[dict[int, int | float]]) : dict result
  • compiled_model(CompiledInstance) : compiled_model to get var_map and fixed_variables.

Returns

  • jm.Record : converted record.

evaluate (samples, compiled_model) -> -