Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Problems with the C# API for CP Optimizer

    Posted 01/19/11 02:19 AM

    Originally posted by: svelten


    Hi,

    I tried to model and solve a scheduling problem using the C# API for CP Optimizer and encountered (up to know) the following problems:

    • If I call the method Model of class CP, I get an “invalid cast” exception.
    • It is not possible to use the interfaces IAnd and IOr since the method Add throws a “not implemented” exception.
    • If I define a NumToNumStepFunction using the method NumToNumStepFunction(double xmin, double xmax, double dval) and attach it to an interval variable as intensity (using the method +SetIntensity+) I get an exception while solving the problem.
    • Defining own constraints by implementing the interface IConstraint is not possible as the method ILOG.Concert.Cppimpl.IloConcertUtils.ToCppIloExtractable(IAddable v) tries to cast the constraint to ILOG.Concert.Cppimpl.IloExtractable although it only takes IAddable.

    Does anybody have experience with the C# API for CP Optimizer? Are these known problems? Any suggestions how to fix them?

    I’m looking forward for your answers.
    Thanks,
    Sebastian
    #CPOptimizer
    #DecisionOptimization


  • 2.  Re: Problems with the C# API for CP Optimizer

    Posted 01/19/11 11:31 AM

    Originally posted by: SystemAdmin


    Hello,
    We are not able to reproduce the 3rd point related with NumToNumStepFunction and intensities. Do you have a piece of code showing the problem? Note that an example of use of intensity function is provided in the example "SchedCalendar".

    We are currently investigating your others issues with the C# API and will get back to you soon with some answers.

    Best regards,

    Philippe
    #CPOptimizer
    #DecisionOptimization


  • 3.  Re: Problems with the C# API for CP Optimizer

    Posted 01/20/11 07:23 AM

    Originally posted by: svelten


    Hi,

    the following piece of code throws an access violation exception during Solve:

    
    CP cp = 
    
    new CP();   IIntervalVar = cp.IntervalVar(5);   INumToNumStepFunction stepFunction = cp.NumToNumStepFunction(0, int.MaxValue, 1);   intervalVar.SetIntensity(stepFunction, 1); cp.Add(cp.ForbidStart(intervalVar, stepFunction));   cp.Solve();
    


    The following, however, works:

    
    CP cp = 
    
    new CP();   IIntervalVar = cp.IntervalVar(5);   INumToNumStepFunction stepFunction = cp.NumToNumStepFunction(); stepFunction.setValue(0, int.MaxValue, 1);   intervalVar.SetIntensity(stepFunction, 1); cp.Add(cp.ForbidStart(intervalVar, stepFunction));   cp.Solve();
    


    Sebastian
    #CPOptimizer
    #DecisionOptimization


  • 4.  Re: Problems with the C# API for CP Optimizer

    Posted 01/20/11 08:07 AM

    Originally posted by: SystemAdmin


    Strange,
    It works for me after fixing the missing name for the interval variable:

    
    using ILOG.CP; using ILOG.Concert; namespace Test 
    { 
    
    public 
    
    class Test 
    { 
    
    static 
    
    void Main() 
    { CP cp = 
    
    new CP(); IIntervalVar intervalVar = cp.IntervalVar(5); INumToNumStepFunction stepFunction = cp.NumToNumStepFunction(0, int.MaxValue, 1); intervalVar.SetIntensity(stepFunction, 1); cp.Add(cp.ForbidStart(intervalVar, stepFunction)); cp.Solve(); 
    } 
    } 
    }
    


    Which version of CPLEX Optimization Studio are you using ? On which platform ?
    I tested using version V12.2.0.1 on Visual Studio 2008, 32 Bit.

    Philippe
    #CPOptimizer
    #DecisionOptimization


  • 5.  Re: Problems with the C# API for CP Optimizer

    Posted 01/20/11 09:13 AM

    Originally posted by: svelten


    Hi,

    I just use ILOG.CP.dll in version 2009.0.0. Moreover, I use VS2008 and 32 Bit as well. The platform is Windows.

    Sebastian
    #CPOptimizer
    #DecisionOptimization


  • 6.  Re: Problems with the C# API for CP Optimizer

    Posted 01/21/11 05:09 AM

    Originally posted by: SystemAdmin


    Hello,

    > 1. If I call the method Model of class CP, I get an “invalid cast” exception.

    Indeed, this method was not supposed to be documented. You should work on the current model of the instance of CP and add the constraints there: cp.Add(ct).

    > 2. It is not possible to use the interfaces IAnd and IOr since the method Add throws
    > a “not implemented” exception.

    These functions are indeed missing. As a work-around, you can create constraint arrays as in the sample below:

    
    CP cp = 
    
    new CP(); IIntVar x = cp.IntVar(0, 3); IIntVar y = cp.IntVar(0, 3); IIntVar z = cp.IntVar(0, 3); IConstraint[] cts = 
    
    new IConstraint[3]; cts[0] = cp.Eq(x, y); cts[1] = cp.Eq(x, z); cts[2] = cp.Eq(y, z); IOr orCt = cp.Or(cts); cp.Add(orCt);
    


    Thank you for reporting these issues.

    > 3. If I define a NumToNumStepFunction using the method NumToNumStepFunction(double xmin,
    > double xmax, double dval) and attach it to an interval variable as intensity (using the
    > method +SetIntensity+) I get an exception while solving the problem.

    It works in last release (CPLEX Optimization Studio V12.2) but indeed crashes on earlier versions (CP Optimizer 6.3). A work-around in earlier versions is to create the step function without default value and define the function values using the SetValue member function.

    > 4. Defining own constraints by implementing the interface IConstraint is not possible as
    > the method ILOG.Concert.Cppimpl.IloConcertUtils.ToCppIloExtractable(IAddable v) tries to
    > cast the constraint to ILOG.Concert.Cppimpl.IloExtractable although it only takes
    > IAddable.

    You cannot subclass in the C# interface. See the release notes, section on "Limitations of the Microsoft .NET Framework languages API". In fact, you cannot define your own constraints in C#. For defining your own constraints you need to use Java or C++. C++ will be much more efficient.

    Philippe
    #CPOptimizer
    #DecisionOptimization


  • 7.  Re: Problems with the C# API for CP Optimizer

    Posted 01/25/11 02:37 AM

    Originally posted by: svelten


    Hi,

    thank you for your answers and work-arounds.

    Sebastian
    #CPOptimizer
    #DecisionOptimization