Decision Optimization

Decision Optimization

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

 View Only
  • 1.  C++ CPLEX UBUNTU

    Posted Thu February 08, 2024 10:28 AM

    Hello! 

    This my first question to the community so I hope to do everything correctly! 

    I have initialized "alpha" in my .mod file as follows:
    float alpha[I0][I0][H][H];
    execute 
    {
      for (var i in I0)
        {
          for (var j in I0)
            {
              for (var p in H)
                {
                   for (var q in H)
                     {
                       if (p==q)
                         {
                            alpha[i][j][p][q] = 0.0;
                         }
                       else if (q>p)
                         {
                            alpha[i][j][p][q] = 1.0;
                         }
                       else
                         {
                            alpha[i][j][p][q] = 2.0;
                         }
                     }
                }
            } 
        }
    }
     
    now I would like to access a value of alpha, e.g. alpha[0][1][0][1], in my .cpp file to check if the initialization is correct before solving the model with .solve(). 
    In the IBM website it says that .getElement() can access all Elements... I have been able to access constants and 1D array but not the multidimensional array of my case. 
          IloNum i_temp = rc.getOplModel().getElement("alpha").asNumMap().get(1);
    any suggestions ?
    Thanks in advance
    Sam


    ------------------------------
    Samuele Viaro
    ------------------------------


  • 2.  RE: C++ CPLEX UBUNTU

    Posted Fri February 16, 2024 06:11 AM
    Edited by PhR Fri February 16, 2024 08:14 AM

    This recursive function should be able to display the "lines" of any n-dimensional matrix of float/IloNum element :

    void displayNumMap(IloNumMap f) {
      if (f.getNbDim() == 1) {
        for (IloInt i = 1; i <= f.getSize(); i++) {
          cout << f.get(i) << " ";
        }
        cout << endl; 
      } else {
        for (IloInt i = 1; i <= f.getSize(); i++) {
          displayNumMap(f.getSub(i));
        }
      }
    }
    

    That function is called this way:

      IloOplElement ie = opl.getElement("alpha");
      displayNumMap(ie.asNumMap());


    Philippe