Generated on Sat Feb 7 2015 02:01:31 for Gecode by doxygen 1.8.9.1
brancher-handle.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, 2013
8  *
9  * Last modified:
10  * $Date: 2013-02-25 21:43:24 +0100 (Mon, 25 Feb 2013) $ by $Author: schulte $
11  * $Revision: 13406 $
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 <gecode/kernel.hh>
39 #include <gecode/int.hh>
40 
41 #include "test/test.hh"
42 
43 namespace Test {
44 
46  class BrancherHandle : public Test::Base {
47  protected:
49  class TestSpace : public Gecode::Space {
50  protected:
53  public:
55  TestSpace(void) : x(*this,2,0,10) {}
57  TestSpace(bool share, TestSpace& s) : Space(share,s) {
58  x.update(*this,share,s.x);
59  }
62  using namespace Gecode;
63  return Gecode::branch(*this, x, INT_VAR_NONE(), INT_VAL_MIN());
64  }
66  virtual Space* copy(bool share) {
67  return new TestSpace(share,*this);
68  }
69  };
71  static const int n_b = 1024;
73  int index(void) {
74  // return rand(n);
75  return 4;
76  }
77  public:
79  BrancherHandle(void) : Test::Base("BrancherHandle") {}
81  bool run(void) {
82  using namespace Gecode;
83  TestSpace* s = new TestSpace;
84 
85  // Create and immediately delete
86  for (int i=0; i<n_b; i++) {
88  if (!b(*s)) return false;
89  b.kill(*s);
90  if (b(*s)) return false;
91  }
92 
93  if (s->status() != SS_SOLVED)
94  return false;
95 
96  // Array of handles for tests
98 
99  // Create and delete
100  for (int i=0; i<n_b; i++) {
102  if (!b(*s)) return false;
103  bs[i] = b;
104  }
105  for (int i=0; i<n_b; i++) {
106  bs[i].kill(*s);
107  if (bs[i](*s)) return false;
108  }
109  if (s->status() != SS_SOLVED)
110  return false;
111 
112  // Create and delete in inverse order
113  for (int i=0; i<n_b; i++) {
115  if (!b(*s)) return false;
116  bs[i] = b;
117  }
118  for (int i=n_b; i--; ) {
119  bs[i].kill(*s);
120  if (bs[i](*s)) return false;
121  }
122  if (s->status() != SS_SOLVED)
123  return false;
124 
125  // Create and delete randomly
126  for (int i=0; i<n_b; i++) {
128  if (!b(*s)) return false;
129  bs[i] = b;
130  }
131  int a = n_b;
132  while (a > 0) {
133  int i = rand(n_b);
134  if (bs[i](*s)) {
135  bs[i].kill(*s); a--;
136  }
137  }
138  if (s->status() != SS_SOLVED)
139  return false;
140 
141  return true;
142  }
143  };
144 
146 
147 }
148 
149 // STATISTICS: test-core
IntVarBranch INT_VAR_NONE(void)
Select first unassigned variable.
Definition: var.hpp:108
Gecode::IntVarArray x
An array of integer variables.
static Gecode::Support::RandomGenerator rand
Random number generator.
Definition: test.hh:138
Handle for brancher.
Definition: core.hpp:1157
Integer variable array.
Definition: int.hh:741
virtual Space * copy(bool share)
Copy during cloning.
Computation spaces.
Definition: core.hpp:1362
bool run(void)
Perform actual tests.
void update(Space &, bool share, VarArray< Var > &a)
Update array to be a clone of array a.
Definition: array.hpp:1072
Gecode::IntArgs i(4, 1, 2, 3, 4)
int index(void)
Return random index.
static const int n_b
How many branchers to create.
IntValBranch INT_VAL_MIN(void)
Select smallest value.
Definition: val.hpp:68
Base class for all tests to be run
Definition: test.hh:107
TestSpace(void)
Constructor for creation.
Test for brancher handles
BrancherHandle bh
General test support.
Definition: afc.cpp:43
BrancherHandle(void)
Initialize test.
Space(void)
Default constructor.
Definition: core.cpp:114
SpaceStatus status(StatusStatistics &stat=unused_status)
Query space status.
Definition: core.cpp:252
Gecode::BrancherHandle post(void)
Post arbitrary brancher and return its handle.
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
Gecode toplevel namespace
BrancherHandle branch(Home home, const FloatVarArgs &x, FloatVarBranch vars, FloatValBranch vals, FloatBranchFilter bf, FloatVarValPrint vvp)
Branch over x with variable selection vars and value selection vals.
Definition: branch.cpp:43
void kill(Space &home)
Kill the brancher.
Definition: core.hpp:3098
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.
TestSpace(bool share, TestSpace &s)
Constructor for cloning s.
Space is solved (no brancher left)
Definition: core.hpp:1302