1
- import scala .concurrent .duration ._
2
- import scala .concurrent .ExecutionContext .Implicits .global
3
- import scala .concurrent ._
4
- import java .util .concurrent .CancellationException
5
1
import java .io .File
2
+ import java .io .FileWriter
3
+
4
+ import scala .concurrent .duration ._
6
5
6
+ import lisa .utils .ProofsConverter .*
7
+ import lisa .utils .RunSolver .*
7
8
import lisa .utils .tptp .*
8
9
import lisa .utils .tptp .KernelParser .*
9
- import lisa .utils .tptp .KernelParser .getProblemInfos
10
10
import lisa .utils .tptp .ProblemGatherer .*
11
- import lisa .utils .ProofsConverter .*
12
11
import lisa .kernel .proof .SCProof
13
- import java .io .FileWriter
14
12
import lisa .kernel .proof .SequentCalculus .Sequent
15
13
16
14
object TPTPSolver extends lisa.Main {
@@ -26,75 +24,62 @@ object TPTPSolver extends lisa.Main {
26
24
val probfiles = d.listFiles.filter(_.isFile)
27
25
28
26
// We limit the execution time to solve each problem
29
- val timeoutTableau = .2 .second
30
- val timeoutTautology = .2 .second
27
+ val timeoutTableau = .1 .second
28
+ val timeoutTautology = .1 .second
31
29
32
- var problems = List [ Problem ]()
33
- var tableauProofs = List [ SolverResult ]()
34
- var tautologyProofs = List [ SolverResult ]()
30
+ var nbProblemsExtracted = 0
31
+ var nbProblemsSolvedByTableau = 0
32
+ var nbProblemsSolvedByTautology = 0
35
33
36
34
for ((probfile, i) <- probfiles.zipWithIndex) {
37
35
// Progress bar
38
36
if ((i + 1 ) % 10 == 0 || i + 1 == probfiles.size) {
39
37
val pbarLength = 30
40
38
var pbarContent = " =" * (((i + 1 ) * pbarLength) / probfiles.size)
41
39
pbarContent += " " * (pbarLength - pbarContent.length)
42
- print(" [ " + pbarContent + " ]" )
43
- print(" -- " + ( i + 1 ) + " / " + probfiles.size + " processed files" )
44
- print(" -- " + problems.size + " extracted problems" )
45
- print(" -- Tableau: " + tableauProofs.count(_. isInstanceOf [ Solved ]) + " solved" )
46
- println(" -- Tautology: " + tautologyProofs.count(_. isInstanceOf [ Solved ]) + " solved" )
40
+ print(s " [ $ pbarContent] " )
41
+ print(s " -- ${ i + 1 } / ${ probfiles.size} processed files " )
42
+ print(s " -- $nbProblemsExtracted extracted problems " )
43
+ print(s " -- Tableau: $nbProblemsSolvedByTableau solved " )
44
+ println(s " -- Tautology: $nbProblemsSolvedByTautology solved " )
47
45
}
48
46
49
- // Try to extract the problem
47
+ // Try to extract and solve the problem
50
48
try {
51
49
val md = getProblemInfos(probfile)
52
50
if (md.spc.exists(spc.contains)) {
53
51
val p = problemToKernel(probfile, md)
54
- problems = problems :+ p
55
52
val seq = problemToSequent(p)
53
+ nbProblemsExtracted += 1
56
54
57
55
// Attempting proof by Tableau
58
- tableauProofs = tableauProofs :+ solveProblem(p, timeoutTableau, Tableau .solve)
56
+ proveSequent(seq, timeoutTableau, Tableau .solve) match {
57
+ case Solved (proof) =>
58
+ nbProblemsSolvedByTableau += 1
59
+ // writeProof(p, proof, "examples/proofs/tableau/")
60
+ case _ => ()
61
+ }
59
62
60
63
// Attempting proof by Tautology
61
64
def tautologySolver (s : lisa.utils.K .Sequent ): Option [SCProof ] = Tautology .solveSequent(s) match
62
65
case Left (proof) => Some (proof)
63
66
case _ => None
64
- tautologyProofs = tautologyProofs :+ solveProblem(p, timeoutTautology, tautologySolver)
67
+ proveSequent(seq, timeoutTautology, tautologySolver) match {
68
+ case Solved (proof) =>
69
+ nbProblemsSolvedByTautology += 1
70
+ // writeProof(p, proof, "examples/proofs/tautology/")
71
+ case _ => ()
72
+ }
65
73
}
66
74
} catch {
67
75
case _ => ()
68
76
}
69
-
70
77
}
71
78
} catch {
72
79
case error : NullPointerException => println(" You can download the tptp library at http://www.tptp.org/ and put it in main/resources" )
73
80
}
74
81
}
75
82
76
- sealed trait SolverResult
77
- case class Solved (proof : SCProof ) extends SolverResult
78
- case object Unsolved extends SolverResult
79
- case object Timeout extends SolverResult
80
- case object Error extends SolverResult
81
-
82
- def solveProblem (problem : Problem , timeout : FiniteDuration , solver : Sequent => Option [SCProof ]): SolverResult = {
83
- val seq = problemToSequent(problem)
84
- val (futureSolver, cancelSolver) = Future .interruptibly { solver(seq) }
85
- try
86
- Await .result(futureSolver, timeout) match
87
- case Some (proof) => Solved (proof)
88
- case None => Unsolved
89
- catch
90
- case e : TimeoutException =>
91
- cancelSolver()
92
- Timeout
93
- case _ =>
94
- cancelSolver()
95
- Error
96
- }
97
-
98
83
def writeProof (problem : Problem , proof : SCProof , path : String ): Unit = {
99
84
// TODO
100
85
val file = new File (path + problem.name + " .sc" )
@@ -103,76 +88,3 @@ def writeProof(problem: Problem, proof: SCProof, path: String): Unit = {
103
88
bw.write(proof.toString)
104
89
bw.close()
105
90
}
106
-
107
- final class Interrupt extends (() => Boolean ) {
108
- // We need a state-machine to track the progress.
109
- // It can have the following states:
110
- // a null reference means execution has not started.
111
- // a Thread reference means that the execution has started but is not done.
112
- // a this reference means that it is already cancelled or is already too late.
113
- private [this ] final var state : AnyRef = null
114
-
115
- /**
116
- * This is the signal to cancel the execution of the logic.
117
- * Returns whether the cancellation signal was successully issued or not.
118
- */
119
- override final def apply (): Boolean = this .synchronized {
120
- state match {
121
- case null =>
122
- state = this
123
- true
124
- case _ : this .type => false
125
- case t : Thread =>
126
- state = this
127
- // t.interrupt()
128
- t.stop()
129
- true
130
- }
131
- }
132
-
133
- // Initializes right before execution of logic and
134
- // allows to not run the logic at all if already cancelled.
135
- private [this ] final def enter (): Boolean =
136
- this .synchronized {
137
- state match {
138
- case _ : this .type => false
139
- case null =>
140
- state = Thread .currentThread
141
- true
142
- }
143
- }
144
-
145
- // Cleans up after the logic has executed
146
- // Prevents cancellation to occur "too late"
147
- private [this ] final def exit (): Boolean =
148
- this .synchronized {
149
- state match {
150
- case _ : this .type => false
151
- case t : Thread =>
152
- state = this
153
- true
154
- }
155
- }
156
-
157
- /**
158
- * Executes the suplied block of logic and returns the result.
159
- * Throws CancellationException if the block was interrupted.
160
- */
161
- def interruptibly [T ](block : => T ): T =
162
- if (enter()) {
163
- try block
164
- catch {
165
- case ie : InterruptedException => throw new CancellationException ()
166
- } finally {
167
- if (! exit() && Thread .interrupted())
168
- () // If we were interrupted and flag was not cleared
169
- }
170
- } else throw new CancellationException ()
171
- }
172
-
173
- implicit class FutureInterrupt (val future : Future .type ) extends AnyVal {
174
- def interruptibly [T ](block : => T )(implicit ec : ExecutionContext ): (Future [T ], () => Boolean ) = {
175
- val interrupt = new Interrupt ()
176
- (Future (interrupt.interruptibly(block))(ec), interrupt)
177
- }
178
- }
0 commit comments