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