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

Commit

Permalink
Allow coupling and cohesion to work with multiple edges
Browse files Browse the repository at this point in the history
  • Loading branch information
floriandejonckheere committed Apr 17, 2024
1 parent c6531ea commit 24a919a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/mosaik/metrics/cohesion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def evaluate

# Calculate sum of edges between vertices in the cluster
sum = vertices_in_cluster
.flat_map { |v| v.edges.filter_map { |i, e| e if i.in?(vertices_in_cluster_id) } }
.map { |v| v.edges.slice(*vertices_in_cluster_id).values }
.flatten(2)
.uniq
.count

Expand Down
4 changes: 2 additions & 2 deletions lib/mosaik/metrics/coupling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ def evaluate

# Iterate over all vertices in the cluster
vertices_in_cluster.each do |v|
v.edges.each do |i, e|
v.edges.each do |i, es|
next if i.in? vertices_in_cluster_id

coupling_c += e.attributes.fetch(:weight, 0.0)
coupling_c += es.sum { |e| e.attributes.fetch(:weight, 0.0) }
end
end

Expand Down

0 comments on commit 24a919a

Please sign in to comment.