Hi everyone!

I am having a great difficult to handle with this problem:

> Error: IloExtractable 3 IloNumVarI has not been extracted by
  IloAlgorithm 0x18106e0

The problem happens with variables "X" and "Y", which are defined as two matrixes.

I have been researched about this and found out that it is related with a mistake and i have defined the variables.

Do you know a good way to treat that?

Thanks so much!!

I will display a part of the code below. But it is all available after that:

crono_sube.start();
if(!cplex_sube.solve()){ //Solve the model
    env_sbe.error() << "Failed to optimize SUB." << endl;
    throw(-1);
}
cout << "T =  "<< d.T<< endl; 
d.H = d.H + 1; 
for (int j = 0; j < d.m; j++){   
    for (int t = 0; t <= d.T; t++){
    cout << " Stop Here!  "<<endl;
        int sbe.yp[0][j][t] = cplex_sube.getValue(sbe.y[j][t]);
}}

for (int j = 0; j < d.n; j++){   
    for (int t = 0; t <= d.T; t++){
    cout << " Stop Here!  "<<endl;
        int sbe.xp[0][j][t] = cplex_sube.getValue(sbe.x[j][t]);
    }}



ALL CODE IS BELOW:

// ==============================================
//
// ==============================================
#include <iomanip>
#include <iostream>
#include <ostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <set>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;

#include <ilcplex/ilocplex.h>

ILOSTLBEGIN
typedef IloArray<IloIntArray>    IntMatrix;
typedef IloArray<IloNumArray>    NumMatrix;
typedef IloArray<NumMatrix>      Num3Matrix;
typedef IloArray<IloNumVarArray> NumVar2Array;
// ==============================================
// data structure 
// ==============================================
typedef struct{
  int n;
  int m; 
  int nT;
  int mT;
  int T;
  int aux;
  int ncols;
  int H;
  vector <double> p1;
  vector <double> p2;
  vector <vector<double > > S;
  char name[256];
  //double ex;
}DAT;
  typedef struct{
  IloNum ub;
  IloNum lb;
  IloNum gap;
  IloTimer *crono_sube;
  IloCplex cplex_sube;
  IloModel mdsube;
  NumVar2Array y;
  NumVar2Array x;
  IloNumArray alpha;
  IloNumArray beta;
  IloNumArray gama;
  IloNumArray delta;
  IloNum u;
  IloNum fosube;
  IloNum H;
  Num3Matrix xp;
  Num3Matrix yp;
  IloRangeArray subeconstraints;
  IloObjective fospe;
  IloNumArray duals;
  Num3Matrix xp;
  Num3Matrix yp;
 } SBe_DAT;

// ==============================================
// functions
// ==============================================
void create_modelesub(DAT &d, SBe_DAT &sbe);

void read_data(char name[], DAT &d);

