-
Notifications
You must be signed in to change notification settings - Fork 0
/
TransitionFunction.java
104 lines (78 loc) · 2.11 KB
/
TransitionFunction.java
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import java.util.LinkedList;
public class TransitionFunction {
static class Edge {
int sourceState;
int destState;
char link;
public Edge(int sourceState, int destState, char link){
this.sourceState = sourceState;
this.destState = destState;
this.link = link;
}
public int getSourceState() {
return sourceState;
}
public void setSourceState(int sourceState) {
this.sourceState = sourceState;
}
public int getDestState() {
return destState;
}
public void setDestState(int destState) {
this.destState = destState;
}
public char getLink() {
return link;
}
public void setLink(char link) {
this.link = link;
}
}
int stateNum;
LinkedList<Edge> [] adjacencyList;
public TransitionFunction(int stateNum) {
//stateNum a.k.a. vertices
this.stateNum = stateNum;
adjacencyList = new LinkedList[stateNum];
for(int i = 0; i < stateNum; i++){
adjacencyList[i] = new LinkedList<>();
}
}
//Getters & Setters
public int getStateNum() {
return stateNum;
}
public void setStateNum(int stateNum) {
this.stateNum = stateNum;
}
public LinkedList<Edge>[] getAdjacencyList() {
return adjacencyList;
}
public void setAdjacencyList(LinkedList<Edge>[] adjacencyList) {
this.adjacencyList = adjacencyList;
}
//Add edge to Transition Function i.e. Weighted Graph
public void addEdge(int sourceState, int destState, char link){
Edge edge = new Edge(sourceState, destState, link);
adjacencyList[sourceState].addFirst(edge);
}
public void generateTransitionFunction(){
for(int i = 0; i < stateNum; i++){
LinkedList<Edge> list = adjacencyList[i];
for(int j = 0; j < list.size(); j++){
System.out.println("(q" + i + ", " + list.get(j).link + ") --> q" + list.get(j).destState );
}
}
}
public void adjustEdges(int newSrcStart, int newDestStart){
for(int i = 0; i < stateNum; i++){
LinkedList<Edge> thaList = adjacencyList[i];
for(int j = 0; j < thaList.size(); j++){
thaList.get(i).setSourceState(newSrcStart);
newSrcStart++;
thaList.get(j).setDestState(newDestStart);
newDestStart++;
}
}
}
}