Generated on Fri Mar 20 15:56:13 2015 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  *  Last modified:
00010  *     $Date: 2012-09-07 17:31:22 +0200 (Fri, 07 Sep 2012) $ by $Author: schulte $
00011  *     $Revision: 13068 $
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/set.hh"
00039 
00040 using namespace Gecode;
00041 
00042 namespace Test { namespace Set {
00043 
00045   namespace Sequence {
00046 
00052 
00053     static IntSet ds_33(-1,2);
00054 
00056     class Sequence : public SetTest {
00057     public:
00059       Sequence(const char* t)
00060         : SetTest(t,4,ds_33,false) {}
00062       virtual bool solution(const SetAssignment& x) const {
00063         int max = Gecode::Set::Limits::min - 1;
00064         for (int i=0; i<4; i++) {
00065           CountableSetRanges xir(x.lub, x[i]);
00066           IntSet xi(xir);
00067           if (xi.ranges() > 0) {
00068             int oldMax = max;
00069             max = xi.max();
00070             if (xi.min() <= oldMax)
00071               return false;
00072           }
00073         }
00074         return true;
00075       }
00077       virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
00078         Gecode::sequence(home, x);
00079       }
00080     };
00081     Sequence _sequence("Sequence::Sequence");
00082 
00084     class SeqU : public SetTest {
00085     private:
00086       int n;
00087     public:
00089       SeqU(int n0)
00090         : SetTest("Sequence::SeqU"+str(n0),n0+1,ds_33,false), n(n0) {}
00092       virtual bool solution(const SetAssignment& x) const {
00093         int max = Gecode::Set::Limits::min - 1;
00094         for (int i=0; i<n; i++) {
00095           CountableSetRanges xir(x.lub, x[i]);
00096           IntSet xi(xir);
00097           if (xi.ranges() > 0) {
00098             int oldMax = max;
00099             max = xi.max();
00100             if (xi.min() <= oldMax)
00101               return false;
00102           }
00103         }
00104         CountableSetRanges* isrs = new CountableSetRanges[n];
00105         for (int i=n; i--; )
00106           isrs[i].init(x.lub, x[i]);
00107         FakeSpace* fs = new FakeSpace;
00108         bool ret;
00109         {
00110           Region r(*fs);
00111           Iter::Ranges::NaryUnion u(r, isrs, n);
00112           CountableSetRanges xnr(x.lub, x[n]);
00113           ret = Iter::Ranges::equal(u, xnr);
00114         }
00115         delete[] isrs;
00116         delete fs;
00117         return ret;
00118       }
00120       virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
00121         SetVarArgs xs(x.size()-1);
00122         for (int i=x.size()-1; i--;)
00123           xs[i]=x[i];
00124         Gecode::sequence(home, xs, x[x.size()-1]);
00125       }
00126     };
00127     SeqU _sequ0(0);
00128     SeqU _sequ1(1);
00129     SeqU _sequ3(3);
00130 
00131 }}}
00132 
00133 // STATISTICS: test-set