Class: CPEE::ProcessTransformation::Graph
- Inherits:
-
Object
- Object
- CPEE::ProcessTransformation::Graph
- Defined in:
- lib/cpee/processtransformation/structures.rb
Overview
}}}
Instance Attribute Summary collapse
-
#flow ⇒ Object
readonly
{{{.
-
#nodes ⇒ Object
readonly
{{{.
Instance Method Summary collapse
- #add_link(l) ⇒ Object
- #add_node(n) ⇒ Object
- #clean_up(&bl) ⇒ Object
- #find_node(niceid) ⇒ Object
- #find_script_id(s) ⇒ Object
-
#initialize ⇒ Graph
constructor
A new instance of Graph.
- #link(f, t) ⇒ Object
- #next_node(from) ⇒ Object
- #next_nodes(from) ⇒ Object
Constructor Details
#initialize ⇒ Graph
Returns a new instance of Graph.
171 172 173 174 |
# File 'lib/cpee/processtransformation/structures.rb', line 171 def initialize @nodes = {} @links = [] end |
Instance Attribute Details
#flow ⇒ Object (readonly)
{{{
165 166 167 |
# File 'lib/cpee/processtransformation/structures.rb', line 165 def flow @flow end |
#nodes ⇒ Object (readonly)
{{{
165 166 167 |
# File 'lib/cpee/processtransformation/structures.rb', line 165 def nodes @nodes end |
Instance Method Details
#add_link(l) ⇒ Object
213 214 215 |
# File 'lib/cpee/processtransformation/structures.rb', line 213 def add_link(l) @links << l end |
#add_node(n) ⇒ Object
205 206 207 |
# File 'lib/cpee/processtransformation/structures.rb', line 205 def add_node(n) @nodes[n.id] = n end |
#clean_up(&bl) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/cpee/processtransformation/structures.rb', line 176 def clean_up(&bl) selnodes = [] @nodes.each do |k,n| ret = bl.call(n) selnodes << n if ret end selnodes.each do |n| if n.incoming > 1 || n.outgoing > 1 raise "#{n.inspect} - not a simple node to remove" end to,from = nil @links.each do |f| to = f if f.to == n.id from = f if f.from == n.id end if to && from to.to = from.to @links.delete(from) @nodes.delete(n.id) else raise "#{n.inspect} - could not remove flow" end end end |
#find_node(niceid) ⇒ Object
167 168 169 |
# File 'lib/cpee/processtransformation/structures.rb', line 167 def find_node(niceid) @nodes.find{|k,v| v.niceid == niceid } end |
#find_script_id(s) ⇒ Object
201 202 203 |
# File 'lib/cpee/processtransformation/structures.rb', line 201 def find_script_id(s) @nodes.find_all{|k,n| n.script_id == s} end |
#link(f, t) ⇒ Object
209 210 211 |
# File 'lib/cpee/processtransformation/structures.rb', line 209 def link(f,t) @links.find{ |x| x.from == f && x.to == t } end |
#next_node(from) ⇒ Object
222 223 224 225 226 227 228 |
# File 'lib/cpee/processtransformation/structures.rb', line 222 def next_node(from) if (nodes = next_nodes(from)).length == 1 nodes.first else raise "#{from.inspect} - multiple outgoing connections" end end |
#next_nodes(from) ⇒ Object
217 218 219 220 |
# File 'lib/cpee/processtransformation/structures.rb', line 217 def next_nodes(from) links = @links.find_all { |x| x.from == from.id } links.map{|x| @nodes[x.to] } end |