Generated on Mon Aug 25 11:35:44 2008 for Gecode by doxygen 1.5.6

sequence.cc

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: 2008-02-19 10:36:44 +0100 (Tue, 19 Feb 2008) $ by $Author: tack $
00011  *     $Revision: 6228 $
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.size() > 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.size() > 0) {
00098             int oldMax = max;
00099             max = xi.max();
00100             if (xi.min() <= oldMax)
00101               return false;
00102           }
00103         }
00104         GECODE_AUTOARRAY(CountableSetRanges, isrs, n);
00105         for (int i=n; i--; )
00106           isrs[i].init(x.lub, x[i]);
00107         Iter::Ranges::NaryUnion<CountableSetRanges> u(isrs, n);
00108         CountableSetRanges xnr(x.lub, x[n]);
00109         return Iter::Ranges::equal(u, xnr);
00110       }
00112       virtual void post(Space* home, SetVarArray& x, IntVarArray&) {
00113         SetVarArgs xs(x.size()-1);
00114         for (int i=x.size()-1; i--;)
00115           xs[i]=x[i];
00116         Gecode::sequentialUnion(home, xs, x[x.size()-1]);
00117       }
00118     };
00119     SeqU _sequ0(0);
00120     SeqU _sequ1(1);
00121     SeqU _sequ3(3);
00122 
00123 }}}
00124 
00125 // STATISTICS: test-set