This repository has been archived by the owner on Jun 13, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
include calculation of representative id from sketch duplicate sets
- Loading branch information
Showing
6 changed files
with
77 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'rubygems' | ||
require "rgl/adjacency" | ||
require "rgl/traversal" | ||
require "rgl/connected_components" | ||
|
||
incident_edge_sum = {} | ||
incident_edge_sum.default = 0 | ||
|
||
g = RGL::AdjacencyGraph.new | ||
|
||
STDIN.each do |line| | ||
id1,id2,res = line.split | ||
id1,id2,res = id1.to_i, id2.to_i, res.to_f | ||
incident_edge_sum[id1] += res | ||
incident_edge_sum[id2] += res | ||
g.add_vertex id1 | ||
g.add_vertex id2 | ||
g.add_edge id1, id2 | ||
end | ||
|
||
g.each_connected_component do |vertexs| | ||
max_sum = 0 | ||
max_vert = nil | ||
vertexs.each do |vertex| | ||
if incident_edge_sum[vertex] > max_sum | ||
max_sum = incident_edge_sum[vertex] | ||
max_vert = vertex | ||
end | ||
end | ||
vertexs.delete max_vert | ||
puts "#{max_vert} #{vertexs.join(' ')}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env ruby | ||
keys_first = false | ||
(keys_first="false"==ARGV[0]) if ARGV[0] | ||
|
||
freqs = {} | ||
freqs.default = 0 | ||
STDIN.each do |line| | ||
line.chomp! | ||
freqs[line] += 1 | ||
end | ||
|
||
freqs.keys.each do |k| | ||
puts keys_first ? "#{k} #{freqs[k]}" : "#{freqs[k]} #{k}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters