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

Running a loaded Model with New Data

回答済み

コメント

3件のコメント

  • Maliheh Aramon
    • Gurobi Staff

    Hi Ryan, 

    I assume that the time required to build a model for a given dataset is relatively small. Therefore, it would be better to re-write your script so that it takes the data as input and returns a Gurobi model object as output. This way, you can easily run the script with different inputs.

    I'm not entirely sure what you mean by “storing the model to disk.” If you're referring to saving the model, you can write it to a file using the MPS format. Later, you can load the model back and use various API methods—such as getVars(), getConstrs(), and chgCoeff()—to inspect or modify the model as needed.

    Hope this answers your question.

    Best regards,

    Maliheh

     

    0
  • Ryan May
    • First Question
    • First Comment

    Hello Maliheh

    Thank you for the quick response in support.

    Yes, the time to build the model is less than a second.

    We are using the model in a cloud architecture. We had planned on building the model and writing it to a .mps file using the write() command. This is then stored in the cloud and called in our python script using read(). This imports the prebuilt model. My attempts to modify it using those API methods is about 50 lines of code and so far have been unsuccessful and I imagine it will take more code to get it to work.

    That said the code used to build it is also about 50 lines.

    Are there any speed or other operational benefits to modifying a prebuilt model vs building a new one? This model will have its structure tailored to different applications and so we will likely have many active models/model building scripts that we will need to maintain. These will be called hundreds to thousands of times a day.

    Thank you for the support.

    0
  • Maliheh Aramon
    • Gurobi Staff

    Are there any speed or other operational benefits to modifying a prebuilt model vs building a new one?

    This depends on how many changes are needed to derive the modified model from the existing one. If only a small number of coefficients need to be updated, it may make sense to reload the pre-built model and apply the changes. However, if most or all of the coefficients must be replaced, it’s more efficient to rebuild the model from scratch—especially since the build time is typically less than a second.

    This model will have its structure tailored to different applications and so we will likely have many active models/model building scripts that we will need to maintain. These will be called hundreds to thousands of times a day.

    I'm not sure why you would need to write separate scripts for models that differ only in the values of their coefficients. If the underlying mathematical formulation changes, then yes, a new function to build the model would be necessary. Otherwise, you can use the same function and simply supply different input data.

    Best regards,

    Maliheh

    0

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