Generated on Tue Jan 19 2021 06:15:49 for Gecode by doxygen 1.8.13
view-values.hpp
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  *
6  * Copyright:
7  * Christian Schulte, 2008
8  *
9  * This file is part of Gecode, the generic constraint
10  * development environment:
11  * http://www.gecode.org
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining
14  * a copy of this software and associated documentation files (the
15  * "Software"), to deal in the Software without restriction, including
16  * without limitation the rights to use, copy, modify, merge, publish,
17  * distribute, sublicense, and/or sell copies of the Software, and to
18  * permit persons to whom the Software is furnished to do so, subject to
19  * the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be
22  * included in all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31  *
32  */
33 
34 namespace Gecode { namespace Int { namespace Branch {
35 
38  private:
40  class PosMin {
41  public:
43  unsigned int pos;
45  int min;
46  };
48  unsigned int n;
50  PosMin* pm;
51  public:
54  PosValuesChoice(const Brancher& b, const Pos& p, IntView x);
57  PosValuesChoice(const Brancher& b, unsigned int alt, Pos p, Archive& e);
59  int val(unsigned int a) const;
62  virtual ~PosValuesChoice(void);
65  virtual void archive(Archive& e) const;
66  };
67 
68  forceinline int
69  PosValuesChoice::val(unsigned int a) const {
70  PosMin* l = &pm[0];
71  PosMin* r = &pm[n-1];
72  while (true) {
73  PosMin* m = l + (r-l)/2;
74  if (a < m->pos) {
75  r=m-1;
76  } else if (a >= (m+1)->pos) {
77  l=m+1;
78  } else {
79  return m->min + static_cast<int>(a - m->pos);
80  }
81  }
83  return 0;
84  }
85 
86 
87  template<int n, bool min, class Filter, class Print>
91  ViewSel<IntView>* vs[n],
92  IntBranchFilter bf,
93  IntVarValPrint vvp)
94  : ViewBrancher<IntView,Filter,n>(home,x,vs,bf), p(vvp) {
95  if (p.notice())
96  home.notice(*this,AP_DISPOSE,true);
97  }
98 
99  template<int n, bool min, class Filter, class Print>
100  forceinline void
104  IntBranchFilter bf,
105  IntVarValPrint vvp) {
106  (void) new (home) ViewValuesBrancher<n,min,Filter,Print>(home,x,vs,bf,vvp);
107  }
108 
109  template<int n, bool min, class Filter, class Print>
113  : ViewBrancher<IntView,Filter,n>(home,b), p(b.p) {}
114 
115  template<int n, bool min, class Filter, class Print>
116  Actor*
119  (home,*this);
120  }
121 
122  template<int n, bool min, class Filter, class Print>
123  const Choice*
126  return new PosValuesChoice(*this,p,
128  }
129 
130  template<int n, bool min, class Filter, class Print>
131  const Choice*
133  (const Space& home, Archive& e) {
134  (void) home;
135  int p;
136  unsigned int a;
137  e >> p >> a;
138  return new PosValuesChoice(*this,a,p,e);
139  }
140 
141  template<int n, bool min, class Filter, class Print>
142  ExecStatus
144  unsigned int a) {
145  const PosValuesChoice& pvc
146  = static_cast<const PosValuesChoice&>(c);
148  unsigned int b = min ? a : (pvc.alternatives() - 1 - a);
149  return me_failed(x.eq(home,pvc.val(b))) ? ES_FAILED : ES_OK;
150  }
151 
152  template<int n, bool min, class Filter, class Print>
153  NGL*
155  unsigned int a) const {
156  const PosValuesChoice& pvc
157  = static_cast<const PosValuesChoice&>(c);
159  unsigned int b = min ? a : (pvc.alternatives() - 1 - a);
160  return new (home) EqNGL<IntView>(home,x,pvc.val(b));
161  }
162 
163  template<int n, bool min, class Filter, class Print>
164  void
166  const Choice& c,
167  unsigned int a,
168  std::ostream& o) const {
169  const PosValuesChoice& pvc
170  = static_cast<const PosValuesChoice&>(c);
172  unsigned int b = min ? a : (pvc.alternatives() - 1 - a);
173  int nn = pvc.val(b);
174  if (p)
175  p(home,*this,a,x,pvc.pos().pos,nn,o);
176  else
177  o << "var[" << pvc.pos().pos << "] = " << nn;
178  }
179 
180  template<int n, bool min, class Filter, class Print>
181  forceinline size_t
183  if (p.notice())
184  home.ignore(*this,AP_DISPOSE,true);
187  }
188 
189  template<int n, bool min>
190  forceinline void
193  IntBranchFilter bf,
194  IntVarValPrint vvp) {
195  if (bf) {
196  if (vvp) {
199  ::post(home,x,vs,bf,vvp);
200  } else {
203  ::post(home,x,vs,bf,vvp);
204  }
205  } else {
206  if (vvp) {
209  ::post(home,x,vs,bf,vvp);
210  } else {
213  ::post(home,x,vs,bf,vvp);
214  }
215  }
216  }
217 
218 
219 }}}
220 
221 // STATISTICS: int-branch
unsigned int alternatives(void) const
Return number of alternatives.
Definition: core.hpp:3697
ViewValuesBrancher(Space &home, ViewValuesBrancher &b)
Constructor for cloning b.
NNF * l
Left subtree.
Definition: bool-expr.cpp:240
Actor must always be disposed.
Definition: core.hpp:561
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition: int.hpp:166
virtual void print(const Space &home, const Choice &c, unsigned int a, std::ostream &o) const
Print branch for choice c and alternative a.
Generic brancher by view selection.
Definition: view.hpp:78
bool pos(const View &x)
Test whether x is postive.
Definition: mult.hpp:41
virtual const Choice * choice(Space &home)
Return choice.
ViewArray< IntView > x
Views to branch on.
Definition: view.hpp:83
#define forceinline
Definition: config.hpp:185
Computation spaces.
Definition: core.hpp:1701
Class storing a print function.
Definition: print.hpp:47
const Pos & pos(void) const
Return position in array.
Definition: view.hpp:126
No-good literal for equality.
Definition: branch.hh:411
Class without print function.
Definition: print.hpp:73
Brancher by view and values selection
Definition: branch.hh:626
Base-class for both propagators and branchers.
Definition: core.hpp:627
ViewSel< IntView > * vs[n]
View selection objects.
Definition: view.hpp:87
Pos pos(Space &home)
Return position information.
Definition: view.hpp:173
Gecode::FloatVal c(-8, 8)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
Base-class for branchers.
Definition: core.hpp:1401
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
Execution has resulted in failure.
Definition: core.hpp:473
virtual Actor * copy(Space &home)
Perform cloning.
struct Gecode::@593::NNF::@62::@63 b
For binary nodes (and, or, eqv)
Choice storing position and values for integer views
Definition: view-values.hpp:37
Choices storing position
Definition: view.hpp:55
std::function< bool(const Space &home, IntVar x, int i)> IntBranchFilter
Branch filter function type for integer variables.
Definition: int.hh:4113
Position information.
Definition: view.hpp:44
void notice(Actor &a, ActorProperty p, bool duplicate=false)
Notice actor property.
Definition: core.hpp:3176
std::function< void(const Space &home, const Brancher &b, unsigned int a, IntVar x, int i, const int &n, std::ostream &o)> IntVarValPrint
Function type for printing branching alternatives for integer variables.
Definition: int.hh:4489
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:767
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:67
Integer view for integer variables.
Definition: view.hpp:129
void ignore(Actor &a, ActorProperty p, bool duplicate=false)
Ignore actor property.
Definition: core.hpp:4001
static void post(Home home, ViewArray< IntView > &x, ViewSel< IntView > *vs[n], IntBranchFilter bf, IntVarValPrint vvp)
Post function for creation.
Choice for performing commit
Definition: core.hpp:1371
Archive representation
Definition: archive.hpp:42
virtual NGL * ngl(Space &home, const Choice &c, unsigned int a) const
Create no-good literal for choice c and alternative a.
ExecStatus
Definition: core.hpp:471
virtual size_t dispose(Space &home)
Delete brancher and return its size.
Post propagator for SetVar x
Definition: set.hh:767
Execution is okay.
Definition: core.hpp:475
virtual ExecStatus commit(Space &home, const Choice &c, unsigned int a)
Perform commit for choice c and alternative a.
Gecode toplevel namespace
int val(unsigned int a) const
Return value to branch with for alternative a.
Definition: view-values.hpp:69
#define GECODE_VTABLE_EXPORT
Definition: support.hh:72
const int pos
Position of view.
Definition: view.hpp:47
#define GECODE_INT_EXPORT
Definition: int.hh:81
Home class for posting propagators
Definition: core.hpp:853
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:56
void postviewvaluesbrancher(Home home, ViewArray< IntView > &x, ViewSel< IntView > *vs[n], IntBranchFilter bf, IntVarValPrint vvp)
Post brancher for view and values.
struct Gecode::@593::NNF::@62::@64 a
For atomic nodes.
bool me_failed(ModEvent me)
Check whether modification event me is failed.
Definition: modevent.hpp:54
No-good literal recorded during search.
Definition: core.hpp:1299