Generated on Thu Apr 5 2018 19:44:19 for Gecode by doxygen 1.8.13
gpi.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, 2009
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 #include <cmath>
39 
40 namespace Gecode { namespace Kernel {
41 
43  class GPI {
44  public:
46  class Info {
47  public:
49  unsigned int pid;
51  unsigned int gid;
53  double afc;
55  void init(unsigned int pid, unsigned int gid);
56  };
57  private:
59  class Block : public HeapAllocated {
60  public:
62  static const int n_info = 8192;
64  Info info[n_info];
66  Block* next;
68  int free;
70  Block(void);
72  void rescale(void);
73  };
75  Block* b;
77  double invd;
79  unsigned int pid;
81  bool us;
83  Block fst;
86  public:
88  GPI(void);
90  void decay(double d);
92  double decay(void) const;
94  void fail(Info& c);
96  Info* allocate(unsigned int p, unsigned int gid);
98  Info* allocate(unsigned int gid);
100  bool unshare(void);
102  ~GPI(void);
103  };
104 
105 
106  forceinline void
107  GPI::Info::init(unsigned int pid0, unsigned int gid0) {
108  pid=pid0; gid=gid0; afc=1.0;
109  }
110 
111 
113  GPI::Block::Block(void)
114  : next(NULL), free(n_info) {}
115 
116  forceinline void
117  GPI::Block::rescale(void) {
118  for (int i=free; i < n_info; i++)
119  info[i].afc *= Kernel::Config::rescale;
120  }
121 
122 
124  GPI::GPI(void)
125  : b(&fst), invd(1.0), pid(0U), us(false) {}
126 
127  forceinline void
129  m.acquire();
130  c.afc = invd * (c.afc + 1.0);
132  for (Block* i = b; i != NULL; i = i->next)
133  i->rescale();
134  m.release();
135  }
136 
137  forceinline double
138  GPI::decay(void) const {
139  double d;
140  const_cast<GPI&>(*this).m.acquire();
141  d = 1.0 / invd;
142  const_cast<GPI&>(*this).m.release();
143  return d;
144  }
145 
146  forceinline bool
147  GPI::unshare(void) {
148  bool u;
149  m.acquire();
150  u = us; us = true;
151  m.release();
152  return u;
153  }
154 
155  forceinline void
156  GPI::decay(double d) {
157  m.acquire();
158  invd = 1.0 / d;
159  m.release();
160  }
161 
163  GPI::allocate(unsigned int p, unsigned int gid) {
164  Info* c;
165  m.acquire();
166  if (b->free == 0) {
167  Block* n = new Block;
168  n->next = b; b = n;
169  }
170  c = &b->info[--b->free];
171  m.release();
172  c->init(p,gid);
173  return c;
174  }
175 
177  GPI::allocate(unsigned int gid) {
178  Info* c;
179  m.acquire();
180  if (b->free == 0) {
181  Block* n = new Block;
182  n->next = b; b = n;
183  }
184  c = &b->info[--b->free];
185  c->init(pid++,gid);
186  m.release();
187  return c;
188  }
189 
191  GPI::~GPI(void) {
192  Block* n = b;
193  while (n != &fst) {
194  Block* d = n;
195  n = n->next;
196  delete d;
197  }
198  }
199 
200 }}
201 
202 // STATISTICS: kernel-prop
Info * allocate(unsigned int p, unsigned int gid)
Allocate info for existing propagator with pid p.
Definition: gpi.hpp:163
void fail(Info &c)
Increment failure count.
Definition: gpi.hpp:128
const double rescale_limit
Rescale action and afc values when larger than this.
Definition: kernel.hh:105
bool unshare(void)
Provide access to unshare info and set to true.
Definition: gpi.hpp:147
void acquire(void)
Acquire the mutex and possibly block.
Definition: none.hpp:46
double decay(void) const
Return decay factor.
Definition: gpi.hpp:138
#define forceinline
Definition: config.hpp:182
A mutex for mutual exclausion among several threads.
Definition: thread.hpp:105
Gecode::IntSet d(v, 7)
Global propagator information.
Definition: gpi.hpp:43
void release(void)
Release the mutex.
Definition: none.hpp:52
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)
GPI(void)
Initialize.
Definition: gpi.hpp:124
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
union Gecode::@585::NNF::@62 u
Union depending on nodetype t.
#define GECODE_KERNEL_EXPORT
Definition: kernel.hh:74
struct Gecode::@585::NNF::@62::@63 b
For binary nodes (and, or, eqv)
Class for storing propagator information.
Definition: gpi.hpp:46
void init(unsigned int pid, unsigned int gid)
Initialize.
Definition: gpi.hpp:107
const double rescale
Rescale factor for action and afc values.
Definition: kernel.hh:103
double afc
The afc value.
Definition: gpi.hpp:53
~GPI(void)
Delete.
Definition: gpi.hpp:191
Gecode toplevel namespace
unsigned int pid
Propagator identifier.
Definition: gpi.hpp:49
unsigned int gid
Group identifier.
Definition: gpi.hpp:51
Base class for heap allocated objects.
Definition: heap.hpp:344