Generated on Thu Apr 5 2018 19:44:19 for Gecode by doxygen 1.8.13
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$ by $Author$
11  * $Revision$
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);
62  virtual Val val(const Space& home, View x, int i) = 0;
64  virtual ModEvent commit(Space& home, unsigned int a,
65  View x, int i, Val n) = 0;
67  virtual NGL* ngl(Space& home, unsigned int a,
68  View x, Val n) const = 0;
70  virtual void print(const Space& home, unsigned int a,
71  View x, int i, const Val& n,
72  std::ostream& o) const = 0;
74  virtual ValSelCommitBase<View,Val>* copy(Space& home) = 0;
76  virtual bool notice(void) const = 0;
78  virtual void dispose(Space& home) = 0;
80  virtual ~ValSelCommitBase(void);
82 
83  static void* operator new(size_t s, Space& home);
86  static void operator delete(void* p, Space& home);
88  static void operator delete(void* p);
90  };
91 
93  template<class ValSel, class ValCommit>
95  : public ValSelCommitBase<typename ValSel::View,typename ValSel::Val> {
96  protected:
97  typedef typename ValSelCommitBase<typename ValSel::View,
98  typename ValSel::Val>::Var Var;
99  typedef typename ValSelCommitBase<typename ValSel::View,
101  typedef typename ValSelCommitBase<typename ValSel::View,
107  public:
109  ValSelCommit(Space& home, const ValBranch<Var>& vb);
113  virtual Val val(const Space& home, View x, int i);
115  virtual ModEvent commit(Space& home, unsigned int a, View x, int i, Val n);
117  virtual NGL* ngl(Space& home, unsigned int a,
118  View x, Val n) const;
120  virtual void print(const Space& home, unsigned int a,
121  View x, int i, const Val& n,
122  std::ostream& o) const;
124  virtual ValSelCommit<ValSel,ValCommit>* copy(Space& home);
126  virtual bool notice(void) const;
128  virtual void dispose(Space& home);
129  };
131 
132 
133  template<class View, class Val>
136  const ValBranch<Var>&) {}
137  template<class View, class Val>
141  template<class View, class Val>
143 
144  template<class View, class Val>
145  forceinline void
147  template<class View, class Val>
148  forceinline void
150  template<class View, class Val>
151  forceinline void*
153  return home.ralloc(s);
154  }
155 
156 
157 
158 
159  template<class ValSel, class ValCommit>
162  const ValBranch<Var>& vb)
163  : ValSelCommitBase<View,Val>(home,vb), s(home,vb), c(home,vb) {}
164 
165  template<class ValSel, class ValCommit>
169  : ValSelCommitBase<View,Val>(home,vsc),
170  s(home,vsc.s), c(home,vsc.c) {}
171 
172  template<class ValSel, class ValCommit>
175  return s.val(home,x,i);
176  }
177 
178  template<class ValSel, class ValCommit>
179  ModEvent
181  View x, int i, Val n) {
182  return c.commit(home,a,x,i,n);
183  }
184 
185  template<class ValSel, class ValCommit>
186  NGL*
188  View x, Val n) const {
189  return c.ngl(home, a, x, n);
190  }
191 
192  template<class ValSel, class ValCommit>
193  void
194  ValSelCommit<ValSel,ValCommit>::print(const Space& home, unsigned int a,
195  View x, int i, const Val& n,
196  std::ostream& o) const {
197  c.print(home,a,x,i,n,o);
198  }
199 
200  template<class ValSel, class ValCommit>
203  return new (home) ValSelCommit<ValSel,ValCommit>(home,*this);
204  }
205 
206  template<class ValSel, class ValCommit>
207  bool
209  return s.notice() || c.notice();
210  }
211 
212  template<class ValSel, class ValCommit>
213  void
215  s.dispose(home);
216  c.dispose(home);
217  }
218 
219 }
220 
221 // 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.
Definition: val-sel.hpp:51
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition: val-commit.hpp:111
virtual ~ValSelCommitBase(void)
Unused destructor.
ValSelCommitBase< typename ValSel::View, typename ValSel::Val >::Var Var
_Val Val
Value type.
Definition: val-sel.hpp:55
ValCommit c
The commit object used.
int ModEvent
Type for modification events.
Definition: core.hpp:64
virtual void dispose(Space &home)=0
Delete value selection.
#define forceinline
Definition: config.hpp:182
virtual ValSelCommit< ValSel, ValCommit > * copy(Space &home)
Perform cloning.
Computation spaces.
Definition: core.hpp:1668
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.
Definition: val-commit.hpp:48
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.
void dispose(Space &home)
Delete value commit.
Definition: val-commit.hpp:116
ValSel s
The value selection object used.
ValSelCommitBase(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
virtual ValSelCommitBase< View, Val > * copy(Space &home)=0
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: 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.
struct Gecode::@585::NNF::@62::@64 a
For atomic nodes.
View::VarType Var
Corresponding variable type.
Post propagator for SetVar x
Definition: set.hh:769
virtual bool notice(void) const =0
Whether dispose must always be called (that is, notice is needed)
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.
Definition: val-sel.hpp:48
No-good literal recorded during search.
Definition: core.hpp:1266