Как получить доступ к многомерному массиву переменных решения в Ilog Cplex с помощью Java - PullRequest
0 голосов
/ 29 ноября 2018

Мне нужно получить доступ к значениям четырехмерной переменной decion после решения моей модели.Вот объявление моей переменной decion в Java:

this.y = new IloIntVar[this.Ncd][][][]; 
        for(int i=0; i<this.y.length;i++) { 
            this.y[i]= new IloIntVar[this.Ncd][][]; 
            for(int j=0; j<this.y[i].length;j++) {
                this.y[i][j]= new IloIntVar[this.Nbv+1][];
                for(int k=1; k<this.y[i][j].length; k++) {
                    this.y[i][j][k]= new IloIntVar[this.T+1];

                        this.y[i][j][k]= this.cplex.boolVarArray(this.T+1);

            }
        }
    }

Мне очень нужна ваша помощь, чтобы использовать результаты моделирования моей модели.

Я с нетерпением жду вашего ответа.

Закария

Ответы [ 2 ]

0 голосов
/ 29 ноября 2018

Похоже, вы успешно создали и решили свою модель.Правильный?Предполагая, что это правда, вы должны иметь доступ к значениям решения с помощью чего-то вроде следующего:

 for (int i = 0; i < this.y.length; i++) {
    for (int j = 0; j < this.y[i].length; j++) {
       for (int k = 1; k < this.y[i][j].length; k++) {
          double[] x = cplex.getValues(y[i][j][k]);
          for (int l = 0; l < this.y[i][j][k].length; ++l) {
             System.out.printf("Variable [%d][%d][%d][%d] = %f%n",
                               i, j, k, l, x[l]);
          }
       }
    }
 }
0 голосов
/ 29 ноября 2018

аналогичный вопрос на https://www.ibm.com/developerworks/community/forums/html/topic?id=1865f18c-0176-48b8-8dbe-daa7f88773c4&ps=25#repliesPg=0

Я бы порекомендовал пример Facility.java в CPLEX_Studio128 \ cplex \ examples \ src \ java

И там вы увидите

// Create variables. We have variables
         // open[j]        if location j is open.
         // supply[i][j]]  how much client i is supplied from location j
         IloNumVar[] open = cplex.boolVarArray(nbLocations);       
         IloNumVar[][] supply = new IloNumVar[nbClients][];
         for (int i = 0; i < nbClients; i++)
            supply[i] = cplex.numVarArray(nbLocations, 0.0, 1.0);
...