Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  IloExtractable has not been extracted by IloAlgorithm

    Posted 08/19/12 09:03 AM

    Originally posted by: Ximenes


    hello, everyone, I want to know why when I run my program it shows an error "IloExtractable 99 IloNumVarI has not been extracted by IloAlgorithm 01AAF848"?
    PS:I is defined as follows
    
    IloNumVarArray I(env,total-1,0.0,T);
    


    Then I cancel all the constraints related to "I", but it still shows the same error. No matter how I cancel the constraints, it remains the same.

    I run it in Visual Studio 2010 with c++ calling cplex.
    The complete codes are as follows.
    
    #include <ilcplex/ilocplex.h>   ILOSTLBEGIN   
    
    int main(
    
    int argc, char** argv) 
    { IloEnv env;   
    
    try 
    { 
    
    const char* filename;    
    //数据输入 
    
    if (argc > 1) filename = argv[1]; 
    
    else filename = 
    "C:\\Users\\Ximenes\\Desktop\\try1.txt"; ifstream f(filename, ios::in); 
    
    if (!f) 
    { cerr << 
    "No such file: " << filename << endl; 
    
    throw(1); 
    } IloNum T; IloNumArray2 r(env); IloNumArray2 p1(env); IloNumArray2 p2(env); IloNumArray2 s(env); f >> T; f >> r; f >> p1; f >> p2; f>>s; cout<<
    "T="<<T<<endl; cout<<
    "r="<<r<<endl; cout<<
    "p1="<<p1<<endl; cout<<
    "p2="<<p2<<endl; cout<<
    "s="<<s<<endl;   
    
    int N=r.getSize();
    //数据输入之后,就晓得了输入订单的类数,每类订单的个数,确定最多的订单数,接下来要做的就是补足订单 cout<<
    "N="<<N<<endl; 
    
    for(
    
    int i=0;i<N;i++)
    { cout<<
    "r["<<i<<
    "]="<<r[i]<<endl; cout<<
    "p1["<<i<<
    "]="<<p1[i]<<endl; cout<<
    "p2["<<i<<
    "]="<<p2[i]<<endl; 
    } IloIntArray n(env,N); IloInt total=0; 
    
    for(
    
    int i=0;i<N;i++)
    { n[i]=r[i].getSize(); cout<<
    "n["<<i<<
    "]="<<n[i]<<
    ","; total+=n[i]; 
    }   cout<<
    "total="<<total<<endl;       IloModel model(env); IloArray <IloArray <IloBoolVarArray > > z (env, N);  
    //z(i,j,k)将i类j订单安排在位置k 
    
    for(
    
    int i=0;i<N;i++)
    { z[i]=IloArray <IloBoolVarArray >(env,n[i]); 
    
    for(
    
    int j=0;j<n[i];j++)
    { z[i][j]=IloBoolVarArray (env,total); 
    } 
    }   IloArray <IloArray <IloBoolVarArray > > e (env, N);  
    //e(i,j,k)=z(i,j,m)*y(i,j) 
    
    for(
    
    int i=0;i<N;i++)
    { e[i]=IloArray <IloBoolVarArray >(env,n[i]); 
    
    for(
    
    int j=0;j<n[i];j++)
    { e[i][j]=IloBoolVarArray (env,total); 
    } 
    }   IloArray <IloBoolVarArray > y(env,N);
    //定义变量y(i,j)是否选择i类j订单 
    
    for(
    
    int i=0;i<N;i++) y[i]=IloBoolVarArray(env,n[i]); IloArray <IloBoolVarArray > t(env,total);
    //定义变量t(m,i)  如t(1,3)表示是否在加工完1之后立即加工3,如果是则取1,这也意味着选择了在1号位和3号位上的订单,而没有选择2号位上的订单 
    
    for(
    
    int i=0;i<total;i++) t[i]=IloBoolVarArray(env,total); IloArray <IloArray < IloArray <IloArray <IloArray <IloBoolVarArray > > > > > a (env, N); 
    //定义a   【a(i,k,m,j,l,h)=z(i,k,m)*z(j,l,h)】 
    
    for(
    
    int i=0;i<N;i++)
    { a[i]=IloArray < IloArray <IloArray <IloArray <IloBoolVarArray > > > >(env,n[i]); 
    
    for(
    
    int k=0;k<n[i];k++)
    { a[i][k]=IloArray <IloArray <IloArray <IloBoolVarArray > > >(env,total); 
    
    for(
    
    int m=0;m<total;m++)
    { a[i][k][m]=IloArray <IloArray <IloBoolVarArray > >(env,N); 
    
    for(
    
    int j=0;j<N;j++)
    { a[i][k][m][j]=IloArray <IloBoolVarArray >(env,n[j]); 
    
    for(
    
    int l=0;l<n[j];l++) a[i][k][m][j][l]=IloBoolVarArray(env,total); 
    } 
    } 
    } 
    }   IloArray <IloArray < IloArray <IloArray <IloArray <IloBoolVarArray > > > > > b (env, N);  
    //定义b   【b(i,k,m,j,l,h)=a(i,k,m,j,l,h)*t(m,h)】 
    
    for(
    
    int i=0;i<N;i++)
    { b[i]=IloArray < IloArray <IloArray <IloArray <IloBoolVarArray > > > >(env,n[i]); 
    
    for(
    
    int k=0;k<n[i];k++)
    { b[i][k]=IloArray <IloArray <IloArray <IloBoolVarArray > > >(env,total); 
    
    for(
    
    int m=0;m<total;m++)
    { b[i][k][m]=IloArray <IloArray <IloBoolVarArray > >(env,N); 
    
    for(
    
    int j=0;j<N;j++)
    { b[i][k][m][j]=IloArray <IloBoolVarArray >(env,n[j]); 
    
    for(
    
    int l=0;l<n[j];l++) b[i][k][m][j][l]=IloBoolVarArray(env,total); 
    } 
    } 
    } 
    } IloArray <IloArray < IloArray <IloArray <IloArray <IloBoolVarArray > > > > > c (env, N);  
    //定义c   【c(i,k,m,j,l,h)=a(i,k,m,j,l,h)*y(i,k)   】 
    
    for(
    
    int i=0;i<N;i++)
    { c[i]=IloArray < IloArray <IloArray <IloArray <IloBoolVarArray > > > >(env,n[i]); 
    
    for(
    
    int k=0;k<n[i];k++)
    { c[i][k]=IloArray <IloArray <IloArray <IloBoolVarArray > > >(env,total); 
    
    for(
    
    int m=0;m<total;m++)
    { c[i][k][m]=IloArray <IloArray <IloBoolVarArray > >(env,N); 
    
    for(
    
    int j=0;j<N;j++)
    { c[i][k][m][j]=IloArray <IloBoolVarArray >(env,n[j]); 
    
    for(
    
    int l=0;l<n[j];l++) c[i][k][m][j][l]=IloBoolVarArray(env,total); 
    } 
    } 
    } 
    }   IloArray <IloArray < IloArray <IloArray <IloArray <IloBoolVarArray > > > > > d (env, N);  
    //定义d   【d(i,k,m,j,l,h)=c(i,k,m,j,l,h)*y(j,l)   】 
    
    for(
    
    int i=0;i<N;i++)
    { d[i]=IloArray < IloArray <IloArray <IloArray <IloBoolVarArray > > > >(env,n[i]); 
    
    for(
    
    int k=0;k<n[i];k++)
    { d[i][k]=IloArray <IloArray <IloArray <IloBoolVarArray > > >(env,total); 
    
    for(
    
    int m=0;m<total;m++)
    { d[i][k][m]=IloArray <IloArray <IloBoolVarArray > >(env,N); 
    
    for(
    
    int j=0;j<N;j++)
    { d[i][k][m][j]=IloArray <IloBoolVarArray >(env,n[j]); 
    
    for(
    
    int l=0;l<n[j];l++) d[i][k][m][j][l]=IloBoolVarArray(env,total); 
    } 
    } 
    } 
    }     IloNumVarArray I(env,total-1,0.0,T);   
    //I,W表示类内 IloNumVarArray W(env,total,0.0,T); 
    //a,b,c,d,e约束 
    
    for(
    
    int i=0;i<N;i++)
    {                       
    //a(i,k,m,j,l,h)=z(i,k,m)*z(j,l,h)  
    
    for(
    
    int k=0;k<n[i];k++)
    { 
    
    for(
    
    int m=0;m<total;m++)
    { 
    
    for(
    
    int j=0;j<N;j++)
    { 
    
    for(
    
    int l=0;l<n[j];l++)
    { 
    
    for(
    
    int h=0;h<total;h++)
    { IloExpr expr(env); expr=a[i][k][m][j][l][h]-z[i][k][m]; model.add(expr<=0); expr.end(); 
    } 
    } 
    } 
    } 
    } 
    } 
    
    for(
    
    int i=0;i<N;i++)
    { 
    
    for(
    
    int k=0;k<n[i];k++)
    { 
    
    for(
    
    int m=0;m<total;m++)
    { 
    
    for(
    
    int j=0;j<N;j++)
    { 
    
    for(
    
    int l=0;l<n[j];l++)
    { 
    
    for(
    
    int h=0;h<total;h++)
    { IloExpr expr(env); expr=a[i][k][m][j][l][h]-z[j][l][h]; model.add(expr<=0); expr.end(); 
    } 
    } 
    } 
    } 
    } 
    } 
    
    for(
    
    int i=0;i<N;i++)
    { 
    
    for(
    
    int k=0;k<n[i];k++)
    { 
    
    for(
    
    int m=0;m<total;m++)
    { 
    
    for(
    
    int j=0;j<N;j++)
    { 
    
    for(
    
    int l=0;l<n[j];l++)
    { 
    
    for(
    
    int h=0;h<total;h++)
    { IloExpr expr(env); expr=a[i][k][m][j][l][h]-z[i][k][m]-z[j][l][h]+1; model.add(expr>=0); expr.end(); 
    } 
    } 
    } 
    } 
    } 
    }   
    
    for(
    
    int i=0;i<N;i++)
    {                    
    //b(i,k,m,j,l,h)=a(i,k,m,j,l,h)*t(m,h) 
    
    for(
    
    int k=0;k<n[i];k++)
    { 
    
    for(
    
    int m=0;m<total;m++)
    { 
    
    for(
    
    int j=0;j<N;j++)
    { 
    
    for(
    
    int l=0;l<n[j];l++)
    { 
    
    for(
    
    int h=0;h<total;h++)
    { IloExpr expr(env); expr=b[i][k][m][j][l][h]-a[i][k][m][j][l][h]; model.add(expr<=0); expr.end(); 
    } 
    } 
    } 
    } 
    } 
    } 
    
    for(
    
    int i=0;i<N;i++)
    { 
    
    for(
    
    int k=0;k<n[i];k++)
    { 
    
    for(
    
    int m=0;m<total;m++)
    { 
    
    for(
    
    int j=0;j<N;j++)
    { 
    
    for(
    
    int l=0;l<n[j];l++)
    { 
    
    for(
    
    int h=0;h<total;h++)
    { IloExpr expr(env); expr=b[i][k][m][j][l][h]-t[m][h]; model.add(expr<=0); expr.end(); 
    } 
    } 
    } 
    } 
    } 
    } 
    
    for(
    
    int i=0;i<N;i++)
    { 
    
    for(
    
    int k=0;k<n[i];k++)
    { 
    
    for(
    
    int m=0;m<total;m++)
    { 
    
    for(
    
    int j=0;j<N;j++)
    { 
    
    for(
    
    int l=0;l<n[j];l++)
    { 
    
    for(
    
    int h=0;h<total;h++)
    { IloExpr expr(env); expr=b[i][k][m][j][l][h]-a[i][k][m][j][l][h]-t[m][h]+1; model.add(expr>=0); expr.end(); 
    } 
    } 
    } 
    } 
    } 
    }   
    
    for(
    
    int i=0;i<N;i++)
    {                    
    //c(i,k,m,j,l,h)=a(i,k,m,j,l,h)*y(i,k) 
    
    for(
    
    int k=0;k<n[i];k++)
    { 
    
    for(
    
    int m=0;m<total;m++)
    { 
    
    for(
    
    int j=0;j<N;j++)
    { 
    
    for(
    
    int l=0;l<n[j];l++)
    { 
    
    for(
    
    int h=0;h<total;h++)
    { IloExpr expr(env); expr=c[i][k][m][j][l][h]-a[i][k][m][j][l][h]; model.add(expr<=0); expr.end(); 
    } 
    } 
    } 
    } 
    } 
    } 
    
    for(
    
    int i=0;i<N;i++)
    { 
    
    for(
    
    int k=0;k<n[i];k++)
    { 
    
    for(
    
    int m=0;m<total;m++)
    { 
    
    for(
    
    int j=0;j<N;j++)
    { 
    
    for(
    
    int l=0;l<n[j];l++)
    { 
    
    for(
    
    int h=0;h<total;h++)
    { IloExpr expr(env); expr=c[i][k][m][j][l][h]-y[i][k]; model.add(expr<=0); expr.end(); 
    } 
    } 
    } 
    } 
    } 
    } 
    
    for(
    
    int i=0;i<N;i++)
    { 
    
    for(
    
    int k=0;k<n[i];k++)
    { 
    
    for(
    
    int m=0;m<total;m++)
    { 
    
    for(
    
    int j=0;j<N;j++)
    { 
    
    for(
    
    int l=0;l<n[j];l++)
    { 
    
    for(
    
    int h=0;h<total;h++)
    { IloExpr expr(env); expr=c[i][k][m][j][l][h]-a[i][k][m][j][l][h]-y[i][k]+1; model.add(expr>=0); expr.end(); 
    } 
    } 
    } 
    } 
    } 
    }     
    
    for(
    
    int i=0;i<N;i++)
    {                    
    //d(i,k,m,j,l,h)=c(i,k,m,j,l,h)*y(j,l) 
    
    for(
    
    int k=0;k<n[i];k++)
    { 
    
    for(
    
    int m=0;m<total;m++)
    { 
    
    for(
    
    int j=0;j<N;j++)
    { 
    
    for(
    
    int l=0;l<n[j];l++)
    { 
    
    for(
    
    int h=0;h<total;h++)
    { IloExpr expr(env); expr=d[i][k][m][j][l][h]-c[i][k][m][j][l][h]; model.add(expr<=0); expr.end(); 
    } 
    } 
    } 
    } 
    } 
    } 
    
    for(
    
    int i=0;i<N;i++)
    { 
    
    for(
    
    int k=0;k<n[i];k++)
    { 
    
    for(
    
    int m=0;m<total;m++)
    { 
    
    for(
    
    int j=0;j<N;j++)
    { 
    
    for(
    
    int l=0;l<n[j];l++)
    { 
    
    for(
    
    int h=0;h<total;h++)
    { IloExpr expr(env); expr=d[i][k][m][j][l][h]-y[j][l]; model.add(expr<=0); expr.end(); 
    } 
    } 
    } 
    } 
    } 
    } 
    
    for(
    
    int i=0;i<N;i++)
    { 
    
    for(
    
    int k=0;k<n[i];k++)
    { 
    
    for(
    
    int m=0;m<total;m++)
    { 
    
    for(
    
    int j=0;j<N;j++)
    { 
    
    for(
    
    int l=0;l<n[j];l++)
    { 
    
    for(
    
    int h=0;h<total;h++)
    { IloExpr expr(env); expr=d[i][k][m][j][l][h]-c[i][k][m][j][l][h]-y[j][l]+1; model.add(expr>=0); expr.end(); 
    } 
    } 
    } 
    } 
    } 
    } 
    
    for(
    
    int i=0;i<N;i++)
    {       
    //e(i,j,m)=z(i,j,m)*y(i,j) 
    
    for(
    
    int j=0;j<n[i];j++)
    { 
    
    for(
    
    int m=0;m<total;m++)
    { IloExpr expr(env); expr=e[i][j][m]-z[i][j][m]; model.add(expr<=0); expr.end(); 
    } 
    } 
    } 
    
    for(
    
    int i=0;i<N;i++)
    { 
    
    for(
    
    int j=0;j<n[i];j++)
    { 
    
    for(
    
    int m=0;m<total;m++)
    { IloExpr expr(env); expr=e[i][j][m]-y[i][j]; model.add(expr<=0); expr.end(); 
    } 
    } 
    } 
    
    for(
    
    int i=0;i<N;i++)
    { 
    
    for(
    
    int j=0;j<n[i];j++)
    { 
    
    for(
    
    int m=0;m<total;m++)
    { IloExpr expr(env); expr=e[i][j][m]-z[i][j][m]-y[i][j]+1; model.add(expr>=0); expr.end(); 
    } 
    } 
    } 
    //时间约束 IloExpr expr(env); 
    
    for(
    
    int i=0;i<N;i++)
    { 
    
    for(
    
    int j=0;j<n[i];j++)
    { expr+=e[i][j][0]*p1[i][j];           
    //第一项令  e[i][j][0]=z[i][j][0]*y[i][j] expr+=p2[i][j]*y[i][j];              
    //第二项机器2上的加工时间 
    } 
    } 
    
    for(
    
    int i=0;i<total-1;i++)
    {                          
    //第三项       跟第一项加起来就是完整的在机器2上的加工时间           expr+=I[i]; 
    }   
    
    for(
    
    int m=0;m<total-1;m++)
    {                
    //setup 项  !!! 
    
    for(
    
    int h=m+1;h<total;h++)
    { 
    
    for(
    
    int i=0;i<N;i++)
    { 
    
    for(
    
    int k=0;k<n[i];k++)
    { 
    
    for(
    
    int j=0;j<N;j++)
    { 
    
    for(
    
    int l=0;l<n[j];l++) expr+=b[i][k][m][j][l][h]*s[i][j];
    //如:expr=z[0][0][0]*y[0][0]*z[0][0][1]*y[0][0]*s[0][0]*t[0][1] 
    } 
    } 
    } 
    } 
    } model.add(expr<=T); expr.end(); 
    //W.I.类间约束 
    
    for(
    
    int m=0;m<total-1;m++)
    { IloExpr expr(env); 
    
    for(
    
    int i=0;i<N;i++)
    { 
    
    for(
    
    int j=0;j<n[i];j++)
    { expr+=e[i][j][m+1]*p1[i][j]-e[i][j][m]*p2[i][j];
    //将e(i,j,m)代替z(i,j,m)*y(i,j).整个程序只有这处是二次,其余的都是一次,所以就令e(i,j,m)=z(i,j,m)*y(i,j)20120819 
    } 
    } expr+=W[m+1]-W[m]-I[m]; model.add(expr==0); expr.end(); 
    }   
    
    for(
    
    int i=0;i<N;i++)
    {            
    //对订单i类j来说,总会被安排在某个位置k 
    
    for(
    
    int j=0;j<n[i];j++)
    { IloExpr expr(env); 
    
    for(
    
    int k=0;k<total;k++) expr+=z[i][j][k]; model.add(expr==1); expr.end(); 
    } 
    } 
    
    for(
    
    int k=0;k<total;k++)
    {       
    //对于每个位置k来说,总有一个订单被安排在了k   IloExpr expr(env); 
    
    for(
    
    int i=0;i<N;i++)
    { 
    
    for(
    
    int j=0;j<n[i];j++) expr+=z[i][j][k]; 
    } model.add(expr==1); expr.end(); 
    } 
    //与t相关的约束 
    
    for(
    
    int m=0;m<total-1;m++)
    { 
    
    for(
    
    int h=m+1;h<total;h++)
    { IloExpr expr(env); 
    
    for(
    
    int i=0;i<N;i++)
    {                    
    //d 
    
    for(
    
    int k=0;k<n[i];k++)
    { 
    
    for(
    
    int j=0;j<N;j++)
    { 
    
    for(
    
    int l=0;l<n[j];l++)
    { expr+=d[i][k][m][j][l][h]; 
    } 
    } 
    } 
    } expr-=t[m][h]; model.add(expr==0); expr.end(); 
    } 
    } 
    
    for(
    
    int m=0;m<total-1;m++)
    { IloExpr expr(env); 
    
    for(
    
    int h=m+1;h<total;h++) expr+=t[m][h]; model.add(expr<=1); expr.end(); 
    }       
    //最大化目标函数 IloExpr profitSum(env); 
    
    for(
    
    int i=0;i<N;i++)
    { 
    
    for(
    
    int j=0;j<n[i];j++)
    { profitSum+=r[i][j]*y[i][j]; 
    } 
    } model.add(IloMaximize(env, profitSum));
    //最优值为什么会出来0呢?检验过r[][]了。那个empty handle的原因是有一个model.add放错地方了。20120816 profitSum.end(); IloCplex cplex(env); cplex.setParam(IloCplex::MIPEmphasis, 4);   
    
    if (cplex.solve())
    { cout << 
    " Optimal Value = " << cplex.getObjValue() << endl; 
    
    for(
    
    int i=0;i<N;i++) 
    
    for(
    
    int j=0;j<n[i];j++) cout<<
    "y["<<i<<
    "]["<<j<<
    "]="<<cplex.getValue(y[i][j]);
    //想通过输出y[][]的值看是否哪里错了。发现一个Error:有一个无法extractable20120819 
    } 
    } 
    
    catch (IloException& ex) 
    { cerr << 
    "Error: " << ex << endl; 
    } 
    
    catch (...) 
    { cerr << 
    "Error" << endl; 
    }   env.end(); system(
    "pause"); 
    
    return 0; 
    }
    


    Thank you very much.
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: IloExtractable has not been extracted by IloAlgorithm

    Posted 08/19/12 04:20 PM

    Originally posted by: SystemAdmin


    I posted a possible answer on http://www.or-exchange.com/questions/6247/iloextractable-99-has-not-been-extracted-by-iloalgorithm.

    Paul

    Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
    #CPLEXOptimizers
    #DecisionOptimization