Generated on Tue Jan 26 2021 00:00:00 for Gecode by doxygen 1.9.1
base.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, 2011
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 NoOverlap {
35 
36  template<class Box>
38  Base<Box>::Base(Home home, Box* b0, int n0)
39  : Propagator(home), b(b0), n(n0) {
40  for (int i=0; i<n; i++)
41  b[i].subscribe(home,*this);
42  }
43 
44  template<class Box>
45  forceinline int
46  Base<Box>::partition(Box* b, int i, int n) {
47  int j = n-1;
48  while (true) {
49  while (!b[j].mandatory() && (--j >= 0)) {}
50  while (b[i].mandatory() && (++i < n)) {}
51  if (j <= i) break;
52  std::swap(b[i],b[j]);
53  }
54  return i;
55  }
56 
57  template<class Box>
58  forceinline size_t
60  for (int i=0; i<n; i++)
61  b[i].cancel(home,*this);
62  (void) Propagator::dispose(home);
63  return sizeof(*this);
64  }
65 
66 
67  template<class Box>
69  Base<Box>::Base(Space& home, Base<Box>& p, int m)
70  : Propagator(home,p), b(home.alloc<Box>(m)), n(p.n) {
71  for (int i=0; i<m; i++)
72  b[i].update(home,p.b[i]);
73  }
74 
75  template<class Box>
76  PropCost
77  Base<Box>::cost(const Space&, const ModEventDelta&) const {
78  return PropCost::quadratic(PropCost::HI,Box::dim()*n);
79  }
80 
81  template<class Box>
82  void
84  for (int i=0; i<n; i++)
85  b[i].reschedule(home,*this);
86  }
87 
88 }}}
89 
90 // STATISTICS: int-prop
91 
struct Gecode::@602::NNF::@65::@66 b
For binary nodes (and, or, eqv)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition: core.hpp:3252
Home class for posting propagators
Definition: core.hpp:856
Base class for no-overlap propagator.
Definition: no-overlap.hh:234
int n
Number of mandatory boxes: b[0] ... b[n-1].
Definition: no-overlap.hh:239
Base(Home home, Box *b, int n)
Constructor for posting with n mandatory boxes.
Definition: base.hpp:38
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function.
Definition: base.hpp:77
virtual size_t dispose(Space &home)
Destructor.
Definition: base.hpp:59
static int partition(Box *b, int i, int n)
Partition n boxes b starting at position i.
Definition: base.hpp:46
virtual void reschedule(Space &home)
Schedule function.
Definition: base.hpp:83
Propagation cost.
Definition: core.hpp:486
static PropCost quadratic(PropCost::Mod m, unsigned int n)
Quadratic complexity for modifier m and size measure n.
Definition: core.hpp:4787
@ HI
Expensive.
Definition: core.hpp:514
Base-class for propagators.
Definition: core.hpp:1064
Computation spaces.
Definition: core.hpp:1742
int ModEventDelta
Modification event deltas.
Definition: core.hpp:89
void cancel(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:81
void subscribe(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:71
void update(IntSet &y, Space &home, IntSet &py)
Definition: rel.hpp:103
void reschedule(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:92
Gecode::IntArgs i({1, 2, 3, 4})
#define forceinline
Definition: config.hpp:185