Generated on Thu Apr 11 13:59:11 2019 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  *  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 "test/int.hh"
00039 
00040 namespace Test { namespace Int {
00041 
00043    namespace Precede {
00044 
00046      class Single : public Test {
00047      private:
00049        int s, t;
00050      public:
00052        Single(int s0, int t0)
00053          : Test("Precede::Single::"+str(s0)+"<"+str(t0),8,1,4),
00054            s(s0), t(t0) {}
00056        virtual bool solution(const Assignment& x) const {
00057          int n = x.size();
00058          for (int i = 0 ; i < n ; i++) {
00059            if (x[i] == t)
00060              return false;
00061            if (x[i] == s)
00062              return true;
00063          }
00064          return true;
00065        }
00067        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00068          Gecode::precede(home, x, s, t);
00069        }
00070      };
00071 
00073      class Multi : public Test {
00074      private:
00076        Gecode::IntArgs c;
00077      public:
00079        Multi(const Gecode::IntArgs& c0)
00080          : Test("Precede::Multi::"+str(c0),6,1,5), c(c0) {
00081          contest = CTL_NONE;
00082        }
00084        virtual bool solution(const Assignment& x) const {
00085          for (int j=0; j<c.size()-1; j++)
00086            for (int i=0; i<x.size(); i++) {
00087              if (x[i] == c[j+1])
00088                return false;
00089              if (x[i] == c[j])
00090                break;
00091            }
00092          return true;
00093        }
00095        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00096          Gecode::precede(home, x, c);
00097        }
00098      };
00099 
00100      Single _a(2, 3);
00101      Single _b(1, 4);
00102 
00103      Multi _c(Gecode::IntArgs({1,2,3}));
00104      Multi _d(Gecode::IntArgs({3,2,1}));
00105      Multi _e(Gecode::IntArgs({4,2,3,1}));
00106 
00107    }
00108 
00109 }}
00110 
00111 // STATISTICS: test-int