Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Unused variable

    Posted 08/07/17 06:13 AM

    Originally posted by: jawadomari


    Hello everyone, 

    I have a small question about creating arrays of variables. I have a 2D array of continuous variables representing the arrival times of each train at each station. I know that some trains do not arrive at some stations.

    If I write something like this:

    IloArray<IloNumVarArray> arrivalTimes(env, noOfTrains);

    for(t = 0; t < noOfTrains; t++)

    {

        arrivalTimes[t] = IloNumVarArray(env, noOfStations);

        if(t arrives at s)

        {

           arrivalTimes[t][s] = IloNumVar(env);

           model.add(arrivalTimes[t][s]);

        }

    }

    Would I have created noOfStations x noOfTrains variables, or just the ones that were added to the model? If it is the latter, would memory have been allocated to the parts of the array where a train does not arrive at a station?

    Thank you. 


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Unused variable

    Posted 08/07/17 06:11 PM

    You would only create as many variables as the number of times the condition "t arrives at s" was satisfied. As for you second question, I believe that memory would be allocated forthe unused variables, but only enough memory in each case for a pointer, not the amount used by a variable. The unused pointers would probably default to zero values. (At least they would in Java; it's been a while since I programmed in C++).

    One caveat: if you take this approach, do not pass arrivalTimes[t] as an argument to a CPLEX method (for instance, getValues). CPLEX will attempt to find a value for each variable, including the unallocated ones, and a null pointer adventure will occur.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Unused variable

    Posted 08/08/17 04:06 AM

    Originally posted by: jawadomari


    Thanks Paul, this is helpful! Have a goo day. 


    #CPLEXOptimizers
    #DecisionOptimization