Generated on Sat Feb 7 2015 02:01:15 for Gecode by doxygen 1.8.9.1
branch.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  * Mikael Lagerkvist <lagerkvist@gecode.org>
6  *
7  * Copyright:
8  * Christian Schulte, 2008
9  * Mikael Lagerkvist, 2008
10  *
11  * Last modified:
12  * $Date: 2013-11-14 14:35:45 +0100 (Thu, 14 Nov 2013) $ by $Author: schulte $
13  * $Revision: 14073 $
14  *
15  * This file is part of Gecode, the generic constraint
16  * development environment:
17  * http://www.gecode.org
18  *
19  * Permission is hereby granted, free of charge, to any person obtaining
20  * a copy of this software and associated documentation files (the
21  * "Software"), to deal in the Software without restriction, including
22  * without limitation the rights to use, copy, modify, merge, publish,
23  * distribute, sublicense, and/or sell copies of the Software, and to
24  * permit persons to whom the Software is furnished to do so, subject to
25  * the following conditions:
26  *
27  * The above copyright notice and this permission notice shall be
28  * included in all copies or substantial portions of the Software.
29  *
30  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37  *
38  */
39 
40 #include <gecode/kernel.hh>
41 
42 namespace Gecode {
43 
46  protected:
49  public:
51  Description(const Brancher& b, unsigned int a) : Choice(b,a) {}
53  virtual size_t size(void) const { return sizeof(Description); }
55  virtual void archive(Archive& e) const {
56  Choice::archive(e);
57  }
58  };
60  void (*f)(Space&);
62  bool done;
64  FunctionBranch(Home home, void (*f0)(Space&))
65  : Brancher(home), f(f0), done(false) {}
67  FunctionBranch(Space& home, bool share, FunctionBranch& b)
68  : Brancher(home,share,b), f(b.f), done(b.done) {}
69  public:
71  virtual bool status(const Space&) const {
72  return !done;
73  }
75  virtual const Choice* choice(Space&) {
76  assert(!done);
77  return new Description(*this,1);
78  }
80  virtual const Choice* choice(const Space&, Archive&) {
81  return new Description(*this,1);
82  }
84  virtual ExecStatus
85  commit(Space& home, const Choice&, unsigned int) {
86  done = true;
87  f(home);
88  return home.failed() ? ES_FAILED : ES_OK;
89  }
91  virtual void
92  print(const Space&, const Choice&, unsigned int,
93  std::ostream& o) const {
94  o << "FunctionBranch(" << f << ")";
95  }
97  virtual Actor* copy(Space& home, bool share) {
98  return new (home) FunctionBranch(home,share,*this);
99  }
101  static BrancherHandle post(Home home, void (*f)(Space&)) {
102  return *new (home) FunctionBranch(home,f);
103  }
104  };
105 
106 
107  BrancherHandle
108  branch(Home home, void (*f)(Space& home)) {
109  if (home.failed())
110  return BrancherHandle();
111  return FunctionBranch::post(home,f);
112  }
113 
114 }
115 
116 // STATISTICS: kernel-branch
bool done
Call function just once.
Definition: branch.cpp:62
virtual const Choice * choice(const Space &, Archive &)
Return choice.
Definition: branch.cpp:80
Handle for brancher.
Definition: core.hpp:1157
Description(const Brancher &b, unsigned int a)
Initialize description for brancher b, number of alternatives a.
Definition: branch.cpp:51
Computation spaces.
Definition: core.hpp:1362
virtual void archive(Archive &e) const
Archive into e.
Definition: branch.cpp:55
bool failed(void) const
Check whether space is failed.
Definition: core.hpp:3442
Base-class for both propagators and branchers.
Definition: core.hpp:666
virtual Actor * copy(Space &home, bool share)
Copy brancher.
Definition: branch.cpp:97
virtual void print(const Space &, const Choice &, unsigned int, std::ostream &o) const
Print explanation.
Definition: branch.cpp:92
virtual const Choice * choice(Space &)
Return choice.
Definition: branch.cpp:75
Base-class for branchers.
Definition: core.hpp:1071
virtual ExecStatus commit(Space &home, const Choice &, unsigned int)
Perform commit.
Definition: branch.cpp:85
Execution has resulted in failure.
Definition: core.hpp:525
Minimal brancher description storing no information.
Definition: branch.cpp:48
virtual void archive(Archive &e) const
Archive into e.
Definition: core.cpp:670
FunctionBranch(Space &home, bool share, FunctionBranch &b)
Copy constructor.
Definition: branch.cpp:67
#define GECODE_KERNEL_EXPORT
Definition: kernel.hh:70
virtual size_t size(void) const
Report size occupied.
Definition: branch.cpp:53
Choice for performing commit
Definition: core.hpp:1036
Archive representation
Definition: archive.hpp:45
ExecStatus
Definition: core.hpp:523
Execution is okay.
Definition: core.hpp:527
Brancher for calling a function
Definition: branch.cpp:45
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
Gecode toplevel namespace
FunctionBranch(Home home, void(*f0)(Space &))
Construct brancher.
Definition: branch.cpp:64
static BrancherHandle post(Home home, void(*f)(Space &))
Post brancher.
Definition: branch.cpp:101
virtual bool status(const Space &) const
Check status of brancher, return true if alternatives left.
Definition: branch.cpp:71
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
Home class for posting propagators
Definition: core.hpp:717
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.