Generated on Sat Feb 7 2015 02:01:16 for Gecode by doxygen 1.8.9.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 12:35:31 +0200 (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  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
NodeType t
Type of node.
Definition: bool-expr.cpp:234
virtual bool solution(const Assignment &x) const
Check whether x is solution.
Definition: exec.cpp:123
Gecode::IntVarArray x
Variables to be tested.
Definition: int.hh:158
BoolWait bw2(2)
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
Definition: arithmetic.cpp:218
Simple test for wait (Boolean variables)
Definition: exec.cpp:84
virtual bool solution(const Assignment &x) const
Check whether x is solution.
Definition: exec.cpp:59
Simple test for when.
Definition: exec.cpp:118
Integer variable array.
Definition: int.hh:741
BoolWait bw1(1)
Space for executing tests.
Definition: int.hh:153
Computation spaces.
Definition: core.hpp:1362
static std::string str(Gecode::ExtensionalPropKind epk)
Map extensional propagation kind to string.
Definition: int.hpp:212
void when(Home home, BoolVar x, void(*t)(Space &home), void(*e)(Space &home), IntConLevel)
Execute t (then) when x is assigned one, and e (else) otherwise.
Definition: exec.cpp:74
Gecode::IntArgs i(4, 1, 2, 3, 4)
IntWait(int n)
Create and register test.
Definition: exec.cpp:56
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
virtual bool solution(const Assignment &x) const
Check whether x is solution.
Definition: exec.cpp:90
void fail(void)
Fail space.
Definition: core.hpp:3428
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post wait on x.
Definition: exec.cpp:97
Simple test for wait (integer variables)
Definition: exec.cpp:53
static void e(Gecode::Space &home)
Else-function to be executed.
Definition: exec.cpp:135
BoolWait(int n)
Create and register test.
Definition: exec.cpp:87
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post when on x.
Definition: exec.cpp:127
Passing Boolean variables.
Definition: int.hh:690
IntWait iw3(3)
BoolWait bw4(4)
General test support.
Definition: afc.cpp:43
static void t(Gecode::Space &home)
Then-function to be executed.
Definition: exec.cpp:131
BoolWait bw3(3)
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
When(void)
Create and register test.
Definition: exec.cpp:121
Base class for assignments
Definition: int.hh:63
IntWait iw4(4)
IntWait iw2(2)
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
void wait(Home home, FloatVar x, void(*c)(Space &home))
Execute c when x becomes assigned.
Definition: exec.cpp:44
IntWait iw1(1)
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:985
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post wait on x.
Definition: exec.cpp:67
int size(void) const
Return number of variables.
Definition: int.hpp:50
static void c(Gecode::Space &_home)
Continuation to be executed.
Definition: exec.cpp:107
static void c(Gecode::Space &_home)
Continuation to be executed.
Definition: exec.cpp:74