-
Notifications
You must be signed in to change notification settings - Fork 0
/
aut.go
54 lines (44 loc) · 1.23 KB
/
aut.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package aut
import (
"bytes"
"fmt"
)
// State is a representation of a state.
type State int
// Transition is a representation of transition between two states.
type Transition struct {
From State
Label string
To State
}
func (t *Transition) String() string {
return fmt.Sprintf("(%d, %s, %d)\n", int(t.From), t.Label, int(t.To))
}
// Aut is the root data structure of an aut file.
type Aut struct {
Init State
NumTransitions int
NumStates int
Transitions []*Transition
}
// SetDes sets the DEScription of an aut representation.
func (a *Aut) SetDes(start, ntrans, nstate int) {
a.Init = State(start)
a.NumTransitions = ntrans
a.NumStates = nstate
}
// AddTransition adds a single transition to the current aut representation.
func (a *Aut) AddTransition(from State, label string, to State) {
a.Transitions = append(a.Transitions, &Transition{From: from, Label: label, To: to})
}
// String returns a string representation of the aut representation in aut
// format.
func (a *Aut) String() string {
var buf bytes.Buffer
buf.WriteString(fmt.Sprintf("des (%d, %d, %d)\n",
int(a.Init), a.NumTransitions, a.NumStates))
for _, t := range a.Transitions {
buf.WriteString(t.String())
}
return buf.String()
}