Class: BooleanMatrix

Inherits:
Object
  • Object
show all
Defined in:
lib/fsm-0.0.0/graph/directed_graph.rb

Constant Summary collapse

@@masks_max =
1000
@@masks =
calc_masks(0,@@masks_max)

Instance Method Summary collapse

Constructor Details

#initialize(objects) ⇒ BooleanMatrix

Returns a new instance of BooleanMatrix.


428
429
430
431
432
433
434
435
436
437
# File 'lib/fsm-0.0.0/graph/directed_graph.rb', line 428

def initialize(objects)
  @index, @objects, @matrix = Hash.new, objects, Array.new 
  cnt = 0
  objects.each do |o| 
    @index[o] = cnt
    @matrix[cnt] = 0 # Use Integers to represent the booleans
    cnt += 1
  end
  @num_obects = cnt
end

Instance Method Details

#directed_graphObject


464
465
466
467
468
469
470
471
472
# File 'lib/fsm-0.0.0/graph/directed_graph.rb', line 464

def directed_graph
  dg = Directedgraph.new
  @matrix.each_with_index do |v,i|
    indices(v) do |index|
	dg.link_nodes(@objects[i], @objects[index])
    end 
  end
  dg
end

#indices(anInteger) ⇒ Object


455
456
457
458
459
460
461
462
# File 'lib/fsm-0.0.0/graph/directed_graph.rb', line 455

def indices(anInteger)
  index = 0
  while anInteger > 0
    yeild(index) if anInteger & 1
    anInteger >>= 1
    index += 1
  end
end

#mask(index) ⇒ Object


442
443
444
445
446
447
448
449
# File 'lib/fsm-0.0.0/graph/directed_graph.rb', line 442

def mask(index)
  mask = @@masks[index]
  unless mask
    calc_masks(@@masks_max+1, index, @@masks)
    mask = @masks[index]
  end
  mask
end

#or(index1, index2) ⇒ Object


451
452
453
# File 'lib/fsm-0.0.0/graph/directed_graph.rb', line 451

def or(index1, index2)
  @matrix[index1] |= @matrix[index2]
end

#transitive_closureObject


474
475
476
477
478
479
480
# File 'lib/fsm-0.0.0/graph/directed_graph.rb', line 474

def transitive_closure
  for i in (0..@num_obects)
    for j in (0..@num_obects)
	
    end
  end
end