petrinet

package
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package petrinet where: P => places T => transitions F subset of (P X T) U (T X P) => arcs F0 subset of (P X T) => inhibitor arcs W: F -> {1,2,3,...} => weights of arcs W0: F0 -> {1,2,3,...} => weights of inhibitor arcs M_0: P -> {0, 1, 2, 3, ...} => Initial marking

{
  P: Number => 1...P places
  T: Number => 1...T transitions
  Fpt: [{p: Number, t: Number, w: Number}] => Arcs from P to T list
  Ftp: [{p: Number, t: Number, w: Number}] => Arcs from T to P list
  Inhibitors: [{p: Number, t: Number, w: Number}] => Inhibitor Arcs from P to T list
  M: [{p: Number, m: Number}] => Initial marking list,
}

eg.

{
  P: 4,
  T: 2,
  Fpt: [{p: 1, t: 1, w: 1}, {p: 2, t: 2, w: 1}, {p: 3, t: 2, w: 1}],
  Ftp: [{t: 1, p: 2, w: 1}, {t: 1, p: 3, w: 1}, {t: 2, p: 4, w: 1}],
  Inhibitors: [{t: 2, p: 4, w: 1 }],
  M: [{p: 1, m: 1}, {p: 3, m: 2}, {p: 4, m: 1}],
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Arc

type Arc struct {
	Place   *Place `json:"place"`
	Weight  int    `json:"weight"`
	PlaceID int    `json:"placeId"`
}

Arc between Petri net components

func (Arc) String

func (a Arc) String() string

type PetriNet

type PetriNet struct {
	ID          int                 `json:"id"`
	Transitions map[int]*Transition `json:"transitions"`
	Places      map[int]*Place      `json:"places"`
	MaxPriority int                 `json:"priority"`
	Interf      string              `json:"intreface"`
}

PetriNet struct, has an id, transitions and places

func InitPN

func InitPN(_id int) *PetriNet

InitPN Initializes a new Petri net

func (*PetriNet) AddInArc

func (pn *PetriNet) AddInArc(from, _transition, _weight int)

func (*PetriNet) AddOutArc

func (pn *PetriNet) AddOutArc(_transition, to, _weight int)

func (*PetriNet) AddPlace

func (pn *PetriNet) AddPlace(_id int, _label, _name string)

AddPlace adds a new place to the local Petri net

func (*PetriNet) AddRemoteOutArc

func (pn *PetriNet) AddRemoteOutArc(_transition, weight int, serviceName string)

AddRemoteOutArc adds a remote arc

func (*PetriNet) AddTransition

func (pn *PetriNet) AddTransition(_id, _priority int)

func (*PetriNet) Init

func (pn *PetriNet) Init()

func (*PetriNet) InitService

func (pn *PetriNet) InitService()

InitService

type Place

type Place struct {
	ID          int     `json:"id"`
	Marks       []Token `json:"tokens"`
	Label       string  `json:"label"`
	Name        string  `json:"name"`
	ServiceName string  `json:"serviceName"`
}

Place of the Petri net

func (*Place) AddMarks

func (p *Place) AddMarks(t []Token)

AddMarks adds an array of tokens to the current token

func (*Place) GetMark

func (p *Place) GetMark(l int) []Token

GetMark gets the mark of the place

func (*Place) GetNumMarks

func (p *Place) GetNumMarks() int

GetNumMarks gets the quantity of tokens in the place

func (*Place) InitService

func (p *Place) InitService(interf string)

InitService creates and runs the node containing the net

func (Place) String

func (p Place) String() string

type RemoteArc

type RemoteArc struct {
	ServiceName string `json:"serviceName"`
	Weight      int    `json:"weight"`
	Client      *sleuth.Client
}

RemoteArc for arcs crossing nodes

func (*RemoteArc) Init

func (rt *RemoteArc) Init()

func (RemoteArc) String

func (rt RemoteArc) String() string

type ServiceNode

type ServiceNode struct {
	Interface   string
	PetriPlace  *Place
	ServiceName string
}

ServiceNode structure of a node associated to its place

func (*ServiceNode) RunService

func (sn *ServiceNode) RunService()

RunService executes the node's server and client

type Token

type Token struct {
	ID int `json:"id"`
}

Token for a petri net

func (Token) String

func (t Token) String() string

type Transition

type Transition struct {
	ID            int         `json:"id"`
	Priority      int         `json:"priority"`
	InArcs        []Arc       `json:"inArcs"`
	OutArcs       []Arc       `json:"outArcs"`
	RemoteOutArcs []RemoteArc `json:"remoteArcs"`
}

Transition of a PetriNet

func (*Transition) AddInArc

func (t *Transition) AddInArc(_arc Arc)

AddInArc adds an arc to \cdot t

func (*Transition) AddOutArc

func (t *Transition) AddOutArc(_arc Arc)

AddOutArc internode arcs

func (*Transition) AddRemoteOutArc

func (t *Transition) AddRemoteOutArc(_rarc RemoteArc)

AddRemoteOutArc arcs crossing nodes, alwasys from transition to place

func (*Transition) CanFire

func (t *Transition) CanFire() bool

CanFire checks if the transition can fire

func (*Transition) Fire

func (t *Transition) Fire() error

Fire fires the transition

func (*Transition) Init

func (t *Transition) Init()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL