Generated on Tue Apr 18 10:21:57 2017 for Gecode by doxygen 1.6.3

member.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2011
00008  *
00009  *  Last modified:
00010  *     $Date: 2011-11-29 17:20:37 +0100 (Tue, 29 Nov 2011) $ by $Author: schulte $
00011  *     $Revision: 12486 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 #include <gecode/minimodel.hh>
00039 #include "test/int.hh"
00040 
00041 namespace Test { namespace Int {
00042 
00044    namespace Member {
00045 
00051 
00052      class Int : public Test {
00053      public:
00055        Int(int n) : Test("Member::Int::"+str(n),n+1,0,n,true) {}
00057        virtual bool solution(const Assignment& x) const {
00058          int n = x.size() - 1;
00059          for (int i=n; i--; )
00060            if (x[i] == x[n])
00061              return true;
00062          return false;
00063        }
00065        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00066          using namespace Gecode;
00067          int n = x.size() - 1;
00068          IntVarArgs y(n);
00069          for (int i=n; i--; )
00070            y[i] = x[i];
00071          member(home, y, x[n]);
00072        }
00074        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
00075                          Gecode::Reify r) {
00076          using namespace Gecode;
00077          int n = x.size() - 1;
00078          IntVarArgs y(n);
00079          for (int i=n; i--; )
00080            y[i] = x[i];
00081          member(home, y, x[n], r);
00082        }
00083      };
00084 
00086      class Bool : public Test {
00087      public:
00089        Bool(int n) : Test("Member::Bool::"+str(n),n+1,0,1,true) {}
00091        virtual bool solution(const Assignment& x) const {
00092          int n = x.size() - 1;
00093          for (int i=n; i--; )
00094            if (x[i] == x[n])
00095              return true;
00096          return false;
00097        }
00099        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00100          using namespace Gecode;
00101          int n = x.size() - 1;
00102          BoolVarArgs y(n);
00103          for (int i=n; i--; )
00104            y[i] = channel(home,x[i]);
00105          member(home, y, channel(home,x[n]));
00106        }
00108        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
00109                          Gecode::Reify r) {
00110          using namespace Gecode;
00111          int n = x.size() - 1;
00112          BoolVarArgs y(n);
00113          for (int i=n; i--; )
00114            y[i] = channel(home,x[i]);
00115          member(home, y, channel(home,x[n]), r);
00116        }
00117      };
00118 
00120      class Create {
00121      public:
00123        Create(void) {
00124          for (int i=0; i<=4; i++) {
00125            (void) new Int(i);
00126            (void) new Bool(i);
00127          }
00128        }
00129      };
00130 
00131      Create c;
00133 
00134    }
00135 }}
00136 
00137 // STATISTICS: test-int
00138