module YPetri::Net::OwnState

A mixin catering to the net's own state (ie. marking owned by the place instances themselves) and its features.

Public Instance Methods

assignment(transition_ids=nil) click to toggle source

Takes an array of A transition identifiers as an optional argument, and returns the array of their actions under current net state. If no argument is supplied, the array of assignments of all net's A transitions is returned.

# File lib/y_petri/net/own_state.rb, line 102
def assignment transition_ids=nil
  return assigment A_tt() if transition_ids.nil?
  transition_ids.map { |id| A_transition( id ).action }
end
delta(place_ids=nil, transitions: tt) click to toggle source

Takes an array of place identifiers, and a named argument :transitions, and returns the array of the place delta contribution by the indicated transitions.

# File lib/y_petri/net/own_state.rb, line 94
def delta place_ids=nil, transitions: tt
  fail NotImplementedError
end
firing(transition_ids=nil) click to toggle source

Takes an array of tS transition identifiers as an optional argument, and returns the array of their firing under current net state. If no argument is supplied, the net is required to contain no TS transtions, and the method returns the array of firing of all net's tS transitions.

# File lib/y_petri/net/own_state.rb, line 61
def firing transition_ids=nil
  if transition_ids.nil? then
    fail TypeError, "Method #firing with no arguments is ambiguous for " +
      "nets with TS transitions!" if timed?
    firing tS_tt
  else
    transition_ids.map { |id| tS_transition( id ).firing }
  end
end
flux(transition_ids=nil) click to toggle source

Takes an array of TS transition identifiers as an optional argument, and returns the array of their fluxes under current net state. If no argument is supplied, the array of fluxes of all net's TS transitions is returned.

# File lib/y_petri/net/own_state.rb, line 75
def flux transition_ids=nil
  return flux TS_tt() if transition_ids.nil?
  transition_ids.map { |id| TS_transition( id ).flux }
end
gradient(place_ids=pp, transitions: tt) click to toggle source

Takes an array of place identifiers, and a named argument :transitions, and returns the array of the place gradient contribution by the indicated transitions. The :transitions argument defaults to all the transitions, place identifiers default to all the places. The net must be timed.

# File lib/y_petri/net/own_state.rb, line 86
def gradient place_ids=pp, transitions: tt
  fail NotImplementedError
end
m(place_ids=nil) click to toggle source

If no argument is supplied, the method returns the array of the markings owned by the net's places. If an array of place identifiers is supplied, the return value is the array of the markings owned by those places.

# File lib/y_petri/net/own_state.rb, line 35
def m place_ids=nil
  return m( pp ) if place_ids.nil?
  place_ids.map { |id| place( id ).marking }
end
marking(*place_ids) click to toggle source

Like m method, but instead of returning an array of markings, it returns a string of the form “A: 1, B: 2, …”, where A, B, … are the places and 1, 2, … their marking. This method is intended to produce output easy to read by humans, while m method produces regular output (an Array) suitable for further processing. Method accepts arbitrary number of optional arguments, each of which must be a place identifier. If no arguments are given, full marking of the net is described. If arguments are given, only marking of the places identified by the arguments is described.

# File lib/y_petri/net/own_state.rb, line 24
def marking *place_ids
  return pp.size == 0 ? "" : marking( *pp ) if place_ids.empty?
  a = [ place_ids.map { |id| place( id ) },
        m( place_ids ) ].transpose
  a.map { |pair| pair.join ": " }.join ', '
end
reset!(place_ids=nil) click to toggle source

If no argument is supplied, the method resets its places to their default marking. If an array of place identifiers is supplied, only the specified places are reset. Attempts to reset places that have no default marking result in TypeError.

# File lib/y_petri/net/own_state.rb, line 45
def reset! place_ids=nil
  return reset!( pp ) if place_ids.nil?
  place_ids.map { |id|
    begin
      place( id ).reset_marking
    rescue TypeError => err
      raise TypeError, "Unable to reset the net! " + err.message
    end
  }
end
state() click to toggle source

State owned by the net. This method returns an instance of Net::State class (a subclass of Array), containing marking owned by the net's places.

# File lib/y_petri/net/own_state.rb, line 10
def state
  State().new( m )
end