google / or-tools

Google's Operations Research tools:
https://developers.google.com/optimization/
Apache License 2.0
11.09k stars 2.11k forks source link

ExportModelAsMpsFormat creates an unreadable char pointer in Python #4349

Open giacomoguiduzzi opened 1 month ago

giacomoguiduzzi commented 1 month ago

What version of OR-Tools and what language are you using? Version: main (9.10.4067 from the venv). Language: Python

Which solver are you using (e.g. CP-SAT, Routing Solver, GLOP, BOP, Gurobi) SCIP

What operating system (Linux, Windows, ...) and version? Ubuntu 22.04 on kernel 5.18

What did you do? Steps to reproduce the behavior:

  1. Create a solver and add variables and constraints to it
  2. Call the solver.ExportModelAsMpsFormat() function and pass its output to an opened file in write mode
  3. Get error from the interpreter as the output is not a string, but a char * SwigPyObject at address 0xnumbers.

I feel like opening the file as 'wb' instead of 'w' wouldn't solve the issue as I'd save the pointer object, not the pointed string. Can you confirm?

What did you expect to see The program successfully saving the model to disk.

What did you see instead? A ValueError exception.

Make sure you include information that can help us debug (full error message, model Proto). I'm not sure what kind of information could be of use. The model is pretty big and it would be difficult to send here.

Anything else we should know about your project / environment The ExportModelasLpFormat function works correctly returning a string. I am using Python3.9.19 in a venv. Let me know if there is anything else that could be useful to know, or if I'm missing something.

Thanks in advance.

Best Regards, Giacomo Guiduzzi

lperron commented 1 month ago

How large is the model ?

giacomoguiduzzi commented 1 month ago

It has a few millions variables and constraints. Do you need the exact number?


From: Laurent Perron @.> Sent: Sunday, August 18, 2024 5:58:25 AM To: google/or-tools @.> Cc: Giacomo Guiduzzi @.>; Author @.> Subject: Re: [google/or-tools] ExportModelAsMpsFormat creates an unreadable char pointer in Python (Issue #4349)

How large is the model ?

— Reply to this email directly, view it on GitHubhttps://github.com/google/or-tools/issues/4349#issuecomment-2295100631, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACTOJW4JU3NLCJ4NRJFMW4TZSALWDAVCNFSM6AAAAABMVZYZ26VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJVGEYDANRTGE. You are receiving this because you authored the thread.Message ID: @.***>