MIP: ExportModelAsMpsFormatToFile #3736
Replies: 2 comments
-
Hi @Mizux ! I noticed you've assigned this discussion to yourself, so I'd like to share what I've done to write models into compressed (.gz) files with new |
Beta Was this translation helpful? Give feedback.
-
Hello, I would like to work on this and create a pull request if that's OK. I didn't want to proceed without confirmation. @lperron , @Mizux |
Beta Was this translation helpful? Give feedback.
-
What language and solver does this apply to?
C#, Linear Solver, MIP
Describe the problem you are trying to solve.
I am using the dotnet nuget package, Google.OrTools, for obtaining the mps format of an optimization problem. The ExportModelAsMpsFormat method works properly in most cases. However, when it comes to obtaining the mps format for huge models, it fails with an out-of-memory error with the following execution:
After analyzing the issue, I ended up looking at the method in the codebase, here, I am seeing that the method constructs a string by appending the sections one by one, and I interpreted that this process results in loading very large string into the memory.
Describe the solution you'd like
To overcome this problem there can be a new method that executes the same logic but appends the data into a file instead of appending it to the string object. For example, for my use cases, I do not need to obtain the output as a string, instead, I need to obtain it as a .mps file and send it to a different service and solved it by a Solver(CBC, Gurobi, etc).
Preferred feature can be implemented as the same as the ExportModelAsMpsFormat but can append each section to a file separately like changing all string append operation with file append
Describe alternatives you've considered
An alternative way can be refactoring the same method as streaming the string data instead of returning it at once.
Additional context
Imagine that there is an architecture that has the components "the model generator" and "the model solver" in separate places and communicates with each other .mps files and restful API. The generator component retrieves all the data related to the model, constructs it, and uploads it to the cloud storage service. Then send a request to a different service to solve the problem. The other service downloads the model file and solves it. In this flow, the generator service only generates the model and does nothing with the model itself. So, no need to obtain the model content in string format. Exporting the model directly into a file is a better(memory-safe) option rather than loading the string into the memory of the generator application because there is no need to obtain it in string format there.
Beta Was this translation helpful? Give feedback.
All reactions