Class: CPEE::ProcessTransformation::Traces
- Inherits:
-
Array
- Object
- Array
- CPEE::ProcessTransformation::Traces
- Defined in:
- lib/cpee/processtransformation/structures.rb
Overview
}}}
Instance Method Summary collapse
- #add_breaks(context, front = true) ⇒ Object
- #all_loops? ⇒ Boolean
- #eliminate(loops) ⇒ Object
- #empty! ⇒ Object
- #extend ⇒ Object
- #find_endnode ⇒ Object
- #finished? ⇒ Boolean
- #first_node ⇒ Object
- #include_in_all?(e) ⇒ Boolean
- #incoming(node) ⇒ Object
-
#initialize_copy(other) ⇒ Object
{{{.
- #legend ⇒ Object
- #loops ⇒ Object
- #pop_all(what = nil) ⇒ Object
- #remove(trcs) ⇒ Object
- #remove_by_endnode(enode) ⇒ Object
- #remove_empty ⇒ Object
- #same_first ⇒ Object
- #second_nodes ⇒ Object
- #segment_by(endnode) ⇒ Object
- #shift_all ⇒ Object
- #shortest ⇒ Object
- #to_s ⇒ Object
Instance Method Details
#add_breaks(context, front = true) ⇒ Object
344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/cpee/processtransformation/structures.rb', line 344 def add_breaks(context,front=true) trueloops = self.find_all{ |t| t.last == t.first }.length tb = Break.new(context) if trueloops == self.length self << (front ? [nil,tb] : [tb,nil]) else self.each do |t| t << tb unless t.last == t.first ### an explicit break end end end |
#all_loops? ⇒ Boolean
338 339 340 341 342 |
# File 'lib/cpee/processtransformation/structures.rb', line 338 def all_loops? num = 0 self.each{|n| num += 1 if n.first == n.last } num == self.length end |
#eliminate(loops) ⇒ Object
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'lib/cpee/processtransformation/structures.rb', line 364 def eliminate(loops) ### find nested loops self.each_with_index do |t,i| maxcut = 0 ### find out which common parts the traces share with theloops loops.each do |l| maxcut.upto(l.length) do |i| maxcut = i if t[0...i] == l[0...i] end end ### 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 loops.uniq! loops.remove_empty self.remove_empty ### cut from non-nested loops self.each_with_index do |t,i| maxcut = 0 ### find out which common parts the traces share with theloops loops.each do |l| maxcut.upto(l.length) do |i| maxcut = i if t[0...i] == l[0...i] end end cutted = self[i].shift(maxcut) loops << cutted if cutted.length > 1 ### if only the loop node is left, no need to attach end end |
#empty! ⇒ Object
274 275 276 |
# File 'lib/cpee/processtransformation/structures.rb', line 274 def empty! self.delete_if{true} end |
#extend ⇒ Object
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
# File 'lib/cpee/processtransformation/structures.rb', line 399 def extend # find largest common max = [] sh = self.shortest sh = sh[0..-2] if sh.first == sh.last sh.each_with_index do |e,i| max << e if self.include_in_all?(e) end max = max.last # if last is the largest common do nothing # else append from last to largest common self.each do |t| 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 max end |
#find_endnode ⇒ Object
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 |
# File 'lib/cpee/processtransformation/structures.rb', line 425 def find_endnode # supress loops trcs = self.dup # dangerous TODO trcs.delete_if { |t| t.uniq.length < t.length } # find common node (except loops) enode = nil unless trcs.empty? trcs.first.each do |n| if trcs.include_in_all?(n) enode = n break end end end enode end |
#finished? ⇒ Boolean
315 316 317 |
# File 'lib/cpee/processtransformation/structures.rb', line 315 def finished? self.reduce(0){|sum,t| sum += t.length} == 0 end |
#first_node ⇒ Object
282 283 284 |
# File 'lib/cpee/processtransformation/structures.rb', line 282 def first_node self.first.first end |
#include_in_all?(e) ⇒ Boolean
332 333 334 335 336 |
# File 'lib/cpee/processtransformation/structures.rb', line 332 def include_in_all?(e) num = 0 self.each{|n| num += 1 if n.include?(e)} num == self.length end |
#incoming(node) ⇒ Object
323 324 325 326 327 328 329 330 |
# File 'lib/cpee/processtransformation/structures.rb', line 323 def incoming(node) tcount = 1 self.each do |t| break if t.length == 1 tcount += 1 if t.last == node end tcount end |
#initialize_copy(other) ⇒ Object
{{{
258 259 260 261 |
# File 'lib/cpee/processtransformation/structures.rb', line 258 def initialize_copy(other) super self.map!{ |t| t.dup } end |
#legend ⇒ Object
293 294 295 296 297 298 |
# File 'lib/cpee/processtransformation/structures.rb', line 293 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 |
#loops ⇒ Object
356 357 358 359 360 361 362 |
# File 'lib/cpee/processtransformation/structures.rb', line 356 def loops lo = Traces.new self.find_all{ |t| t.first == t.last } self.each do |t| lo << t if lo.second_nodes.include?(t[1]) end lo.uniq end |
#pop_all(what = nil) ⇒ Object
307 308 309 310 311 312 313 |
# File 'lib/cpee/processtransformation/structures.rb', line 307 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 |
#remove(trcs) ⇒ Object
263 264 265 266 267 |
# File 'lib/cpee/processtransformation/structures.rb', line 263 def remove(trcs) trcs.each do |t| self.delete(t) end end |
#remove_by_endnode(enode) ⇒ Object
268 269 270 271 272 |
# File 'lib/cpee/processtransformation/structures.rb', line 268 def remove_by_endnode(enode) self.delete_if do |t| t[0] != enode end end |
#remove_empty ⇒ Object
278 279 280 |
# File 'lib/cpee/processtransformation/structures.rb', line 278 def remove_empty self.delete_if{|t| t.empty? } end |
#same_first ⇒ Object
319 320 321 |
# File 'lib/cpee/processtransformation/structures.rb', line 319 def same_first (n = self.map{|t| t.first }.uniq).length == 1 ? n.first : nil end |
#second_nodes ⇒ Object
285 286 287 |
# File 'lib/cpee/processtransformation/structures.rb', line 285 def second_nodes self.map { |t| t.length > 1 ? t[1] : t[0] } end |
#segment_by(endnode) ⇒ Object
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 |
# File 'lib/cpee/processtransformation/structures.rb', line 444 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| # slice upto common node, collect the sliced away part len = t.index(endnode) if len cut = t.slice!(0...len) cut << t.first else # if endnode is nil, then return the whole t end end.uniq Traces.new(coltrace) end [tracesgroup,endnode] end |
#shift_all ⇒ Object
304 305 306 |
# File 'lib/cpee/processtransformation/structures.rb', line 304 def shift_all self.each{ |tr| tr.shift } end |
#shortest ⇒ Object
289 290 291 |
# File 'lib/cpee/processtransformation/structures.rb', line 289 def shortest self.min_by{|e|e.length} end |
#to_s ⇒ Object
300 301 302 |
# File 'lib/cpee/processtransformation/structures.rb', line 300 def to_s "TRACES: " + self.collect { |t| t.empty? ? '∅' : t.collect{|n| "%2d" % n.niceid }.join('→ ') }.join("\n ") end |