Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected exception #75

Closed
zohannn opened this issue Jan 26, 2016 · 13 comments
Closed

Unexpected exception #75

zohannn opened this issue Jan 26, 2016 · 13 comments

Comments

@zohannn
Copy link

zohannn commented Jan 26, 2016

Hi I have a weird problem.
I have the attached nl file I want to read.
I successfully run the nl-exampl.cc but when I run the following code in my own library:

        std::string filename = std::string("FinalPosture.nl");
        DimensionPrinter printer;
        try
        {
              mp::ReadNLFile(filename, printer);
        }
        catch (const std::exception &exc)
        {

            std::cerr << exc.what();
        }     

I get the following exception:
FinalPosture.nl:22677:5: expected double.

Please what does it mean? How can I solve the problem?
Thank you.

FinalPosture.nl.zip

@vitaut
Copy link
Contributor

vitaut commented Jan 26, 2016

Thanks for the bug report. Unfortunately I cannot reproduce it, compiling and running

#include "mp/nl.h"
#include <iostream>

struct DimensionPrinter : mp::NLHandler<int> {
  void OnHeader(const mp::NLHeader &h) {
    fmt::print("Variables:   {}\n", h.num_vars);
    fmt::print("Constraints: {}\n", h.num_algebraic_cons);
    fmt::print("Nonzeros:    {}\n", h.num_con_nonzeros);
  }
};

int main() {
  std::string filename = std::string("FinalPosture.nl");
  DimensionPrinter printer;
  try {
    mp::ReadNLFile(filename, printer);
  } catch (const std::exception &exc) {
    std::cerr << exc.what();
  }     
}

gives

Variables:   7
Constraints: 184
Nonzeros:    1130

on your .nl file.

Are you using the latest version of the library from the repo?

@zohannn
Copy link
Author

zohannn commented Jan 26, 2016

Yes, it is the latest version.
I am currently trying to reproduce the exception outside my software.

@zohannn
Copy link
Author

zohannn commented Jan 26, 2016

Hi,

here a project you can open with Qt creator. It is a simple form with a push button.
When you push the button, the nl file should be read. However, I get the exception I was talking about.

Could you replicate the error? Please let me know.

Thank you very much.

testQt.zip

@vitaut
Copy link
Contributor

vitaut commented Jan 27, 2016

No, I still can't replicate an exception. I get the same output as before when clicking PushButton:

Variables:   7
Constraints: 184
Nonzeros:    1130

@vitaut
Copy link
Contributor

vitaut commented Jan 27, 2016

Moreover, I get the same result even without recompiling testQt which suggests that the problem is not due to difference in how libmp is compiled. What OS do you use?

@zohannn
Copy link
Author

zohannn commented Jan 27, 2016

Linux Mint.
It is very weird. Here a screenshot. To what is the error related ?
screenshot from 2016-01-27 00 26 21

@vitaut
Copy link
Contributor

vitaut commented Jan 27, 2016

Yes, quite weird. Could you replace line 1066 of mp/nl.h

      ReportError("expected double");

with the following

      ReportError("expected double: '{}' {} {}", fmt::StringRef(ptr_, 10),
                  static_cast<const void*>(ptr_), static_cast<const void*>(end));

recompile, rerun and post the output? This might shed some light on what's going on.

@zohannn
Copy link
Author

zohannn commented Jan 27, 2016

Here the result.
screenshot from 2016-01-27 00 50 46

@vitaut
Copy link
Contributor

vitaut commented Jan 27, 2016

One possible explanation for this is that strtod is locale-dependent and you have a locale with , as a decimal separator. As a workaround you can set the locale to C before calling ReadNLFile:

setlocale(LC_NUMERIC, "C");

@zohannn
Copy link
Author

zohannn commented Jan 27, 2016

The workaround works. I am not sure about the reason of this result, but I will get information about it.
Thank you.

screenshot from 2016-01-27 00 57 45

@vitaut
Copy link
Contributor

vitaut commented Jan 27, 2016

Great, thanks for the confirmation. I think a better solution is to replace strtod with something locale-independent, so I'll keep this issue open for now.

@zohannn
Copy link
Author

zohannn commented Jan 27, 2016

Hi Victor,
Now I perfectly understand the problem.

I'll be waiting for your update. Meanwhile I put export LC_NUMERIC="C"
in my .bashrc and it works.

Thank you again.

On 27-01-2016 01:03, Victor Zverovich wrote:

Great, thanks for the confirmation. I think a better solution is to
replace |strtod| with something locale-independent, so I'll keep this
issue open for now.


Reply to this email directly or view it on GitHub
#75 (comment).

Gianpaolo Gulletta

@vitaut
Copy link
Contributor

vitaut commented Jan 29, 2016

Fixed in 1028153 and two commits after it which implement MSVC compatibility. Thanks again for reporting!

@zohannn zohannn closed this as completed Jan 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants