Decision Optimization

Decision Optimization

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

 View Only
  • 1.  create a 2D array

    Posted Mon May 25, 2015 05:37 AM

    Originally posted by: fatmam


     

    i have made like this. the compilation is perfect but while executing " pg.exe stop running" what's wrong?

    
    typedef IloArray<IloFloatVarArray> VarMatrix;
     
    VarMatrix f
    (env,N
    );
     
        
    for
    (i=
    0;i<N;i++
    )
     
            f
    [i
    ]= IloFloatVarArray 
    (env,K
    );
    
     
    
    /* Objective Function */
        IloExpr expa
    (env
    );
        
    for
    (k=
    0;k<K;k++
    )
     
            
    {
     
            
    for
    (i=
    0;i<N;i++
    )
            
    {expa+=  f
    [i
    ]
    [k
    ];
    }
    }
     
     
        model.add
    (IloMinimize
    (env,expa
    )
    );
     
        
    // Constraint 1
     
        
    for
    (k=
    0;k<K;k++
    )
     
            
    {IloExpr exp
    (env
    );
     
            
    for
    (i=
    0;i<N;i++
    )
            
    {exp+=  f
    [i
    ]
    [k
    ];
    }
     
     
                     model.add
    (exp <=
    0
    );
     
           
    }
    

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: create a 2D array

    Posted Tue May 26, 2015 12:53 AM

    Please try to format your code in a more readable/compact way next time.

    You are using the wrong constructor to create your arrays. As you can see in the reference documentation (note that IloFloatVarArray is just another name for IloNumVarArray):

    public IloNumVarArray(const IloEnv env, IloInt n=0)
    This constructor creates an extensible array of n numeric variables in env. Initially, the n elements are empty handles.

    Since you are using that constructor you only create arrays with empty handles. They arrays are not populated with variable objects. Thus you get an invalid memory access as soon as you attempt to use any of those empty handles. You should instead use a constructor that actually creates variable objects in the array, for example this one:

    public IloNumVarArray(const IloEnv env, const IloNumArray lb, const IloNumArray ub, IloNumVar::Type type=ILOFLOAT)
    This constructor creates an extensible array of numeric variables in env with lower and upper bounds and type as specified. The instances of IloNumVar to fill this array are constructed at the same time. The length of the array lb must be the same as the length of the array ub. In other words, lb.getSize == ub.getSize. This constructor will construct an array with the number of elements in the array ub.

     


    #CPLEXOptimizers
    #DecisionOptimization