Generated on Thu Mar 22 10:39:40 2012 for Gecode by doxygen 1.6.3

precede.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christopher Mears <Chris.Mears@monash.edu>
00005  *
00006  *  Contributing authors:
00007  *     Christian Schulte <schulte@gecode.org>
00008  *
00009  *  Copyright:
00010  *     Christopher Mears, 2011
00011  *     Christian Schulte, 2011
00012  *
00013  *  Last modified:
00014  *     $Date: 2011-07-12 12:49:06 +0200 (Tue, 12 Jul 2011) $ by $Author: tack $
00015  *     $Revision: 12172 $
00016  *
00017  *  This file is part of Gecode, the generic constraint
00018  *  development environment:
00019  *     http://www.gecode.org
00020  *
00021  *  Permission is hereby granted, free of charge, to any person obtaining
00022  *  a copy of this software and associated documentation files (the
00023  *  "Software"), to deal in the Software without restriction, including
00024  *  without limitation the rights to use, copy, modify, merge, publish,
00025  *  distribute, sublicense, and/or sell copies of the Software, and to
00026  *  permit persons to whom the Software is furnished to do so, subject to
00027  *  the following conditions:
00028  *
00029  *  The above copyright notice and this permission notice shall be
00030  *  included in all copies or substantial portions of the Software.
00031  *
00032  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00033  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00034  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00035  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00036  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00037  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00038  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00039  *
00040  */
00041 
00042 #include "test/int.hh"
00043 
00044 namespace Test { namespace Int {
00045 
00047    namespace Precede {
00048             
00050      class Single : public Test {
00051      private:
00053        int s, t;
00054      public:
00056        Single(int s0, int t0)
00057          : Test("Precede::Single::"+str(s0)+"<"+str(t0),8,1,4),
00058            s(s0), t(t0) {}
00060        virtual bool solution(const Assignment& x) const {
00061          int n = x.size();
00062          for (int i = 0 ; i < n ; i++) {
00063            if (x[i] == t)
00064              return false;
00065            if (x[i] == s)
00066              return true;
00067          }
00068          return true;
00069        }
00071        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00072          Gecode::precede(home, x, s, t);
00073        }
00074      };
00075      
00077      class Multi : public Test {
00078      private:
00080        Gecode::IntArgs c;
00081      public:
00083        Multi(const Gecode::IntArgs& c0)
00084          : Test("Precede::Multi::"+str(c0),6,1,5), c(c0) {
00085          contest = CTL_NONE;
00086        }
00088        virtual bool solution(const Assignment& x) const {
00089          for (int j=0; j<c.size()-1; j++)
00090            for (int i=0; i<x.size(); i++) {
00091              if (x[i] == c[j+1])
00092                return false;
00093              if (x[i] == c[j])
00094                break;
00095            }
00096          return true;
00097        }
00099        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00100          Gecode::precede(home, x, c);
00101        }
00102      };
00103      
00104      Single _a(2, 3);
00105      Single _b(1, 4);
00106 
00107      Multi _c(Gecode::IntArgs(3, 1,2,3));
00108      Multi _d(Gecode::IntArgs(3, 3,2,1));
00109      Multi _e(Gecode::IntArgs(4, 4,2,3,1));
00110 
00111    }
00112 
00113 }}
00114 
00115 // STATISTICS: test-int