pnml

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2023 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Copyright 2023. Silvano DAL ZILIO (LAAS-CNRS). All rights reserved. Use of this source code is governed by the GNU Affero license that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtomIsLess

func AtomIsLess(ai, aj Atom) bool

AtomIsLess will sort all the Atom with multiplicity 0 first; otherwise the order is based on Value.

func ValueIsLess

func ValueIsLess(vi, vj *Value) bool

ValueIsLess reports if vi is before vj in comparaison order.

Types

type Add

type Add []Expression

Add is the type of add expressions.

func (Add) AddEnv

func (p Add) AddEnv(env Env) Env

func (Add) Eval

func (p Add) Eval(net *Net, venv VEnv) []Atom

func (Add) String

func (p Add) String() string

func (Add) Unify

func (p Add) Unify(net *Net, v *Value, venv VEnv) (int, error)

type All

type All string

All is the type of all expressions.

func (All) AddEnv

func (p All) AddEnv(env Env) Env

func (All) Eval

func (p All) Eval(net *Net, venv VEnv) []Atom

func (All) String

func (p All) String() string

func (All) Unify

func (p All) Unify(net *Net, v *Value, venv VEnv) (int, error)

This is one of the rare cases where we need to match against several values and not just one. It is observed on transition Initialize of PhilosophersDyn and on model QuasiCertifProtocol. We could return a negative number in order to test for this particular case but the model has other problems.

type Arc

type Arc struct {
	Source  string `xml:"source,attr"`
	Target  string `xml:"target,attr"`
	XML     RawXML `xml:"hlinscription>structure"`
	Pattern Expression
}

Arc is the type of edges element in a PNML net.

type Atom

type Atom struct {
	*Value
	Mult int
}

Atom is a pair of a multiplicity and a colored value.

type Constant

type Constant string

Constant is the type of constant expressions.

func (Constant) AddEnv

func (p Constant) AddEnv(env Env) Env

func (Constant) Eval

func (p Constant) Eval(net *Net, venv VEnv) []Atom

func (Constant) String

func (p Constant) String() string

func (Constant) Unify

func (p Constant) Unify(net *Net, v *Value, venv VEnv) (int, error)

type Declaration

type Declaration struct {
	Sorts      []*TypeDecl      `xml:"namedsort"`
	Vars       []*VarDecl       `xml:"variabledecl"`
	Partitions []*PartitionDecl `xml:"partition"`
}

Declaration is the type of a PNML net declaration. It contains declarations for types and variables used in the net. We also added partitions (and partitionelement) from model VehicularWifi

type Decoder

type Decoder struct {
	*xml.Decoder
}

A Decoder represents an XML parser reading a particular input stream that should be a valid PNML file. It embeds an xml.Decoder for parsing a PNML stream passed as an io.Reader. Like with xml.Decoder, the parser assumes that its input is encoded in UTF-8.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder creates a new XML parser reading from r.

func (*Decoder) Build

func (d *Decoder) Build(net *Net) error

Build creates a pnml.Net object by parsing the content of the provided file.

type Dot

type Dot struct{}

Dot is the type of dot constants.

func (Dot) AddEnv

func (p Dot) AddEnv(env Env) Env

func (Dot) Eval

func (p Dot) Eval(net *Net, venv VEnv) []Atom

func (Dot) String

func (p Dot) String() string

func (Dot) Unify

func (p Dot) Unify(net *Net, v *Value, venv VEnv) (int, error)

type Env

type Env []string

Env is an environment, that is a sorted list of variable (names) occuring in an Expressions.

func (Env) Extra

func (p Env) Extra(p2 Env) Env

Extra returns a list of varnames that are in p2 but not in p

func (Env) String

func (p Env) String() string

type Expression

type Expression interface {
	String() string
	AddEnv(Env) Env
	Eval(*Net, VEnv) []Atom
	Unify(*Net, *Value, VEnv) (int, error)
}

Expression is the interface that wraps the type of PNML expression (we only consider symmetric nets).

We assume that Add-expressions (like a + b) are always top-level and that <subtract> expressions cannot occur in the condition of an input arc.

AddEnv is used to accumulate the free variables in the Expression to an existing environment. It can be used to add the free variables of an expression to an alreay existing environment. It creates a (sorted) slice containing the names of all the variables.

Eval returns the set of constant values that match a ground Expression (an expression without free variables, such as the ones used to define the initial marking), together with their multiplicities.

Unify reports if a pattern expression matches a given *Value. For this we can use the VEnv to check that we respect previously unified variables. We can also update the VEnv by adding new associations. A return value of 0 means no match; otherwise it is the number of "copies" of the value that we need to match. Unify can change the values in the VEnv even if it fails. Unification can fail, for instance if there is an <All> expression in one of the input arc.

