Class: MOSAIK::Metrics::ABCSize

Inherits:
MOSAIK::Metric show all
Defined in:
lib/mosaik/metrics/abc_size.rb,
lib/mosaik/metrics/abc_size/parser.rb,
lib/mosaik/metrics/abc_size/processor.rb

Overview

ABC Size (J. Fitzpatrick, 1997)

Defined Under Namespace

Classes: Parser, Processor

Instance Attribute Summary

Attributes inherited from MOSAIK::Metric

#graph, #options

Instance Method Summary collapse

Methods inherited from MOSAIK::Metric

#initialize

Constructor Details

This class inherits a constructor from MOSAIK::Metric

Instance Method Details

#evaluateObject



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
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/mosaik/metrics/abc_size.rb', line 9

def evaluate
  # Total ABC size
  abc_size = 0.0

  # Iterate over each cluster
  graph.clusters.each_value do |cluster|
    # Find all vertices in the cluster
    vertices_in_cluster = cluster.vertices

    # Calculate ABC size for the cluster
    abc_size_c = 0.0

    # Iterate over all vertices in the cluster
    vertices_in_cluster.each do |v|
      # Resolve the constant name to a file
      file = resolver.resolve_constant(v.id)

      warn "Could not resolve constant #{v.id}" and next unless file
      warn "#{v.id} (#{file}) is a directory" and next if File.directory?(file)

      # Parse file to extract ABC sizes
      abc_sizes = Parser
        .new
        .parse(file)

      # Calculate the ABC size for the vertex
      abc_size_v = abc_sizes.any? ? (abc_sizes.values.sum.to_f / abc_sizes.size) : 0.0

      # Store ABC size value in the vertex
      v.attributes[:abc_size] = abc_size_v

      # Store ABC size value in the cluster
      abc_size_c += abc_size_v
    end

    # Store ABC size value in the cluster
    cluster.attributes[:abc_size] = abc_size_c

    # Calculate ABC size contribution from this cluster
    abc_size += abc_size_c
  end

  # Store ABC size value in the graph
  graph.attributes[:abc_size] = abc_size

  # Return the total ABC size
  abc_size
end