Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Multiple Array INumVar Syntax

    Posted Sun May 13, 2018 03:02 PM

    Originally posted by: OrhanOzguven


    Hi,

    I try to use multiple array variable in C# .NET VS 2017. There is a error below codes & also find in the attachment. How can i correct this problem?

     

    internal static voidPopulateByRow(IMPModeler model,

                                           INumVar[][] var,

                                           IRange[][] rng,

                                           List<XX> XX_,

                                           List<YY> YY_)

            {

                INumVar[] x = newINumVar[4];

     

                INumVar[,] vrx = newINumVar[XX_.Count,YY_.Count];

                for(intxi = 0; xi < XX_.Count; xi++)

                {

                    for(intyi = 0; yi < YY_.Count; yi++)

                    {

                        vrx[xi,yi] = model.IntVar(0, 1, "x"+ xi.ToString() +"y"+ xi.ToString());

                    }

                }

                var[0] = vrx;


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Multiple Array INumVar Syntax

    Posted Mon May 14, 2018 02:36 AM

    Isn't the problem obvious from the error message? var[0] is a 1-dimensional array while vrx is a 2-dimensional array. Since these are incompatible types you cannot assign one to the other. What are you trying to do here? Are you trying to return vrx from the function in var? In that case maybe 'byref' passing may be useful (see here and here)?

    BTW, this seems more a generic C# question than a CPLEX specific question. So you may find better help on a C# forum.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Multiple Array INumVar Syntax

    Posted Mon May 14, 2018 04:04 PM

    Originally posted by: OrhanOzguven


    Thanks for reply Daniel Junglas. In fact, the error message is very obvious. I am pretty new at using cplex library in VS. I didnt know how to describe multiple dimensional array in .NET Syntax.

    Solution:

    before model expr:

    -INumVar[][,] var = new INumVar[1][,];

    internal model expr:

    -INumVar [,] vrx,

    return variable from model:

    -var[0] = vrx;

     


    #CPLEXOptimizers
    #DecisionOptimization