lib/cpee/processtransformation/structures.rb in cpee-1.3.221 vs lib/cpee/processtransformation/structures.rb in cpee-1.3.222
- old
+ new
@@ -1,19 +1,19 @@
# encoding: UTF-8
#
# This file is part of CPEE.
#
# Apache License, Version 2.0
-#
+#
# Copyright (c) 2013 Juergen Mangler
-#
+#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
@@ -31,14 +31,14 @@
def each(&a)
@sub.each{|s| a.call(s)}
end
def length
@sub.length
- end
+ end
end #}}}
- class Node #{{{
+ class Node #{{{
include Container
@@niceid = {}
attr_reader :id, :label, :niceid
attr_reader :endpoints, :methods, :parameters, :attributes
attr_accessor :script, :script_id, :script_var, :script_type, :incoming, :outgoing, :type
@@ -57,11 +57,11 @@
@parameters = {}
@incoming = incoming
@outgoing = outgoing
@attributes = {}
end
- end # }}}
+ end # }}}
class Link #{{{
attr_accessor :from, :to
attr_reader :condition, :attributes
def initialize(from,to,cond=nil)
@from = from
@@ -114,11 +114,11 @@
@mode = :exclusive
@condition = []
@sub = []
@condition_type = nil
@attributes = {}
- end
+ end
def new_branch
(@sub << Alternative.new(@id)).last
end
end #}}}
@@ -136,11 +136,11 @@
@wait = wait
end
def new_branch
(@sub << Branch.new(@id)).last
end
- end #}}}
+ end #}}}
class Conditional #{{{
include Container
include Struct
include Enumerable
@@ -153,11 +153,11 @@
@id = id
@sub = []
@mode = mode
@type = type
@attributes = {}
- end
+ end
def new_branch
(@sub << Alternative.new(@id)).last
end
end #}}}
@@ -180,11 +180,11 @@
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
+ end
to,from = nil
@links.each do |f|
to = f if f.to == n.id
from = f if f.from == n.id
end
@@ -192,21 +192,21 @@
to.to = from.to
@links.delete(from)
@nodes.delete(n.id)
else
raise "#{n.inspect} - could not remove flow"
- end
+ end
end
end
def find_script_id(s)
@nodes.find_all{|k,n| n.script_id == s}
end
def add_node(n)
@nodes[n.id] = n
- end
+ end
def link(f,t)
@links.find{ |x| x.from == f && x.to == t }
end
@@ -222,11 +222,11 @@
def next_node(from)
if (nodes = next_nodes(from)).length == 1
nodes.first
else
raise "#{from.inspect} - multiple outgoing connections"
- end
+ end
end
end #}}}
class Tree < Array #{{{
def condition?; false; end
@@ -261,15 +261,15 @@
end
def remove(trcs)
trcs.each do |t|
self.delete(t)
- end
+ end
end
def remove_by_endnode(enode)
self.delete_if do |t|
- t[0] != enode
+ t[0] != enode
end
end
def empty!
self.delete_if{true}
@@ -288,20 +288,31 @@
def shortest
self.min_by{|e|e.length}
end
+ def legend
+ ret = "Legend:\n"
+ a = self.flatten.uniq
+ a.each {|n| ret << " " + n.niceid.to_s + ' ' + n.type.to_s + ' ' + n.label.to_s + "\n" }
+ ret
+ end
+
def to_s
"TRACES: " + self.collect { |t| t.empty? ? '∅' : t.collect{|n| "%2d" % n.niceid }.join('→ ') }.join("\n ")
end
def shift_all
self.each{ |tr| tr.shift }
- end
- def pop_all
- self.each{ |tr| tr.pop }
- end
+ end
+ def pop_all(what=nil)
+ if node.nil?
+ self.each{ |tr| tr.pop }
+ else
+ self.each{ |tr| tr.pop if tr.last == what }
+ end
+ end
def finished?
self.reduce(0){|sum,t| sum += t.length} == 0
end
@@ -312,17 +323,17 @@
def incoming(node)
tcount = 1
self.each do |t|
break if t.length == 1
tcount += 1 if t.last == node
- end
+ end
tcount
end
def include_in_all?(e)
num = 0
- self.each{|n| num += 1 if n.include?(e)}
+ self.each{|n| num += 1 if n.include?(e)}
num == self.length
end
def all_loops?
num = 0
@@ -337,11 +348,11 @@
self << (front ? [nil,tb] : [tb,nil])
else
self.each do |t|
t << tb unless t.last == t.first ### an explicit break
end
- end
+ end
end
def loops
lo = Traces.new self.find_all{ |t| t.first == t.last }
self.each do |t|
@@ -363,11 +374,11 @@
### in case of nested loop (common part occurs at end of loop), include the whole
0.upto (maxcut-1) do |j|
if self[i][j] == self[i].last
loops << self[i].shift(self[i].length)
end
- end
+ end
end
loops.uniq!
loops.remove_empty
self.remove_empty
@@ -401,13 +412,13 @@
unless t.last == max
last = t.last
if t.index(last) && t.index(max)
(t.index(last) + 1).upto(t.index(max)) do |i|
t << t[i]
- end
+ end
end
- end
+ end
end
max
end
@@ -422,14 +433,14 @@
unless trcs.empty?
trcs.first.each do |n|
if trcs.include_in_all?(n)
enode = n
break
- end
+ end
end
- end
+ end
enode
- end
+ end
def segment_by(endnode)
# cut shit until common node, return the shit you cut away
tracesgroup = self.group_by{|t| t.first}.map do |k,trace|
coltrace = trace.map do |t|