func SplitAdds

func SplitAdds(e Expression) []Expression

SplitAdds takes an expression and splits the top-level Add operator, if any.

type FIRConstant

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

FIRConstant is the type of finite int range constant expressions.

func (FIRConstant) AddEnv

func (p FIRConstant) AddEnv(env Env) Env

func (FIRConstant) Eval

func (p FIRConstant) Eval(net *Net, venv VEnv) []Atom

func (FIRConstant) String

func (p FIRConstant) String() string

func (FIRConstant) Unify

func (p FIRConstant) Unify(net *Net, v *Value, venv VEnv) (int, error)

type FIRangeConstant

type FIRangeConstant struct {
	Value int      `xml:"value,attr"`
	Range IntRange `xml:"finiteintrange"`
}

FIRangeConstant is used in PNML expressions.

type Fec

type Fec struct {
	ID string `xml:"id,attr"`
}

Fec is the type of PNML enumeration constants.

type Hue

type Hue []Atom

Hue is a slice of Atoms meant to represent the possible value in a colored place

func (Hue) Sum

func (pm Hue) Sum() int

type IntRange

type IntRange struct {
	Start int `xml:"start,attr"`
	End   int `xml:"end,attr"`
}

IntRange is the type of PNML int ranges

type Marking

type Marking []Hue

Marking is an association between places and Hues.

func (Marking) Clone

func (m0 Marking) Clone() Marking

type Net

type Net struct {
	Name        string      `xml:"name>text"`
	Page        Page        `xml:"page"`
	Declaration Declaration `xml:"declaration>structure>declarations"`
	// TypeEnvt is an association between a variable name and its type name, found in declaration
	TypeEnvt map[string]string

	// Unique associates a Unique representant for each Value
	Unique map[Value]*Value
	// World associates a type (name) with a list of all its possible values
	World map[string][]*Value
	// contains filtered or unexported fields
}

Net is the type of the net element in a PNML file.

func (*Net) Next

func (e *Net) Next(i int, val *Value) *Value

Next gives the ith successor (i can be negative) of the constant with id name. We assume that the type of val is circular and do not check the particular case where we should report overflows.

func (*Net) PrintHue

func (net *Net) PrintHue(pm Hue) string

func (*Net) PrintValue

func (net *Net) PrintValue(val *Value) string

PrintValue returns a readable description of a Value

func (Net) String

func (net Net) String() string

type NumberConstant

type NumberConstant struct {
	Value int `xml:"value,attr"`
}

NumberConstant is used in PNML expressions.

type Numberof

type Numberof struct {
	Expression
	Mult int
}

Numberof is the type of numberof expressions in PNML. This is used to add a multiplicity Mult to an Expression in a multiset.

func (Numberof) AddEnv

func (p Numberof) AddEnv(env Env) Env

func (Numberof) Eval

func (p Numberof) Eval(net *Net, venv VEnv) []Atom

func (Numberof) String

func (p Numberof) String() string

func (Numberof) Unify

func (p Numberof) Unify(net *Net, v *Value, venv VEnv) (int, error)

We can return a negative number of

type OP

type OP int

OP is the type of operations in a PNML expression

const (
	NIL OP = iota
	EQ
	INEQ
	LESSTHAN
	LESSTHANEQ
	GREATTHAN
	GREATTHANEQ
	OR
	AND
)

func (OP) String

func (p OP) String() string

type Operation

type Operation struct {
	Op   OP
	Elem []Expression
}

Operation is the type of expressions that apply an operation to a slice of expressions.

func (Operation) AddEnv

func (p Operation) AddEnv(env Env) Env

func (Operation) Eval

func (p Operation) Eval(net *Net, venv VEnv) []Atom

func (Operation) OK

func (p Operation) OK(net *Net, venv VEnv) bool

OK returns whether the condition evaluates to true.

func (Operation) String

func (p Operation) String() string

func (Operation) Unify

func (p Operation) Unify(net *Net, v *Value, venv VEnv) (int, error)

type Page

type Page struct {
	Places []*Place      `xml:"place"`
	Trans  []*Transition `xml:"transition"`
	Arcs   []*Arc        `xml:"arc"`
}

Page is the type of the page element in a PNML file.

type Partition

type Partition struct {
	ID   string `xml:"id,attr"`
	Elem []Type `xml:"useroperator,omitempty"`
}

Partition list a subset of values of a given (enumeration) type.

type PartitionDecl

type PartitionDecl struct {
	ID         string `xml:"id,attr"`
	Type       `xml:"usersort,omitempty"`
	Partitions []Partition `xml:"partitionelement,omitempty"`
}

PartitionDecl is the type of PNML partition declarations.

type Place

