/usr/include/gecode/int/view-val-graph/graph.hpp is in libgecode-dev 5.1.0-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Christian Schulte, 2003
*
* Last modified:
* $Date: 2017-03-08 11:58:56 +0100 (Wed, 08 Mar 2017) $ by $Author: schulte $
* $Revision: 15562 $
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include <climits>
namespace Gecode { namespace Int { namespace ViewValGraph {
template<class View>
forceinline
Graph<View>::Graph(void)
: view(NULL), val(NULL), n_view(0), n_val(0), count(1U) {}
template<class View>
forceinline
Graph<View>::operator bool(void) const {
return view != NULL;
}
template<class View>
forceinline void
Graph<View>::init(Space& home, ViewNode<View>* x) {
Edge<View>** edge_p = x->val_edges_ref();
ViewValues<View> xi(x->view());
ValNode<View>** v = &val;
while (xi() && (*v != NULL)) {
if ((*v)->val() == xi.val()) {
// Value node does already exist, create new edge
*edge_p = new (home) Edge<View>(*v,x);
edge_p = (*edge_p)->next_edge_ref();
v = (*v)->next_val_ref();
++xi;
} else if ((*v)->val() < xi.val()) {
// Skip to next value node
v = (*v)->next_val_ref();
} else {
// Value node does not yet exist, create and link it
ValNode<View>* nv = new (home) ValNode<View>(xi.val(),*v);
*v = nv; v = nv->next_val_ref();
*edge_p = new (home) Edge<View>(nv,x);
edge_p = (*edge_p)->next_edge_ref();
++xi; n_val++;
}
}
// Create missing value nodes
while (xi()) {
ValNode<View>* nv = new (home) ValNode<View>(xi.val(),*v);
*v = nv; v = nv->next_val_ref();
*edge_p = new (home) Edge<View>(nv,x);
edge_p = (*edge_p)->next_edge_ref();
++xi; n_val++;
}
*edge_p = NULL;
}
template<class View>
forceinline bool
Graph<View>::match(ViewNodeStack& m, ViewNode<View>* x) {
count++;
start:
// Try to find matching edge cheaply: is there a free edge around?
{
Edge<View>* e = x->val_edges();
// This holds true as domains are never empty
assert(e != NULL);
do {
if (!e->val(x)->matching()) {
e->revert(x); e->val(x)->matching(e);
// Found a matching, revert all edges on stack
while (!m.empty()) {
x = m.pop(); e = x->iter;
e->val(x)->matching()->revert(e->val(x));
e->revert(x); e->val(x)->matching(e);
}
return true;
}
e = e->next_edge();
} while (e != NULL);
}
// No, find matching edge by augmenting path method
Edge<View>* e = x->val_edges();
do {
if (e->val(x)->matching()->view(e->val(x))->min < count) {
e->val(x)->matching()->view(e->val(x))->min = count;
m.push(x); x->iter = e;
x = e->val(x)->matching()->view(e->val(x));
goto start;
}
next:
e = e->next_edge();
} while (e != NULL);
if (!m.empty()) {
x = m.pop(); e = x->iter; goto next;
}
// All nodes and edges unsuccessfully tried
return false;
}
template<class View>
forceinline void
Graph<View>::purge(void) {
if (count > (UINT_MAX >> 1)) {
count = 1;
for (int i=n_view; i--; )
view[i]->min = 0;
for (ValNode<View>* v = val; v != NULL; v = v->next_val())
v->min = 0;
}
}
template<class View>
forceinline void
Graph<View>::scc(Space& home) {
Region r(home);
Support::StaticStack<Node<View>*,Region> scc(r,n_val+n_view);
Support::StaticStack<Node<View>*,Region> visit(r,n_val+n_view);
count++;
unsigned int cnt0 = count;
unsigned int cnt1 = count;
for (int i = n_view; i--; )
/*
* The following test is subtle: for scc, the test should be:
* view[i]->min < count
* However, if view[i] < count-1, then the node has already been
* reached on a path and all edges connected to the node have been
* marked anyway! So just ignore this node altogether for scc.
*/
if (view[i]->min < count-1) {
Node<View>* w = view[i];
start:
w->low = w->min = cnt0++;
scc.push(w);
Edge<View>* e = w->edge_fst();
while (e != w->edge_lst()) {
if (e->dst(w)->min < count) {
visit.push(w); w->iter = e;
w=e->dst(w);
goto start;
}
next:
if (e->dst(w)->low < w->min)
w->min = e->dst(w)->low;
e = e->next();
}
if (w->min < w->low) {
w->low = w->min;
} else {
Node<View>* v;
do {
v = scc.pop();
v->comp = cnt1;
v->low = UINT_MAX;
} while (v != w);
cnt1++;
}
if (!visit.empty()) {
w=visit.pop(); e=w->iter; goto next;
}
}
count = cnt0+1;
}
}}}
// STATISTICS: int-prop
|