Generated on Thu Mar 22 10:39:36 2012 for Gecode by doxygen 1.6.3

distinct.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: 2010-04-08 12:35:31 +0200 (Thu, 08 Apr 2010) $ by $Author: schulte $
00011  *     $Revision: 10684 $
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 Distinct {
00046 
00052 
00053     static IntSet ds_33(-2,2);
00054     static IntSet ds_44(-4,4);
00055 
00057     class AtmostOne : public SetTest {
00058     public:
00060       AtmostOne(const char* t)
00061         : SetTest(t,3,ds_33,false) {}
00063       virtual bool solution(const SetAssignment& x) const {
00064         {
00065           CountableSetRanges xr0(x.lub, x[0]);
00066           CountableSetRanges xr1(x.lub, x[1]);
00067           Iter::Ranges::Inter<CountableSetRanges,CountableSetRanges>
00068             i(xr0,xr1);
00069           if (Iter::Ranges::size(i)>1)
00070             return false;
00071         }
00072         {
00073           CountableSetRanges xr0(x.lub, x[0]);
00074           CountableSetRanges xr2(x.lub, x[2]);
00075           Iter::Ranges::Inter<CountableSetRanges,CountableSetRanges>
00076             i(xr0,xr2);
00077           if (Iter::Ranges::size(i)>1)
00078             return false;
00079         }
00080         {
00081           CountableSetRanges xr1(x.lub, x[1]);
00082           CountableSetRanges xr2(x.lub, x[2]);
00083           Iter::Ranges::Inter<CountableSetRanges,CountableSetRanges>
00084             i(xr1,xr2);
00085           if (Iter::Ranges::size(i)>1)
00086             return false;
00087         }
00088         {
00089           CountableSetRanges xr0(x.lub, x[0]);
00090           CountableSetRanges xr1(x.lub, x[1]);
00091           CountableSetRanges xr2(x.lub, x[2]);
00092           if (Iter::Ranges::size(xr0)!=3 ||
00093               Iter::Ranges::size(xr1)!=3 ||
00094               Iter::Ranges::size(xr2)!=3)
00095             return false;
00096         }
00097         return true;
00098       }
00100       virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
00101         SetVar s1(home, IntSet::empty, -2, 2, 0,1);
00102         Gecode::rel(home, x[0], SOT_INTER, x[1], SRT_EQ, s1);
00103         SetVar s2(home, IntSet::empty, -2, 2, 0,1);
00104         Gecode::rel(home, x[0], SOT_INTER, x[2], SRT_EQ, s2);
00105         SetVar s3(home, IntSet::empty, -2, 2, 0,1);
00106         Gecode::rel(home, x[1], SOT_INTER, x[2], SRT_EQ, s3);
00107         Gecode::atmostOne(home, x, 3);
00108       }
00109     };
00110     AtmostOne _atmostone("Distinct::AtmostOne");
00111 
00113 
00114 }}}
00115 
00116 // STATISTICS: test-set