this repo has no description
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, 2006
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#ifndef GECODE_INT_CIRCUIT_HH
35#define GECODE_INT_CIRCUIT_HH
36
37#include <gecode/int.hh>
38#include <gecode/int/distinct.hh>
39
40/**
41 * \namespace Gecode::Int::Circuit
42 * \brief %Circuit propagators
43 */
44
45namespace Gecode { namespace Int { namespace Circuit {
46
47 /**
48 * \brief Base-class for circuit propagator
49 *
50 * Provides routines for checking that the induced variable value graph
51 * is strongly connected and for pruning short cycles.
52 *
53 */
54 template<class View, class Offset>
55 class Base : public NaryPropagator<View,Int::PC_INT_DOM> {
56 protected:
57 using NaryPropagator<View,Int::PC_INT_DOM>::x;
58 /// Remember where to start the next time the propagator runs
59 int start;
60 /// Array for performing value propagation for distinct
61 ViewArray<View> y;
62 /// Offset transformation
63 Offset o;
64 /// Constructor for cloning \a p
65 Base(Space& home, Base& p);
66 /// Constructor for posting
67 Base(Home home, ViewArray<View>& x, Offset& o);
68 /// Check whether the view value graph is strongly connected
69 ExecStatus connected(Space& home);
70 /// Ensure path property: prune edges that could give too small cycles
71 ExecStatus path(Space& home);
72 public:
73 /// Delete propagator and return its size
74 virtual size_t dispose(Space& home);
75 };
76
77 /**
78 * \brief "Value-consistent" circuit propagator
79 *
80 * Propagates value-consistent distinct, checks that
81 * the induced variable value graph is stronlgy connected, and
82 * prunes too short cycles.
83 *
84 * Requires \code #include <gecode/int/circuit.hh> \endcode
85 * \ingroup FuncIntProp
86 */
87 template<class View, class Offset>
88 class Val : public Base<View,Offset> {
89 protected:
90 using Base<View,Offset>::x;
91 using Base<View,Offset>::y;
92 using Base<View,Offset>::connected;
93 using Base<View,Offset>::path;
94 using Base<View,Offset>::o;
95 /// Constructor for cloning \a p
96 Val(Space& home, Val& p);
97 /// Constructor for posting
98 Val(Home home, ViewArray<View>& x, Offset& o);
99 public:
100 /// Copy propagator during cloning
101 virtual Actor* copy(Space& home);
102 /// Cost function (returns high linear)
103 virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
104 /// Perform propagation
105 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
106 /// Post propagator for circuit on \a x
107 static ExecStatus post(Home home, ViewArray<View>& x, Offset& o);
108 };
109
110 /**
111 * \brief "Domain consistent" circuit propagator
112 *
113 * Propagates domain consistent distinct, checks that
114 * the induced variable value graph is stronlgy connected, and
115 * prunes too shot cycles.
116 *
117 * Requires \code #include <gecode/int/circuit.hh> \endcode
118 * \ingroup FuncIntProp
119 */
120 template<class View, class Offset>
121 class Dom : public Base<View,Offset> {
122 protected:
123 using Base<View,Offset>::x;
124 using Base<View,Offset>::y;
125 using Base<View,Offset>::connected;
126 using Base<View,Offset>::path;
127 using Base<View,Offset>::o;
128 /// Propagation controller for propagating distinct
129 Int::Distinct::DomCtrl<View> dc;
130 /// Constructor for cloning \a p
131 Dom(Space& home, Dom& p);
132 /// Constructor for posting
133 Dom(Home home, ViewArray<View>& x, Offset& o);
134 public:
135 /// Copy propagator during cloning
136 virtual Actor* copy(Space& home);
137 /**
138 * \brief Cost function
139 *
140 * If in stage for naive value propagation, the cost is
141 * low linear. Otherwise it is high quadratic.
142 */
143 virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
144 /// Schedule function
145 virtual void reschedule(Space& home);
146 /// Perform propagation
147 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
148 /// Post propagator for circuit on \a x
149 static ExecStatus post(Home home, ViewArray<View>& x, Offset& o);
150 };
151
152}}}
153
154#include <gecode/int/circuit/base.hpp>
155#include <gecode/int/circuit/val.hpp>
156#include <gecode/int/circuit/dom.hpp>
157
158#endif
159
160// STATISTICS: int-prop