simple_graph 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/.yardopts +3 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +75 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docs/SimpleGraph.html +127 -0
- data/docs/SimpleGraph/Graph.html +825 -0
- data/docs/SimpleGraph/Graph/Node.html +483 -0
- data/docs/_index.html +137 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +492 -0
- data/docs/file.README.html +147 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +147 -0
- data/docs/js/app.js +248 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +163 -0
- data/docs/top-level-namespace.html +110 -0
- data/lib/simple_graph.rb +134 -0
- data/lib/simple_graph/version.rb +3 -0
- data/simple_graph.gemspec +27 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7d18636a755c3abfcbfecd3f6f64c21024126a17
|
4
|
+
data.tar.gz: c300ccf22026e00271ee1dce43d48e3acaecf004
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 050fc8f52c0ef9dd4b0a5d4a9c7043bbf7428a6ea1763dbf12a9e994a7b4b57d99135e8fdae3daceec24b65bc1b36922c64f22f39c9e7d18fa21791ed764fc4e
|
7
|
+
data.tar.gz: 63d0d1e856c9a1bf41ccac6d4146c24983ed4cec00fe8356b83d16666abe77153bfa31b559b26825a693020526b8242ab42f6737f0c7a3f426e34fb6c81ab2c5
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Kevin Nowald
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# SimpleGraph
|
2
|
+
|
3
|
+
A very basic graph gem for Ruby.
|
4
|
+
|
5
|
+
Currently only unweighted, undirected graphs are supported.
|
6
|
+
This means that multiple edges between nodes are ignored, although self loops are allowed.
|
7
|
+
|
8
|
+
#### Warning
|
9
|
+
Note that this is a very early version, and everything about this library is subject to change at any given time without notice. Expect breaking changes.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'simple_graph'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install simple_graph
|
26
|
+
|
27
|
+
## Documentation
|
28
|
+
|
29
|
+
Docs are built using YARD and are available at https://vesther.github.io/simple_graph/
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
### Quickstart
|
34
|
+
```ruby
|
35
|
+
require "simple_graph"
|
36
|
+
|
37
|
+
# Creating a new, empty graph
|
38
|
+
graph = SimpleGraph::Graph.new
|
39
|
+
|
40
|
+
# Adding nodes to the graph
|
41
|
+
# Creates a empty node containing only a autogenerated identifier
|
42
|
+
# Returns a graph-unique identifier for the newly created node
|
43
|
+
foo = graph.add_node()
|
44
|
+
# IDs can also be set manually
|
45
|
+
graph.add_node(id: "Kevin")
|
46
|
+
# Graphs can also hold arbitrary information in the 'data' hash
|
47
|
+
stuff = {
|
48
|
+
age: 21,
|
49
|
+
depression: true
|
50
|
+
}
|
51
|
+
bar = graph.add_node(id: "Igor", data: stuff)
|
52
|
+
|
53
|
+
# Edges can be created by passing the two node IDs to the connect_nodes method
|
54
|
+
graph.connect_nodes(foo, "Kevin")
|
55
|
+
|
56
|
+
# Paths between two nodes can be found by breadth-first search
|
57
|
+
# This method will return a array of arrays containing node IDs describing the path
|
58
|
+
paths = graph.find_paths(foo, bar)
|
59
|
+
|
60
|
+
# Retrieving info about the graph
|
61
|
+
graph.node_count # Returns the amount of nodes in the graph
|
62
|
+
graph.node_ids # Array of node identifiers in the graph
|
63
|
+
|
64
|
+
# Graphs can be written to files in the DOT format to be used with Graphviz
|
65
|
+
# Note that the node ID will be used for labels
|
66
|
+
File.write("test.dot", graph.to_dot_string)
|
67
|
+
```
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/vesther/simple_graph.
|
72
|
+
|
73
|
+
## License
|
74
|
+
|
75
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "simple_graph"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
require "pry"
|
11
|
+
Pry.start
|
12
|
+
|
13
|
+
# require "irb"
|
14
|
+
# IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
Module: SimpleGraph
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.9
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
pathId = "SimpleGraph";
|
19
|
+
relpath = '';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="_index.html">Index (S)</a> »
|
40
|
+
|
41
|
+
|
42
|
+
<span class="title">SimpleGraph</span>
|
43
|
+
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<div id="search">
|
47
|
+
|
48
|
+
<a class="full_list_link" id="class_list_link"
|
49
|
+
href="class_list.html">
|
50
|
+
|
51
|
+
<svg width="24" height="24">
|
52
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
+
</svg>
|
56
|
+
</a>
|
57
|
+
|
58
|
+
</div>
|
59
|
+
<div class="clear"></div>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<div id="content"><h1>Module: SimpleGraph
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
<dl>
|
80
|
+
<dt>Defined in:</dt>
|
81
|
+
<dd>lib/simple_graph.rb<span class="defines">,<br />
|
82
|
+
lib/simple_graph/version.rb</span>
|
83
|
+
</dd>
|
84
|
+
</dl>
|
85
|
+
|
86
|
+
</div>
|
87
|
+
|
88
|
+
<h2>Defined Under Namespace</h2>
|
89
|
+
<p class="children">
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="SimpleGraph/Graph.html" title="SimpleGraph::Graph (class)">Graph</a></span>
|
95
|
+
|
96
|
+
|
97
|
+
</p>
|
98
|
+
|
99
|
+
<h2>Constant Summary</h2>
|
100
|
+
<dl class="constants">
|
101
|
+
|
102
|
+
<dt id="VERSION-constant" class="">VERSION =
|
103
|
+
|
104
|
+
</dt>
|
105
|
+
<dd><pre class="code"><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>0.1.0</span><span class='tstring_end'>"</span></span></pre></dd>
|
106
|
+
|
107
|
+
</dl>
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
</div>
|
118
|
+
|
119
|
+
<div id="footer">
|
120
|
+
Generated on Thu Nov 23 18:04:53 2017 by
|
121
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
122
|
+
0.9.9 (ruby-2.3.1).
|
123
|
+
</div>
|
124
|
+
|
125
|
+
</div>
|
126
|
+
</body>
|
127
|
+
</html>
|
@@ -0,0 +1,825 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
Class: SimpleGraph::Graph
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.9
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
pathId = "SimpleGraph::Graph";
|
19
|
+
relpath = '../';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="../class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="../_index.html">Index (G)</a> »
|
40
|
+
<span class='title'><span class='object_link'><a href="../SimpleGraph.html" title="SimpleGraph (module)">SimpleGraph</a></span></span>
|
41
|
+
»
|
42
|
+
<span class="title">Graph</span>
|
43
|
+
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<div id="search">
|
47
|
+
|
48
|
+
<a class="full_list_link" id="class_list_link"
|
49
|
+
href="../class_list.html">
|
50
|
+
|
51
|
+
<svg width="24" height="24">
|
52
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
+
</svg>
|
56
|
+
</a>
|
57
|
+
|
58
|
+
</div>
|
59
|
+
<div class="clear"></div>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<div id="content"><h1>Class: SimpleGraph::Graph
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
<dl>
|
70
|
+
<dt>Inherits:</dt>
|
71
|
+
<dd>
|
72
|
+
<span class="inheritName">Object</span>
|
73
|
+
|
74
|
+
<ul class="fullTree">
|
75
|
+
<li>Object</li>
|
76
|
+
|
77
|
+
<li class="next">SimpleGraph::Graph</li>
|
78
|
+
|
79
|
+
</ul>
|
80
|
+
<a href="#" class="inheritanceTree">show all</a>
|
81
|
+
|
82
|
+
</dd>
|
83
|
+
</dl>
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
<dl>
|
96
|
+
<dt>Defined in:</dt>
|
97
|
+
<dd>lib/simple_graph.rb</dd>
|
98
|
+
</dl>
|
99
|
+
|
100
|
+
</div>
|
101
|
+
|
102
|
+
<h2>Defined Under Namespace</h2>
|
103
|
+
<p class="children">
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="Graph/Node.html" title="SimpleGraph::Graph::Node (class)">Node</a></span>
|
109
|
+
|
110
|
+
|
111
|
+
</p>
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
<h2>
|
121
|
+
Instance Method Summary
|
122
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
123
|
+
</h2>
|
124
|
+
|
125
|
+
<ul class="summary">
|
126
|
+
|
127
|
+
<li class="public ">
|
128
|
+
<span class="summary_signature">
|
129
|
+
|
130
|
+
<a href="#add_node-instance_method" title="#add_node (instance method)">#<strong>add_node</strong>(id: nil, data: {}) ⇒ Object </a>
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
</span>
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
<span class="summary_desc"><div class='inline'><p>Add a new node to the graph.</p>
|
145
|
+
</div></span>
|
146
|
+
|
147
|
+
</li>
|
148
|
+
|
149
|
+
|
150
|
+
<li class="public ">
|
151
|
+
<span class="summary_signature">
|
152
|
+
|
153
|
+
<a href="#connect_nodes-instance_method" title="#connect_nodes (instance method)">#<strong>connect_nodes</strong>(first, second) ⇒ Object </a>
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
</span>
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
<span class="summary_desc"><div class='inline'><p>Method to connect 2 nodes.</p>
|
168
|
+
</div></span>
|
169
|
+
|
170
|
+
</li>
|
171
|
+
|
172
|
+
|
173
|
+
<li class="public ">
|
174
|
+
<span class="summary_signature">
|
175
|
+
|
176
|
+
<a href="#delete_node-instance_method" title="#delete_node (instance method)">#<strong>delete_node</strong>(node) ⇒ Object </a>
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
</span>
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
<span class="summary_desc"><div class='inline'><p>Delete a node from the graph.</p>
|
191
|
+
</div></span>
|
192
|
+
|
193
|
+
</li>
|
194
|
+
|
195
|
+
|
196
|
+
<li class="public ">
|
197
|
+
<span class="summary_signature">
|
198
|
+
|
199
|
+
<a href="#find_paths-instance_method" title="#find_paths (instance method)">#<strong>find_paths</strong>(source_id, terminal_id) ⇒ Object </a>
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
</span>
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
<span class="summary_desc"><div class='inline'></div></span>
|
214
|
+
|
215
|
+
</li>
|
216
|
+
|
217
|
+
|
218
|
+
<li class="public ">
|
219
|
+
<span class="summary_signature">
|
220
|
+
|
221
|
+
<a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong> ⇒ Graph </a>
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
</span>
|
226
|
+
|
227
|
+
|
228
|
+
<span class="note title constructor">constructor</span>
|
229
|
+
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
<span class="summary_desc"><div class='inline'><p>Constructor.</p>
|
238
|
+
</div></span>
|
239
|
+
|
240
|
+
</li>
|
241
|
+
|
242
|
+
|
243
|
+
<li class="public ">
|
244
|
+
<span class="summary_signature">
|
245
|
+
|
246
|
+
<a href="#load_from_string-instance_method" title="#load_from_string (instance method)">#<strong>load_from_string</strong>(str) ⇒ Object </a>
|
247
|
+
|
248
|
+
|
249
|
+
|
250
|
+
</span>
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
<span class="summary_desc"><div class='inline'></div></span>
|
261
|
+
|
262
|
+
</li>
|
263
|
+
|
264
|
+
|
265
|
+
<li class="public ">
|
266
|
+
<span class="summary_signature">
|
267
|
+
|
268
|
+
<a href="#node_count-instance_method" title="#node_count (instance method)">#<strong>node_count</strong> ⇒ Object </a>
|
269
|
+
|
270
|
+
|
271
|
+
|
272
|
+
</span>
|
273
|
+
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
|
282
|
+
<span class="summary_desc"><div class='inline'><p>Retrieve the amount of nodes in the graph.</p>
|
283
|
+
</div></span>
|
284
|
+
|
285
|
+
</li>
|
286
|
+
|
287
|
+
|
288
|
+
<li class="public ">
|
289
|
+
<span class="summary_signature">
|
290
|
+
|
291
|
+
<a href="#node_ids-instance_method" title="#node_ids (instance method)">#<strong>node_ids</strong> ⇒ Object </a>
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
</span>
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
<span class="summary_desc"><div class='inline'><p>Retrieve a array of node ids in the graph.</p>
|
306
|
+
</div></span>
|
307
|
+
|
308
|
+
</li>
|
309
|
+
|
310
|
+
|
311
|
+
<li class="public ">
|
312
|
+
<span class="summary_signature">
|
313
|
+
|
314
|
+
<a href="#to_dot_string-instance_method" title="#to_dot_string (instance method)">#<strong>to_dot_string</strong> ⇒ Object </a>
|
315
|
+
|
316
|
+
|
317
|
+
|
318
|
+
</span>
|
319
|
+
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
|
328
|
+
<span class="summary_desc"><div class='inline'><p>Retrieve the current graph in the DOT format to be used with Graphviz.</p>
|
329
|
+
</div></span>
|
330
|
+
|
331
|
+
</li>
|
332
|
+
|
333
|
+
|
334
|
+
</ul>
|
335
|
+
|
336
|
+
|
337
|
+
<div id="constructor_details" class="method_details_list">
|
338
|
+
<h2>Constructor Details</h2>
|
339
|
+
|
340
|
+
<div class="method_details first">
|
341
|
+
<h3 class="signature first" id="initialize-instance_method">
|
342
|
+
|
343
|
+
#<strong>initialize</strong> ⇒ <tt><span class='object_link'><a href="" title="SimpleGraph::Graph (class)">Graph</a></span></tt>
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
</h3><div class="docstring">
|
350
|
+
<div class="discussion">
|
351
|
+
<p>Constructor</p>
|
352
|
+
|
353
|
+
|
354
|
+
</div>
|
355
|
+
</div>
|
356
|
+
<div class="tags">
|
357
|
+
|
358
|
+
|
359
|
+
</div><table class="source_code">
|
360
|
+
<tr>
|
361
|
+
<td>
|
362
|
+
<pre class="lines">
|
363
|
+
|
364
|
+
|
365
|
+
22
|
366
|
+
23
|
367
|
+
24
|
368
|
+
25
|
369
|
+
26
|
370
|
+
27
|
371
|
+
28
|
372
|
+
29</pre>
|
373
|
+
</td>
|
374
|
+
<td>
|
375
|
+
<pre class="code"><span class="info file"># File 'lib/simple_graph.rb', line 22</span>
|
376
|
+
|
377
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span>
|
378
|
+
<span class='comment'># Our array of internal nodes
|
379
|
+
</span> <span class='ivar'>@nodes</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
|
380
|
+
<span class='comment'># Helper hash lookup table
|
381
|
+
</span> <span class='ivar'>@nodes_by_id</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
|
382
|
+
<span class='comment'># Tracks the highest used id for autoincrement
|
383
|
+
</span> <span class='ivar'>@last_id</span> <span class='op'>=</span> <span class='int'>0</span>
|
384
|
+
<span class='kw'>end</span></pre>
|
385
|
+
</td>
|
386
|
+
</tr>
|
387
|
+
</table>
|
388
|
+
</div>
|
389
|
+
|
390
|
+
</div>
|
391
|
+
|
392
|
+
|
393
|
+
<div id="instance_method_details" class="method_details_list">
|
394
|
+
<h2>Instance Method Details</h2>
|
395
|
+
|
396
|
+
|
397
|
+
<div class="method_details first">
|
398
|
+
<h3 class="signature first" id="add_node-instance_method">
|
399
|
+
|
400
|
+
#<strong>add_node</strong>(id: nil, data: {}) ⇒ <tt>Object</tt>
|
401
|
+
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
|
406
|
+
</h3><div class="docstring">
|
407
|
+
<div class="discussion">
|
408
|
+
<p>Add a new node to the graph</p>
|
409
|
+
|
410
|
+
|
411
|
+
</div>
|
412
|
+
</div>
|
413
|
+
<div class="tags">
|
414
|
+
|
415
|
+
|
416
|
+
</div><table class="source_code">
|
417
|
+
<tr>
|
418
|
+
<td>
|
419
|
+
<pre class="lines">
|
420
|
+
|
421
|
+
|
422
|
+
32
|
423
|
+
33
|
424
|
+
34
|
425
|
+
35
|
426
|
+
36
|
427
|
+
37
|
428
|
+
38</pre>
|
429
|
+
</td>
|
430
|
+
<td>
|
431
|
+
<pre class="code"><span class="info file"># File 'lib/simple_graph.rb', line 32</span>
|
432
|
+
|
433
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_add_node'>add_node</span><span class='lparen'>(</span><span class='label'>id:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>data:</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
|
434
|
+
<span class='id identifier rubyid_id'>id</span> <span class='op'>||=</span> <span class='id identifier rubyid_next_id'>next_id</span>
|
435
|
+
<span class='id identifier rubyid_node'>node</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="" title="SimpleGraph::Graph (class)">Graph</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Graph/Node.html" title="SimpleGraph::Graph::Node (class)">Node</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Graph/Node.html#initialize-instance_method" title="SimpleGraph::Graph::Node#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='label'>id:</span> <span class='id identifier rubyid_id'>id</span><span class='comma'>,</span> <span class='label'>data:</span> <span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
|
436
|
+
<span class='ivar'>@nodes</span> <span class='op'><<</span> <span class='id identifier rubyid_node'>node</span>
|
437
|
+
<span class='ivar'>@nodes_by_id</span><span class='lbracket'>[</span><span class='id identifier rubyid_id'>id</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_node'>node</span>
|
438
|
+
<span class='id identifier rubyid_node'>node</span>
|
439
|
+
<span class='kw'>end</span></pre>
|
440
|
+
</td>
|
441
|
+
</tr>
|
442
|
+
</table>
|
443
|
+
</div>
|
444
|
+
|
445
|
+
<div class="method_details ">
|
446
|
+
<h3 class="signature " id="connect_nodes-instance_method">
|
447
|
+
|
448
|
+
#<strong>connect_nodes</strong>(first, second) ⇒ <tt>Object</tt>
|
449
|
+
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
|
454
|
+
</h3><div class="docstring">
|
455
|
+
<div class="discussion">
|
456
|
+
<p>Method to connect 2 nodes</p>
|
457
|
+
|
458
|
+
|
459
|
+
</div>
|
460
|
+
</div>
|
461
|
+
<div class="tags">
|
462
|
+
|
463
|
+
|
464
|
+
</div><table class="source_code">
|
465
|
+
<tr>
|
466
|
+
<td>
|
467
|
+
<pre class="lines">
|
468
|
+
|
469
|
+
|
470
|
+
62
|
471
|
+
63
|
472
|
+
64
|
473
|
+
65</pre>
|
474
|
+
</td>
|
475
|
+
<td>
|
476
|
+
<pre class="code"><span class="info file"># File 'lib/simple_graph.rb', line 62</span>
|
477
|
+
|
478
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_connect_nodes'>connect_nodes</span><span class='lparen'>(</span><span class='id identifier rubyid_first'>first</span><span class='comma'>,</span> <span class='id identifier rubyid_second'>second</span><span class='rparen'>)</span>
|
479
|
+
<span class='ivar'>@nodes_by_id</span><span class='lbracket'>[</span><span class='id identifier rubyid_first'>first</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_add_neighbor'>add_neighbor</span><span class='lparen'>(</span><span class='ivar'>@nodes_by_id</span><span class='lbracket'>[</span><span class='id identifier rubyid_second'>second</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
480
|
+
<span class='ivar'>@nodes_by_id</span><span class='lbracket'>[</span><span class='id identifier rubyid_second'>second</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_add_neighbor'>add_neighbor</span><span class='lparen'>(</span><span class='ivar'>@nodes_by_id</span><span class='lbracket'>[</span><span class='id identifier rubyid_first'>first</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
481
|
+
<span class='kw'>end</span></pre>
|
482
|
+
</td>
|
483
|
+
</tr>
|
484
|
+
</table>
|
485
|
+
</div>
|
486
|
+
|
487
|
+
<div class="method_details ">
|
488
|
+
<h3 class="signature " id="delete_node-instance_method">
|
489
|
+
|
490
|
+
#<strong>delete_node</strong>(node) ⇒ <tt>Object</tt>
|
491
|
+
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
|
496
|
+
</h3><div class="docstring">
|
497
|
+
<div class="discussion">
|
498
|
+
<p>Delete a node from the graph</p>
|
499
|
+
|
500
|
+
|
501
|
+
</div>
|
502
|
+
</div>
|
503
|
+
<div class="tags">
|
504
|
+
|
505
|
+
|
506
|
+
</div><table class="source_code">
|
507
|
+
<tr>
|
508
|
+
<td>
|
509
|
+
<pre class="lines">
|
510
|
+
|
511
|
+
|
512
|
+
41
|
513
|
+
42
|
514
|
+
43
|
515
|
+
44
|
516
|
+
45
|
517
|
+
46
|
518
|
+
47
|
519
|
+
48</pre>
|
520
|
+
</td>
|
521
|
+
<td>
|
522
|
+
<pre class="code"><span class="info file"># File 'lib/simple_graph.rb', line 41</span>
|
523
|
+
|
524
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_delete_node'>delete_node</span><span class='lparen'>(</span><span class='id identifier rubyid_node'>node</span><span class='rparen'>)</span>
|
525
|
+
<span class='comment'># Remove all edges connected with this node
|
526
|
+
</span> <span class='id identifier rubyid_node'>node</span><span class='period'>.</span><span class='id identifier rubyid_neighbors'>neighbors</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_neighbor'>neighbor</span><span class='op'>|</span>
|
527
|
+
<span class='id identifier rubyid_neighbor'>neighbor</span><span class='period'>.</span><span class='id identifier rubyid_neighbors'>neighbors</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='id identifier rubyid_node'>node</span><span class='rparen'>)</span>
|
528
|
+
<span class='kw'>end</span>
|
529
|
+
<span class='comment'># Remove the node itself
|
530
|
+
</span> <span class='ivar'>@nodes</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='id identifier rubyid_node'>node</span><span class='rparen'>)</span>
|
531
|
+
<span class='kw'>end</span></pre>
|
532
|
+
</td>
|
533
|
+
</tr>
|
534
|
+
</table>
|
535
|
+
</div>
|
536
|
+
|
537
|
+
<div class="method_details ">
|
538
|
+
<h3 class="signature " id="find_paths-instance_method">
|
539
|
+
|
540
|
+
#<strong>find_paths</strong>(source_id, terminal_id) ⇒ <tt>Object</tt>
|
541
|
+
|
542
|
+
|
543
|
+
|
544
|
+
|
545
|
+
|
546
|
+
</h3><table class="source_code">
|
547
|
+
<tr>
|
548
|
+
<td>
|
549
|
+
<pre class="lines">
|
550
|
+
|
551
|
+
|
552
|
+
97
|
553
|
+
98
|
554
|
+
99
|
555
|
+
100
|
556
|
+
101
|
557
|
+
102
|
558
|
+
103
|
559
|
+
104
|
560
|
+
105
|
561
|
+
106
|
562
|
+
107
|
563
|
+
108
|
564
|
+
109
|
565
|
+
110
|
566
|
+
111
|
567
|
+
112
|
568
|
+
113
|
569
|
+
114
|
570
|
+
115
|
571
|
+
116
|
572
|
+
117
|
573
|
+
118
|
574
|
+
119
|
575
|
+
120
|
576
|
+
121
|
577
|
+
122
|
578
|
+
123
|
579
|
+
124
|
580
|
+
125</pre>
|
581
|
+
</td>
|
582
|
+
<td>
|
583
|
+
<pre class="code"><span class="info file"># File 'lib/simple_graph.rb', line 97</span>
|
584
|
+
|
585
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_find_paths'>find_paths</span><span class='lparen'>(</span><span class='id identifier rubyid_source_id'>source_id</span><span class='comma'>,</span> <span class='id identifier rubyid_terminal_id'>terminal_id</span><span class='rparen'>)</span>
|
586
|
+
<span class='id identifier rubyid_found_paths'>found_paths</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
|
587
|
+
|
588
|
+
<span class='comment'># Path queue
|
589
|
+
</span> <span class='id identifier rubyid_paths'>paths</span> <span class='op'>=</span> <span class='const'>Queue</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
590
|
+
|
591
|
+
<span class='id identifier rubyid_destination'>destination</span> <span class='op'>=</span> <span class='ivar'>@nodes_by_id</span><span class='lbracket'>[</span><span class='id identifier rubyid_terminal_id'>terminal_id</span><span class='rbracket'>]</span>
|
592
|
+
|
593
|
+
<span class='comment'># Current Path
|
594
|
+
</span> <span class='id identifier rubyid_path'>path</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='ivar'>@nodes_by_id</span><span class='lbracket'>[</span><span class='id identifier rubyid_source_id'>source_id</span><span class='rbracket'>]</span><span class='rbracket'>]</span>
|
595
|
+
|
596
|
+
<span class='id identifier rubyid_paths'>paths</span> <span class='op'><<</span> <span class='id identifier rubyid_path'>path</span>
|
597
|
+
|
598
|
+
<span class='kw'>until</span> <span class='id identifier rubyid_paths'>paths</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
|
599
|
+
<span class='id identifier rubyid_path'>path</span> <span class='op'>=</span> <span class='id identifier rubyid_paths'>paths</span><span class='period'>.</span><span class='id identifier rubyid_pop'>pop</span>
|
600
|
+
|
601
|
+
<span class='id identifier rubyid_last'>last</span> <span class='op'>=</span> <span class='id identifier rubyid_path'>path</span><span class='period'>.</span><span class='id identifier rubyid_last'>last</span>
|
602
|
+
|
603
|
+
<span class='id identifier rubyid_found_paths'>found_paths</span> <span class='op'><<</span> <span class='id identifier rubyid_path'>path</span> <span class='kw'>if</span> <span class='id identifier rubyid_last'>last</span> <span class='op'>==</span> <span class='id identifier rubyid_destination'>destination</span>
|
604
|
+
|
605
|
+
<span class='id identifier rubyid_last'>last</span><span class='period'>.</span><span class='id identifier rubyid_neighbors'>neighbors</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_neighbor'>neighbor</span><span class='op'>|</span>
|
606
|
+
<span class='kw'>next</span> <span class='kw'>if</span> <span class='id identifier rubyid_path'>path</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='id identifier rubyid_neighbor'>neighbor</span><span class='rparen'>)</span>
|
607
|
+
<span class='comment'># Note that this creates a copy of the current path.
|
608
|
+
</span> <span class='id identifier rubyid_paths'>paths</span> <span class='op'><<</span> <span class='id identifier rubyid_path'>path</span> <span class='op'>+</span> <span class='lbracket'>[</span><span class='id identifier rubyid_neighbor'>neighbor</span><span class='rbracket'>]</span>
|
609
|
+
<span class='kw'>end</span>
|
610
|
+
<span class='kw'>end</span>
|
611
|
+
|
612
|
+
<span class='id identifier rubyid_found_paths'>found_paths</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_found_path'>found_path</span><span class='op'>|</span> <span class='id identifier rubyid_found_path'>found_path</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:id</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
613
|
+
<span class='kw'>end</span></pre>
|
614
|
+
</td>
|
615
|
+
</tr>
|
616
|
+
</table>
|
617
|
+
</div>
|
618
|
+
|
619
|
+
<div class="method_details ">
|
620
|
+
<h3 class="signature " id="load_from_string-instance_method">
|
621
|
+
|
622
|
+
#<strong>load_from_string</strong>(str) ⇒ <tt>Object</tt>
|
623
|
+
|
624
|
+
|
625
|
+
|
626
|
+
|
627
|
+
|
628
|
+
</h3><table class="source_code">
|
629
|
+
<tr>
|
630
|
+
<td>
|
631
|
+
<pre class="lines">
|
632
|
+
|
633
|
+
|
634
|
+
80
|
635
|
+
81
|
636
|
+
82
|
637
|
+
83
|
638
|
+
84
|
639
|
+
85
|
640
|
+
86
|
641
|
+
87
|
642
|
+
88
|
643
|
+
89
|
644
|
+
90
|
645
|
+
91
|
646
|
+
92
|
647
|
+
93
|
648
|
+
94
|
649
|
+
95</pre>
|
650
|
+
</td>
|
651
|
+
<td>
|
652
|
+
<pre class="code"><span class="info file"># File 'lib/simple_graph.rb', line 80</span>
|
653
|
+
|
654
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_load_from_string'>load_from_string</span><span class='lparen'>(</span><span class='id identifier rubyid_str'>str</span><span class='rparen'>)</span>
|
655
|
+
<span class='id identifier rubyid_lines'>lines</span> <span class='op'>=</span> <span class='id identifier rubyid_str'>str</span><span class='period'>.</span><span class='id identifier rubyid_lines'>lines</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:chomp</span><span class='rparen'>)</span>
|
656
|
+
|
657
|
+
<span class='id identifier rubyid_separator_position'>separator_position</span> <span class='op'>=</span> <span class='id identifier rubyid_lines'>lines</span><span class='period'>.</span><span class='id identifier rubyid_index'>index</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>#</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
658
|
+
|
659
|
+
<span class='id identifier rubyid_nodes'>nodes</span> <span class='op'>=</span> <span class='id identifier rubyid_lines'>lines</span><span class='lbracket'>[</span><span class='int'>0</span><span class='op'>..</span><span class='id identifier rubyid_separator_position'>separator_position</span> <span class='op'>-</span> <span class='int'>1</span><span class='rbracket'>]</span>
|
660
|
+
<span class='id identifier rubyid_edges'>edges</span> <span class='op'>=</span> <span class='id identifier rubyid_lines'>lines</span><span class='lbracket'>[</span><span class='id identifier rubyid_separator_position'>separator_position</span> <span class='op'>+</span> <span class='int'>1</span><span class='op'>..</span><span class='op'>-</span><span class='int'>1</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:split</span><span class='rparen'>)</span>
|
661
|
+
|
662
|
+
<span class='id identifier rubyid_nodes'>nodes</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_node'>node</span><span class='op'>|</span>
|
663
|
+
<span class='id identifier rubyid_add_node'>add_node</span><span class='lparen'>(</span><span class='label'>id:</span> <span class='id identifier rubyid_node'>node</span><span class='rparen'>)</span>
|
664
|
+
<span class='kw'>end</span>
|
665
|
+
|
666
|
+
<span class='id identifier rubyid_edges'>edges</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_edge'>edge</span><span class='op'>|</span>
|
667
|
+
<span class='id identifier rubyid_connect_nodes'>connect_nodes</span><span class='lparen'>(</span><span class='id identifier rubyid_edge'>edge</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='comma'>,</span> <span class='id identifier rubyid_edge'>edge</span><span class='period'>.</span><span class='id identifier rubyid_last'>last</span><span class='rparen'>)</span>
|
668
|
+
<span class='kw'>end</span>
|
669
|
+
<span class='kw'>end</span></pre>
|
670
|
+
</td>
|
671
|
+
</tr>
|
672
|
+
</table>
|
673
|
+
</div>
|
674
|
+
|
675
|
+
<div class="method_details ">
|
676
|
+
<h3 class="signature " id="node_count-instance_method">
|
677
|
+
|
678
|
+
#<strong>node_count</strong> ⇒ <tt>Object</tt>
|
679
|
+
|
680
|
+
|
681
|
+
|
682
|
+
|
683
|
+
|
684
|
+
</h3><div class="docstring">
|
685
|
+
<div class="discussion">
|
686
|
+
<p>Retrieve the amount of nodes in the graph</p>
|
687
|
+
|
688
|
+
|
689
|
+
</div>
|
690
|
+
</div>
|
691
|
+
<div class="tags">
|
692
|
+
|
693
|
+
|
694
|
+
</div><table class="source_code">
|
695
|
+
<tr>
|
696
|
+
<td>
|
697
|
+
<pre class="lines">
|
698
|
+
|
699
|
+
|
700
|
+
51
|
701
|
+
52
|
702
|
+
53</pre>
|
703
|
+
</td>
|
704
|
+
<td>
|
705
|
+
<pre class="code"><span class="info file"># File 'lib/simple_graph.rb', line 51</span>
|
706
|
+
|
707
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_node_count'>node_count</span>
|
708
|
+
<span class='ivar'>@nodes</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span>
|
709
|
+
<span class='kw'>end</span></pre>
|
710
|
+
</td>
|
711
|
+
</tr>
|
712
|
+
</table>
|
713
|
+
</div>
|
714
|
+
|
715
|
+
<div class="method_details ">
|
716
|
+
<h3 class="signature " id="node_ids-instance_method">
|
717
|
+
|
718
|
+
#<strong>node_ids</strong> ⇒ <tt>Object</tt>
|
719
|
+
|
720
|
+
|
721
|
+
|
722
|
+
|
723
|
+
|
724
|
+
</h3><div class="docstring">
|
725
|
+
<div class="discussion">
|
726
|
+
<p>Retrieve a array of node ids in the graph</p>
|
727
|
+
|
728
|
+
|
729
|
+
</div>
|
730
|
+
</div>
|
731
|
+
<div class="tags">
|
732
|
+
|
733
|
+
|
734
|
+
</div><table class="source_code">
|
735
|
+
<tr>
|
736
|
+
<td>
|
737
|
+
<pre class="lines">
|
738
|
+
|
739
|
+
|
740
|
+
56
|
741
|
+
57
|
742
|
+
58
|
743
|
+
59</pre>
|
744
|
+
</td>
|
745
|
+
<td>
|
746
|
+
<pre class="code"><span class="info file"># File 'lib/simple_graph.rb', line 56</span>
|
747
|
+
|
748
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_node_ids'>node_ids</span>
|
749
|
+
<span class='comment'># The .to_a call is used to return a copy of the array so it cannot be modified from the outside.
|
750
|
+
</span> <span class='ivar'>@nodes_by_id</span><span class='period'>.</span><span class='id identifier rubyid_keys'>keys</span><span class='period'>.</span><span class='id identifier rubyid_to_a'>to_a</span>
|
751
|
+
<span class='kw'>end</span></pre>
|
752
|
+
</td>
|
753
|
+
</tr>
|
754
|
+
</table>
|
755
|
+
</div>
|
756
|
+
|
757
|
+
<div class="method_details ">
|
758
|
+
<h3 class="signature " id="to_dot_string-instance_method">
|
759
|
+
|
760
|
+
#<strong>to_dot_string</strong> ⇒ <tt>Object</tt>
|
761
|
+
|
762
|
+
|
763
|
+
|
764
|
+
|
765
|
+
|
766
|
+
</h3><div class="docstring">
|
767
|
+
<div class="discussion">
|
768
|
+
<p>Retrieve the current graph in the DOT format to be used with Graphviz</p>
|
769
|
+
|
770
|
+
|
771
|
+
</div>
|
772
|
+
</div>
|
773
|
+
<div class="tags">
|
774
|
+
|
775
|
+
|
776
|
+
</div><table class="source_code">
|
777
|
+
<tr>
|
778
|
+
<td>
|
779
|
+
<pre class="lines">
|
780
|
+
|
781
|
+
|
782
|
+
68
|
783
|
+
69
|
784
|
+
70
|
785
|
+
71
|
786
|
+
72
|
787
|
+
73
|
788
|
+
74
|
789
|
+
75
|
790
|
+
76
|
791
|
+
77
|
792
|
+
78</pre>
|
793
|
+
</td>
|
794
|
+
<td>
|
795
|
+
<pre class="code"><span class="info file"># File 'lib/simple_graph.rb', line 68</span>
|
796
|
+
|
797
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_to_dot_string'>to_dot_string</span>
|
798
|
+
<span class='id identifier rubyid_str'>str</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>strict graph {\n</span><span class='tstring_end'>"</span></span>
|
799
|
+
|
800
|
+
<span class='ivar'>@nodes</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_node'>node</span><span class='op'>|</span>
|
801
|
+
<span class='id identifier rubyid_node'>node</span><span class='period'>.</span><span class='id identifier rubyid_neighbors'>neighbors</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_neighbor'>neighbor</span><span class='op'>|</span>
|
802
|
+
<span class='id identifier rubyid_str'>str</span> <span class='op'><<</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> \"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_node'>node</span><span class='period'>.</span><span class='id identifier rubyid_data'>data</span><span class='lbracket'>[</span><span class='symbol'>:name</span><span class='rbracket'>]</span><span class='embexpr_end'>}</span><span class='tstring_content'>\" -- \"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_neighbor'>neighbor</span><span class='period'>.</span><span class='id identifier rubyid_data'>data</span><span class='lbracket'>[</span><span class='symbol'>:name</span><span class='rbracket'>]</span><span class='embexpr_end'>}</span><span class='tstring_content'>\";\n</span><span class='tstring_end'>"</span></span>
|
803
|
+
<span class='kw'>end</span>
|
804
|
+
<span class='kw'>end</span>
|
805
|
+
|
806
|
+
<span class='id identifier rubyid_str'>str</span> <span class='op'><<</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>}</span><span class='tstring_end'>"</span></span>
|
807
|
+
<span class='kw'>end</span></pre>
|
808
|
+
</td>
|
809
|
+
</tr>
|
810
|
+
</table>
|
811
|
+
</div>
|
812
|
+
|
813
|
+
</div>
|
814
|
+
|
815
|
+
</div>
|
816
|
+
|
817
|
+
<div id="footer">
|
818
|
+
Generated on Thu Nov 23 18:04:53 2017 by
|
819
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
820
|
+
0.9.9 (ruby-2.3.1).
|
821
|
+
</div>
|
822
|
+
|
823
|
+
</div>
|
824
|
+
</body>
|
825
|
+
</html>
|