Generated on Fri Aug 24 2012 04:52:17 for Gecode by doxygen 1.8.1.1
exec.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2009
8  *
9  * Last modified:
10  * $Date: 2010-04-08 20:35:31 +1000 (Thu, 08 Apr 2010) $ by $Author: schulte $
11  * $Revision: 10684 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #include "test/int.hh"
39 
40 #include <gecode/minimodel.hh>
41 
42 namespace Test { namespace Int {
43 
45  namespace Exec {
46 
52 
53  class IntWait : public Test {
54  public:
56  IntWait(int n)
57  : Test("Wait::Int::"+str(n),n,0,n,false) {}
59  virtual bool solution(const Assignment& x) const {
60  for (int i=0; i<x.size(); i++)
61  for (int j=i+1; j<x.size(); j++)
62  if (x[i] == x[j])
63  return false;
64  return true;
65  }
67  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
68  if (x.size() > 1)
69  Gecode::wait(home, x, &c);
70  else
71  Gecode::wait(home, x[0], &c);
72  }
74  static void c(Gecode::Space& _home) {
75  TestSpace& home = static_cast<TestSpace&>(_home);
76  for (int i=0; i<home.x.size(); i++)
77  for (int j=i+1; j<home.x.size(); j++)
78  if (home.x[i].val() == home.x[j].val())
79  home.fail();
80  }
81  };
82 
84  class BoolWait : public Test {
85  public:
87  BoolWait(int n)
88  : Test("Wait::Bool::"+str(n),n,0,1,false) {}
90  virtual bool solution(const Assignment& x) const {
91  int t=0;
92  for (int i=0; i<x.size(); i++)
93  t += x[i];
94  return t==2;
95  }
97  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
99  for (int i=b.size(); i--; )
100  b[i]=Gecode::channel(home,x[i]);
101  if (b.size() > 1)
102  Gecode::wait(home, b, &c);
103  else
104  Gecode::wait(home, b[0], &c);
105  }
107  static void c(Gecode::Space& _home) {
108  TestSpace& home = static_cast<TestSpace&>(_home);
109  int t=0;
110  for (int i=0; i<home.x.size(); i++)
111  t += home.x[i].val();
112  if (t!=2)
113  home.fail();
114  }
115  };
116 
118  class When : public Test {
119  public:
121  When(void) : Test("When",1,0,1,false) {}
123  virtual bool solution(const Assignment& x) const {
124  return x[0]==0;
125  }
127  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
128  Gecode::when(home, Gecode::channel(home, x[0]), &t, &e);
129  }
131  static void t(Gecode::Space& home) {
132  home.fail();
133  }
135  static void e(Gecode::Space& home) {
136  (void) home;
137  }
138  };
139 
140  IntWait iw1(1), iw2(2), iw3(3), iw4(4);
141  BoolWait bw1(1), bw2(2), bw3(3), bw4(4);
142 
145 
146  }
147 
148 }}
149 
150 // STATISTICS: test-int