Load model from txt file

349 views
Skip to first unread message

Alberto Manzini

unread,
Jan 13, 2024, 7:32:34 PM1/13/24
to or-tools-discuss
Hi everyone, I've saved my model in a txt file using method
model.ExportToFile(filename)

I don't understand how to load back my model from this file. I assume I have to load the proto message from file and setting it to a (empty) model, but I'm looking for the exact python commands to follow

Thanks for any help

Laurent Perron

unread,
Jan 14, 2024, 2:55:04 AM1/14/24
to or-tools...@googlegroups.com

There are no api. This is used mostly for debugging purposes.


--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/583adb61-1a9a-449f-ab56-44265d58454cn%40googlegroups.com.

watchdogs132

unread,
Jan 14, 2024, 7:29:13 AM1/14/24
to or-tools-discuss
from ortools.sat.python import cp_model
from google.protobuf import text_format

model = cp_model.CpModel()
with open("model.txt", "r") as file:
    text_format.Parse(file.read(), model.Proto())

Alberto Manzini

unread,
Jan 14, 2024, 11:34:54 AM1/14/24
to or-tools-discuss
Cool, many thanks!

Laurent Perron

unread,
Jan 14, 2024, 12:07:27 PM1/14/24
to or-tools...@googlegroups.com
The question is to recover solutions.

You can use model.Get{Int|Bool|Interval}VarFromProtoIndex to rebuild variables to use to recover solutions.
Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00



Alberto Manzini

unread,
Jan 15, 2024, 2:30:51 PM1/15/24
to or-tools-discuss
Hi, I was looking for a method to export and load the model, not the solutions, to debug it
Thank you both

Reply all
Reply to author
Forward
0 new messages