Generated on Thu Mar 16 2017 03:24:22 for Gecode by doxygen 1.8.13
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: 2016-06-18 14:20:49 +0200 (Sat, 18 Jun 2016) $ by $Author: schulte $
11  * $Revision: 15118 $
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  virtual ~ValSelCommitBase(void);
81 
82  static void* operator new(size_t s, Space& home);
85  static void operator delete(void* p, Space& home);
87  static void operator delete(void* p);
89  };
90 
92  template<class ValSel, class ValCommit>
94  : public ValSelCommitBase<typename ValSel::View,typename ValSel::Val> {
95  protected:
96  typedef typename ValSelCommitBase<typename ValSel::View,
97  typename ValSel::Val>::Val Val;
98  typedef typename ValSelCommitBase<typename ValSel::View,
104  public:
106  ValSelCommit(Space& home, const ValBranch& vb);
108  ValSelCommit(Space& home, bool shared,
111  virtual Val val(const Space& home, View x, int i);
113  virtual ModEvent commit(Space& home, unsigned int a, View x, int i, Val n);
115  virtual NGL* ngl(Space& home, unsigned int a,
116  View x, Val n) const;
118  virtual void print(const Space& home, unsigned int a,
119  View x, int i, const Val& n,
120  std::ostream& o) const;
122  virtual ValSelCommit<ValSel,ValCommit>* copy(Space& home, bool shared);
124  virtual bool notice(void) const;
126  virtual void dispose(Space& home);
127  };
129 
130 
131  template<class View, class Val>
134  template<class View, class Val>
138  template<class View, class Val>
140 
141  template<class View, class Val>
142  forceinline void
144  template<class View, class Val>
145  forceinline void
147  template<class View, class Val>
148  forceinline void*
150  return home.ralloc(s);
151  }
152 
153 
154 
155 
156  template<class ValSel, class ValCommit>
159  const ValBranch& vb)
160  : ValSelCommitBase<View,Val>(home,vb), s(home,vb), c(home,vb) {}
161 
162  template<class ValSel, class ValCommit>
166  : ValSelCommitBase<View,Val>(home,shared,vsc),
167  s(home,shared,vsc.s), c(home,shared,vsc.c) {}
168 
169  template<class ValSel, class ValCommit>
172  return s.val(home,x,i);
173  }
174 
175  template<class ValSel, class ValCommit>
176  ModEvent
178  View x, int i, Val n) {
179  return c.commit(home,a,x,i,n);
180  }
181 
182  template<class ValSel, class ValCommit>
183  NGL*
185  View x, Val n) const {
186  return c.ngl(home, a, x, n);
187  }
188 
189  template<class ValSel, class ValCommit>
190  void
191  ValSelCommit<ValSel,ValCommit>::print(const Space& home, unsigned int a,
192  View x, int i, const Val& n,
193  std::ostream& o) const {
194  c.print(home,a,x,i,n,o);
195  }
196 
197  template<class ValSel, class ValCommit>
200  return new (home) ValSelCommit<ValSel,ValCommit>(home,shared,*this);
201  }
202 
203  template<class ValSel, class ValCommit>
204  bool
206  return s.notice() || c.notice();
207  }
208 
209  template<class ValSel, class ValCommit>
210  void
212  s.dispose(home);
213  c.dispose(home);
214  }
215 
216 }
217 
218 // 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.
_View View
View type.
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
ValSelCommitBase(Space &home, const ValBranch &vb)
Constructor for initialization.
virtual ~ValSelCommitBase(void)
Unused destructor.
_Val Val
Value type.
ValCommit c
The commit object used.
int ModEvent
Type for modification events.
Definition: core.hpp:142
virtual void dispose(Space &home)=0
Delete value selection.
Computation spaces.
Definition: core.hpp:1672
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.
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)
struct Gecode::@554::NNF::@60::@62 a
For atomic nodes.
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.
void dispose(Space &home)
Delete value commit.
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 bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
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:173
virtual ValSelCommitBase< View, Val > * copy(Space &home, bool shared)=0
Perform cloning.
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:690
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 NGL * ngl(Space &home, unsigned int a, View x, Val n) const
Create no-good literal for choice c and alternative a.
Base class for value selection.
No-good literal recorded during search.
Definition: core.hpp:1260