Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Using Cplex.Converter() with .NET

    Posted 06/23/13 07:23 PM

    Originally posted by: aysenur


    Dear All,

    I am trying to solve the LP relaxation of my MIP model without going through the pain of redefining the entire model. I figured that Cplex.SolveRelaxed() is not available for the latest versions of Cplex. Someone then suggested using the IloConvert() class which locally converts variables from one type to another. However, this is for C++ coders. I am a .NET framework user and the closest thing I could find was the Cplex.Converter() function which takes a variable and converts its type. However, when I did this for all my integer variables and solved the model Cplex would still solve the integer model.

    Has anyone ever worked with this Converter() function with success? Any ideas/comments about what might have gone wrong? Does anyone know alternative ways of doing this in .NET?

    Thanks for the help in advance.


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Using Cplex.Converter() with .NET

    Posted 06/24/13 02:32 AM

    What you need to use is function Cplex.Conversion which returns instances of IConversion (I think there is no function or class named Converter). These conversions must then be added to the Cplex instance. Maybe take a look at the AdMIPex6.cs example that is shipped with the cplex distribution. It illustrates the usage of conversions.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Using Cplex.Converter() with .NET

    Posted 06/24/13 10:07 AM

    Originally posted by: aysenur


    Hi,

    Thank you for the response. Apparently I mistakenly wrote .Converter() instead of .Conversion(), that is what I meant. But still I was using it wrong in the sense that I wasn't adding it to my model. Thank you for directing me to the example, that really helped me understand how to use it. On a side note is it possible to add this to the Cplex documentation? When I read about using the .Conversion(), I didn't see a reference to an example, that would save a lot of trouble.

    That being said I am still having trouble getting this to work. I have the following piece of code:

    foreach(Pairp inPairsIn)

    {foreach(Noden inSTIn.Nodes)

    {foreach(VesselClassvc inVCIn)

    {IConversionrelax = model.Conversion(ypnvc[PairsIn.IndexOf(p)][STIn.Nodes.IndexOf(n)][VCIn.IndexOf(vc)],  NumVarType.Float);

    model.Add(relax);

    }}}

    I am relaxing my variables one by one because I have 3-index variables and I didn't want to go through a loop to put them in an array. I checked model.NintVars field in debug mode to see what Cplex was doing inside the loop. And what I see is although it will decrease the number of integer variables in first several rounds, it will stop after a point. So I end up with a partially relaxed model. Maybe I am doing something wrong, should I put the variables in an array instead? Best.

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Using Cplex.Converter() with .NET

    Posted 06/24/13 10:45 AM

    That sounds odd indeed. And the log still suggests that the model is solved as a MIP instead of an LP?

    BTW, in the innermost loop you should probably do

       model.Add(model.Conversion(ypnvc[PairsIn.IndexOf(p)][STIn.Nodes.IndexOf(n)], NumVarType.Float))

    so as to add a conversion for all elements in the array in one shot. This will be much faster than looping over the array.

    Are you sure that all your variables are of integer type. If some are not and you apply a Conversion to them then the number of integer variables will not change.

    We consider the suggestions you made about the reference documentation.


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Using Cplex.Converter() with .NET

    Posted 06/24/13 03:08 PM

    Originally posted by: aysenur


    Yes, the log still suggests it is solved as a MIP, that is what prompted me to a debug actually.

    Thank you for the suggestion by the way, that indeed makes more sense.

    Your suggestion about variables already being float made me check one other thing. I use these variables in subproblem models that I solve and  then end with .EndModel(). Regardless I commented out this part of the code to see what Cplex would do. Only after that I got a zero for Model.NintVars... This makes me think that there is some kind of memory leak that is a remnant of destroyed models that makes Cplex think some of these variables are float (although these variables are never defined as floats even in subproblem models).

    I don't know how this is happening or how to prevent this though. Any ideas?


    #CPLEXOptimizers
    #DecisionOptimization