Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Handle multi-dimensional array

    Posted 12/23/10 08:50 AM

    Originally posted by: HKUcivil


    Hi,
    I used C++ to build A matrix,(i.e.,double InputA[I][J]) , which is the parameter matrix for LP.
    Can I use this matrix directly?
    I am worry about the type.
    so First, i create a IloNumArray A,than give its corresponding value in inputA get from C++.

    "double ImatrxA[2][3]={-1,1,1,1,-3,1};"
    IloNumArray matrxA(env,6);
    for (i=0;i<2;i++){
    for (j=0;j<3;j++){
    matrxAi*3+j=ImatrxA[i][j];
    }
    }"
    Is there any shorter way to do the above thing?
    And also, i really do not how to give value to the 2-dimension array.

    Regards.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Handle multi-dimensional array

    Posted 12/30/10 07:46 AM

    Originally posted by: SystemAdmin


    you can use the
    
    IloArray
    
    template.
    For example, you can do something like:

    
    
    
    class IloMyNumArray : 
    
    public IloArray<IloNum> 
    { 
    
    public: IloMyNumArray(
    
    const IloEnv env, IloInt n1) : IloArray<IloNum>(env, n1) 
    {
    } IloMyNumArray(
    
    const IloMyNumArray& cpy) : IloArray<IloNum>(cpy) 
    {
    } 
    };   
    
    class IloMyNumArray2 : 
    
    public IloArray<IloMyNumArray> 
    { 
    
    public: IloMyNumArray2(
    
    const IloEnv env, IloInt n1, IloInt n2) : IloArray<IloMyNumArray>(env) 
    { 
    
    for (IloInt i=0; i< n1; i++)
    { add(IloMyNumArray(env, n2)); 
    } 
    } IloMyNumArray2(
    
    const IloMyNumArray2& cpy) : IloArray<IloMyNumArray>(cpy) 
    {
    } 
    }; 
    
    class IloMyNumArray3 : 
    
    public IloArray<IloMyNumArray2> 
    { 
    
    public: IloMyNumArray3(
    
    const IloEnv env, IloInt n1, IloInt n2, IloInt n3) : IloArray<IloMyNumArray2>(env) 
    { 
    
    for (IloInt i=0; i< n1; i++)
    { add(IloMyNumArray2(env, n2, n3)); 
    } 
    } IloMyNumArray3(
    
    const IloMyNumArray3& cpy) : IloArray<IloMyNumArray2>(cpy) 
    {
    } 
    }; 
    
    class IloMyNumArray4 : 
    
    public IloArray<IloMyNumArray3> 
    { 
    
    public: IloMyNumArray4(
    
    const IloEnv env, IloInt n1, IloInt n2, IloInt n3, IloInt n4) : IloArray<IloMyNumArray3>(env) 
    { 
    
    for (IloInt i=0; i< n1; i++)
    { add(IloMyNumArray3(env, n2, n3, n4)); 
    } 
    } IloMyNumArray4(
    
    const IloMyNumArray4& cpy) : IloArray<IloMyNumArray3>(cpy) 
    {
    } 
    };     
    
    int main(
    
    int argc,char* argv[]) 
    { IloEnv env; IloInt n1 = 2; IloInt n2 = 2; IloInt n3 = 2; IloInt n4 = 2; IloMyNumArray myArray1(env, n1); IloMyNumArray2 myArray2(env, n1, n2); IloMyNumArray3 myArray3(env, n1, n2, n3); IloMyNumArray4 myArray4(env, n1, n2, n3, n4); 
    
    for (IloInt i=0; i< n1; i++)
    { myArray1[i] = i; 
    
    for (IloInt j = 0; j<n2; j++)
    { myArray2[i][j] = i+j; 
    
    for (IloInt k = 0; k< n3; k++)
    { myArray3[i][j][k] = i+j+k; 
    
    for (IloInt l = 0; l < n4; l++)
    { myArray4[i][j][k][l] = i+j+k+l; 
    } 
    } 
    } 
    }   cout << myArray1 << 
    "\n"; cout << myArray2 << 
    "\n"; cout << myArray3 << 
    "\n"; cout << myArray4 << 
    "\n"; env.end();   cout << endl;   
    
    return 0; 
    }
    

    #DecisionOptimization
    #OPLusingCPLEXOptimizer