2017-05-05 32 views
0

使用addMIPStart()時遇到問題。首先,爲了測試目的,我採用了廣義指派問題(只有一組二進制決策變量x [i] [] j),並使用addMIPStart()添加一個邊界。它工作完美。在CPLEX C++中使用addMIPStart()時出錯

但是,當我試圖在我自己的問題一樣,我得到了一個錯誤的問題CPLEX:「IloExtractable 189 IloNumVarl尚未被Iloalgorithm 000001ECF89B160提取」。

在我的問題,有四種類型的變量:

x[k][p][t] = IloNumVar(env, 0.0, 1, ILOINT, name.str().c_str()); //binary 
y[p][t] = IloNumVar(env, 0.0, 1, ILOINT, name.str().c_str()); //binary 
z[k][p][t] = IloNumVar(env, 0.0, 1, ILOINT, name.str().c_str()); //binary 
w[p][t] = IloNumVar(env, 0.0, IloInfinity, ILOINT, name.str().c_str()); //pure integer 

現在,我已經添加下面的代碼.................. ....

/*************************************************/ 
    IloNumVarArray startVar(env); 
    IloNumArray startVal(env); 
    IloNum remExtResource = 0; 
    IloInt cutOffTime = 0; 
    IloInt totExtResource = 0; 

    for (k = 0; k < K; k++) { 
     for (p = 0; p<P; p++) { 
      for (t = 0; t<T + 2; t++) { 
       startVar.add(x[k][p][t]); 
       startVal.add(0); 
      } 
     } 
    } 
    for (k = 0; k < K; k++) { 
     for (p = 0; p<P2; p++) { 
      for (t = 0; t<T + 1; t++) { 
       startVar.add(z[k][p][t]); 
       startVal.add(0); 
      } 
     } 
    } 
    for (p = 0; p<P2; p++) { 
     totExtResource = ceil(D[p]/a_e[p]); 
     cutOffTime = ceil(totExtResource/Q[p]); 
     for (t_p = 0; t_p<T + 2; t_p++) { 
      if (t <= cutOffTime){ 
       startVar.add(y[p][t]); 
       startVal.add(0); 
      } 
      if (t > cutOffTime){ 
       startVar.add(y[p][t]); 
       startVal.add(1); 
      } 
     } 
     totExtResource = 0; 
     cutOffTime = 0; 
    } 
    for (p = 0; p<P2; p++) { 
     remExtResource = ceil(D[p]/a_e[p]); 
     for (t = 0; t<T + 1; t++) { 
      if (t == 0) { 
       startVar.add(w[p][t]); 
       startVal.add(0); 
      } 
      else { 
       if (remExtResource == 0) { 
        startVar.add(w[p][t]); 
        startVal.add(0); 
       } 
       else if ((remExtResource > 0) && (remExtResource <= Q[p])) { 
        startVar.add(w[p][t]); 
        startVal.add(remExtResource); 
        remExtResource = 0; 
       } 
       else { 
        startVar.add(w[p][t]); 
        startVal.add(Q[p]); 
        remExtResource = remExtResource - Q[p]; 
       } 
      } 
     } 
     remExtResource = 0; 
    } 
    // cplex.addMIPStart(startVar, startVal, IloCplex::MIPStartAuto, "secondMIPStart"); 
    cplex.addMIPStart(startVar, startVal); 
    startVal.end(); 
    startVar.end(); 
/*************************************************/ 

作爲起始溶液,我使所有的X變量的z變量到。和基於某些邏輯一些的y變量是有的,而一些瓦特變量被分配給全容量Q [P],而其它的是。

它具有我遵循的相同的邏輯,但可以找到我在這裏錯過的東西。你可以幫我嗎?

回答

0

大多數情況下,當我看到這種錯誤時,這是​​因爲我正在嘗試爲不在我的問題中的變量添加mipstart值。例如,變量被聲明,但不涉及任何約束或目標,所以cplex在其提取的模型中不具有它們。