Fileformat .cip gives wrong decimal separator at WIN 10
Problem The file *.cip written from pyscipopt to disc has the wrong decimal separator. It uses "," instead of ".".
Expected beaviour Write a *.cip file on Win 10 using python 3.9 and pyscipopt 3.4 with SCIP version 8.1.0 *.cip should be importable via cmd console.
Screenshots [continuous] <m_pipe_F544_to_F571>: obj=0, original bounds=[-0,0223201928920082,0,0223201928920082] [continuous] <m_pipe_F414_to_F329>: obj=0, original bounds=[-0,351125515405446,0,351125515405446] [continuous] <m_pipe_F610_to_F649>: obj=0, original bounds=[-0,00699655334823101,0,00699655334823101] [continuous] <m_pipe_F497_to_F219>: obj=0, original bounds=[-0,0532264217914526,0,0532264217914526]
System
- OS: Win 10
- Version '??
- SCIP version 8.1.0
- How did you install
pyscipopt? Via conda
Additional context
Hello, @JPelda! Can you please share a code that reproduces your error? My cip files are working well:
It may be a Windows-specific issue, but still, I'd like to test the model that you're having trouble with.
thank you for your fast response!
Here is my outcome of test.cip if taking your model, adding an original bound to x, and initializing it via pyscipopt. I have got „,“ as decimal separator for the bounds as well as for the constraints.
Problem is the bound. That was given with: x = m.addVar(lb=0, ub=2.1)
but it turn out as
[continuous]
If the test.cip is imported into scip via cmd and exported into test2.cip, scip interprets the original bounds as:
original bounds=[0,2] and
Wow, this is very strange indeed. I'll try to figure out who to tag that might be able to help with this.
To make sure, what happens if you use something other than .cip? Just want to make sure the problem is actually with .cip and not with some settings in your windows.
In the meantime, you could maybe write a script that replaces the incorrect commas, if you need a solution urgently.
Hi,
I found the reason for it. If the package "locale" (I need it for my graphics output correct decimal separator) is imported in your pyscipopt script with any file imported at the beginning, then pyscipopt writes the *.cip and also *.mps with the decimal separator defined in the locale.setlocale(...):
from pyscipopt import Module
import locale
locale.setlocale(locale.LC_NUMERIC, "de_DE.UTF-8") # For German the decimal sep is ",".
m = Model()
x = m.addVar(lb=0, ub=2.1)
m.addCons(x <= 1.3141212)
m.writeProblem('test.cip')
This will end up in a wrong dec sep.
Calling
locale.setlocale(locale.LC_NUMERIC, "eng_BR.UTF-8")
before
m.writeProblem('test.cip')
seems to solve the problem.
Hey, @JPelda! We've been discussing the best way to handle this. We could be doing the same thing you did (setting locale in before all the write and print methods and restoring it afterward) in the PySCIPOpt source code, which might take a bit of work and make things slightly slower, or we could add some sort of warning here on the Github page, and perhaps link to your response on how to fix it. Do you think this problem is big enough/common enough to warrant such a change in the code, or does the warning suffice?
Dear João,
I think the problem affects many people in countries that use „,“ instead of „.“ as decimal separator (see https://herrmann.tech/en/blog/2021/02/05/how-to-deal-with-international-data-formats-in-python.html ). For graphical output with matplotlib using the package locale and setting the decimal separator seems to be the mostly used approach to achieve the rigth decimal separator in the figure. Of course, it would be great to make pyscipopt compatible with the package „locale“ and its individuel setting of comma or point.
Maybe it is appropriate to include the package into pyscipopt and let it do the check for „how is the decimal separator configures“ and raise an error if false or envelope the pyscipotp package into a setting with explicit defined decimale separator.
Unfortunately, I am not so good in programming. There might be a better solution.
Best regards, Johannes
Von: João Dionísio @.> Gesendet: Dienstag, 6. Februar 2024 17:52 An: scipopt/PySCIPOpt @.> Cc: Pelda, Johannes @.>; Mention @.> Betreff: Re: [scipopt/PySCIPOpt] Fileformat .cip gives wrong decimal separator at WIN 10 (Issue #788)
Hey, @JPeldahttps://github.com/JPelda! We've been discussing the best way to handle this. We could be doing the same thing you did (setting locale in before all the write and print methods and restoring it afterward) in the PySCIPOpt source code, or we could add some sort of warning here on the Github page, and perhaps link to your response on how to fix it. Do you think this problem is big enough/common enough to warrant such a change in the code, or does the warning suffice?
— Reply to this email directly, view it on GitHubhttps://github.com/scipopt/PySCIPOpt/issues/788#issuecomment-1930347949, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AFH3TCPXHHEEECGUPUMESGDYSJNSXAVCNFSM6AAAAABCONVGV6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMZQGM2DOOJUHE. You are receiving this because you were mentioned.Message ID: @.***>