Generated on Thu Apr 5 2018 19:44:19 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  * 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 { namespace Int { namespace Branch {
39 
42  private:
44  class PosMin {
45  public:
47  unsigned int pos;
49  int min;
50  };
52  unsigned int n;
54  PosMin* pm;
55  public:
58  PosValuesChoice(const Brancher& b, const Pos& p, IntView x);
61  PosValuesChoice(const Brancher& b, unsigned int alt, Pos p, Archive& e);
63  int val(unsigned int a) const;
66  virtual ~PosValuesChoice(void);
69  virtual void archive(Archive& e) const;
70  };
71 
72  forceinline int
73  PosValuesChoice::val(unsigned int a) const {
74  PosMin* l = &pm[0];
75  PosMin* r = &pm[n-1];
76  while (true) {
77  PosMin* m = l + (r-l)/2;
78  if (a < m->pos) {
79  r=m-1;
80  } else if (a >= (m+1)->pos) {
81  l=m+1;
82  } else {
83  return m->min + static_cast<int>(a - m->pos);
84  }
85  }
87  return 0;
88  }
89 
90 
91  template<int n, bool min, class Filter, class Print>
95  ViewSel<IntView>* vs[n],
96  IntBranchFilter bf,
97  IntVarValPrint vvp)
98  : ViewBrancher<IntView,Filter,n>(home,x,vs,bf), p(vvp) {
99  if (p.notice())
100  home.notice(*this,AP_DISPOSE,true);
101  }
102 
103  template<int n, bool min, class Filter, class Print>
104  forceinline void
108  IntBranchFilter bf,
109  IntVarValPrint vvp) {
110  (void) new (home) ViewValuesBrancher<n,min,Filter,Print>(home,x,vs,bf,vvp);
111  }
112 
113  template<int n, bool min, class Filter, class Print>
117  : ViewBrancher<IntView,Filter,n>(home,b), p(b.p) {}
118 
119  template<int n, bool min, class Filter, class Print>
120  Actor*
123  (home,*this);
124  }
125 
126  template<int n, bool min, class Filter, class Print>
127  const Choice*
130  return new PosValuesChoice(*this,p,
132  }
133 
134  template<int n, bool min, class Filter, class Print>
135  const Choice*
137  (const Space& home, Archive& e) {
138  (void) home;
139  int p;
140  unsigned int a;
141  e >> p >> a;
142  return new PosValuesChoice(*this,a,p,e);
143  }
144 
145  template<int n, bool min, class Filter, class Print>
146  ExecStatus
148  unsigned int a) {
149  const PosValuesChoice& pvc
150  = static_cast<const PosValuesChoice&>(c);
152  unsigned int b = min ? a : (pvc.alternatives() - 1 - a);
153  return me_failed(x.eq(home,pvc.val(b))) ? ES_FAILED : ES_OK;
154  }
155 
156  template<int n, bool min, class Filter, class Print>
157  NGL*
159  unsigned int a) const {
160  const PosValuesChoice& pvc
161  = static_cast<const PosValuesChoice&>(c);
163  unsigned int b = min ? a : (pvc.alternatives() - 1 - a);
164  return new (home) EqNGL<IntView>(home,x,pvc.val(b));
165  }
166 
167  template<int n, bool min, class Filter, class Print>
168  void
170  const Choice& c,
171  unsigned int a,
172  std::ostream& o) const {
173  const PosValuesChoice& pvc
174  = static_cast<const PosValuesChoice&>(c);
176  unsigned int b = min ? a : (pvc.alternatives() - 1 - a);
177  int nn = pvc.val(b);
178  if (p)
179  p(home,*this,a,x,pvc.pos().pos,nn,o);
180  else
181  o << "var[" << pvc.pos().pos << "] = " << nn;
182  }
183 
184  template<int n, bool min, class Filter, class Print>
185  forceinline size_t
187  if (p.notice())
188  home.ignore(*this,AP_DISPOSE,true);
191  }
192 
193  template<int n, bool min>
194  forceinline void
197  IntBranchFilter bf,
198  IntVarValPrint vvp) {
199  if (bf) {
200  if (vvp) {
203  ::post(home,x,vs,bf,vvp);
204  } else {
207  ::post(home,x,vs,bf,vvp);
208  }
209  } else {
210  if (vvp) {
213  ::post(home,x,vs,bf,vvp);
214  } else {
217  ::post(home,x,vs,bf,vvp);
218  }
219  }
220  }
221 
222 
223 }}}
224 
225 // STATISTICS: int-branch
unsigned int alternatives(void) const
Return number of alternatives.
Definition: core.hpp:3640
ViewValuesBrancher(Space &home, ViewValuesBrancher &b)
Constructor for cloning b.
NNF * l
Left subtree.
Definition: bool-expr.cpp:244
Actor must always be disposed.
Definition: core.hpp:554
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition: int.hpp:160
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:82
bool pos(const View &x)
Test whether x is postive.
Definition: mult.hpp:45
virtual const Choice * choice(Space &home)
Return choice.
ViewArray< IntView > x
Views to branch on.
Definition: view.hpp:87
#define forceinline
Definition: config.hpp:182
Computation spaces.
Definition: core.hpp:1668
Class storing a print function.
Definition: print.hpp:51
const Pos & pos(void) const
Return position in array.
Definition: view.hpp:130
No-good literal for equality.
Definition: branch.hh:411
Class without print function.
Definition: print.hpp:77
Brancher by view and values selection
Definition: branch.hh:626
Base-class for both propagators and branchers.
Definition: core.hpp:620
ViewSel< IntView > * vs[n]
View selection objects.
Definition: view.hpp:91
Pos pos(Space &home)
Return position information.
Definition: view.hpp:177
Gecode::FloatVal c(-8, 8)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Base-class for branchers.
Definition: core.hpp:1368
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Execution has resulted in failure.
Definition: core.hpp:466
virtual Actor * copy(Space &home)
Perform cloning.
Choice storing position and values for integer views
Definition: view-values.hpp:41
Choices storing position
Definition: view.hpp:59
std::function< bool(const Space &home, IntVar x, int i)> IntBranchFilter
Branch filter function type for integer variables.
Definition: int.hh:3973
Position information.
Definition: view.hpp:48
void notice(Actor &a, ActorProperty p, bool duplicate=false)
Notice actor property.
Definition: core.hpp:3139
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:4349
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:769
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:71
struct Gecode::@585::NNF::@62::@63 b
For binary nodes (and, or, eqv)
Integer view for integer variables.
Definition: view.hpp:129
void ignore(Actor &a, ActorProperty p, bool duplicate=false)
Ignore actor property.
Definition: core.hpp:3944
static void post(Home home, ViewArray< IntView > &x, ViewSel< IntView > *vs[n], IntBranchFilter bf, IntVarValPrint vvp)
Post function for creation.
struct Gecode::@585::NNF::@62::@64 a
For atomic nodes.
Choice for performing commit
Definition: core.hpp:1338
Archive representation
Definition: archive.hpp:46
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:464
virtual size_t dispose(Space &home)
Delete brancher and return its size.
Post propagator for SetVar x
Definition: set.hh:769
Execution is okay.
Definition: core.hpp:468
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:73
#define GECODE_VTABLE_EXPORT
Definition: support.hh:76
const int pos
Position of view.
Definition: view.hpp:51
#define GECODE_INT_EXPORT
Definition: int.hh:81
Home class for posting propagators
Definition: core.hpp:846
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
void postviewvaluesbrancher(Home home, ViewArray< IntView > &x, ViewSel< IntView > *vs[n], IntBranchFilter bf, IntVarValPrint vvp)
Post brancher for view and values.
bool me_failed(ModEvent me)
Check whether modification event me is failed.
Definition: modevent.hpp:58
No-good literal recorded during search.
Definition: core.hpp:1266