Generated on Sat Feb 7 2015 02:01:20 for Gecode by doxygen 1.8.9.1
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: 2013-07-04 17:03:13 +0200 (Thu, 04 Jul 2013) $ by $Author: schulte $
11  * $Revision: 13801 $
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 size_t size(void) const;
69  virtual ~PosValuesChoice(void);
72  virtual void archive(Archive& e) const;
73  };
74 
75  forceinline int
76  PosValuesChoice::val(unsigned int a) const {
77  PosMin* l = &pm[0];
78  PosMin* r = &pm[n-1];
79  while (true) {
80  PosMin* m = l + (r-l)/2;
81  if (a < m->pos) {
82  r=m-1;
83  } else if (a >= (m+1)->pos) {
84  l=m+1;
85  } else {
86  return m->min + static_cast<int>(a - m->pos);
87  }
88  }
90  return 0;
91  }
92 
93 
94  template<int n, bool min>
98  ViewSel<IntView>* vs[n],
99  BranchFilter bf, IntVarValPrint vvp0)
100  : ViewBrancher<IntView,n>(home,x,vs,bf), vvp(vvp0) {}
101 
102  template<int n, bool min>
105  ViewSel<IntView>* vs[n],
106  BranchFilter bf, IntVarValPrint vvp) {
107  return *new (home) ViewValuesBrancher<n,min>(home,x,vs,bf,vvp);
108  }
109 
110  template<int n, bool min>
114  : ViewBrancher<IntView,n>(home,shared,b), vvp(b.vvp) {}
115 
116  template<int n, bool min>
117  Actor*
119  return new (home) ViewValuesBrancher<n,min>(home,shared,*this);
120  }
121 
122  template<int n, bool min>
123  const Choice*
126  return new PosValuesChoice(*this,p,
128  }
129 
130  template<int n, bool min>
131  const Choice*
133  (void) home;
134  int p;
135  unsigned int a;
136  e >> p >> a;
137  return new PosValuesChoice(*this,a,p,e);
138  }
139 
140  template<int n, bool min>
141  ExecStatus
143  unsigned int a) {
144  const PosValuesChoice& pvc
145  = static_cast<const PosValuesChoice&>(c);
147  unsigned int b = min ? a : (pvc.alternatives() - 1 - a);
148  return me_failed(x.eq(home,pvc.val(b))) ? ES_FAILED : ES_OK;
149  }
150 
151  template<int n, bool min>
152  NGL*
154  unsigned int a) const {
155  const PosValuesChoice& pvc
156  = static_cast<const PosValuesChoice&>(c);
158  unsigned int b = min ? a : (pvc.alternatives() - 1 - a);
159  return new (home) EqNGL<IntView>(home,x,pvc.val(b));
160  }
161 
162  template<int n, bool min>
163  void
165  unsigned int a, std::ostream& o) const {
166  const PosValuesChoice& pvc
167  = static_cast<const PosValuesChoice&>(c);
168  IntVar x(ViewBrancher<IntView,n>::view(pvc.pos()).varimp());
169  unsigned int b = min ? a : (pvc.alternatives() - 1 - a);
170  int nn = pvc.val(b);
171  if (vvp != NULL)
172  vvp(home,*this,a,x,pvc.pos().pos,nn,o);
173  else
174  o << "var[" << pvc.pos().pos << "] = " << nn;
175  }
176 
177 }}}
178 
179 // STATISTICS: int-branch
const Pos & pos(void) const
Return position in array.
int val(unsigned int a) const
Return value to branch with for alternative a.
Definition: view-values.hpp:76
static BrancherHandle post(Home home, ViewArray< IntView > &x, ViewSel< IntView > *vs[n], BranchFilter bf, IntVarValPrint vvp)
Constructor for creation.
NNF * l
Left subtree.
Definition: bool-expr.cpp:244
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition: int.hpp:160
Handle for brancher.
Definition: core.hpp:1157
Generic brancher by view selection.
bool pos(const View &x)
Test whether x is postive.
Definition: mult.hpp:45
unsigned int alternatives(void) const
Return number of alternatives.
Definition: core.hpp:3173
Computation spaces.
Definition: core.hpp:1362
No-good literal for equality.
Definition: branch.hh:421
virtual NGL * ngl(Space &home, const Choice &c, unsigned int a) const
Create no-good literal for choice c and alternative a.
Brancher by view and values selection
Definition: branch.hh:632
Base-class for both propagators and branchers.
Definition: core.hpp:666
Gecode::FloatVal c(-8, 8)
Pos pos(Space &home)
Return position information.
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Base-class for branchers.
Definition: core.hpp:1071
ViewValuesBrancher(Space &home, bool shared, ViewValuesBrancher &b)
Constructor for cloning b.
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Execution has resulted in failure.
Definition: core.hpp:525
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
unsigned int size(I &i)
Size of all ranges of range iterator i.
virtual Actor * copy(Space &home, bool share)
Perform cloning.
Choice storing position and values for integer views
Definition: view-values.hpp:41
Choices storing position
Position information.
virtual const Choice * choice(Space &home)
Return choice.
virtual void print(const Space &home, const Choice &c, unsigned int a, std::ostream &o) const
Print branch for choice c and alternative a.
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:75
Integer view for integer variables.
Definition: view.hpp:129
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Choice for performing commit
Definition: core.hpp:1036
Archive representation
Definition: archive.hpp:45
ExecStatus
Definition: core.hpp:523
Integer variables.
Definition: int.hh:350
void(* IntVarValPrint)(const Space &home, const BrancherHandle &bh, unsigned int a, IntVar x, int i, const int &n, std::ostream &o)
Function type for printing branching alternatives for integer variables.
Definition: int.hh:3778
#define forceinline
Definition: config.hpp:132
Execution is okay.
Definition: core.hpp:527
bool shared(const ConstView< ViewA > &, const ConstView< ViewB > &)
Test whether views share same variable.
Definition: view.hpp:662
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
Gecode toplevel namespace
#define GECODE_VTABLE_EXPORT
Definition: support.hh:76
const int pos
Position of view.
#define GECODE_INT_EXPORT
Definition: int.hh:78
Home class for posting propagators
Definition: core.hpp:717
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
virtual ExecStatus commit(Space &home, const Choice &c, unsigned int a)
Perform commit for choice c and alternative a.
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.
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:971