Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

Multiplication of 3-D decision variable with 2-D integer array

  • 1.  Multiplication of 3-D decision variable with 2-D integer array

    Posted 08/20/13 07:43 PM

    Originally posted by: guvencdik


    Hello everybody,

    I am trying to embed my mathematical model using concert,cplex libraries with cSharp.

    This is my first attemp and i have a couple of problems in understanding the explanations.( should be basic:) sorry for inconvenience)

    I have a 3 D decision variable, as far as I understand i can create this with the code below without any problem.

     IIntVar[][][] x = new IIntVar[nb1][][];//creation of i
                    for (int i = 0; i < nb2; i++)
                    {
                        x[i] = new IIntVar[nb2][];//creation of j
                        for (int j = 0; j < nb3; j++)
                        {
                            x[i][j] = new IIntVar[nb3];//creation of v
                        }
                    }// nb1,nb2,nb3 are integer parameters.

    I also have a 2-D integer parameter int d[i][j].// let's say it has got cost values from i to j, which is given.

    My question is how can i

    minimize sum(v,i,j) X[i][j][v]*d[i][j] // X is binary variable.

    Code i have (I dont know if it is efficient?)

                for (int i = 0; i < nb1; i++)
                    for (int j = 0; j < nb2; j++)
                        for (int v = 0; v < nb3; v++)
                        {
                            x[i][j][v] = model.BoolVar();   //decision variable is binary
                        }

    and in a way, here I should manipulate INumExpr/// this part is my trouble

                model.AddMinimize(expr);

    Thanks for your help in advance.


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Multiplication of 3-D decision variable with 2-D integer array

    Posted 08/22/13 04:40 AM

    Try this:

    ILinearNumExpr expr = model.LinearNumExpr();
    for (int i = 0; i < nb1; ++i)
      for (int j = 0; j < nb2; ++j)
        for (int v = 0; v < nb3; ++v) {
          x[i][j][v] = model.BoolVar();
          expr.AddTerm(x[i][j][v], d[i][j]);
        }
    model.AddMinimize(expr);

     


    #CPLEXOptimizers
    #DecisionOptimization