[gecode-users] Indexing into arrays

Guido Tack tack at gecode.org
Fri Nov 18 08:23:14 CET 2011


Hi Milt,

just posting a constraint does not mean it is "executed".  Running search for your problem (or, in fact, just calling status() on the space you post the constraints in) should determine that ds[0]=1.  See Tip 2.2 "Propagation is explicit" in Modeling and Programing with Gecode.

Cheers,
Guido

On 18 Nov 2011, at 02:28, Milton Friedman wrote:

> I've been learning and coding in Gecode for the past few weeks.  I read and re-read the modeling parts of MPG, and checked the online docs for syntax.
> 
> I've tried recasting my application several times and each time I get blocked by syntax I'd expect to exist that doesn't.
> 
> I hardly ever seem to have a reification-suitable situation, and when I do, it's with a function that doesn't support reification.
> 
> 
> I'm used to languages that let you put data in arrays and then index into the arrays to solve problems.  The Gecode examples seem to have variable arrays, and constant integer indices into them, based on a fixed problem structures, like Sudoku etc., but in my case the application structure that's constant is the array, and the parts of it that I need to index into are determined by the finite-domain variables.
> 
> 
> 
> Below is an example.  I'm trying to use an IntVarArgs to index into a vector of constants (in this case booleans).
> 
> I can't figure out how to get Gecode to index directly into the C++ vector, so I create a BoolVarArgs vector and copy the constants into it...seems wasteful but ok.
> 
> Then I do the indexing into a vector of constants, with a single number (1-item domain), and it tells me the binary result is [0..1] -- not especially enlightening news about a binary.
> 
> So I must be missing something obvious about how to index in Gecode.  Any thoughts?
> 
> Any help or guidance would be appreciated.
> 
> Thanks,
> 
> -Milt   
> 
> 
> 
> 	//notCD is a C++ boolean vector: knows nothing about Gecode
> 
>         bool * notCD
> 
>         notCD = new bool [VecLength];
> 
>         for (int i = 0; i<VecLength; i++) {
> 
>                 notCD[i] = abs(some2D_integer_array[i][2])==1;  
> 
>         }              
> 
>         //Create nCD: BoolVarArgs vector of notCD       //only creating nCD because I can't get Gecode to let me work directly with notCD
> 
>         BoolVarArgs nCD(VecLength);
> 
>         for(int i=0; i<VecLength; i++){ //expected to write nCD[i]=notCD[i]; or maybe nCD[i]=expr(*this,notCD[i]); or nCD[i]=expr(*this,element(notCD,i));
> 
>                                         // but none of these forms compiled
> 
>                 if (notCD[i]){
> 
>                         nCD[i]=T;
> 
>                 }
> 
>                 else {
> 
>                         nCD[i]=F;
> 
>                 }
> 
>         }
> 
>         //I'm really just trying to index with an item of an IntVarArgs vector into a C++ boolean vector
> 
>         IntVar da;
> 
>         for(int i=0; i<3; i++){
> 
>                 da = p[iterm+i];        //p is an IntVarArgs with all terms assigned, and p[iTerm+0] is 192
> 
>                 ds[i] = expr(*this,element(nCD,da),ICL_DOM);
> 
>                 cout<<"da: "<<da<<", ds["<<i<<"]: "<<ds[i]<<", nCD[192]: "<<nCD[192]<<"  ";
> 
>         }
> 
>         //-------------------
> 
>         //so unfortunately the output is:
> 
>         //da: 192, ds[0]: [0..1], nCD[192]: 1
> 
>         //
> 
>         //why isn't the output:
> 
>         //da: 192, ds[0]: 1, nCD[192]: 1
> 
>         //why is there indecision about ds[0]?...how do I get Gecode to understand that ds[0] must be 1?
> 
> _______________________________________________
> Gecode users mailing list
> users at gecode.org
> https://www.gecode.org/mailman/listinfo/gecode-users

-- 
Guido Tack, http://people.cs.kuleuven.be/~guido.tack/




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.gecode.org/pipermail/users/attachments/20111118/3bb75249/attachment-0001.htm>


More information about the users mailing list