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