metamodel

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2023 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

View Source
const (
	BadInhibitorSource  = "inhibitor source must be a place"
	BadInhibitorTarget  = "inhibitor target must be a transition"
	BadWeight           = "arc weight must be positive integer"
	BadMultiple         = "multiple must be positive integer"
	BadArcTransition    = "source and target are both transitions"
	BadArcPlace         = "source and target are both places"
	UnknownAction       = "unknown action"
	Underflow           = "output cannot be negative"
	Overflow            = "output exceeds capacity"
	FailedRoleAssertion = "role assertion failed"
	ExpectedTransition  = "element was expected to be a transition"
	ExpectedPlace       = "element was expected to be a place"
	InhibitedTransition = "transition is inhibited by place %s"
	UnexpectedArguments = "expected %v arguments got %v"
	OK                  = "OK"
)

Variables

This section is empty.

Functions

func VectorToBytes

func VectorToBytes(v Vector) []byte

Types

type Arc

type Arc struct {
	Source    Node
	Target    Node
	Weight    int64
	Inhibitor bool
	Inverted  bool
}

type ArcDefinition added in v1.0.0

type ArcDefinition struct {
	Source  string `json:"source"`
	Target  string `json:"target"`
	Weight  int64  `json:"weight"`
	Inhibit bool   `json:"inhibit"`
}

type ArcListDefinition added in v1.0.0

type ArcListDefinition []ArcDefinition

type Declaration

type Declaration interface {
	Cell(...func(p *Place)) Node
	Fn(...func(t *Transition)) Node
}

REVIEW: should we expose Role here also?

type DeclarationObject added in v1.0.0

type DeclarationObject struct {
	ModelType   string                  `json:"modelType"`
	Version     string                  `json:"version"`
	Places      PlaceMapDefinition      `json:"places"`
	Transitions TransitionMapDefinition `json:"transitions"`
	Arcs        ArcListDefinition       `json:"arcs"`
}

type Editor

type Editor interface {
	PlaceSeq() Label
	TransitionSeq() Label
	Index() Editor
	Graph() Editor
}

type Event

type Event struct {
	Seq   int64
	State Vector
	Op
}

type Guard

type Guard struct {
	Label    string `json:"label"`
	Delta    Vector `json:"delta"`
	Inverted bool   `json:"inverted"`
}

Guard attributes inhibit a transition

type GuardMap

type GuardMap = map[string]*Guard

type Label

type Label = string

type MetaModel

type MetaModel interface {
	Net() *PetriNet
	Define(...func(Declaration)) MetaModel
	Execute(...Vector) Process
	Edit() Editor
	Node(oid string) Node
	UnzipUrl(url string, filename string) (obj string, ok bool)
	ZipUrl(...string) (url string, ok bool)
	GetViewPort() (int, int, int, int)
}

func New

func New(schema string) MetaModel

type Model

type Model struct {
	*PetriNet
}

func (*Model) Arc

func (m *Model) Arc(source Node, target Node, weight int64)

Arc connects places and transitions at runtime Arcs are indexed as adjacency matrix by converting Arcs to vectors

func (*Model) Cell

func (m *Model) Cell(def ...func(p *Place)) Node

Cell declares a new transition element

func (*Model) Define

func (m *Model) Define(def ...func(declaration Declaration)) MetaModel

func (*Model) Edit

func (m *Model) Edit() Editor

Edit returns the internal interface used to edit and reindex a model

func (*Model) Execute

func (m *Model) Execute(initialVec ...Vector) Process

Execute run the m

func (*Model) Fn

func (m *Model) Fn(def ...func(t *Transition)) Node

Fn declares a new transition element

func (*Model) GetViewPort added in v1.0.1

func (m *Model) GetViewPort() (x1 int, y1 int, width int, height int)

func (*Model) Graph

func (m *Model) Graph() Editor

Graph repopulates Arcs using delta vectors and guards

func (*Model) Guard

func (m *Model) Guard(source Node, target Node, weight int64)

func (*Model) Index

func (m *Model) Index() Editor

Index loads Arcs into delta vectors and guards

func (*Model) Net

func (m *Model) Net() *PetriNet

func (*Model) Node

func (m *Model) Node(oid string) Node

func (*Model) PlaceSeq

func (m *Model) PlaceSeq() Label

PlaceSeq generates unique labels for places

func (*Model) TransitionSeq

func (m *Model) TransitionSeq() Label

TransitionSeq generate unique labels for transitions

func (*Model) UnzipUrl added in v1.0.0

