exec.cpp
Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 00002 /* 00003 * Main authors: 00004 * Christian Schulte <schulte@gecode.org> 00005 * 00006 * Copyright: 00007 * Christian Schulte, 2009 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/int.hh" 00039 00040 #include <gecode/minimodel.hh> 00041 00042 namespace Test { namespace Int { 00043 00045 namespace Exec { 00046 00052 00053 class IntWait : public Test { 00054 public: 00056 IntWait(int n) 00057 : Test("Wait::Int::"+str(n),n,0,n,false) {} 00059 virtual bool solution(const Assignment& x) const { 00060 for (int i=0; i<x.size(); i++) 00061 for (int j=i+1; j<x.size(); j++) 00062 if (x[i] == x[j]) 00063 return false; 00064 return true; 00065 } 00067 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { 00068 if (x.size() > 1) 00069 Gecode::wait(home, x, &c); 00070 else 00071 Gecode::wait(home, x[0], &c); 00072 } 00074 static void c(Gecode::Space& _home) { 00075 TestSpace& home = static_cast<TestSpace&>(_home); 00076 for (int i=0; i<home.x.size(); i++) 00077 for (int j=i+1; j<home.x.size(); j++) 00078 if (home.x[i].val() == home.x[j].val()) 00079 home.fail(); 00080 } 00081 }; 00082 00084 class BoolWait : public Test { 00085 public: 00087 BoolWait(int n) 00088 : Test("Wait::Bool::"+str(n),n,0,1,false) {} 00090 virtual bool solution(const Assignment& x) const { 00091 int t=0; 00092 for (int i=0; i<x.size(); i++) 00093 t += x[i]; 00094 return t==2; 00095 } 00097 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { 00098 Gecode::BoolVarArgs b(x.size()); 00099 for (int i=b.size(); i--; ) 00100 b[i]=Gecode::channel(home,x[i]); 00101 if (b.size() > 1) 00102 Gecode::wait(home, b, &c); 00103 else 00104 Gecode::wait(home, b[0], &c); 00105 } 00107 static void c(Gecode::Space& _home) { 00108 TestSpace& home = static_cast<TestSpace&>(_home); 00109 int t=0; 00110 for (int i=0; i<home.x.size(); i++) 00111 t += home.x[i].val(); 00112 if (t!=2) 00113 home.fail(); 00114 } 00115 }; 00116 00118 class When : public Test { 00119 public: 00121 When(void) : Test("When",1,0,1,false) {} 00123 virtual bool solution(const Assignment& x) const { 00124 return x[0]==0; 00125 } 00127 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { 00128 Gecode::when(home, Gecode::channel(home, x[0]), &t, &e); 00129 } 00131 static void t(Gecode::Space& home) { 00132 home.fail(); 00133 } 00135 static void e(Gecode::Space& home) { 00136 (void) home; 00137 } 00138 }; 00139 00140 IntWait iw1(1), iw2(2), iw3(3), iw4(4); 00141 BoolWait bw1(1), bw2(2), bw3(3), bw4(4); 00142 00143 When when; 00145 00146 } 00147 00148 }} 00149 00150 // STATISTICS: test-int