Class: Diagrams::VarGraph

Inherits:
Object show all
Defined in:
lib/maruku/ext/diagrams/layout.rb

Defined Under Namespace

Classes: Node

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVarGraph

Returns a new instance of VarGraph.



73
74
75
# File 'lib/maruku/ext/diagrams/layout.rb', line 73

def initialize 
	self.name2node = {}
end

Instance Attribute Details

#name2nodeObject

Returns the value of attribute name2node.



71
72
73
# File 'lib/maruku/ext/diagrams/layout.rb', line 71

def name2node
  @name2node
end

Instance Method Details

#==(other) ⇒ Object



67
68
69
# File 'lib/maruku/ext/diagrams/layout.rb', line 67

def ==(other)
	self.name == other.name
end

#add_edge(var1, var2) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/maruku/ext/diagrams/layout.rb', line 77

def add_edge(var1, var2)
	raise "var1 = var2 = #{var1.inspect}" if var1 == var2
	
	name2node[var1] = Node.new(var1) if not name2node.has_key? var1
	name2node[var2] = Node.new(var2) if not name2node.has_key? var2
	
	n1,n2 = name2node[var1],name2node[var2]

	n1.children.push n2
	n2.parents.push n1
end

#compute_closureObject



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/maruku/ext/diagrams/layout.rb', line 89

def compute_closure
	@name2node.each do |var, node|
		node.compute_children_closure
		node.compute_parents_closure
	end
	
	@name2node.each do |var, node|
#				puts "Node #{var} -> #{node.next.inspect}"
#				puts "Node #{var} <- #{node.prev.inspect}"
	end
end

#do_it(name2node, function) ⇒ Object



133
134
135
136
137
138
139
140
141
# File 'lib/maruku/ext/diagrams/layout.rb', line 133

def do_it(name2node, function)
	dist2nodes = []
	name2node.each do |var, node|
		dist = node.send function
		dist2nodes[dist] =[] if dist2nodes[dist] == nil
		dist2nodes[dist].push node	
	end
	dist2nodes
end

#go!Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/maruku/ext/diagrams/layout.rb', line 131

def go!
	
	def do_it(name2node, function)
		dist2nodes = []
		name2node.each do |var, node|
			dist = node.send function
			dist2nodes[dist] =[] if dist2nodes[dist] == nil
			dist2nodes[dist].push node	
		end
		dist2nodes
	end

	up = do_it(@name2node, :dist_up)
	down = do_it(@name2node, :dist_down)

	up.each_with_index do  |nodes, i|
		puts "U Generation #{i}: #{nodes.inspect}"
	end
	down.each_with_index do  |nodes, i|
		puts "D Generation #{i}: #{nodes.inspect}"
	end
	
#			go_recursive(@name2node[DIAG_TL], "root")
end

#go_recursive(node_head, id) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/maruku/ext/diagrams/layout.rb', line 101

def go_recursive(node_head, id)
	sub = []
	node_head.children.each do |child|
		if child.parents.size == 1
			sub.push child
		end
	end

	puts "#{id} Found #{sub.size} subs: #{sub.inspect}"

	node_head.children.each do |child|
		if (not sub.include?(child)) and child.parents.size != 1
			adottare = []
			sub.each do |su|
				if child.prev.include? su
					adottare.push su
				end
			end
			
			puts "#{id} child #{child} might be associated with #{adottare.inspect} - #{child.parents.inspect}"
			
		end
	end
	
	sub.each_with_index do |sub, i|
		puts "#{id}/#{i}: #{sub}"
		go_recursive(sub, "#{id}/#{i}")
	end
end