// ========================================================
//
// ========================================================
void read_data(char name[], DAT &d) {
  ifstream arq(name);
  if (!arq.is_open()){
    help();
  }
  strcpy (d.name, name);
  arq >> d.n;
  arq >> d.m;
  d.aux = 0;
  d.p1 = vector<double>(d.n + 1);
  d.p2 = vector<double>(d.m + 1);
  d.S = vector<vector<double > > (d.m + 1, vector<double> (d.n + 1));

  //Process time

  for (int i = 0; i < d.n; i++){
    arq >> d.p1[i];

  }
  for (int i = 0; i < d.m; i++){
    arq >> d.p2[i];

  }
  //Matriz de precedência
  for (int i = 0; i <= d.m-1; i++){
    arq >> d.S[i][0];
       for (int j = 1; j <= d.S[i][0]; j++){
           arq >> d.S[i][j];
       }
  }
  d.T = 0;
  for (int j = 0; j < d.n; j++){
    d.T += d.p1[j];
  }
  for (int j = 0; j < d.m; j++){
      d.T += d.p2[j];
  }

  arq.close();
  cout << "saiu do read_data" << endl; 
}
// ========================================================
//
// ========================================================
void create_modelesub(DAT &d, SBe_DAT &sbe){ 
 IloEnv env_sbe = sbe.cplex_sube.getEnv();
 // Variable definitions 
 sbe.y = NumVar2Array (env_sbe, d.m); 
  for (int j = 0; j < d.m; j++){
    sbe.y[j] = IloNumVarArray (env_sbe, (d.T + 1), 0, 1, ILOBOOL);
  }  
 sbe.x = NumVar2Array (env_sbe, d.n); 
  for (int j = 0; j < d.n; j++){
    sbe.x[j] = IloNumVarArray (env_sbe, (d.T + 1), 0, 1, ILOBOOL);
  }
    // Param. definitions

  sbe.xp = Num3Matrix(env_sbe,d.H);

    for (int h = 0; h <= d.H; h++ ){
       sbe.xp[h] = NumMatrix (env_sbe,(d.n));
       }

       for (int h = 0; h <= d.H; h++ ){
       for ( int j = 0; j < d.n; j++){
  sbe.xp[h][j] = IloNumArray(env_sbe,(d.T + 1));
       }
       }
  sbe.yp = Num3Matrix(env_sbe,d.H);

    for (int h = 0; h <= d.H; h++ ){
       sbe.yp[h] = NumMatrix (env_sbe,(d.n));
       }

       for (int h = 0; h <= d.H; h++ ){
       for ( int j = 0; j < d.m; j++){
 sbe.yp[h][j] = IloNumArray(env_sbe,(d.T + 1));
       }
       }  
 sbe.duals = IloNumArray(env_sbe, d.n + d.T + d.m  + d.T + 1);  
 sbe.subeconstraints = IloRangeArray(env_sbe);

 // ===============
 // objective function
 // ===============
  IloExpr xpfo(env_sbe);  
  for (int j = 0; j < d.n; j++ ){
    for( int t = 0; t <= (d.T - d.p1[j]); t++ ){
      xpfo -= sbe.alpha[j] * sbe.x[j][t];
    }
  }  
  for (int t = 0; t <= d.T; t++){
     for (int j = 0; j < d.n; j++){
       if (t - d.p1[j] + 1 > 0 ) 
        d.aux = t - d.p1[j] + 1;
       else
        d.aux = 0;       
         for (int s = d.aux ; s <= t; s++){
             xpfo -= sbe.x[j][s] * sbe.beta[t];
     }
    }
  }
  for (int j = 0; j < d.m; j++ ){
    for( int t = 0; t <= (d.T - d.p2[j]); t++ ){
      xpfo -= sbe.gama[j] * sbe.y[j][t];
    }
  }  
   for (int t = 0; t <= d.T; t++){
     for (int j = 0; j < d.m; j++){
       if (t - d.p2[j] + 1 > 0 ) 
        d.aux = t - d.p2[j] + 1;
       else
        d.aux = 0;

         for (int s = d.aux ; s <= t; s++){
             xpfo -= sbe.y[j][s] * sbe.delta[t];
     }
    }
  }  
  xpfo -= sbe.u;  
  sbe.fospe = IloAdd(sbe.mdsube, IloMinimize(env_sbe, xpfo));
 // ===============
// constraint sum_{t} t* y_jt  - sum{t} (t + p1_k)*_x_kt = 1 \forall  j in j2 e k in S_j
// ===============        
    for (int j = 0; j < d.m; j++){  
    for (int k = 1; k <= d.S[j][0]; k++){
      IloExpr r1 (env_sbe);
      for (int t = 0; t <= (d.T); t++){
    r1 += t * sbe.y[j][t];
      }

      for (int t = 0; t <= d.T; t++){

    r1 -= (t + d.p1[d.S[j][k]-1]) * sbe.x[d.S[j][k]-1][t];
      }
      sbe.subeconstraints.add(r1>=0.0);
      r1.end();
    }
  }
} 
// ========================================================
//
// ========================================================
int main (int argc, char *argv[]){
  cout << "entrou no main "<< endl;
  // ===============
  // data - Exemplo de leitura de dados - entrada manual
  // ===============
 DAT d;
  if (argc < 2){
    help();
  }
  //d.ex = (argc > 2) ? atof(argv[2]) : 1.0;
  read_data(argv[1],d);

  // ===============
  // cplex environment 
  // ===============  
  SBe_DAT sbe;
 d.H = 0;  
  try{
  IloEnv env_sbe;
  // Subproblema
  IloModel mdsube(env_sbe);
  IloCplex  cplex_sube(mdsube);
  IloTimer crono_sube (env_sbe);
  sbe.cplex_sube =  cplex_sube;
  sbe.mdsube = mdsube;
  sbe.crono_sube = &crono_sube;

  sbe.alpha = IloNumArray (env_sbe, d.n);
  sbe.beta =  IloNumArray (env_sbe, d.T);
  sbe.gama =  IloNumArray (env_sbe, d.m);
  sbe.delta = IloNumArray (env_sbe, d.T);
   //INITIAL VALUES
  for (int j = 0; j < d.n; j++){
  sbe.alpha[j] = 0;
  }
  for (int j = 0; j < d.m; j++){
  sbe.gama[j] = 0;
  }
  for (int t = 0; t <= d.T; t++){
  sbe.beta[t] = 0;
  }
  for (int t = 0; t <= d.T; t++){
  sbe.delta[t] = 0;
  }
  sbe.u = 1;

  create_modelesub(d,sbe);  
  // ===============
  // solving using CPLEX
  // =============== 
   IloInt iter = 0;
      IloBool stop = IloFalse;
      while (stop == IloFalse){
         iter++;

    //Solve sub
        //Seta sol.

    crono_sube.start();
     if(!cplex_sube.solve() ) { //Resolve o submodelo
            env_sbe.error() << "Failed to optimize SUB." << endl;
          throw(-1);
        }
        cout << "T =  "<< d.T<< endl; 
    d.H = d.H + 1; 
    for (int j = 0; j < d.m; j++){   
            for (int t = 0; t <= d.T; t++){
          cout << " Stop Here!  "<<endl;
        int sbe.yp[0][j][t] = cplex_sube.getValue(sbe.y[j][t]);
        }}     
     for (int j = 0; j < d.n; j++){   
            for (int t = 0; t <= d.T; t++){
          cout << " Stop Here!  "<<endl;
        int sbe.xp[0][j][t] = cplex_sube.getValue(sbe.x[j][t]);     
        }}

        sbe.fosube = cplex_sube.getObjValue();
        int fim = crono_sube.stop();    
    IloExpr time_sube (env_sbe);
        time_sube += (IloNum) fim;
    time_sube.end();
        fim = crono_sube.stop();

    }       
    if (sbe.fosube < -0.000001) {               
           env_sbe.end();      
           stop = IloTrue;
        }     
     } 
    // ===============
    // wrapping up
    // ===============

   catch (IloException& name) {
   cerr << "Error: " << name << endl;
}
}

