Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
Add progress bar to reassignment
Browse files Browse the repository at this point in the history
  • Loading branch information
floriandejonckheere committed Apr 27, 2024
1 parent a50435b commit 5218078
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/mosaik/algorithms/louvain.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "ruby-progressbar"

module MOSAIK
module Algorithms
##
Expand Down Expand Up @@ -41,16 +43,25 @@ def call
debug "Iteration #{i}: start modularity=#{modularity}, vertices=#{graph.vertices.count}, communities=#{graph.clusters.count}"

# Phase 1: reassign vertices to optimize modularity
progress = ProgressBar.create(
title: "Reassigning vertices",
total: graph.vertices.size,
length: 80,
format: "%t%e [%b>%i] %p%%".cyan,
output: options[:debug] ? $stderr : File.open(File::NULL, "w"),
)

graph.vertices.each_value do |vertex|
progress.increment

reassign_vertex(graph, vertex)
end

# Phase 2: reduce communities to a single node
debug "Reducing graph"
g, reduced_mapping = reduce_graph(graph)

debug "Reduced #{graph.vertices.size} vertices to #{g.vertices.size} vertices"
debug "Mapping: #{reduced_mapping.inspect}"
debug "Changes: #{reduced_mapping.reject { |a, b| a == b }.inspect}"

if options[:visualize]
MOSAIK::Graph::Visualizer
Expand Down
1 change: 1 addition & 0 deletions mosaik.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "parser", "~> 3.3.0.5"
spec.add_runtime_dependency "rubocop", "~> 1.63.1"
spec.add_runtime_dependency "rubocop-ast", "~> 1.31.2"
spec.add_runtime_dependency "ruby-progressbar", "~> 1.13.0"
spec.add_runtime_dependency "sorbet-runtime", "~> 0.5.11346"
spec.add_runtime_dependency "zeitwerk", "~> 2.6"
end

0 comments on commit 5218078

Please sign in to comment.