class Petrinet::Net::Builder
Public Class Methods
new()
click to toggle source
# File lib/petrinet/net.rb, line 106 def initialize @place_names = Set.new @transition_by_name = Hash.new @state_vector = [] end
Public Instance Methods
net()
click to toggle source
# File lib/petrinet/net.rb, line 120 def net place_index_by_place_name = Hash.new @place_names.sort.each_with_index do |place_name, index| place_index_by_place_name[place_name] = index end transition_vectors_by_transition_name_pairs = @transition_by_name.map do |transition_name, transition| [transition_name, transition.to_vectors(@place_names.size, place_index_by_place_name)] end transition_vectors_by_transition_name = Hash[transition_vectors_by_transition_name_pairs] Net.new(@state_vector.freeze, place_index_by_place_name.freeze, transition_vectors_by_transition_name.freeze) end
transition(transition_name, arcs)
click to toggle source
# File lib/petrinet/net.rb, line 112 def transition(transition_name, arcs) take_place_names = [arcs[:take]].flatten give_place_names = [arcs[:give]].flatten @place_names.merge(take_place_names) @place_names.merge(give_place_names) @transition_by_name[transition_name] = Transition.new(take_place_names, give_place_names) end