Generated on Tue May 22 09:40:14 2018 for Gecode by doxygen 1.6.3

convex.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 Convex {
00042 
00048 
00049     static IntSet ds_33(-4,4);
00050 
00052     class Convex : public SetTest {
00053     public:
00055       Convex(const char* t)
00056         : SetTest(t,1,ds_33,false) {}
00058       virtual bool solution(const SetAssignment& x) const {
00059         CountableSetRanges xr0(x.lub, x[0]);
00060         if (!xr0())
00061           return true;
00062         ++xr0;
00063         if (!xr0())
00064           return true;
00065         return false;
00066       }
00068       virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
00069         Gecode::convex(home, x[0]);
00070       }
00071     };
00072     Convex _convex("Convex::Convex");
00073 
00075     class ConvexHull : public SetTest {
00076     public:
00078       ConvexHull(const char* t)
00079         : SetTest(t,2,ds_33,false) {}
00081       virtual bool solution(const SetAssignment& x) const {
00082         CountableSetRanges xr0(x.lub, x[0]);
00083         CountableSetRanges xr1(x.lub, x[1]);
00084 
00085         if (!xr0())
00086           return !xr1();
00087 
00088         int x0min = xr0.min();
00089         int x0max = xr0.max();
00090         ++xr0;
00091         if (!xr0()) {
00092           if (!xr1()) return false;
00093           if (x0min != xr1.min()) return false;
00094           int x1max = Gecode::Set::Limits::min;
00095           while (xr1()) { x1max = xr1.max(); ++xr1;}
00096           if (x0max != x1max) return false;
00097           return true;
00098         }
00099         return false;
00100       }
00102       virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
00103         Gecode::convex(home, x[1], x[0]);
00104       }
00105     };
00106     ConvexHull _convexhull("Convex::ConvexHull");
00107 
00109     class ConvexHullS : public SetTest {
00110     public:
00112       ConvexHullS(const char* t)
00113         : SetTest(t,1,ds_33,false) {}
00115       virtual bool solution(const SetAssignment& x) const {
00116         CountableSetRanges xr0(x.lub, x[0]);
00117         if (!xr0())
00118           return true;
00119         ++xr0;
00120         if (!xr0())
00121           return true;
00122         return false;
00123       }
00125       virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
00126         Gecode::convex(home, x[0], x[0]);
00127       }
00128     };
00129     ConvexHullS _convexhulls("Convex::Sharing::ConvexHullS");
00130 
00132 
00133 }}}
00134 
00135 // STATISTICS: test-set