メインコンテンツへスキップ

Serialize/deserialize Gurobi models

回答済み

コメント

3件のコメント

  • David Torres Sanchez
    • Gurobi Staff

    You can save a Gurobi model as an MPS file by calling

    model.write("model.mps")
    # Read it later
    model = gp.read("model.mps")

    This will preserve variable and constraint names which you can then use to identify them.

    I'm not sure pickling is supported or recommended.

    Cheers, 
    David

    0
  • Fabian Rigterink
    • Gurobi-versary
    • First Comment
    • First Question

    Thanks, David. We're aware of the common formats supported by the write function.

    However, we'd like to avoid separately storing all other Gurobi model attributes that are not part of, e.g., MPS files (for example, solver hyperparameters, variable and constraint attributes, etc.).

    Is there no other way to dump a model and load it back into memory? For example, models may be run as part of a cron job over night. If there is something going wrong, we'd like to be able to investigate the model as-is - without having to fully reconstruct it from scratch using MPS files and separate attribute files we'd have to manage ourselves.

    0
  • David Torres Sanchez
    • Gurobi Staff

    We replied to this query via a separate internal ticket.

    I post the answer from Alison for others in the forum:

    It sounds like simply storing the MPS model file is insufficient for this case.  You noted that you also wanted to store additional attribute information.  There are two additional files that I recommend you output and store:

    • Attribute file (ATTR).  The Gurobi attribute file serves as a repository for storing and retrieving attribute information related to a model. This information can be either specified by the user or generated during a previous solution call. This is the main information our customers look for in the attributes  If they are available, this file stores the following key attributes:
    • Parameter file (PRM).  The Gurobi parameter file stores the parameter-value pairs specified in the model object.

    Cheers, 
    David

    0

サインインしてコメントを残してください。