Generated on Thu Apr 11 13:59:12 2019 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  *     Guido Tack <tack@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Guido Tack, 2005
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 #include "test/set.hh"
00035 
00036 using namespace Gecode;
00037 
00038 namespace Test { namespace Set {
00039 
00041   namespace Sequence {
00042 
00048 
00049     static IntSet ds_33(-1,2);
00050 
00052     class Sequence : public SetTest {
00053     public:
00055       Sequence(const char* t)
00056         : SetTest(t,4,ds_33,false) {}
00058       virtual bool solution(const SetAssignment& x) const {
00059         int max = Gecode::Set::Limits::min - 1;
00060         for (int i=0; i<4; i++) {
00061           CountableSetRanges xir(x.lub, x[i]);
00062           IntSet xi(xir);
00063           if (xi.ranges() > 0) {
00064             int oldMax = max;
00065             max = xi.max();
00066             if (xi.min() <= oldMax)
00067               return false;
00068           }
00069         }
00070         return true;
00071       }
00073       virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
00074         Gecode::sequence(home, x);
00075       }
00076     };
00077     Sequence _sequence("Sequence::Sequence");
00078 
00080     class SeqU : public SetTest {
00081     private:
00082       int n;
00083     public:
00085       SeqU(int n0)
00086         : SetTest("Sequence::SeqU"+str(n0),n0+1,ds_33,false), n(n0) {}
00088       virtual bool solution(const SetAssignment& x) const {
00089         int max = Gecode::Set::Limits::min - 1;
00090         for (int i=0; i<n; i++) {
00091           CountableSetRanges xir(x.lub, x[i]);
00092           IntSet xi(xir);
00093           if (xi.ranges() > 0) {
00094             int oldMax = max;
00095             max = xi.max();
00096             if (xi.min() <= oldMax)
00097               return false;
00098           }
00099         }
00100         CountableSetRanges* isrs = new CountableSetRanges[n];
00101         for (int i=n; i--; )
00102           isrs[i].init(x.lub, x[i]);
00103         bool ret;
00104         {
00105           Region r;
00106           Iter::Ranges::NaryUnion u(r, isrs, n);
00107           CountableSetRanges xnr(x.lub, x[n]);
00108           ret = Iter::Ranges::equal(u, xnr);
00109         }
00110         delete[] isrs;
00111         return ret;
00112       }
00114       virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
00115         SetVarArgs xs(x.size()-1);
00116         for (int i=x.size()-1; i--;)
00117           xs[i]=x[i];
00118         Gecode::sequence(home, xs, x[x.size()-1]);
00119       }
00120     };
00121     SeqU _sequ0(0);
00122     SeqU _sequ1(1);
00123     SeqU _sequ3(3);
00124 
00125 }}}
00126 
00127 // STATISTICS: test-set