Generated on Thu Apr 11 13:59:07 2019 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  *  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 Distinct {
00042 
00048 
00049     static IntSet ds_33(-2,2);
00050     static IntSet ds_44(-4,4);
00051 
00053     class AtmostOne : public SetTest {
00054     public:
00056       AtmostOne(const char* t)
00057         : SetTest(t,3,ds_33,false) {}
00059       virtual bool solution(const SetAssignment& x) const {
00060         {
00061           CountableSetRanges xr0(x.lub, x[0]);
00062           CountableSetRanges xr1(x.lub, x[1]);
00063           Iter::Ranges::Inter<CountableSetRanges,CountableSetRanges>
00064             i(xr0,xr1);
00065           if (Iter::Ranges::size(i)>1)
00066             return false;
00067         }
00068         {
00069           CountableSetRanges xr0(x.lub, x[0]);
00070           CountableSetRanges xr2(x.lub, x[2]);
00071           Iter::Ranges::Inter<CountableSetRanges,CountableSetRanges>
00072             i(xr0,xr2);
00073           if (Iter::Ranges::size(i)>1)
00074             return false;
00075         }
00076         {
00077           CountableSetRanges xr1(x.lub, x[1]);
00078           CountableSetRanges xr2(x.lub, x[2]);
00079           Iter::Ranges::Inter<CountableSetRanges,CountableSetRanges>
00080             i(xr1,xr2);
00081           if (Iter::Ranges::size(i)>1)
00082             return false;
00083         }
00084         {
00085           CountableSetRanges xr0(x.lub, x[0]);
00086           CountableSetRanges xr1(x.lub, x[1]);
00087           CountableSetRanges xr2(x.lub, x[2]);
00088           if (Iter::Ranges::size(xr0)!=3 ||
00089               Iter::Ranges::size(xr1)!=3 ||
00090               Iter::Ranges::size(xr2)!=3)
00091             return false;
00092         }
00093         return true;
00094       }
00096       virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
00097         SetVar s1(home, IntSet::empty, -2, 2, 0U, 1U);
00098         Gecode::rel(home, x[0], SOT_INTER, x[1], SRT_EQ, s1);
00099         SetVar s2(home, IntSet::empty, -2, 2, 0U, 1U);
00100         Gecode::rel(home, x[0], SOT_INTER, x[2], SRT_EQ, s2);
00101         SetVar s3(home, IntSet::empty, -2, 2, 0U, 1U);
00102         Gecode::rel(home, x[1], SOT_INTER, x[2], SRT_EQ, s3);
00103         Gecode::atmostOne(home, x, 3);
00104       }
00105     };
00106     AtmostOne _atmostone("Distinct::AtmostOne");
00107 
00109 
00110 }}}
00111 
00112 // STATISTICS: test-set