-
Notifications
You must be signed in to change notification settings - Fork 2
/
nodes.scala
182 lines (137 loc) · 4.13 KB
/
nodes.scala
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package KeYmaeraD
object Nodes {
type NodeID = Int
private var nextID = 0
def nextNodeID : NodeID = {
val res = nextID;
nextID += 1;
res
}
sealed abstract class Status
case object Proved extends Status
case object Disproved extends Status
case object Open extends Status
case object Aborted extends Status
case class Irrelevant(old: Status) extends Status
abstract class ProofNode() {
//val nodeType : NodeType = t
val nodeID = nextNodeID
private var children : List[NodeID] = Nil
private var parent : Option[NodeID] = None
private var status: Status = Open
def getParent : Option[NodeID] = synchronized{
parent
}
def setParent(p: Option[NodeID]) : Unit = synchronized{
parent = p
}
def getStatus : Status = synchronized{
status
}
def setStatus(s: Status) : Unit = synchronized{
status = s
}
def addchild(c: NodeID): Unit = synchronized{
children = children ++ List(c)
}
def getChildren : List[NodeID] = synchronized{
children
}
override def toString: String = {
"ProofNode " + nodeID.toString
}
def toPrettyString: String = {
val sb = new StringBuilder()
sb.append("nodeID = " + nodeID + "\n")
sb.append("status = " + status + "\n")
sb.append("parent = " + parent + "\n")
sb.append("children = " + children + "\n")
sb.toString
}
override def hashCode : Int = {
nodeID.hashCode
}
}
case class AndNode(rule: String,
goal:Sequent,
svs: List[String]) extends ProofNode() {
val schemavars = svs
override def toString: String = {
nodeID.toString + " & " + rule
}
override def toPrettyString : String = {
val sb = new StringBuilder()
sb.append(Printing.stringOfSequent(goal) + "\n\n\n")
sb.append("AndNode\n")
sb.append("rule = " + rule + "\n")
sb.append("schemavars = " + schemavars + "\n")
sb.append(super.toPrettyString)
sb.toString
}
}
case class OrNode (rule: String,
goal: Sequent) extends ProofNode() {
override def toString: String = {
nodeID.toString + " | " + rule
}
override def toPrettyString : String = {
val sb = new StringBuilder()
sb.append(Printing.stringOfSequent(goal) + "\n\n\n")
sb.append("OrNode\n")
sb.append("rule = " + rule + "\n")
sb.append(super.toPrettyString)
sb.toString
}
}
case class WorkingNode (rule: String,
goal: Sequent) extends ProofNode() {
setStatus(Open)
override def toString: String = {
"WorkingNode " + nodeID.toString
}
override def toPrettyString : String = {
val sb = new StringBuilder()
sb.append(Printing.stringOfSequent(goal) + "\n\n\n\n")
sb.append("WorkingNode\n")
sb.append("rule = " + rule + "\n")
sb.append(super.toPrettyString)
sb.toString
}
}
case class DoneNode (rule: String,
goal: Sequent) extends ProofNode() {
setStatus(Proved)
override def toString: String = {
"DoneNode " + nodeID.toString
}
override def toPrettyString : String = {
val sb = new StringBuilder()
sb.append(Printing.stringOfSequent(goal) + "\n")
sb.append("DoneNode\n")
sb.append("rule = " + rule + "\n")
sb.append(super.toPrettyString)
sb.toString
}
}
// do I need the synchronization?
class SyncHashMap extends
scala.collection.mutable.HashMap[NodeID, ProofNode] with
scala.collection.mutable.SynchronizedMap[NodeID, ProofNode]
val nodeTable =
new SyncHashMap
def register(nd: ProofNode): Unit = {
nodeTable.put(nd.nodeID, nd)
}
val nullNode = new OrNode("null",
Sequent(scala.collection.immutable.HashMap.empty,
Nil,Nil))
register(nullNode)
var rootNode = nullNode
var sourceFileName: Option[String] = None
def getnode(ndID: NodeID) : ProofNode = nodeTable.get(ndID) match {
case Some(nd) =>
nd
case None =>
throw new Error("node does not exist: " + ndID)
}
}