Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

[.NET] CP.SetOut makes CP.Next throw ExecutionEngineException [before it was: CP.SetOut throws OverflowException]

Archive User

Archive UserSun June 07, 2015 04:12 AM

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

    Posted Wed November 13, 2013 06:28 AM

    Originally posted by: s.st1led


    Hi everybody,

    I have a strange issue while using the ILOG CP library for .NET. 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 CP solver
                ILOG.CP.CP cp = oplFactory.CreateCP();
                
                    StreamWriter streamWriter = File.CreateText(@"log.log");
                    TextWriter synchronizedStreamWriter = TextWriter.Synchronized(streamWriter);
                    cp.SetOut(synchronizedStreamWriter);


                cp.SetParameter(ILOG.CP.CP.DoubleParam.OptimalityTolerance, 0);
                cp.SetParameter(ILOG.CP.CP.DoubleParam.RelativeOptimalityTolerance, 0);
                cp.SetParameter(ILOG.CP.CP.IntParam.TimeMode, ILOG.CP.CP.ParameterValues.ElapsedTime);

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

               
                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 CP.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.CP.CP.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 Cp.SetOut(Console.Out), but this same exception is thrown. Basically, every CP.SetOut() call (apart from CP.SetOut(null)) throws this exception.

    Ideas?

     

    Regards,

    Stefano


    #DecisionOptimization
    #OPLusingCPOptimizer


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

    Posted Thu November 21, 2013 11:53 AM

    Originally posted by: ChrisBr


    Hello Stefano,

    Sorry to not have answered earlier, but I'm afraid I couldn't help so far.
    We failed to reproduce the problem.
    Could you give us the stacktrace? This might help us to find out the problem.

    Regards,

    Chris.

     


    #DecisionOptimization
    #OPLusingCPOptimizer


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

    Posted Thu November 21, 2013 11:59 AM

    Originally posted by: s.st1led


    Hi Chris, I posted this issue in the CPLEX forum as well because I have this error while using the CPLEX library too. The stacktrace is attached at the bottom of the previous message, I'll paste it here for commodity:

    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.CP.CP.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:

    The strange thing is that this also happens on another computer that I'm using with the same configuration (VS 2012, CP x64 libraries, Windows 8 x64).

     

    Regards,

    Stefano

     


    #DecisionOptimization
    #OPLusingCPOptimizer


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

    Posted Mon November 25, 2013 09:55 AM

    Originally posted by: ChrisBr


    Hello Stefano,

    As you may have noticed, both issues come from the same root cause.
    We are working on this and we will update one of the forums when we'll have more information.
    Sorry to not be able to help more for the moment.

    Regards,


    Chris.


    #DecisionOptimization
    #OPLusingCPOptimizer


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

    Posted Mon November 25, 2013 10:06 AM

    Originally posted by: s.st1led


    Thank you for you support Chris. I'm actively following both discussions (this one, and the one on the CPLEX forum). Keep me posted!

     

    Regards,

    Stefano


    #DecisionOptimization
    #OPLusingCPOptimizer


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

    Posted Tue November 04, 2014 11:32 AM

    Originally posted by: Wooi Fun


    I have the same issue too when running on Windows 8: Details below. Stefano, not sure if you manage to solve it? Thanks.

    Arithmetic operation resulted in an overflow. |    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.CP.CP.WriteConflict(TextWriter s)
      


    #DecisionOptimization
    #OPLusingCPOptimizer


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

    Posted Tue November 04, 2014 11:41 AM

    Originally posted by: s.st1led


    Actually, I never managed to fix this issue, so I just commented out the SetOut call in my code. Updating CPLEX to 12.6.0.1 did not help, and indeed there is no mention for this particular issue in the update release notes (http://pic.dhe.ibm.com/infocenter/cosinfoc/v12r6/index.jsp?topic=%2Filog.odms.studio.help%2FOptimization_Studio%2Ftopics%2FCOS_relnotes_intro.html).

     

    I was told in another topic I opened (https://www.ibm.com/developerworks/community/forums/html/topic?id=01aa8faa-66e5-41c2-a9dd-384026934874#5fa8186a-a40e-4790-aee4-5dcf3ac7f798) that they identified the cause of the problem, and I have to guess a fix will be released in the next update (or major version), but I'd rather to wait for someone from IBM to confirm it. It has been almost a year now.

     

    Regards,

    Stefano


    #DecisionOptimization
    #OPLusingCPOptimizer


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

    Posted Tue November 04, 2014 11:49 AM

    Originally posted by: Wooi Fun


    Stefano, Thanks for the reply. Regards.


    #DecisionOptimization
    #OPLusingCPOptimizer


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

    Posted Sun January 11, 2015 12:09 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=01aa8faa-66e5-41c2-a9dd-384026934874#5fa8186a-a40e-4790-aee4-5dcf3ac7f798).

    After updating to v.12.6.1, this issue just seems to have gotten worse. Instead of an OverflowException upon calling CP.SetOut(), now I seem to be getting a System.ExecutionEngineException upon calling CP.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


    #DecisionOptimization
    #OPLusingCPOptimizer


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

    Posted Tue January 13, 2015 09:23 AM

    Originally posted by: PhilippeLaborie


    Hello,

    This is probably a different issue than the one you found with 12.6. Could you send a small model that illustrates the problem ?

    Is it like the original problem: can you reproduce it only using the .NET API of CP Optimizer (no OPL) ?

    Do you still get the crash if you do not change the output stream ?

    Philippe


    #DecisionOptimization
    #OPLusingCPOptimizer


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

    Posted Tue January 13, 2015 09:54 AM

    Originally posted by: s.st1led


    Hi Philippe,

    this is a MWE that fires the exception upon calling CP.Next()

     

                // 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.CP.CP cp = oplFactory.CreateCP();

                StreamWriter streamWriter = File.CreateText(@"C:\Users\Stefano\Desktop\TestLogCp.log");
                TextWriter synchronizedStreamWriter = TextWriter.Synchronized(streamWriter);
                cp.SetOut(synchronizedStreamWriter)

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

                


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

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


                cp.StartNewSearch();
            

                // Solves the model
                while (oplModel.CP.Next())
                {
                    // Sets the optimal value
                    double objectiveValue = cp.ObjValue;

                    Console.Out.WriteLine("Obj Value: " + objectiveValue);
                }

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

    If I comment out the CP.SetOut() call, then I have no exception and the code runs fine. The OPL model and data can be something arbitrarily trivial I guess. For instance, I get the error with these model and data files:

    using CP;

    int wx = ...;
    int wy = ...;

    dvar int x in 1..10;
    dvar int y in 1..10;

    maximize
        wx * x + wy * y;

    subject to {
        x > y;
    }

     

    wx = 1;
    wy = 2;

     

    Regards,

    Stefano


    #DecisionOptimization
    #OPLusingCPOptimizer


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

    Posted Tue June 02, 2015 08:36 AM

    Originally posted by: PhilippeLaborie


    Hello,

    We identified the problem. It will be fixed in a forthcoming release.

    Regards,

    Philippe


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 13.  Re: [.NET] CP.SetOut makes CP.Next throw ExecutionEngineException [before it was: CP.SetOut throws OverflowException]

    Posted Sun June 07, 2015 04:12 AM

    Originally posted by: s.st1led


    Hi Philippe,

     

    I almost forgot I posted this issue! Good to hear that a fix is coming.

     

    Regards,

    Stefano


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 14.  Re: [.NET] CP.SetOut makes CP.Next throw ExecutionEngineException [before it was: CP.SetOut throws OverflowException]

    Posted Tue June 23, 2015 11:43 AM

    Originally posted by: s.st1led


    And this is just to confirm that v12.6.2.0 fixed this issue!

     

    Regards,

    Stefano


    #DecisionOptimization
    #OPLusingCPOptimizer