asked 14 Feb '13, 17:48

Marcelus's gravatar image

Marcelus
1
accept rate: 0%

edited 15 Feb '13, 07:32

fbahr's gravatar image

fbahr ♦
3.5k313


You have the same problem as the OP here.

You are trying to access an empty handle. With other words the values you are trying to extract from the model have never been inserted in the model.

My guess you are trying to access an element in one of these lines that isn't there.

 int sbe.yp[0][j][t] = cplex_sube.getValue(sbe.y[j][t]);
 int sbe.xp[0][j][t] = cplex_sube.getValue(sbe.x[j][t]);

With other words, you probably haven't added all the sbe.y[j][t] variables that you are trying to extract the value from.

Write out j and t for each iteration and you will now at which iteration it goes wrong.

link

answered 15 Feb '13, 03:58

Buxley's gravatar image

Buxley
534312
accept rate: 9%

edited 15 Feb '13, 07:34

fbahr's gravatar image

fbahr ♦
3.5k313

Make sure you add everything you need to the model.

If you cannot fix your code then please use our support forum

link

answered 15 Feb '13, 03:33

jfpuget's gravatar image

jfpuget
2.0k18
accept rate: 8%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×76
×2
×2
×1

Asked: 14 Feb '13, 17:48

Seen: 685 times

Last updated: 15 Feb '13, 07:34

OR-Exchange! Your site for questions, answers, and announcements about operations research.