func (m *Model) UnzipUrl(url string, filename string) (obj string, ok bool)

func (*Model) ZipUrl added in v1.0.1

func (m *Model) ZipUrl(path ...string) (url string, ok bool)

type Node

type Node interface {
	Tx(weight int64, target Node) Node
	Guard(weight int64, target Node) Node
	IsPlace() bool
	IsTransition() bool
	GetPlace() *Place
	GetTransition() *Transition
	Label(string) Node
	Position(x int64, y int64, z ...int64) Node
	Initial(int64) Node
	Capacity(int64) Node
	Role(string) Node
}

Node is an interstitial interface used when composing m elements

type Op

type Op struct {
	Action   string
	Multiple int64
	Role     string
}

type PetriNet

type PetriNet struct {
	Schema      string        `json:"schema"`
	Places      PlaceMap      `json:"places"`
	Transitions TransitionMap `json:"transitions"`
	Arcs        []Arc         `json:"-"`
	Roles       RoleMap       `json:"-"`
	Path        string        `json:"path"`
	Cid         string        `json:"cid"`
}

func (*PetriNet) CapacityVector

func (n *PetriNet) CapacityVector() (v Vector)

func (*PetriNet) EmptyVector

func (n *PetriNet) EmptyVector() (v Vector)

func (*PetriNet) InitialVector

func (n *PetriNet) InitialVector() (v Vector)

type Place

type Place struct {
	Label    string `json:"label"`
	Offset   int64  `json:"offset"`
	Position `json:"position"`
	Initial  int64 `json:"initial"`
	Capacity int64 `json:"capacity"`
}

Place elements contain tokens

type PlaceDefinition added in v1.0.0

type PlaceDefinition struct {
	Offset   int64 `json:"offset"`
	Initial  int64 `json:"initial"`
	Capacity int64 `json:"capacity"`
	X        int64 `json:"x"`
	Y        int64 `json:"y"`
}

type PlaceMap

type PlaceMap = map[string]*Place

type PlaceMapDefinition added in v1.0.0

type PlaceMapDefinition map[string]PlaceDefinition

type Position

type Position struct {
	X int64 `json:"x"`
	Y int64 `json:"y"`
	Z int64 `json:"z"`
}

Position defines location of a Place or Transition element

type Process

type Process interface {
	GetState() Vector
	TokenCount(string) int64
	Inhibited(Op) (flag bool, label string)
	TestFire(Op) (flag bool, msg string, out Vector)
	Fire(Op) (ok bool, msg string, out Vector)
}

type Role

type Role = struct {
	Label `json:"label"`
}

Role defines user permission

type RoleMap

type RoleMap = map[string]Role

type StateMachine

type StateMachine struct {
	// contains filtered or unexported fields
}

func (*StateMachine) Fire

func (sm *StateMachine) Fire(op Op) (ok bool, msg string, out Vector)

func (*StateMachine) GetState

func (sm *StateMachine) GetState() Vector

func (*StateMachine) Inhibited

func (sm *StateMachine) Inhibited(op Op) (inhibited bool, msg string)

func (*StateMachine) TestFire

func (sm *StateMachine) TestFire(op Op) (flag bool, msg string, out Vector)

func (*StateMachine) TokenCount

func (sm *StateMachine) TokenCount(label string) int64

type SubnetNode added in v1.0.0

type SubnetNode struct {
	*PetriNet  `json:"-"`
	SubnetType string `json:"subnetType"`
	Schema     string `json:"schema"`
}

type Transition

type Transition struct {
	Label        string `json:"label"`
	Position     `json:"position"`
	Role         Role     `json:"role"`
	Delta        Vector   `json:"delta"`
	Guards       GuardMap `json:"guards"`
	AllowReentry bool     `json:"allowReentry"`
	*SubnetNode  `json:"subNet"`
}

Transition defines a token transfer action

type TransitionDefinition added in v1.0.0

type TransitionDefinition struct {
	Role string `json:"role"`
	X    int64  `json:"x"`
	Y    int64  `json:"y"`
}

type TransitionMap

type TransitionMap = map[string]*Transition

type TransitionMapDefinition added in v1.0.0

type TransitionMapDefinition map[string]TransitionDefinition

type Vector

type Vector = []int64

func Add

func Add(state Vector, delta Vector, multiple int64, capacity ...Vector) (ok bool, msg string, out Vector)

Add vectors while asserting underflow & capacity checks

func VectorFromBytes

func VectorFromBytes(bv []byte) (v Vector)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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