Topic
3 replies Latest Post - ‏2013-11-06T04:57:53Z by CP-Man
CP-Man
CP-Man
8 Posts
ACCEPTED ANSWER

Pinned topic Access to domain

‏2013-10-31T02:12:08Z |

Hello,

 

For some reason, I need to check the elements in the domain of a variable of IloIntVarAray, one by one in a loop like:

for (i=0; i<X[var].getDomainSize(); i++){

     if (distance[var][X[var].Domain[i]])<min){

            min=distance[var][X.Domain[i]];

            val=i;

     }

} where distance is a from-to distance matrix, var, and val are int.  

 

In fact, at each step, I need to find the closest node (value) to each variable (X[var] a IloIntVar, which shows the successor of the node var) at anytime during the search. Bt this, I mean once a value is removed from the domain, I don't want to have access to it any more, in other words, I need the updated domain of the variable.

 

So I wonder if there exist any function through which I could have access to the elements in a variable domain. I came across getDomain(), but I don't think it helps.

 

Thanks!

  • CP-Man
    CP-Man
    8 Posts
    ACCEPTED ANSWER

    Re: Access to domain

    ‏2013-10-31T02:23:32Z  in response to CP-Man

    I forgot to mention, that previously, I was using IloValueSelector to return me the value. It worked well, however, whene I used it in IloGoal, they had compatibility problem, So I gave up using IloValueSelector.

    • GGR
      GGR
      54 Posts
      ACCEPTED ANSWER

      Re: Access to domain

      ‏2013-10-31T16:18:48Z  in response to CP-Man

      Hi

      I figure out you want to enumerate the possible values of a integer variable in the constraint engine. To achieve this you need to handle the instance of IlcIntVar from the model instance of IloIntVar v and the instance of IloCP cp.

       

      IlcIntVar x;
      if (cp.isExtracted(v))
         x = cp.getIntVar(v);

       

      Please refer to the following entry in the reference manual.

      CPLEX > CPLEX C++ Reference Manual > optim.cpoptimizer > Classes item IloCP

      Then to iterate the domain of the IlcIntVar:

      IlcInt threshold = x.getMin() -1;
      for(IlcInt value = x.getMin();value > threshold; value = x.getNextHigher(threshold)) { 
           /* your code with value */        
           threshold = value;
      }

      Please refer to the following entry in the reference manual.

       

      Hope that helps

      Updated on 2013-10-31T16:24:44Z at 2013-10-31T16:24:44Z by GGR
      • CP-Man
        CP-Man
        8 Posts
        ACCEPTED ANSWER

        Re: Access to domain

        ‏2013-11-06T04:57:53Z  in response to GGR

        That works! 

         

        Thanks.