[gecode-users] Avoid the appearance of several simultaneous values
Lorenzo Gatti
lorenzo.gatti at gmail.com
Thu Jan 2 14:23:35 CET 2014
In C++, operator ^ is exclusive OR: 1^1 is 0. You are also not initializing
bool1 and bool2 properly; maybe cardinality constraints would be simpler.
On Mon, Dec 30, 2013 at 10:10 PM, inspecteur <inspecteur.rick at gmail.com>wrote:
> Hi
>
> I tried a track but that does not seem to work
> I may be wrong on boolean
> 1 && 1 =1
> 1 && 0 = 0
> 0 && 0 = 0
>
> 1 ^ 0 = 1
> 0 ^ 0 = 0
> 1 ^ 1 = 1
>
> Code :
>
> IntVarArgs d1(4);
> BoolVar bool1(*this,0,1);
> BoolVar bool2(*this,0,1);
>
> for (int i = 0; i < n; i++) {
> for (int j = 0; j < 4; j++) {
> d1[j]=tab(i,j);
> }
>
> // I tested if the value 3 appears at least once
> for (int j = 0; j < 4; j++) {
> bool1 = expr(*this, (d1[j]==3) ^ (bool1==1));
> }
>
> // I tested if the value 4 appears at least once
> for (int j = 0; j < 4; j++) {
> bool2 = expr(*this, (d1[j]==4) ^ (bool2==1));
> }
>
> //I constrained that the two values 3 et 4 do not appear together
> rel(*this, (bool1 + bool2) != 1);
>
>
>
>
> Le 28/12/2013 14:50, Christian Schulte a écrit :
>
> Hi,
>
>
>
> This is not really a Gecode-specific question but a general constraint
> modeling question, so you might want to turn elsewhere for help.
>
>
>
> Christian
>
>
>
> --
>
> Christian Schulte, www.ict.kth.se/~cschulte
>
>
>
> *From:* users-bounces at gecode.org [mailto:users-bounces at gecode.org<users-bounces at gecode.org>]
> *On Behalf Of *inspecteur
> *Sent:* Tuesday, December 24, 2013 03:59 PM
> *To:* users at gecode.org
> *Subject:* [gecode-users] Avoid the appearance of several simultaneous
> values
>
>
>
> Hi
> Sorry for my english, I'm french and beginner on gecode.
>
> I want to create an array of integers (4 * 4) with the constraints:
> 1) Possible values between 1 and 6
> 2) no repeating values on lines
> 3) The values 3 and 4 must not be on the same line
> 4) No more than 2 times the same value on each column
>
> I stumble on the constraint number 3)
>
> If someone could put me on the track
>
>
>
> Here is my code
>
> class CarreMagique : public Script {
> private:
> const int n;
> IntVarArray carreMag;
>
> public:
> CarreMagique(const SizeOptions& opt)
> : n(opt.size()), carreMag(*this,n*4,1,6) {
>
> Matrix<IntVarArray> tab(carreMag, n, 4);
> IntVarArgs d1(4);
> for (int i = 0; i < n; i++) {
> for (int j = 0; j < 4; j++) {
> d1[j]=tab(i,j);
> }
> distinct(*this, d1);
> }
>
> IntVarArgs d2(n);
> for (int j = 0; j < 4; j++) {
> for (int i = 0; i < n; i++) {
> d2[i]=tab(i,j);
> }
> count(*this, d2, IntSet(0,2), IntArgs::create(6,1,1));
> }
>
> }
> branch(*this, carreMag, INT_VAR_NONE(), INT_VAL_SPLIT_MIN());
> }
>
> CarreMagique(bool share, CarreMagique& s) : Script(share,s), n(s.n) {
> carreMag.update(*this, share, s.carreMag);
> }
>
> virtual Space* copy(bool share) {
> return new CarreMagique(share,*this);
> }
>
> virtual void print(std::ostream& os) const {
> // Pour acceder au tableau comme à une matrice
> Matrix<IntVarArray> m(carreMag, n, 4);
> for (int i = 0; i < n; i++) {
> os << "\t";
> for (int j = 0; j < 4; j++) {
> os.width(2);
> os << m(i,j) << " ";
> }
> os << std::endl;
> }
> }
>
> };
>
> int main(int argc, char* argv[]) {
> SizeOptions opt("CarreMagique");
> opt.size(4);
> Script::run<CarreMagique,DFS,SizeOptions>(opt);
> return 0;
> }
>
>
>
> _______________________________________________
> Gecode users mailing list
> users at gecode.org
> https://www.gecode.org/mailman/listinfo/gecode-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.gecode.org/pipermail/users/attachments/20140102/c5b50deb/attachment.html>
More information about the users
mailing list