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.
Files changed (240) hide show
  1. data/.gitignore +29 -0
  2. data/History.txt +4 -0
  3. data/License-fr.txt +519 -0
  4. data/License.txt +515 -0
  5. data/Manifest.txt +245 -0
  6. data/NOTES +4 -0
  7. data/README.txt +163 -0
  8. data/Rakefile +161 -0
  9. data/TODO.txt +146 -0
  10. data/app/README.txt +24 -0
  11. data/app/Rakefile +8 -0
  12. data/app/config/ROBOT.rb +5 -0
  13. data/app/config/app.yml +91 -0
  14. data/app/config/init.rb +7 -0
  15. data/app/config/roby.yml +3 -0
  16. data/app/controllers/.gitattributes +0 -0
  17. data/app/controllers/ROBOT.rb +2 -0
  18. data/app/data/.gitattributes +0 -0
  19. data/app/planners/ROBOT/main.rb +6 -0
  20. data/app/planners/main.rb +5 -0
  21. data/app/scripts/distributed +3 -0
  22. data/app/scripts/generate/bookmarks +3 -0
  23. data/app/scripts/replay +3 -0
  24. data/app/scripts/results +3 -0
  25. data/app/scripts/run +3 -0
  26. data/app/scripts/server +3 -0
  27. data/app/scripts/shell +3 -0
  28. data/app/scripts/test +3 -0
  29. data/app/tasks/.gitattributes +0 -0
  30. data/app/tasks/ROBOT/.gitattributes +0 -0
  31. data/bin/roby +210 -0
  32. data/bin/roby-log +168 -0
  33. data/bin/roby-shell +25 -0
  34. data/doc/images/event_generalization.png +0 -0
  35. data/doc/images/exception_propagation_1.png +0 -0
  36. data/doc/images/exception_propagation_2.png +0 -0
  37. data/doc/images/exception_propagation_3.png +0 -0
  38. data/doc/images/exception_propagation_4.png +0 -0
  39. data/doc/images/exception_propagation_5.png +0 -0
  40. data/doc/images/replay_handler_error.png +0 -0
  41. data/doc/images/replay_handler_error_0.png +0 -0
  42. data/doc/images/replay_handler_error_1.png +0 -0
  43. data/doc/images/roby_cycle_overview.png +0 -0
  44. data/doc/images/roby_replay_02.png +0 -0
  45. data/doc/images/roby_replay_03.png +0 -0
  46. data/doc/images/roby_replay_04.png +0 -0
  47. data/doc/images/roby_replay_event_representation.png +0 -0
  48. data/doc/images/roby_replay_first_state.png +0 -0
  49. data/doc/images/roby_replay_relations.png +0 -0
  50. data/doc/images/roby_replay_startup.png +0 -0
  51. data/doc/images/task_event_generalization.png +0 -0
  52. data/doc/papers.rdoc +11 -0
  53. data/doc/styles/allison.css +314 -0
  54. data/doc/styles/allison.js +316 -0
  55. data/doc/styles/allison.rb +276 -0
  56. data/doc/styles/jamis.rb +593 -0
  57. data/doc/tutorials/01-GettingStarted.rdoc +86 -0
  58. data/doc/tutorials/02-GoForward.rdoc +220 -0
  59. data/doc/tutorials/03-PlannedPath.rdoc +268 -0
  60. data/doc/tutorials/04-EventPropagation.rdoc +236 -0
  61. data/doc/tutorials/05-ErrorHandling.rdoc +319 -0
  62. data/doc/tutorials/06-Overview.rdoc +40 -0
  63. data/doc/videos.rdoc +69 -0
  64. data/ext/droby/dump.cc +175 -0
  65. data/ext/droby/extconf.rb +3 -0
  66. data/ext/graph/algorithm.cc +746 -0
  67. data/ext/graph/extconf.rb +7 -0
  68. data/ext/graph/graph.cc +529 -0
  69. data/ext/graph/graph.hh +183 -0
  70. data/ext/graph/iterator_sequence.hh +102 -0
  71. data/ext/graph/undirected_dfs.hh +226 -0
  72. data/ext/graph/undirected_graph.hh +421 -0
  73. data/lib/roby.rb +41 -0
  74. data/lib/roby/app.rb +870 -0
  75. data/lib/roby/app/rake.rb +56 -0
  76. data/lib/roby/app/run.rb +14 -0
  77. data/lib/roby/app/scripts/distributed.rb +13 -0
  78. data/lib/roby/app/scripts/generate/bookmarks.rb +162 -0
  79. data/lib/roby/app/scripts/replay.rb +31 -0
  80. data/lib/roby/app/scripts/results.rb +15 -0
  81. data/lib/roby/app/scripts/run.rb +26 -0
  82. data/lib/roby/app/scripts/server.rb +18 -0
  83. data/lib/roby/app/scripts/shell.rb +88 -0
  84. data/lib/roby/app/scripts/test.rb +40 -0
  85. data/lib/roby/basic_object.rb +151 -0
  86. data/lib/roby/config.rb +5 -0
  87. data/lib/roby/control.rb +747 -0
  88. data/lib/roby/decision_control.rb +17 -0
  89. data/lib/roby/distributed.rb +32 -0
  90. data/lib/roby/distributed/base.rb +440 -0
  91. data/lib/roby/distributed/communication.rb +871 -0
  92. data/lib/roby/distributed/connection_space.rb +592 -0
  93. data/lib/roby/distributed/distributed_object.rb +206 -0
  94. data/lib/roby/distributed/drb.rb +62 -0
  95. data/lib/roby/distributed/notifications.rb +539 -0
  96. data/lib/roby/distributed/peer.rb +550 -0
  97. data/lib/roby/distributed/protocol.rb +529 -0
  98. data/lib/roby/distributed/proxy.rb +343 -0
  99. data/lib/roby/distributed/subscription.rb +311 -0
  100. data/lib/roby/distributed/transaction.rb +498 -0
  101. data/lib/roby/event.rb +897 -0
  102. data/lib/roby/exceptions.rb +234 -0
  103. data/lib/roby/executives/simple.rb +30 -0
  104. data/lib/roby/graph.rb +166 -0
  105. data/lib/roby/interface.rb +390 -0
  106. data/lib/roby/log.rb +3 -0
  107. data/lib/roby/log/chronicle.rb +303 -0
  108. data/lib/roby/log/console.rb +72 -0
  109. data/lib/roby/log/data_stream.rb +197 -0
  110. data/lib/roby/log/dot.rb +279 -0
  111. data/lib/roby/log/event_stream.rb +151 -0
  112. data/lib/roby/log/file.rb +340 -0
  113. data/lib/roby/log/gui/basic_display.ui +83 -0
  114. data/lib/roby/log/gui/chronicle.rb +26 -0
  115. data/lib/roby/log/gui/chronicle_view.rb +40 -0
  116. data/lib/roby/log/gui/chronicle_view.ui +70 -0
  117. data/lib/roby/log/gui/data_displays.rb +172 -0
  118. data/lib/roby/log/gui/data_displays.ui +155 -0
  119. data/lib/roby/log/gui/notifications.rb +26 -0
  120. data/lib/roby/log/gui/relations.rb +248 -0
  121. data/lib/roby/log/gui/relations.ui +123 -0
  122. data/lib/roby/log/gui/relations_view.rb +185 -0
  123. data/lib/roby/log/gui/relations_view.ui +149 -0
  124. data/lib/roby/log/gui/replay.rb +327 -0
  125. data/lib/roby/log/gui/replay_controls.rb +200 -0
  126. data/lib/roby/log/gui/replay_controls.ui +259 -0
  127. data/lib/roby/log/gui/runtime.rb +130 -0
  128. data/lib/roby/log/hooks.rb +185 -0
  129. data/lib/roby/log/logger.rb +202 -0
  130. data/lib/roby/log/notifications.rb +244 -0
  131. data/lib/roby/log/plan_rebuilder.rb +470 -0
  132. data/lib/roby/log/relations.rb +1056 -0
  133. data/lib/roby/log/server.rb +550 -0
  134. data/lib/roby/log/sqlite.rb +47 -0
  135. data/lib/roby/log/timings.rb +164 -0
  136. data/lib/roby/plan-object.rb +247 -0
  137. data/lib/roby/plan.rb +762 -0
  138. data/lib/roby/planning.rb +13 -0
  139. data/lib/roby/planning/loops.rb +302 -0
  140. data/lib/roby/planning/model.rb +906 -0
  141. data/lib/roby/planning/task.rb +151 -0
  142. data/lib/roby/propagation.rb +562 -0
  143. data/lib/roby/query.rb +619 -0
  144. data/lib/roby/relations.rb +583 -0
  145. data/lib/roby/relations/conflicts.rb +70 -0
  146. data/lib/roby/relations/ensured.rb +20 -0
  147. data/lib/roby/relations/error_handling.rb +23 -0
  148. data/lib/roby/relations/events.rb +9 -0
  149. data/lib/roby/relations/executed_by.rb +193 -0
  150. data/lib/roby/relations/hierarchy.rb +239 -0
  151. data/lib/roby/relations/influence.rb +10 -0
  152. data/lib/roby/relations/planned_by.rb +63 -0
  153. data/lib/roby/robot.rb +7 -0
  154. data/lib/roby/standard_errors.rb +218 -0
  155. data/lib/roby/state.rb +5 -0
  156. data/lib/roby/state/events.rb +221 -0
  157. data/lib/roby/state/information.rb +55 -0
  158. data/lib/roby/state/pos.rb +110 -0
  159. data/lib/roby/state/shapes.rb +32 -0
  160. data/lib/roby/state/state.rb +353 -0
  161. data/lib/roby/support.rb +92 -0
  162. data/lib/roby/task-operations.rb +182 -0
  163. data/lib/roby/task.rb +1618 -0
  164. data/lib/roby/test/common.rb +399 -0
  165. data/lib/roby/test/distributed.rb +214 -0
  166. data/lib/roby/test/tasks/empty_task.rb +9 -0
  167. data/lib/roby/test/tasks/goto.rb +36 -0
  168. data/lib/roby/test/tasks/simple_task.rb +23 -0
  169. data/lib/roby/test/testcase.rb +519 -0
  170. data/lib/roby/test/tools.rb +160 -0
  171. data/lib/roby/thread_task.rb +87 -0
  172. data/lib/roby/transactions.rb +462 -0
  173. data/lib/roby/transactions/proxy.rb +292 -0
  174. data/lib/roby/transactions/updates.rb +139 -0
  175. data/plugins/fault_injection/History.txt +4 -0
  176. data/plugins/fault_injection/README.txt +37 -0
  177. data/plugins/fault_injection/Rakefile +18 -0
  178. data/plugins/fault_injection/TODO.txt +0 -0
  179. data/plugins/fault_injection/app.rb +52 -0
  180. data/plugins/fault_injection/fault_injection.rb +89 -0
  181. data/plugins/fault_injection/test/test_fault_injection.rb +84 -0
  182. data/plugins/subsystems/README.txt +40 -0
  183. data/plugins/subsystems/Rakefile +18 -0
  184. data/plugins/subsystems/app.rb +171 -0
  185. data/plugins/subsystems/test/app/README +24 -0
  186. data/plugins/subsystems/test/app/Rakefile +8 -0
  187. data/plugins/subsystems/test/app/config/app.yml +71 -0
  188. data/plugins/subsystems/test/app/config/init.rb +9 -0
  189. data/plugins/subsystems/test/app/config/roby.yml +3 -0
  190. data/plugins/subsystems/test/app/planners/main.rb +20 -0
  191. data/plugins/subsystems/test/app/scripts/distributed +3 -0
  192. data/plugins/subsystems/test/app/scripts/replay +3 -0
  193. data/plugins/subsystems/test/app/scripts/results +3 -0
  194. data/plugins/subsystems/test/app/scripts/run +3 -0
  195. data/plugins/subsystems/test/app/scripts/server +3 -0
  196. data/plugins/subsystems/test/app/scripts/shell +3 -0
  197. data/plugins/subsystems/test/app/scripts/test +3 -0
  198. data/plugins/subsystems/test/app/tasks/services.rb +15 -0
  199. data/plugins/subsystems/test/test_subsystems.rb +71 -0
  200. data/test/distributed/test_communication.rb +178 -0
  201. data/test/distributed/test_connection.rb +282 -0
  202. data/test/distributed/test_execution.rb +373 -0
  203. data/test/distributed/test_mixed_plan.rb +341 -0
  204. data/test/distributed/test_plan_notifications.rb +238 -0
  205. data/test/distributed/test_protocol.rb +516 -0
  206. data/test/distributed/test_query.rb +102 -0
  207. data/test/distributed/test_remote_plan.rb +491 -0
  208. data/test/distributed/test_transaction.rb +463 -0
  209. data/test/mockups/tasks.rb +27 -0
  210. data/test/planning/test_loops.rb +380 -0
  211. data/test/planning/test_model.rb +427 -0
  212. data/test/planning/test_task.rb +106 -0
  213. data/test/relations/test_conflicts.rb +42 -0
  214. data/test/relations/test_ensured.rb +38 -0
  215. data/test/relations/test_executed_by.rb +149 -0
  216. data/test/relations/test_hierarchy.rb +158 -0
  217. data/test/relations/test_planned_by.rb +54 -0
  218. data/test/suite_core.rb +24 -0
  219. data/test/suite_distributed.rb +9 -0
  220. data/test/suite_planning.rb +3 -0
  221. data/test/suite_relations.rb +8 -0
  222. data/test/test_bgl.rb +508 -0
  223. data/test/test_control.rb +399 -0
  224. data/test/test_event.rb +894 -0
  225. data/test/test_exceptions.rb +592 -0
  226. data/test/test_interface.rb +37 -0
  227. data/test/test_log.rb +114 -0
  228. data/test/test_log_server.rb +132 -0
  229. data/test/test_plan.rb +584 -0
  230. data/test/test_propagation.rb +210 -0
  231. data/test/test_query.rb +266 -0
  232. data/test/test_relations.rb +180 -0
  233. data/test/test_state.rb +414 -0
  234. data/test/test_support.rb +16 -0
  235. data/test/test_task.rb +938 -0
  236. data/test/test_testcase.rb +122 -0
  237. data/test/test_thread_task.rb +73 -0
  238. data/test/test_transactions.rb +569 -0
  239. data/test/test_transactions_proxy.rb +198 -0
  240. metadata +570 -0
@@ -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