Class: MOSAIK::Metrics::Coupling
- Inherits:
-
MOSAIK::Metric
- Object
- MOSAIK::Metric
- MOSAIK::Metrics::Coupling
- Defined in:
- lib/mosaik/metrics/coupling.rb
Overview
Coupling (S. Chidamber and C. Kemerer, 1994)
Instance Attribute Summary
Attributes inherited from MOSAIK::Metric
Instance Method Summary collapse
Methods inherited from MOSAIK::Metric
Constructor Details
This class inherits a constructor from MOSAIK::Metric
Instance Method Details
#evaluate ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/mosaik/metrics/coupling.rb', line 9 def evaluate # Total coupling coupling = 0.0 # Iterate over each cluster graph.clusters.each_value do |cluster| # Find all vertices in the cluster vertices_in_cluster = cluster.vertices vertices_in_cluster_id = vertices_in_cluster.map(&:id) # Calculate coupling value for the cluster coupling_c = 0.0 # Iterate over all vertices in the cluster vertices_in_cluster.each do |v| v.edges.each do |i, es| next if i.in? vertices_in_cluster_id coupling_c += es.sum { |e| e.attributes.fetch(:weight, 0.0) } end end # Store coupling value in the cluster cluster.attributes[:coupling] = coupling_c # Calculate coupling contribution from this cluster coupling += coupling_c end # Store coupling value in the graph graph.attributes[:coupling] = coupling # Return the total coupling coupling end |