Sha256: 971f7fb9a76a1115e596bde038a3f32fac65785070c49167d22197ab11f53e81

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

module Jumoku
  module Strategies
    # Edge labeling strategies are concerned with the way edges or arcs are
    # labeled. Simple labeling schemes are based on indexing with increasing
    # integers, whereas some other strategies elaborate on notions such as
    # weight or symetry.
    #
    # This module provides basic implementation for the common ground used
    # by custom strategies.
    #
    module EdgeLabelingBackend
      # Sort edges by the provided block's logic. The block takes edge as
      # parameter, and this method delegates to Enumerable#sort_by for
      # sorting edges. Return unsorted edges list if no block is provided.
      #
      # @return [Array]
      #
      def sorted_edges(&block)
        return edges.sort_by { |edge| block.call(edge) } if block_given?
        edges
      end

      private

      # Callback triggered when labeling a new edge. Does nothing by default.
      # Labeling strategies may implement their own logic and call super to
      # chain callbacks, or impose their behavior (caution!).
      #
      def _edge_labeling_inc
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jumoku-0.2.5 lib/jumoku/strategies/edge_labeling.rb