数理モデルのシリアライズ#
JijModeling で作られた数理モデルは、Protobuf で簡単にシリアライズできます。具体的には、jijmodeling.to_protobuf()関数かProblem.to_protobuf <jijmodeling.Problem.to_protobuf>メソッドを使えばシリアライズできます。
import jijmodeling as jm
problem = jm.Problem("my problem")
N = problem.Placeholder("N", dtype=jm.DataType.NATURAL)
x = problem.BinaryVar("x", shape=(N,))
problem += x.sum()
serialized = problem.to_protobuf()
デシリアライズは、jijmodeling.from_protobuf() かProblem.from_protobufで行えます。
deserialized = jm.from_protobuf(serialized)