Generated on Sat Feb 7 2015 02:01:27 for Gecode by doxygen 1.8.9.1
brancher-val-sel-commit.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main author:
4  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2012
8  *
9  * Last modified:
10  * $Date: 2013-07-04 17:03:13 +0200 (Thu, 04 Jul 2013) $ by $Author: schulte $
11  * $Revision: 13801 $
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 namespace Gecode {
39 
46  template<class _View, class _Val>
49  public:
51  typedef _View View;
53  typedef _Val Val;
54  public:
56  ValSelCommitBase(Space& home, const ValBranch& vb);
58  ValSelCommitBase(Space& home, bool shared,
61  virtual Val val(const Space& home, View x, int i) = 0;
63  virtual ModEvent commit(Space& home, unsigned int a,
64  View x, int i, Val n) = 0;
66  virtual NGL* ngl(Space& home, unsigned int a,
67  View x, Val n) const = 0;
69  virtual void print(const Space& home, unsigned int a,
70  View x, int i, const Val& n,
71  std::ostream& o) const = 0;
73  virtual ValSelCommitBase<View,Val>* copy(Space& home, bool shared) = 0;
75  virtual bool notice(void) const = 0;
77  virtual void dispose(Space& home) = 0;
79 
80  static void* operator new(size_t s, Space& home);
83  static void operator delete(void* p, Space& home);
85  static void operator delete(void* p);
87  };
88 
90  template<class ValSel, class ValCommit>
91  class ValSelCommit
92  : public ValSelCommitBase<typename ValSel::View,typename ValSel::Val> {
93  protected:
94  typedef typename ValSelCommitBase<typename ValSel::View,
95  typename ValSel::Val>::Val Val;
96  typedef typename ValSelCommitBase<typename ValSel::View,
102  public:
104  ValSelCommit(Space& home, const ValBranch& vb);
106  ValSelCommit(Space& home, bool shared,
109  virtual Val val(const Space& home, View x, int i);
111  virtual ModEvent commit(Space& home, unsigned int a, View x, int i, Val n);
113  virtual NGL* ngl(Space& home, unsigned int a,
114  View x, Val n) const;
116  virtual void print(const Space& home, unsigned int a,
117  View x, int i, const Val& n,
118  std::ostream& o) const;
120  virtual ValSelCommit<ValSel,ValCommit>* copy(Space& home, bool shared);
122  virtual bool notice(void) const;
124  virtual void dispose(Space& home);
125  };
127 
128 
129  template<class View, class Val>
132  template<class View, class Val>
136 
137  template<class View, class Val>
138  forceinline void
140  template<class View, class Val>
141  forceinline void
143  template<class View, class Val>
144  forceinline void*
146  return home.ralloc(s);
147  }
148 
149 
150 
151 
152  template<class ValSel, class ValCommit>
155  const ValBranch& vb)
156  : ValSelCommitBase<View,Val>(home,vb), s(home,vb), c(home,vb) {}
157 
158  template<class ValSel, class ValCommit>
162  : ValSelCommitBase<View,Val>(home,shared,vsc),
163  s(home,shared,vsc.s), c(home,shared,vsc.c) {}
164 
165  template<class ValSel, class ValCommit>
168  return s.val(home,x,i);
169  }
170 
171  template<class ValSel, class ValCommit>
172  ModEvent
174  View x, int i, Val n) {
175  return c.commit(home,a,x,i,n);
176  }
177 
178  template<class ValSel, class ValCommit>
179  NGL*
181  View x, Val n) const {
182  return c.ngl(home, a, x, n);
183  }
184 
185  template<class ValSel, class ValCommit>
186  void
187  ValSelCommit<ValSel,ValCommit>::print(const Space& home, unsigned int a,
188  View x, int i, const Val& n,
189  std::ostream& o) const {
190  c.print(home,a,x,i,n,o);
191  }
192 
193  template<class ValSel, class ValCommit>
196  return new (home) ValSelCommit<ValSel,ValCommit>(home,shared,*this);
197  }
198 
199  template<class ValSel, class ValCommit>
200  bool
202  return s.notice() || c.notice();
203  }
204 
205  template<class ValSel, class ValCommit>
206  void
208  s.dispose(home);
209  c.dispose(home);
210  }
211 
212 }
213 
214 // STATISTICS: kernel-branch
virtual void dispose(Space &home)
Delete value selection.
ValSelCommitBase< typename ValSel::View, typename ValSel::Val >::Val Val
Class for value selection and commit.
virtual bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
_View View
View type.
ValSelCommitBase(Space &home, const ValBranch &vb)
Constructor for initialization.
_Val Val
Value type.
ValCommit c
The commit object used.
int ModEvent
Type for modification events.
Definition: core.hpp:146
virtual void dispose(Space &home)=0
Delete value selection.
Computation spaces.
Definition: core.hpp:1362
Base class for value selection and commit.
virtual Val val(const Space &home, View x, int i)
Return value of view x at position i.
Base class for value commit.
Gecode::FloatVal c(-8, 8)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
virtual void print(const Space &home, unsigned int a, View x, int i, const Val &n, std::ostream &o) const =0
Print on o branch for alternative a, view x at position i, and value n.
ValSel s
The value selection object used.
ValSelCommit(Space &home, const ValBranch &vb)
Constructor for initialization.
virtual ValSelCommit< ValSel, ValCommit > * copy(Space &home, bool shared)
Perform cloning.
virtual ModEvent commit(Space &home, unsigned int a, View x, int i, Val n)=0
Commit view x at position i to value n for alternative a.
Value branching information.
Definition: branch-val.hpp:44
ValSelCommitBase< typename ValSel::View, typename ValSel::Val >::View View
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
virtual NGL * ngl(Space &home, unsigned int a, View x, Val n) const =0
Create no-good literal for choice c and alternative a.
#define forceinline
Definition: config.hpp:132
virtual ValSelCommitBase< View, Val > * copy(Space &home, bool shared)=0
Perform cloning.
virtual NGL * ngl(Space &home, unsigned int a, View x, Val n) const
Create no-good literal for choice c and alternative a.
virtual bool notice(void) const =0
Whether dispose must always be called (that is, notice is needed)
bool shared(const ConstView< ViewA > &, const ConstView< ViewB > &)
Test whether views share same variable.
Definition: view.hpp:662
Gecode toplevel namespace
virtual ModEvent commit(Space &home, unsigned int a, View x, int i, Val n)
Commit view x at position i to value n for alternative a.
virtual Val val(const Space &home, View x, int i)=0
Return value of view x at position i.
virtual void print(const Space &home, unsigned int a, View x, int i, const Val &n, std::ostream &o) const
Print on o branch for alternative a, view x at position i, and value n.
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.
Base class for value selection.
No-good literal recorded during search.
Definition: core.hpp:971