Generated on Tue May 22 09:40:04 2018 for Gecode by doxygen 1.6.3

sequence.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     David Rijsman <David.Rijsman@quintiq.com>
00005  *
00006  *  Contributing authors:
00007  *     Christian Schulte <schulte@gecode.org>
00008  *
00009  *  Copyright:
00010  *     David Rijsman, 2009
00011  *     Christian Schulte, 2009
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 #include <gecode/minimodel.hh>
00041 #include <climits>
00042 
00043 namespace Test { namespace Int {
00044 
00046    namespace Sequence {
00047 
00053 
00054      class SequenceTest : public Test {
00055      protected:
00056        Gecode::IntSet s;
00057        int q,l,u;
00058      public:
00060        SequenceTest(const std::string& s,
00061                     const Gecode::IntSet& s0, int q0, int l0, int u0,
00062                     int size, int min, int max)
00063          : Test("Sequence::"+s,size,min,max), s(s0), q(q0), l(l0), u(u0) {
00064        }
00066        virtual bool solution(const Assignment& x) const {
00067          for (int i=0; i< (x.size() - q + 1); i++ ) {
00068            int total = 0;
00069            for (int j=i; j < i + q; j++ ) {
00070              if (s.in(x[j]))
00071                total++;
00072              if (total > u)
00073                return false;
00074            }
00075            if ( total < l )
00076              return false;
00077          }
00078          return true;
00079        }
00080      };
00081 
00082 
00084      class SequenceBoolTest : public SequenceTest {
00085      public:
00087        SequenceBoolTest(const std::string& s, const Gecode::IntSet& s0,
00088                         int q0, int l0, int u0, int size)
00089          : SequenceTest("Bool::"+s,s0,q0,l0,u0,size,0,1) {
00090        }
00091 
00093        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00094          Gecode::BoolVarArgs c(x.size());
00095 
00096          for (int i=0; i<x.size(); i++) {
00097            c[i]=Gecode::channel(home,x[i]);
00098          }
00099 
00100          Gecode::sequence(home,c,s,q,l,u);
00101        }
00102      };
00103 
00105      class SequenceIntTest : public SequenceTest {
00106      public:
00108        SequenceIntTest(const std::string& s, const Gecode::IntSet& s0,
00109                        int q0, int l0, int u0, int size, int min, int max)
00110          : SequenceTest("Int::"+s,s0,q0,l0,u0,size,min,max) {
00111        }
00112 
00114        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00115          Gecode::sequence(home,x,s,q,l,u);
00116        }
00117      };
00118 
00120      class Create {
00121      public:
00122 
00124        Create(void) {
00125          using namespace Gecode;
00126 
00127          IntSet a(0,0);
00128          IntSet b(1,1);
00129          IntSet c(2,2);
00130          IntSet d(0,1);
00131          IntArgs ie(2, 0,2);
00132          IntSet e(ie);
00133 
00134          (void) new SequenceBoolTest("A",a,3,2,2,6);
00135          (void) new SequenceBoolTest("B",b,3,2,2,6);
00136          (void) new SequenceBoolTest("C",b,6,2,2,6);
00137          (void) new SequenceBoolTest("D",b,6,0,0,6);
00138          (void) new SequenceBoolTest("E",b,6,6,6,6);
00139 
00140 
00141          (void) new SequenceIntTest ("A",c,3,2,2,6,2,3);
00142          (void) new SequenceIntTest ("B",c,3,2,2,6,2,4);
00143          (void) new SequenceIntTest ("C",b,3,2,2,6,1,3);
00144          (void) new SequenceIntTest ("D",c,3,0,0,3,1,3);
00145          (void) new SequenceIntTest ("E",c,3,3,3,3,1,3);
00146          (void) new SequenceIntTest ("F",c,3,2,2,10,2,3);
00147 
00148          (void) new SequenceIntTest ("G",d,3,2,2,6,0,3);
00149          (void) new SequenceIntTest ("H",d,3,2,2,6,0,4);
00150          (void) new SequenceIntTest ("I",d,3,2,2,6,1,3);
00151          (void) new SequenceIntTest ("J",e,3,0,0,6,0,3);
00152          (void) new SequenceIntTest ("K",e,3,3,3,6,0,3);
00153          (void) new SequenceIntTest ("L",e,3,2,2,6,0,3);
00154 
00155        }
00156      };
00157 
00158      Create c;
00160 
00161    }
00162 }}
00163 
00164 // STATISTICS: test-int