Generated on Thu Jan 31 2019 20:56:39 for Gecode by doxygen 1.8.15
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: 2017-02-23 01:27:48 +0100 (Thu, 23 Feb 2017) $ by $Author: tack $
11  * $Revision: 15472 $
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 typename View::VarType Var;
55  typedef _Val Val;
56  public:
58  ValSelCommitBase(Space& home, const ValBranch<Var>& vb);
60  ValSelCommitBase(Space& home, bool shared,
63  virtual Val val(const Space& home, View x, int i) = 0;
65  virtual ModEvent commit(Space& home, unsigned int a,
66  View x, int i, Val n) = 0;
68  virtual NGL* ngl(Space& home, unsigned int a,
69  View x, Val n) const = 0;
71  virtual void print(const Space& home, unsigned int a,
72  View x, int i, const Val& n,
73  std::ostream& o) const = 0;
75  virtual ValSelCommitBase<View,Val>* copy(Space& home, bool shared) = 0;
77  virtual bool notice(void) const = 0;
79  virtual void dispose(Space& home) = 0;
81  virtual ~ValSelCommitBase(void);
83 
84  static void* operator new(size_t s, Space& home);
87  static void operator delete(void* p, Space& home);
89  static void operator delete(void* p);
91  };
92 
94  template<class ValSel, class ValCommit>
96  : public ValSelCommitBase<typename ValSel::View,typename ValSel::Val> {
97  protected:
98  typedef typename ValSelCommitBase<typename ValSel::View,
99  typename ValSel::Val>::Var Var;
100  typedef typename ValSelCommitBase<typename ValSel::View,
102  typedef typename ValSelCommitBase<typename ValSel::View,
108  public:
110  ValSelCommit(Space& home, const ValBranch<Var>& vb);
112  ValSelCommit(Space& home, bool shared,
115  virtual Val val(const Space& home, View x, int i);
117  virtual ModEvent commit(Space& home, unsigned int a, View x, int i, Val n);
119  virtual NGL* ngl(Space& home, unsigned int a,
120  View x, Val n) const;
122  virtual void print(const Space& home, unsigned int a,
123  View x, int i, const Val& n,
124  std::ostream& o) const;
126  virtual ValSelCommit<ValSel,ValCommit>* copy(Space& home, bool shared);
128  virtual bool notice(void) const;
130  virtual void dispose(Space& home);
131  };
133 
134 
135  template<class View, class Val>
138  const ValBranch<Var>&) {}
139  template<class View, class Val>
143  template<class View, class Val>
145 
146  template<class View, class Val>
147  forceinline void
149  template<class View, class Val>
150  forceinline void
152  template<class View, class Val>
153  forceinline void*
155  return home.ralloc(s);
156  }
157 
158 
159 
160 
161  template<class ValSel, class ValCommit>
164  const ValBranch<Var>& vb)
165  : ValSelCommitBase<View,Val>(home,vb), s(home,vb), c(home,vb) {}
166 
167  template<class ValSel, class ValCommit>
171  : ValSelCommitBase<View,Val>(home,shared,vsc),
172  s(home,shared,vsc.s), c(home,shared,vsc.c) {}
173 
174  template<class ValSel, class ValCommit>
177  return s.val(home,x,i);
178  }
179 
180  template<class ValSel, class ValCommit>
181  ModEvent
183  View x, int i, Val n) {
184  return c.commit(home,a,x,i,n);
185  }
186 
187  template<class ValSel, class ValCommit>
188  NGL*
190  View x, Val n) const {
191  return c.ngl(home, a, x, n);
192  }
193 
194  template<class ValSel, class ValCommit>
195  void
196  ValSelCommit<ValSel,ValCommit>::print(const Space& home, unsigned int a,
197  View x, int i, const Val& n,
198  std::ostream& o) const {
199  c.print(home,a,x,i,n,o);
200  }
201 
202  template<class ValSel, class ValCommit>
205  return new (home) ValSelCommit<ValSel,ValCommit>(home,shared,*this);
206  }
207 
208  template<class ValSel, class ValCommit>
209  bool
211  return s.notice() || c.notice();
212  }
213 
214  template<class ValSel, class ValCommit>
215  void
217  s.dispose(home);
218  c.dispose(home);
219  }
220 
221 }
222 
223 // 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.
virtual ~ValSelCommitBase(void)
Unused destructor.
ValSelCommitBase< typename ValSel::View, typename ValSel::Val >::Var Var
_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:1748
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.
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
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.
ValSelCommit(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
ValSel s
The value selection object used.
ValSelCommitBase(Space &home, const ValBranch< Var > &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:45
ValSelCommitBase< typename ValSel::View, typename ValSel::Val >::View View
virtual NGL * ngl(Space &home, unsigned int a, View x, Val n) const =0
Create no-good literal for choice c and alternative a.
View::VarType Var
Corresponding variable type.
#define forceinline
Definition: config.hpp:173
virtual ValSelCommitBase< View, Val > * copy(Space &home, bool shared)=0
Perform cloning.
Post propagator for SetVar x
Definition: set.hh:784
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:702
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:1342