Class: CPEE::ProcessTransformation::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/cpee/processtransformation/structures.rb

Overview

}}}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGraph

Returns a new instance of Graph.



173
174
175
176
# File 'lib/cpee/processtransformation/structures.rb', line 173

def initialize
  @nodes = {}
  @links = []
end

Instance Attribute Details

#flowObject (readonly)

{{{



167
168
169
# File 'lib/cpee/processtransformation/structures.rb', line 167

def flow
  @flow
end

#nodesObject (readonly)

{{{



167
168
169
# File 'lib/cpee/processtransformation/structures.rb', line 167

def nodes
  @nodes
end

Instance Method Details



215
216
217
# File 'lib/cpee/processtransformation/structures.rb', line 215

def add_link(l)
  @links << l
end

#add_node(n) ⇒ Object



207
208
209
# File 'lib/cpee/processtransformation/structures.rb', line 207

def add_node(n)
  @nodes[n.id] = n
end

#clean_up(&bl) ⇒ Object



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/cpee/processtransformation/structures.rb', line 178

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



169
170
171
# File 'lib/cpee/processtransformation/structures.rb', line 169

def find_node(niceid)
  @nodes.find{|k,v| v.niceid == niceid }
end

#find_script_id(s) ⇒ Object



203
204
205
# File 'lib/cpee/processtransformation/structures.rb', line 203

def find_script_id(s)
  @nodes.find_all{|k,n| n.script_id == s}
end


211
212
213
# File 'lib/cpee/processtransformation/structures.rb', line 211

def link(f,t)
  @links.find{ |x| x.from == f && x.to == t }
end

#next_node(from) ⇒ Object



224
225
226
227
228
229
230
# File 'lib/cpee/processtransformation/structures.rb', line 224

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



219
220
221
222
# File 'lib/cpee/processtransformation/structures.rb', line 219

def next_nodes(from)
  links = @links.find_all { |x| x.from == from.id }
  links.map{|x| @nodes[x.to] }
end