Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
Expand all | Collapse all

[.NET] Cplex.SetOut makes Cplex.Solve throw ExecutionEngineException [before it was: Cplex.SetOut throws OverflowException]

  • 1.  [.NET] Cplex.SetOut makes Cplex.Solve throw ExecutionEngineException [before it was: Cplex.SetOut throws OverflowException]

    Posted Sat November 16, 2013 11:44 AM

    Originally posted by: s.st1led


    Hi everybody, I posted this issue in the CP forum, but after some further testing I found out this also applies to Cplex so it's relevant also here (and, to be fully honest, this forum looks much more active than the CP one :). At this point, I'm thinking it might be a bug. I report my further test here, even though it's basically the same as the other.

    I'm using the x64 library delivered with CPLEX Optimization Studio 12.5.1 under Windows 8 x64 and Visual Studio 2012. Let's assume I have this pretty straightforward code:

                // Initializes the OPL Factory and Error Handler
                OplFactory.DebugMode = false;
                OplFactory oplFactory = new OplFactory();
                OplErrorHandler oplErrorHandler = oplFactory.CreateOplErrorHandler();

                // Initializes the OPL Run Settings
                OplSettings oplSettings = oplFactory.CreateOplSettings(oplErrorHandler);
                oplSettings.setWithWarnings(false);

                // Initializes the OPL Model
                OplModelSource oplModelSource = oplFactory.CreateOplModelSource(@"model.mod");
                OplModelDefinition oplModelDefinition = oplFactory.CreateOplModelDefinition(oplModelSource, oplSettings);

                // Initializes the OPL Data
                OplDataSource oplDataSource = oplFactory.CreateOplDataSource(@"data.dat");


                // Initializes the Cplex solver
                ILOG.CPLEX.Cplex cplex = oplFactory.CreateCplex();
                
                    StreamWriter streamWriter = File.CreateText(@"log.log");
                    TextWriter synchronizedStreamWriter = TextWriter.Synchronized(streamWriter);
                    cplex.SetOut(synchronizedStreamWriter);

                // Instantiates the OPL Model
                OplModel oplModel = oplFactory.CreateOplModel(oplModelDefinition, cplex);

               
                oplModel.AddDataSource(oplDataSource);

                // Generates the OPL Model
                oplModel.Generate();

                // Returns the loaded and configured OplModel
                return oplModel;

    When I execute it, I have the following runtime execption upon the Cplex.SetOut call:

    System.OverflowException was unhandled
      HResult=-2146233066
      Message=Arithmetic operation resulted in an overflow.
      Source=mscorlib
      StackTrace:
           at System.IntPtr.ToInt32()
           at ILOG.Concert.Cppimpl.NotifierStream.initCppCallback()
           at ILOG.Concert.Cppimpl.NotifierStream..ctor(IntPtr cPtr, Boolean cMemoryOwn)
           at ILOG.Concert.Cppimpl.NotifierStream..ctor()
           at ILOG.Concert.Cppimpl.DotnetToCppOutputStreamAdapter..ctor(TextWriter os)
           at ILOG.CPLEX.Cplex.SetOut(TextWriter s)
           at Test.Test.InitializeNewSearch() in Test.cs:line 42
           at Test.Program.Main(String[] args) in Program.cs:line 14
           at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException:
     

    Am I doing something wrong? I also tried with Cplex.SetOut(Console.Out), but this same exception is thrown. Basically, every Cplex.SetOut() call (apart from Cplex.SetOut(null)) throws this exception.

    Is anyone else experiencing the same thing?

     

    Regards,

    Stefano


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: [.NET] Cplex.SetOut throws OverflowException

    Posted Mon November 18, 2013 10:33 AM

    So far we could not reproduce this issue here. Are you sure you are using a 64bit CPLEX library? Can you please double check and make sure you are not using any 32bit CPLEX DLLs?


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: [.NET] Cplex.SetOut throws OverflowException

    Posted Mon November 18, 2013 12:22 PM

    Originally posted by: s.st1led


    I'm pretty sure I'm using the x64 version, because this is the path of the dll I linked in my project: "C:\Program Files\IBM\ILOG\CPLEX_Studio1251\opl\lib\oplall.dll". Since I'm using Windows 8 x64, the x86 version would have been in the "Program Files (x86)". Moreover, I only installed the x64 version of CPLEX Optimization Studio, and for large enough problems I can manage to have the CPLEX process go beyond 3GB of RAM usage, so it can only be x64.

    If you can't reproduce the issue, I'm a bit scared. I also tried with another computer (with the same software involved, Windows 8 x64, VS2012, x64 libraries) and I could reproduce the issue. Furthermore, it also looks like this issue doesn't depend on the specific model that I load. Even this minimal code throws the exception:

    OplFactory oplFactory = new OplFactory();
    ILOG.CPLEX.Cplex cp = oplFactory.CreateCplex();
    cp.SetOut(Console.Out);

    What could cause the problem? Some bad compiler setting in VS? The stacktrace of the exception is pretty much meaningless, but the fact it's popping out on two different machines is somehow suspicious.

     

    Regards,

    Stefano


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: [.NET] Cplex.SetOut throws OverflowException

    Posted Fri November 22, 2013 10:36 AM

    Originally posted by: s.st1led


    I went a bit further investigating this problem, and I found out that it's something related to the .NET library (not sure about the C++ one, since I didn't test that). For instance, the code above runs just fine with the Java library.

    If you can't reproduce it, it might be something related to some settings of my VS project. I also tried creating a fresh new project with only one class that has that 3 lines of code, and I still have the exception. I'm kind of running out of ideas.


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: [.NET] Cplex.SetOut throws OverflowException

    Posted Fri November 22, 2013 10:52 AM

    We are working on this. We have not been able to reproduce it yet but have not run of ideas either :-) We have also found some internal stuff that looks suspicious but are not yet sure whether this is indeed a problem.

    By the way, how much RAM do you have on your machine? Did you by any chance set any option anywhere that would cause memory to be allocated at large addresses rather than small ones?


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: [.NET] Cplex.SetOut throws OverflowException

    Posted Fri November 22, 2013 12:51 PM

    Originally posted by: s.st1led


    Thank you very much Daniel for your support and time you are spending on this. I have 8GB RAM, but I don't think I have set up any kind of option like that: I wouldn't even know where to set it. Might it be a Visual Studio setting hidden somewhere?


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: [.NET] Cplex.SetOut throws OverflowException

    Posted Thu November 28, 2013 12:52 AM

    We have found the issue. Unfortunately there is no easy workaround. The best workaround I can see at the moment is to use 32bit CPLEX and run your application as a 32bit application.


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: [.NET] Cplex.SetOut throws OverflowException

    Posted Thu November 28, 2013 03:16 AM

    Originally posted by: s.st1led


    Ok, good job. As for now, the constraint model I'm working on is quite large and needs the x64 version for more memory. I guess I'll just wait for a fix. Are there any chances to see a fix in the upcoming 12.6 version?


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: [.NET] Cplex.SetOut throws OverflowException

    Posted Sat November 30, 2013 04:53 AM

    I'm afraid it might already be too late to get the fix into 12.6. So please do not count on that :-(


    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: [.NET] Cplex.SetOut throws OverflowException

    Posted Sun January 11, 2015 12:10 PM

    Originally posted by: s.st1led


    I got an update on this issue (sorry for crossposting on https://www.ibm.com/developerworks/community/forums/html/topic?id=2fe1a563-3e59-4bac-8a57-75049e56ba4d#97e12638-6736-4723-8739-13904e46db8a).

    After updating to v.12.6.1, this issue just seems to have gotten worse. Instead of an OverflowException upon calling CPLEX.SetOut(), now I seem to be getting a System.ExecutionEngineException upon calling CPLEX.Next() later in the code. For some obscure reason I'm not even able to catch this exception with try/catch statements, so upon execution my program simply crashes.

    This is the (not very meaningful) exception log that I get in Visual Studio:

    System.ExecutionEngineException was unhandled
      HResult=-2146233082
      Message=Exception of type 'System.ExecutionEngineException' was thrown.
      InnerException:

    Any update from IBM side?

     

    Regards,

    Stefano


    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: [.NET] Cplex.SetOut throws OverflowException

    Posted Mon January 12, 2015 07:49 AM

    The Overflow issue related to SetOut() should be fixed in 12.6.1. This ExecutionEngineException seems to be something else.

    I am not clear what you mean by function CPLEX.Next(). The Cplex class does not define a 'Next()' method. So what exactly are you doing?


    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: [.NET] Cplex.SetOut throws OverflowException

    Posted Mon January 12, 2015 10:20 AM

    Originally posted by: s.st1led


    I'm sorry, that was a wrong copy/paste from the CP example in the other thread. I meant CPLEX.Solve(). I past a fresh new MWE that results in this error. Mind that I'm using the 64bit version of the library: I didn't have a chance yet to test with the 32bit one.

                // Initializes the OPL Factory and Error Handler
                OplFactory.DebugMode = false;
                OplFactory oplFactory = new OplFactory();
                OplErrorHandler oplErrorHandler = oplFactory.CreateOplErrorHandler();

                // Initializes the OPL Run Settings
                OplSettings oplSettings = oplFactory.CreateOplSettings(oplErrorHandler);
                oplSettings.setWithWarnings(false);

                // Initializes the OPL Model
                OplModelSource oplModelSource = oplFactory.CreateOplModelSource(@"model.mod");

                OplModelDefinition oplModelDefinition = oplFactory.CreateOplModelDefinition(oplModelSource, oplSettings);

                // Initializes the OPL Data
                 OplDataSource oplDataSource = oplFactory.CreateOplDataSource(@"data.dat");


                // Initializes the CP solver
                ILOG.CPLEX.Cplex cplex = oplFactory.CreateCplex();

                StreamWriter streamWriter = File.CreateText(@"TestLogCplex.log");
                TextWriter synchronizedStreamWriter = TextWriter.Synchronized(streamWriter);
                cplex.SetOut(synchronizedStreamWriter);



                // Instantiates the OPL Model
                OplModel oplModel = oplFactory.CreateOplModel(oplModelDefinition, cplex);




                // Adds the data source to the model
                oplModel.AddDataSource(oplDataSource);

                // Generates the OPL Model
                oplModel.Generate();


                // Solves the model
                while (oplModel.Cplex.Solve() == false)
                {
                    // Sets the optimal value
                    double objectiveValue = oplModel.Cplex.ObjValue;

                    Console.Out.WriteLine(objectiveValue);
                }

                // Terminates the Program
                Console.WriteLine(Environment.NewLine + "Press any key to exit");
                Console.ReadKey();

     

    Upon the Cplex.Solve() call, I get the ExecutionEngineException. This happens every time I call Cplex.SetOut() with a non-null argument before the Solve call.

     

    Regards,

    Stefano


    #CPLEXOptimizers
    #DecisionOptimization


  • 13.  Re: [.NET] Cplex.SetOut throws OverflowException

    Posted Tue January 20, 2015 10:53 AM

    Sorry, I cannot reproduce this here with CPLEX 12.6.1 on 64bit Windows and Visual Studio 2012. What is your exact setup? What CPLEX assembly do you use (oplall.dll?). Have you configured your project for AnyCPU or for x64?

    Could you please post the exception details here (with all InnerException frames expanded)? Maybe we can spot the problem from that.


    #CPLEXOptimizers
    #DecisionOptimization


  • 14.  Re: [.NET] Cplex.SetOut throws OverflowException

    Posted Tue January 20, 2015 11:22 AM

    Originally posted by: s.st1led


    I'm running CPLEX 12.6.1 x64 on Windows 8.1 x64 and Visual Studio 2013. In the reference of the projects I added the oplall.dll file that is located in C:\Program Files\IBM\ILOG\CPLEX_Studio1261\opl\lib\. The exception happens both when I configure the project for AnyCPU and for x64.

    When I execute the code I get a System.ExecutionEngineException, but unfortunately the exception detail (the one you get when clicking on "Copy exception detail to the clipboard" in the exception popup of VS) is not very meaningful:

    System.ExecutionEngineException was unhandled
      HResult=-2146233082
      Message=Exception of type 'System.ExecutionEngineException' was thrown.
      InnerException:

    I uploaded a screenshot of the exception snapshot (that I can' copy/paste), which seems to have some more detail. The Data field has a recursive structure that I can't unfold completely, but tell me if you need something specific. Note that the InnerException is null, so there is nothing to show when I expand it in the dialog.

    I can sense it is something strange, because I'm not even able to catch the exception with a try/catch construct: the code just crashes bypassing the catch.

     

    Regards,

    Stefano


    #CPLEXOptimizers
    #DecisionOptimization


  • 15.  Re: [.NET] Cplex.SetOut throws OverflowException

    Posted Sun May 24, 2015 11:01 PM

    Originally posted by: MattChilcott


    Hi Daniel,

    we too are experiencing this issue on Windows 8.1 64bit machines.

    You indicated there might be a fix in the works - could you tell me approximately when this might be available so I can pass this information on to our customers as a guide?

     

    thanks,

    Matt


    #CPLEXOptimizers
    #DecisionOptimization


  • 16.  Re: [.NET] Cplex.SetOut throws OverflowException

    Posted Tue June 02, 2015 08:56 AM

    My colleague updated the correponding thread in the CP Forum. Please check there for more details.


    #CPLEXOptimizers
    #DecisionOptimization


  • 17.  Re: [.NET] Cplex.SetOut makes Cplex.Solve throw ExecutionEngineException [before it was: Cplex.SetOut throws OverflowException]

    Posted Tue June 23, 2015 11:46 AM

    Originally posted by: s.st1led


    As I reported on the thread in the CP forums, v12.6.2.0 fixed this issue.

     

    Regards,

    Stefano


    #CPLEXOptimizers
    #DecisionOptimization