Class: BooleanMatrix

Inherits:
Object
  • Object
show all
Defined in:
lib/graphr/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.



420
421
422
423
424
425
426
427
428
429
# File 'lib/graphr/directed_graph.rb', line 420

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



456
457
458
459
460
461
462
463
464
# File 'lib/graphr/directed_graph.rb', line 456

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



447
448
449
450
451
452
453
454
# File 'lib/graphr/directed_graph.rb', line 447

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

#mask(index) ⇒ Object



434
435
436
437
438
439
440
441
# File 'lib/graphr/directed_graph.rb', line 434

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



443
444
445
# File 'lib/graphr/directed_graph.rb', line 443

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

#transitive_closureObject



466
467
468
469
470
471
472
# File 'lib/graphr/directed_graph.rb', line 466

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