A Go library for parsing Petri nets
Nets is a Go library for parsing Petri nets, and Time Petri nets, written using the textual description format of the Tina toolbox. The format is defined in the section on the .net format described in the manual pages for Tina.
The library provides an exported type for dealing with Petri nets that can be useful to build new tools. We also provide methods to marshall a Net into a .net file or a PNML file for Place/Transition nets.
go get github.com/dalzilio/nets
You can find some examples of code in the *_test.go
files and some example of
.net
files in directory testdata
. The main function, Parse
, returns a
Net
struct from an io.Reader
.
package main
import (
"fmt"
"os"
"github.com/dalzilio/nets"
)
func main() {
file, _ := os.Open("testdata/sokoban_3.net")
net, err := nets.Parse(file)
if err != nil {
log.Fatal("parsing error: ", err)
}
fmt.Printf("net %s has %d transitions\n", net.Name, len(net.Tr))
// Output:
// net Sokoban has 452 transitions
}
The library has no dependencies outside of the standard Go library. It uses Go modules and has been tested with Go 1.16.
This software is distributed under the GNU Affero GPL v3. A copy of the license agreement is found in the LICENSE file.
- Silvano DAL ZILIO - LAAS/CNRS