roby 0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +29 -0
- data/History.txt +4 -0
- data/License-fr.txt +519 -0
- data/License.txt +515 -0
- data/Manifest.txt +245 -0
- data/NOTES +4 -0
- data/README.txt +163 -0
- data/Rakefile +161 -0
- data/TODO.txt +146 -0
- data/app/README.txt +24 -0
- data/app/Rakefile +8 -0
- data/app/config/ROBOT.rb +5 -0
- data/app/config/app.yml +91 -0
- data/app/config/init.rb +7 -0
- data/app/config/roby.yml +3 -0
- data/app/controllers/.gitattributes +0 -0
- data/app/controllers/ROBOT.rb +2 -0
- data/app/data/.gitattributes +0 -0
- data/app/planners/ROBOT/main.rb +6 -0
- data/app/planners/main.rb +5 -0
- data/app/scripts/distributed +3 -0
- data/app/scripts/generate/bookmarks +3 -0
- data/app/scripts/replay +3 -0
- data/app/scripts/results +3 -0
- data/app/scripts/run +3 -0
- data/app/scripts/server +3 -0
- data/app/scripts/shell +3 -0
- data/app/scripts/test +3 -0
- data/app/tasks/.gitattributes +0 -0
- data/app/tasks/ROBOT/.gitattributes +0 -0
- data/bin/roby +210 -0
- data/bin/roby-log +168 -0
- data/bin/roby-shell +25 -0
- data/doc/images/event_generalization.png +0 -0
- data/doc/images/exception_propagation_1.png +0 -0
- data/doc/images/exception_propagation_2.png +0 -0
- data/doc/images/exception_propagation_3.png +0 -0
- data/doc/images/exception_propagation_4.png +0 -0
- data/doc/images/exception_propagation_5.png +0 -0
- data/doc/images/replay_handler_error.png +0 -0
- data/doc/images/replay_handler_error_0.png +0 -0
- data/doc/images/replay_handler_error_1.png +0 -0
- data/doc/images/roby_cycle_overview.png +0 -0
- data/doc/images/roby_replay_02.png +0 -0
- data/doc/images/roby_replay_03.png +0 -0
- data/doc/images/roby_replay_04.png +0 -0
- data/doc/images/roby_replay_event_representation.png +0 -0
- data/doc/images/roby_replay_first_state.png +0 -0
- data/doc/images/roby_replay_relations.png +0 -0
- data/doc/images/roby_replay_startup.png +0 -0
- data/doc/images/task_event_generalization.png +0 -0
- data/doc/papers.rdoc +11 -0
- data/doc/styles/allison.css +314 -0
- data/doc/styles/allison.js +316 -0
- data/doc/styles/allison.rb +276 -0
- data/doc/styles/jamis.rb +593 -0
- data/doc/tutorials/01-GettingStarted.rdoc +86 -0
- data/doc/tutorials/02-GoForward.rdoc +220 -0
- data/doc/tutorials/03-PlannedPath.rdoc +268 -0
- data/doc/tutorials/04-EventPropagation.rdoc +236 -0
- data/doc/tutorials/05-ErrorHandling.rdoc +319 -0
- data/doc/tutorials/06-Overview.rdoc +40 -0
- data/doc/videos.rdoc +69 -0
- data/ext/droby/dump.cc +175 -0
- data/ext/droby/extconf.rb +3 -0
- data/ext/graph/algorithm.cc +746 -0
- data/ext/graph/extconf.rb +7 -0
- data/ext/graph/graph.cc +529 -0
- data/ext/graph/graph.hh +183 -0
- data/ext/graph/iterator_sequence.hh +102 -0
- data/ext/graph/undirected_dfs.hh +226 -0
- data/ext/graph/undirected_graph.hh +421 -0
- data/lib/roby.rb +41 -0
- data/lib/roby/app.rb +870 -0
- data/lib/roby/app/rake.rb +56 -0
- data/lib/roby/app/run.rb +14 -0
- data/lib/roby/app/scripts/distributed.rb +13 -0
- data/lib/roby/app/scripts/generate/bookmarks.rb +162 -0
- data/lib/roby/app/scripts/replay.rb +31 -0
- data/lib/roby/app/scripts/results.rb +15 -0
- data/lib/roby/app/scripts/run.rb +26 -0
- data/lib/roby/app/scripts/server.rb +18 -0
- data/lib/roby/app/scripts/shell.rb +88 -0
- data/lib/roby/app/scripts/test.rb +40 -0
- data/lib/roby/basic_object.rb +151 -0
- data/lib/roby/config.rb +5 -0
- data/lib/roby/control.rb +747 -0
- data/lib/roby/decision_control.rb +17 -0
- data/lib/roby/distributed.rb +32 -0
- data/lib/roby/distributed/base.rb +440 -0
- data/lib/roby/distributed/communication.rb +871 -0
- data/lib/roby/distributed/connection_space.rb +592 -0
- data/lib/roby/distributed/distributed_object.rb +206 -0
- data/lib/roby/distributed/drb.rb +62 -0
- data/lib/roby/distributed/notifications.rb +539 -0
- data/lib/roby/distributed/peer.rb +550 -0
- data/lib/roby/distributed/protocol.rb +529 -0
- data/lib/roby/distributed/proxy.rb +343 -0
- data/lib/roby/distributed/subscription.rb +311 -0
- data/lib/roby/distributed/transaction.rb +498 -0
- data/lib/roby/event.rb +897 -0
- data/lib/roby/exceptions.rb +234 -0
- data/lib/roby/executives/simple.rb +30 -0
- data/lib/roby/graph.rb +166 -0
- data/lib/roby/interface.rb +390 -0
- data/lib/roby/log.rb +3 -0
- data/lib/roby/log/chronicle.rb +303 -0
- data/lib/roby/log/console.rb +72 -0
- data/lib/roby/log/data_stream.rb +197 -0
- data/lib/roby/log/dot.rb +279 -0
- data/lib/roby/log/event_stream.rb +151 -0
- data/lib/roby/log/file.rb +340 -0
- data/lib/roby/log/gui/basic_display.ui +83 -0
- data/lib/roby/log/gui/chronicle.rb +26 -0
- data/lib/roby/log/gui/chronicle_view.rb +40 -0
- data/lib/roby/log/gui/chronicle_view.ui +70 -0
- data/lib/roby/log/gui/data_displays.rb +172 -0
- data/lib/roby/log/gui/data_displays.ui +155 -0
- data/lib/roby/log/gui/notifications.rb +26 -0
- data/lib/roby/log/gui/relations.rb +248 -0
- data/lib/roby/log/gui/relations.ui +123 -0
- data/lib/roby/log/gui/relations_view.rb +185 -0
- data/lib/roby/log/gui/relations_view.ui +149 -0
- data/lib/roby/log/gui/replay.rb +327 -0
- data/lib/roby/log/gui/replay_controls.rb +200 -0
- data/lib/roby/log/gui/replay_controls.ui +259 -0
- data/lib/roby/log/gui/runtime.rb +130 -0
- data/lib/roby/log/hooks.rb +185 -0
- data/lib/roby/log/logger.rb +202 -0
- data/lib/roby/log/notifications.rb +244 -0
- data/lib/roby/log/plan_rebuilder.rb +470 -0
- data/lib/roby/log/relations.rb +1056 -0
- data/lib/roby/log/server.rb +550 -0
- data/lib/roby/log/sqlite.rb +47 -0
- data/lib/roby/log/timings.rb +164 -0
- data/lib/roby/plan-object.rb +247 -0
- data/lib/roby/plan.rb +762 -0
- data/lib/roby/planning.rb +13 -0
- data/lib/roby/planning/loops.rb +302 -0
- data/lib/roby/planning/model.rb +906 -0
- data/lib/roby/planning/task.rb +151 -0
- data/lib/roby/propagation.rb +562 -0
- data/lib/roby/query.rb +619 -0
- data/lib/roby/relations.rb +583 -0
- data/lib/roby/relations/conflicts.rb +70 -0
- data/lib/roby/relations/ensured.rb +20 -0
- data/lib/roby/relations/error_handling.rb +23 -0
- data/lib/roby/relations/events.rb +9 -0
- data/lib/roby/relations/executed_by.rb +193 -0
- data/lib/roby/relations/hierarchy.rb +239 -0
- data/lib/roby/relations/influence.rb +10 -0
- data/lib/roby/relations/planned_by.rb +63 -0
- data/lib/roby/robot.rb +7 -0
- data/lib/roby/standard_errors.rb +218 -0
- data/lib/roby/state.rb +5 -0
- data/lib/roby/state/events.rb +221 -0
- data/lib/roby/state/information.rb +55 -0
- data/lib/roby/state/pos.rb +110 -0
- data/lib/roby/state/shapes.rb +32 -0
- data/lib/roby/state/state.rb +353 -0
- data/lib/roby/support.rb +92 -0
- data/lib/roby/task-operations.rb +182 -0
- data/lib/roby/task.rb +1618 -0
- data/lib/roby/test/common.rb +399 -0
- data/lib/roby/test/distributed.rb +214 -0
- data/lib/roby/test/tasks/empty_task.rb +9 -0
- data/lib/roby/test/tasks/goto.rb +36 -0
- data/lib/roby/test/tasks/simple_task.rb +23 -0
- data/lib/roby/test/testcase.rb +519 -0
- data/lib/roby/test/tools.rb +160 -0
- data/lib/roby/thread_task.rb +87 -0
- data/lib/roby/transactions.rb +462 -0
- data/lib/roby/transactions/proxy.rb +292 -0
- data/lib/roby/transactions/updates.rb +139 -0
- data/plugins/fault_injection/History.txt +4 -0
- data/plugins/fault_injection/README.txt +37 -0
- data/plugins/fault_injection/Rakefile +18 -0
- data/plugins/fault_injection/TODO.txt +0 -0
- data/plugins/fault_injection/app.rb +52 -0
- data/plugins/fault_injection/fault_injection.rb +89 -0
- data/plugins/fault_injection/test/test_fault_injection.rb +84 -0
- data/plugins/subsystems/README.txt +40 -0
- data/plugins/subsystems/Rakefile +18 -0
- data/plugins/subsystems/app.rb +171 -0
- data/plugins/subsystems/test/app/README +24 -0
- data/plugins/subsystems/test/app/Rakefile +8 -0
- data/plugins/subsystems/test/app/config/app.yml +71 -0
- data/plugins/subsystems/test/app/config/init.rb +9 -0
- data/plugins/subsystems/test/app/config/roby.yml +3 -0
- data/plugins/subsystems/test/app/planners/main.rb +20 -0
- data/plugins/subsystems/test/app/scripts/distributed +3 -0
- data/plugins/subsystems/test/app/scripts/replay +3 -0
- data/plugins/subsystems/test/app/scripts/results +3 -0
- data/plugins/subsystems/test/app/scripts/run +3 -0
- data/plugins/subsystems/test/app/scripts/server +3 -0
- data/plugins/subsystems/test/app/scripts/shell +3 -0
- data/plugins/subsystems/test/app/scripts/test +3 -0
- data/plugins/subsystems/test/app/tasks/services.rb +15 -0
- data/plugins/subsystems/test/test_subsystems.rb +71 -0
- data/test/distributed/test_communication.rb +178 -0
- data/test/distributed/test_connection.rb +282 -0
- data/test/distributed/test_execution.rb +373 -0
- data/test/distributed/test_mixed_plan.rb +341 -0
- data/test/distributed/test_plan_notifications.rb +238 -0
- data/test/distributed/test_protocol.rb +516 -0
- data/test/distributed/test_query.rb +102 -0
- data/test/distributed/test_remote_plan.rb +491 -0
- data/test/distributed/test_transaction.rb +463 -0
- data/test/mockups/tasks.rb +27 -0
- data/test/planning/test_loops.rb +380 -0
- data/test/planning/test_model.rb +427 -0
- data/test/planning/test_task.rb +106 -0
- data/test/relations/test_conflicts.rb +42 -0
- data/test/relations/test_ensured.rb +38 -0
- data/test/relations/test_executed_by.rb +149 -0
- data/test/relations/test_hierarchy.rb +158 -0
- data/test/relations/test_planned_by.rb +54 -0
- data/test/suite_core.rb +24 -0
- data/test/suite_distributed.rb +9 -0
- data/test/suite_planning.rb +3 -0
- data/test/suite_relations.rb +8 -0
- data/test/test_bgl.rb +508 -0
- data/test/test_control.rb +399 -0
- data/test/test_event.rb +894 -0
- data/test/test_exceptions.rb +592 -0
- data/test/test_interface.rb +37 -0
- data/test/test_log.rb +114 -0
- data/test/test_log_server.rb +132 -0
- data/test/test_plan.rb +584 -0
- data/test/test_propagation.rb +210 -0
- data/test/test_query.rb +266 -0
- data/test/test_relations.rb +180 -0
- data/test/test_state.rb +414 -0
- data/test/test_support.rb +16 -0
- data/test/test_task.rb +938 -0
- data/test/test_testcase.rb +122 -0
- data/test/test_thread_task.rb +73 -0
- data/test/test_transactions.rb +569 -0
- data/test/test_transactions_proxy.rb +198 -0
- metadata +570 -0
data/ext/graph/graph.hh
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
#ifndef RUBY_BGL_GRAPH_HH
|
|
2
|
+
#define RUBY_BGL_GRAPH_HH
|
|
3
|
+
|
|
4
|
+
#include <ruby.h>
|
|
5
|
+
#include <boost/graph/adjacency_list.hpp>
|
|
6
|
+
#include <set>
|
|
7
|
+
#include <boost/tuple/tuple.hpp>
|
|
8
|
+
|
|
9
|
+
extern VALUE bglModule;
|
|
10
|
+
extern VALUE bglGraph;
|
|
11
|
+
extern VALUE bglReverseGraph;
|
|
12
|
+
extern VALUE bglUndirectedGraph;
|
|
13
|
+
extern VALUE bglVertex;
|
|
14
|
+
|
|
15
|
+
/**********************************************************************
|
|
16
|
+
* Definition of base C++ types
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
struct EdgeProperty
|
|
20
|
+
{
|
|
21
|
+
VALUE info;
|
|
22
|
+
boost::default_color_type color; // needed by some algorithms
|
|
23
|
+
|
|
24
|
+
EdgeProperty(VALUE info)
|
|
25
|
+
: info(info) { }
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
typedef boost::adjacency_list< boost::setS, boost::setS
|
|
29
|
+
, boost::bidirectionalS, VALUE, EdgeProperty> RubyGraph;
|
|
30
|
+
typedef std::map<VALUE, RubyGraph::vertex_descriptor> graph_map;
|
|
31
|
+
|
|
32
|
+
inline RubyGraph& graph_wrapped(VALUE self)
|
|
33
|
+
{
|
|
34
|
+
RubyGraph* object = 0;
|
|
35
|
+
Data_Get_Struct(self, RubyGraph, object);
|
|
36
|
+
return *object;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
extern graph_map& vertex_descriptor_map(VALUE self);
|
|
40
|
+
|
|
41
|
+
/* Return the vertex_descriptor of +self+ in +graph+. The boolean is true if
|
|
42
|
+
* +self+ is in graph, and false otherwise.
|
|
43
|
+
*/
|
|
44
|
+
inline std::pair<RubyGraph::vertex_descriptor, bool>
|
|
45
|
+
rb_to_vertex(VALUE vertex, VALUE graph)
|
|
46
|
+
{
|
|
47
|
+
graph_map& descriptors = vertex_descriptor_map(vertex);
|
|
48
|
+
graph_map::iterator it = descriptors.find(graph);
|
|
49
|
+
if(it == descriptors.end())
|
|
50
|
+
return std::make_pair(static_cast<void*>(0), false);
|
|
51
|
+
else
|
|
52
|
+
return std::make_pair(it->second, true);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/* Returns a range for all descriptors of +self+
|
|
56
|
+
*/
|
|
57
|
+
inline std::pair<graph_map::iterator, graph_map::iterator> vertex_descriptors(VALUE self)
|
|
58
|
+
{
|
|
59
|
+
graph_map& descriptors = vertex_descriptor_map(self);
|
|
60
|
+
return make_pair(descriptors.begin(), descriptors.end());
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
namespace details
|
|
65
|
+
{
|
|
66
|
+
template<typename Graph, bool direct> struct vertex_range;
|
|
67
|
+
|
|
68
|
+
template<typename Graph>
|
|
69
|
+
struct vertex_range<Graph, true>
|
|
70
|
+
{
|
|
71
|
+
typedef typename Graph::adjacency_iterator iterator;
|
|
72
|
+
typedef std::pair<iterator, iterator> range;
|
|
73
|
+
|
|
74
|
+
static range get(RubyGraph::vertex_descriptor v, Graph& graph)
|
|
75
|
+
{ return adjacent_vertices(v, graph); }
|
|
76
|
+
static range get(RubyGraph::vertex_descriptor v, Graph const& graph)
|
|
77
|
+
{ return adjacent_vertices(v, graph); }
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
template<typename Graph>
|
|
81
|
+
struct vertex_range<Graph, false>
|
|
82
|
+
{
|
|
83
|
+
typedef typename Graph::inv_adjacency_iterator iterator;
|
|
84
|
+
typedef std::pair<iterator, iterator> range;
|
|
85
|
+
|
|
86
|
+
static range get(RubyGraph::vertex_descriptor v, Graph& graph)
|
|
87
|
+
{ return inv_adjacent_vertices(v, graph); }
|
|
88
|
+
static range get(RubyGraph::vertex_descriptor v, Graph const& graph)
|
|
89
|
+
{ return inv_adjacent_vertices(v, graph); }
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Iterates on all vertices in the range */
|
|
94
|
+
template <typename Range, typename F>
|
|
95
|
+
static bool for_each_value(Range range, RubyGraph& graph, F f)
|
|
96
|
+
{
|
|
97
|
+
typedef typename Range::first_type Iterator;
|
|
98
|
+
Iterator it, end;
|
|
99
|
+
for (boost::tie(it, end) = range; it != end; )
|
|
100
|
+
{
|
|
101
|
+
VALUE value = graph[*it];
|
|
102
|
+
++it;
|
|
103
|
+
|
|
104
|
+
if (!f(value))
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Iterates on each adjacent vertex of +v+ in +graph+ which are not yet in +already_seen+ */
|
|
111
|
+
template <typename Graph, bool direct>
|
|
112
|
+
static bool for_each_adjacent_uniq(RubyGraph::vertex_descriptor v, Graph const& graph, std::set<VALUE>& already_seen)
|
|
113
|
+
{
|
|
114
|
+
typedef details::vertex_range<Graph, direct> getter;
|
|
115
|
+
typedef typename getter::iterator Iterator;
|
|
116
|
+
|
|
117
|
+
Iterator it, end;
|
|
118
|
+
for (boost::tie(it, end) = details::vertex_range<Graph, direct>::get(v, graph); it != end; )
|
|
119
|
+
{
|
|
120
|
+
VALUE related_object = graph[*it];
|
|
121
|
+
bool inserted;
|
|
122
|
+
boost::tie(boost::tuples::ignore, inserted) = already_seen.insert(related_object);
|
|
123
|
+
++it;
|
|
124
|
+
|
|
125
|
+
if (inserted)
|
|
126
|
+
rb_yield_values(1, related_object);
|
|
127
|
+
}
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/* Iterates on all graphs +vertex+ is part of, calling f(RubyGraph&, vertex_descriptor). If the calling
|
|
132
|
+
* function returns false, stop iteration here */
|
|
133
|
+
template<typename F>
|
|
134
|
+
static bool for_each_graph(VALUE vertex, F f)
|
|
135
|
+
{
|
|
136
|
+
graph_map::iterator graph, graph_end;
|
|
137
|
+
for (boost::tie(graph, graph_end) = vertex_descriptors(vertex); graph != graph_end;)
|
|
138
|
+
{
|
|
139
|
+
RubyGraph& g = graph_wrapped(graph->first);
|
|
140
|
+
RubyGraph::vertex_descriptor v = graph->second;
|
|
141
|
+
++graph;
|
|
142
|
+
|
|
143
|
+
if (!f(v, g))
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Returns true if +v+ has either no child (if +direct+ is true) or no parents (if +direct+ is false)
|
|
150
|
+
template<typename Graph, bool direct>
|
|
151
|
+
bool vertex_has_adjacent_i(RubyGraph::vertex_descriptor v, Graph const& g)
|
|
152
|
+
{
|
|
153
|
+
typedef typename details::vertex_range<Graph, direct> getter;
|
|
154
|
+
typename getter::iterator begin, end;
|
|
155
|
+
boost::tie(begin, end) = getter::get(v, g);
|
|
156
|
+
return begin == end;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
template<bool direct>
|
|
160
|
+
VALUE vertex_has_adjacent(int argc, VALUE* argv, VALUE self)
|
|
161
|
+
{
|
|
162
|
+
VALUE graph = Qnil;
|
|
163
|
+
rb_scan_args(argc, argv, "01", &graph);
|
|
164
|
+
|
|
165
|
+
bool result;
|
|
166
|
+
if (NIL_P(graph))
|
|
167
|
+
result = for_each_graph(self, vertex_has_adjacent_i<RubyGraph, direct>);
|
|
168
|
+
else
|
|
169
|
+
{
|
|
170
|
+
RubyGraph::vertex_descriptor v; bool exists;
|
|
171
|
+
boost::tie(v, exists) = rb_to_vertex(self, graph);
|
|
172
|
+
if (! exists)
|
|
173
|
+
return Qtrue;
|
|
174
|
+
|
|
175
|
+
RubyGraph& g = graph_wrapped(graph);
|
|
176
|
+
result = vertex_has_adjacent_i<RubyGraph, direct>(v, g);
|
|
177
|
+
}
|
|
178
|
+
return result ? Qtrue : Qfalse;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
#endif
|
|
183
|
+
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#ifndef UTILMM_ITERATOR_SEQUENCE_HPP
|
|
2
|
+
#define UTILMM_ITERATOR_SEQUENCE_HPP
|
|
3
|
+
|
|
4
|
+
#include <boost/iterator/iterator_facade.hpp>
|
|
5
|
+
#include <boost/iterator/iterator_traits.hpp>
|
|
6
|
+
|
|
7
|
+
namespace utilmm {
|
|
8
|
+
/**
|
|
9
|
+
* The iterator_sequence template takes two iterator ranges and iterates in the two ranges
|
|
10
|
+
* as if they were a single sequence. The only constraint is that both iterator types have
|
|
11
|
+
* the same value_type.
|
|
12
|
+
*/
|
|
13
|
+
template<typename It1, typename It2>
|
|
14
|
+
class iterator_sequence :
|
|
15
|
+
public boost::iterator_facade<
|
|
16
|
+
iterator_sequence<It1, It2>,
|
|
17
|
+
typename It1::value_type,
|
|
18
|
+
typename boost::iterator_traversal<It1>::type,
|
|
19
|
+
typename It1::reference >
|
|
20
|
+
{
|
|
21
|
+
typedef iterator_sequence<It1, It2> Self;
|
|
22
|
+
|
|
23
|
+
public:
|
|
24
|
+
/** Builds a new sequence
|
|
25
|
+
* Note that for an iterator sequence (fb, fe) + (sb, se),
|
|
26
|
+
* <ul>
|
|
27
|
+
* <li> the begin iterator is i_s(fb, fe, sb, sb)
|
|
28
|
+
* <li> the end iterator is i_s(fe, fe, se, se)
|
|
29
|
+
* </ul>
|
|
30
|
+
*
|
|
31
|
+
* @param first the position in the first range
|
|
32
|
+
* @param first_end the end of the first range
|
|
33
|
+
* @param second_begin the beginning of the second range
|
|
34
|
+
* @param second the position in the second range
|
|
35
|
+
*/
|
|
36
|
+
iterator_sequence(
|
|
37
|
+
It1 first, It1 first_end,
|
|
38
|
+
It2 second_begin, It2 second)
|
|
39
|
+
: m_first(first), m_first_end(first_end)
|
|
40
|
+
, m_second_begin(second_begin), m_second(second) {}
|
|
41
|
+
iterator_sequence() {}
|
|
42
|
+
|
|
43
|
+
private:
|
|
44
|
+
friend class boost::iterator_core_access;
|
|
45
|
+
|
|
46
|
+
It1 m_first, m_first_end;
|
|
47
|
+
It2 m_second_begin, m_second;
|
|
48
|
+
|
|
49
|
+
typename Self::reference dereference() const
|
|
50
|
+
{
|
|
51
|
+
if (m_first == m_first_end)
|
|
52
|
+
return *m_second;
|
|
53
|
+
else
|
|
54
|
+
return *m_first;
|
|
55
|
+
}
|
|
56
|
+
bool equal(Self x) const
|
|
57
|
+
{ return (x.m_first == m_first && x.m_second == m_second); }
|
|
58
|
+
void increment()
|
|
59
|
+
{
|
|
60
|
+
if (m_first == m_first_end)
|
|
61
|
+
++m_second;
|
|
62
|
+
else
|
|
63
|
+
++m_first;
|
|
64
|
+
}
|
|
65
|
+
void decrement()
|
|
66
|
+
{
|
|
67
|
+
if (m_second == m_second_begin)
|
|
68
|
+
--m_first;
|
|
69
|
+
else
|
|
70
|
+
--m_second;
|
|
71
|
+
}
|
|
72
|
+
void advance(typename Self::difference_type i)
|
|
73
|
+
{
|
|
74
|
+
if (i > 0)
|
|
75
|
+
{
|
|
76
|
+
typename Self::difference_type remains = m_first_end - m_first;
|
|
77
|
+
if (remains > i)
|
|
78
|
+
m_first += i;
|
|
79
|
+
else
|
|
80
|
+
{
|
|
81
|
+
m_first = m_first_end;
|
|
82
|
+
m_second += i - remains;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else
|
|
86
|
+
{
|
|
87
|
+
typename Self::difference_type remains = m_second_begin - m_second;
|
|
88
|
+
if (remains < i)
|
|
89
|
+
m_second += i;
|
|
90
|
+
else
|
|
91
|
+
{
|
|
92
|
+
m_second = m_second_begin;
|
|
93
|
+
m_first += i - remains;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
typename Self::difference_type distance_to(Self x) const
|
|
99
|
+
{ return (x.m_first - m_first) + (x.m_second - m_second); }
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
#endif
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
//=======================================================================
|
|
2
|
+
// Copyright 2006 Sylvain Joyeux
|
|
3
|
+
// * added a terminator function to undirected_dfs_visit
|
|
4
|
+
// * specialize for use with undirected_graph<>
|
|
5
|
+
//
|
|
6
|
+
// Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
|
|
7
|
+
// Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
|
|
8
|
+
//
|
|
9
|
+
// Distributed under the Boost Software License, Version 1.0. (See
|
|
10
|
+
// accompanying file LICENSE_1_0.txt or copy at
|
|
11
|
+
// http://www.boost.org/LICENSE_1_0.txt)
|
|
12
|
+
//=======================================================================
|
|
13
|
+
//
|
|
14
|
+
#ifndef UTILMM_GRAPH_UNDIRECTED_DFS_HPP
|
|
15
|
+
#define UTILMM_GRAPH_UNDIRECTED_DFS_HPP
|
|
16
|
+
|
|
17
|
+
#include <boost/graph/depth_first_search.hpp>
|
|
18
|
+
#include <vector>
|
|
19
|
+
|
|
20
|
+
namespace utilmm {
|
|
21
|
+
namespace detail {
|
|
22
|
+
using namespace boost;
|
|
23
|
+
struct nontruth2 {
|
|
24
|
+
template<class T, class T2>
|
|
25
|
+
bool operator()(const T&, const T2&) const { return false; }
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
template <typename IncidenceGraph, typename DFSVisitor,
|
|
29
|
+
typename VertexColorMap, typename EdgeColorMap,
|
|
30
|
+
typename TerminatorFunc>
|
|
31
|
+
void undir_dfv_impl_term
|
|
32
|
+
(const IncidenceGraph& g,
|
|
33
|
+
typename graph_traits<IncidenceGraph>::vertex_descriptor u,
|
|
34
|
+
DFSVisitor& vis,
|
|
35
|
+
VertexColorMap vertex_color,
|
|
36
|
+
EdgeColorMap edge_color,
|
|
37
|
+
TerminatorFunc func = TerminatorFunc())
|
|
38
|
+
{
|
|
39
|
+
function_requires<IncidenceGraphConcept<IncidenceGraph> >();
|
|
40
|
+
function_requires<DFSVisitorConcept<DFSVisitor, IncidenceGraph> >();
|
|
41
|
+
typedef typename graph_traits<IncidenceGraph>::vertex_descriptor Vertex;
|
|
42
|
+
typedef typename graph_traits<IncidenceGraph>::edge_descriptor Edge;
|
|
43
|
+
function_requires<ReadWritePropertyMapConcept<VertexColorMap,Vertex> >();
|
|
44
|
+
function_requires<ReadWritePropertyMapConcept<EdgeColorMap,Edge> >();
|
|
45
|
+
typedef typename property_traits<VertexColorMap>::value_type ColorValue;
|
|
46
|
+
typedef typename property_traits<EdgeColorMap>::value_type EColorValue;
|
|
47
|
+
function_requires< ColorValueConcept<ColorValue> >();
|
|
48
|
+
function_requires< ColorValueConcept<EColorValue> >();
|
|
49
|
+
typedef color_traits<ColorValue> Color;
|
|
50
|
+
typedef color_traits<EColorValue> EColor;
|
|
51
|
+
typedef typename graph_traits<IncidenceGraph>::out_edge_iterator Iter;
|
|
52
|
+
typedef std::pair<Vertex, std::pair<Iter, Iter> > VertexInfo;
|
|
53
|
+
|
|
54
|
+
std::vector<VertexInfo> stack;
|
|
55
|
+
|
|
56
|
+
put(vertex_color, u, Color::gray());
|
|
57
|
+
vis.discover_vertex(u, g);
|
|
58
|
+
|
|
59
|
+
Iter ei, ei_end;
|
|
60
|
+
tie(ei, ei_end) = out_edges(u, g);
|
|
61
|
+
if (func(u, g))
|
|
62
|
+
stack.push_back(std::make_pair(u, std::make_pair(ei_end, ei_end)));
|
|
63
|
+
else
|
|
64
|
+
stack.push_back(std::make_pair(u, std::make_pair(ei, ei_end)));
|
|
65
|
+
|
|
66
|
+
while (!stack.empty()) {
|
|
67
|
+
VertexInfo& back = stack.back();
|
|
68
|
+
u = back.first;
|
|
69
|
+
tie(ei, ei_end) = back.second;
|
|
70
|
+
stack.pop_back();
|
|
71
|
+
while (ei != ei_end) {
|
|
72
|
+
Vertex v = target(*ei, g);
|
|
73
|
+
vis.examine_edge(*ei, g);
|
|
74
|
+
ColorValue v_color = get(vertex_color, v);
|
|
75
|
+
EColorValue uv_color = get(edge_color, *ei);
|
|
76
|
+
put(edge_color, *ei, EColor::black());
|
|
77
|
+
if (v_color == Color::white()) {
|
|
78
|
+
vis.tree_edge(*ei, g);
|
|
79
|
+
stack.push_back(std::make_pair(u, std::make_pair(++ei, ei_end)));
|
|
80
|
+
u = v;
|
|
81
|
+
put(vertex_color, u, Color::gray());
|
|
82
|
+
vis.discover_vertex(u, g);
|
|
83
|
+
tie(ei, ei_end) = out_edges(u, g);
|
|
84
|
+
if (func(u, g))
|
|
85
|
+
ei = ei_end;
|
|
86
|
+
} else if (v_color == Color::gray()) {
|
|
87
|
+
if (uv_color == EColor::white()) vis.back_edge(*ei, g);
|
|
88
|
+
++ei;
|
|
89
|
+
} else { // if (v_color == Color::black())
|
|
90
|
+
vis.forward_or_cross_edge(*ei, g);
|
|
91
|
+
++ei;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
put(vertex_color, u, Color::black());
|
|
95
|
+
vis.finish_vertex(u, g);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
} // namespace detail
|
|
99
|
+
|
|
100
|
+
template <typename Graph, typename DFSVisitor,
|
|
101
|
+
typename VertexColorMap, typename EdgeColorMap,
|
|
102
|
+
typename Vertex>
|
|
103
|
+
void
|
|
104
|
+
undirected_dfs(const Graph& g, DFSVisitor vis,
|
|
105
|
+
VertexColorMap vertex_color, EdgeColorMap edge_color,
|
|
106
|
+
Vertex start_vertex)
|
|
107
|
+
{
|
|
108
|
+
using namespace boost;
|
|
109
|
+
function_requires<DFSVisitorConcept<DFSVisitor, Graph> >();
|
|
110
|
+
function_requires<EdgeListGraphConcept<Graph> >();
|
|
111
|
+
|
|
112
|
+
typedef typename property_traits<VertexColorMap>::value_type ColorValue;
|
|
113
|
+
typedef color_traits<ColorValue> Color;
|
|
114
|
+
|
|
115
|
+
typename graph_traits<Graph>::vertex_iterator ui, ui_end;
|
|
116
|
+
for (tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) {
|
|
117
|
+
put(vertex_color, *ui, Color::white()); vis.initialize_vertex(*ui, g);
|
|
118
|
+
}
|
|
119
|
+
typename graph_traits<Graph>::edge_iterator ei, ei_end;
|
|
120
|
+
for (tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
|
|
121
|
+
put(edge_color, *ei, Color::white());
|
|
122
|
+
|
|
123
|
+
if (start_vertex != *vertices(g).first){ vis.start_vertex(start_vertex, g);
|
|
124
|
+
detail::undir_dfv_impl_term(g, start_vertex, vis, vertex_color, edge_color, detail::nontruth2());
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
for (tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) {
|
|
128
|
+
ColorValue u_color = get(vertex_color, *ui);
|
|
129
|
+
if (u_color == Color::white()) { vis.start_vertex(*ui, g);
|
|
130
|
+
detail::undir_dfv_impl_term(g, *ui, vis, vertex_color, edge_color, detail::nontruth2());
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
template <typename Graph, typename DFSVisitor, typename VertexColorMap,
|
|
136
|
+
typename EdgeColorMap>
|
|
137
|
+
void
|
|
138
|
+
undirected_dfs(const Graph& g, DFSVisitor vis,
|
|
139
|
+
VertexColorMap vertex_color, EdgeColorMap edge_color)
|
|
140
|
+
{
|
|
141
|
+
using namespace boost;
|
|
142
|
+
undirected_dfs(g, vis, vertex_color, edge_color, *vertices(g).first, detail::nontruth2());
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
namespace detail {
|
|
146
|
+
template <typename VertexColorMap>
|
|
147
|
+
struct udfs_dispatch {
|
|
148
|
+
|
|
149
|
+
template <typename Graph, typename Vertex,
|
|
150
|
+
typename DFSVisitor, typename EdgeColorMap,
|
|
151
|
+
typename P, typename T, typename R>
|
|
152
|
+
static void
|
|
153
|
+
apply(const Graph& g, DFSVisitor vis, Vertex start_vertex,
|
|
154
|
+
const bgl_named_params<P, T, R>&,
|
|
155
|
+
EdgeColorMap edge_color,
|
|
156
|
+
VertexColorMap vertex_color)
|
|
157
|
+
{
|
|
158
|
+
undirected_dfs(g, vis, vertex_color, edge_color, start_vertex);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
template <>
|
|
163
|
+
struct udfs_dispatch<boost::detail::error_property_not_found> {
|
|
164
|
+
template <typename Graph, typename Vertex, typename DFSVisitor,
|
|
165
|
+
typename EdgeColorMap,
|
|
166
|
+
typename P, typename T, typename R>
|
|
167
|
+
static void
|
|
168
|
+
apply(const Graph& g, DFSVisitor vis, Vertex start_vertex,
|
|
169
|
+
const bgl_named_params<P, T, R>& params,
|
|
170
|
+
EdgeColorMap edge_color,
|
|
171
|
+
boost::detail::error_property_not_found)
|
|
172
|
+
{
|
|
173
|
+
std::vector<default_color_type> color_vec(num_vertices(g));
|
|
174
|
+
default_color_type c = white_color; // avoid warning about un-init
|
|
175
|
+
undirected_dfs
|
|
176
|
+
(g, vis, make_iterator_property_map
|
|
177
|
+
(color_vec.begin(),
|
|
178
|
+
choose_const_pmap(get_param(params, vertex_index),
|
|
179
|
+
g, vertex_index), c),
|
|
180
|
+
edge_color,
|
|
181
|
+
start_vertex);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
} // namespace detail
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
// Named Parameter Variant
|
|
189
|
+
template <typename Graph, typename P, typename T, typename R>
|
|
190
|
+
void
|
|
191
|
+
undirected_dfs(const Graph& g,
|
|
192
|
+
const boost::bgl_named_params<P, T, R>& params)
|
|
193
|
+
{
|
|
194
|
+
using namespace boost;
|
|
195
|
+
typedef typename property_value< bgl_named_params<P, T, R>,
|
|
196
|
+
vertex_color_t>::type C;
|
|
197
|
+
detail::udfs_dispatch<C>::apply
|
|
198
|
+
(g,
|
|
199
|
+
choose_param(get_param(params, graph_visitor),
|
|
200
|
+
make_dfs_visitor(null_visitor())),
|
|
201
|
+
choose_param(get_param(params, root_vertex_t()),
|
|
202
|
+
*vertices(g).first),
|
|
203
|
+
params,
|
|
204
|
+
get_param(params, edge_color),
|
|
205
|
+
get_param(params, vertex_color)
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
template <typename IncidenceGraph, typename DFSVisitor,
|
|
211
|
+
typename VertexColorMap, typename EdgeColorMap,
|
|
212
|
+
typename TerminatorFunc>
|
|
213
|
+
void undirected_depth_first_visit
|
|
214
|
+
(const IncidenceGraph& g,
|
|
215
|
+
typename boost::graph_traits<IncidenceGraph>::vertex_descriptor u,
|
|
216
|
+
DFSVisitor vis, VertexColorMap vertex_color, EdgeColorMap edge_color,
|
|
217
|
+
TerminatorFunc func = TerminatorFunc())
|
|
218
|
+
{
|
|
219
|
+
detail::undir_dfv_impl_term(g, u, vis, vertex_color, edge_color, func);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
} // namespace boost
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
#endif
|