to_mip
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 MIPBuilder
MIP Builder
Attributes
- compiled_model(CompiledInstance) : compiled model.
- model(mip.Model) : mip model.
decode_from_mip (self, status, model) -> jm.SampleSet
Decode from mip model.
Parameters
- status(mip.OptimizationStatus) : status of optimization.
- model(mip.Model) : mip model.
Returns
- jm.SampleSet : sample set.
get_model (self) -> mip.Model
Get mip model.
Returns
- mip.Model : mip model.
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) -> -
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) -> -
transpile_to_mip (compiled_model, relax_list, solver_name, mip_model) -> MIPBuilder
Transpile a compiled model into a MIP model.
Parameters
- compiled_model(CompiledInstance) : a compiled model
- relax_list(list[str]) : a list of labels to be relaxed. Defaults to None.
- solver_name(str) : the name of the solver. Defaults to "CBC".
- mip_model(mip.Model) : a MIP model to be used. Defaults to None.
Returns
- MIPBuilder : a MIP model builder