type Place struct {
	ID             string `xml:"id,attr"`
	Type           Type   `xml:"type>structure>usersort"`
	XML            RawXML `xml:"hlinitialMarking>structure"`
	InitialMarking Expression
}

Place is the type of a PNML place. It can contain a type and an (optional) initial marking.

type RawXML

type RawXML struct {
	InnerXML []byte `xml:",innerxml"`
}

RawXML is the type of PNML initial marking expressions, patterns and conditions.

type Subtract

type Subtract []Expression

Subtract is the type of subtract expressions. It is an array of two expressions denoting the left and right elements of a subtract operation.

func (Subtract) AddEnv

func (p Subtract) AddEnv(env Env) Env

func (Subtract) Eval

func (p Subtract) Eval(net *Net, venv VEnv) []Atom

func (Subtract) String

func (p Subtract) String() string

func (Subtract) Unify

func (p Subtract) Unify(net *Net, v *Value, venv VEnv) (int, error)

type Successor

type Successor struct {
	Var
	Incr int
}

Successor is the type of successor and predecessor operations.

func (Successor) AddEnv

func (p Successor) AddEnv(env Env) Env

func (Successor) Eval

func (p Successor) Eval(net *Net, venv VEnv) []Atom

func (Successor) String

func (p Successor) String() string

func (Successor) Unify

func (p Successor) Unify(net *Net, v *Value, venv VEnv) (int, error)

Unification with a successor occurs in models BART and TokenRing. We use the fact that var++k matches val if and only if var matches val--k.

type TYP

type TYP int

TYP describes the possible kind of PNML types in PNML.

const (
	DOT TYP = iota
	CENUM
	FENUM
	FINTRANGE
	PROD
	NUMERIC
)

func (TYP) String

func (i TYP) String() string

type Transition

type Transition struct {
	ID        string `xml:"id,attr"`
	XML       RawXML `xml:"condition>structure"`
	Condition Operation
}

Transition is the type of a PNML transition. It can contain a type and an (optional) initial marking.

type Tuple

type Tuple []Expression

Tuple is the type of tuple expressions.

func (Tuple) AddEnv

func (p Tuple) AddEnv(env Env) Env

func (Tuple) Eval

func (p Tuple) Eval(net *Net, venv VEnv) []Atom

func (Tuple) String

func (p Tuple) String() string

func (Tuple) Unify

func (p Tuple) Unify(net *Net, v *Value, venv VEnv) (int, error)

type Type

type Type struct {
	ID string `xml:"declaration,attr"`
}

Type is the type of a type declaration.

type TypeDecl

type TypeDecl struct {
	Sort    TYP
	Elem    []string
	ID      string    `xml:"id,attr"`
	CEnum   []Fec     `xml:"cyclicenumeration>feconstant,omitempty"`
	FEnum   []Fec     `xml:"finiteenumeration>feconstant,omitempty"`
	FIntRan *IntRange `xml:"finiteintrange,omitempty"`
	Product []Type    `xml:"productsort>usersort,omitempty"`
	Dot     *struct{} `xml:"dot,omitempty"`
}

TypeDecl is the type of PNML type declarations. We use a pointer field for Dot in order to discriminate to differentiate between default value and field initialized. Same with finite int range.

func (TypeDecl) String

func (typ TypeDecl) String() string

type VEnv

type VEnv map[string]*Value

VEnv is the type of association lists between environment variables and values.

func NewVEnv

func NewVEnv(env Env) VEnv

func (VEnv) Clone

func (venv VEnv) Clone() VEnv

func (VEnv) Copy

func (venv VEnv) Copy(venv2 VEnv)

func (VEnv) Reset

func (venv VEnv) Reset(env Env)

func (VEnv) ResetAll

func (venv VEnv) ResetAll()

type Value

type Value struct {
	Head int
	Tail *Value
}

Value provides a more efficient representation for values

{0 nil} is a Dot {i nil} is Constant(name) where i uniquely identifies name {i {j {...}}} is for tuples we encode a range value, x, using a constant named _intx

type Var

type Var string

Var is the type of variables.

func (Var) AddEnv

func (p Var) AddEnv(env Env) Env

func (Var) Eval

func (p Var) Eval(net *Net, venv VEnv) []Atom

func (Var) String

func (p Var) String() string

func (Var) Unify

func (p Var) Unify(net *Net, v *Value, venv VEnv) (int, error)

type VarDecl

type VarDecl struct {
	ID   string `xml:"id,attr"`
	Type Type   `xml:"usersort"`
}

VarDecl is the type of PNML variable declarations.

type Variable

type Variable struct {
	RefVariable string `xml:"refvariable,attr"`
}

Variable is used in PNML expressions.

Jump to

Keyboard shortcuts

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