FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaRes/src/atp/Subsumption.java at master · eprover/JavaRes · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
eprover
/
JavaRes
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaRes
/
src
/
atp
/
Subsumption.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
157 lines (136 loc) · 6.05 KB
Breadcrumbs
JavaRes
/
src
/
atp
/
Subsumption.java
Copy path
File metadata and controls
157 lines (136 loc) · 6.05 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
Copyright 2010-2011 Adam Pease, apease@articulatesoftware.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program ; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston,
MA 02111-1307 USA
*/
package
atp
;
import
java
.
io
.
StringReader
;
import
java
.
util
.*;
import
java
.
text
.*;
public
class
Subsumption
{
/** ***************************************************************
* Try to extend subst so that subst(subsumer) is a multi-subset of
* subsumed. Recursively call this routine, checking the first literal
* of subsumer for a match with subsumed, then calling again with
* the first literal removed.
*/
private
static
boolean
subsumeLitLists
(
Clause
subsumer
,
Clause
subsumed
,
BacktrackSubstitution
subst
) {
if
(
subsumer
==
null
||
subsumer
.
literals
.
size
() <
1
)
return
true
;
for
(
int
i
=
0
;
i
<
subsumed
.
literals
.
size
();
i
++) {
int
btstate
=
subst
.
getState
();
if
(
subsumer
.
literals
.
get
(
0
).
match
(
subsumed
.
literals
.
get
(
i
),
subst
)) {
Clause
rest
=
new
Clause
();
for
(
int
j
=
0
;
j
<
subsumer
.
literals
.
size
();
j
++)
if
(
subsumer
.
literals
.
get
(
j
) !=
subsumed
.
literals
.
get
(
i
))
rest
.
literals
.
add
(
subsumer
.
literals
.
get
(
j
));
if
(
subsumeLitLists
(
subsumer
.
deepCopy
(
1
),
rest
,
subst
))
return
true
;
}
subst
.
backtrackToState
(
btstate
);
}
return
false
;
}
/** ***************************************************************
* Return True if subsumer subsumes subsumed, False otherwise.
*/
private
static
boolean
subsumes
(
Clause
subsumer
,
Clause
subsumed
) {
if
(
subsumer
.
literals
.
size
() >
subsumed
.
literals
.
size
())
return
false
;
BacktrackSubstitution
subst
=
new
BacktrackSubstitution
();
return
subsumeLitLists
(
subsumer
,
subsumed
,
subst
);
}
/** ***************************************************************
* Return True if any clause from set subsumes clause, False otherwise.
*/
public
static
boolean
forwardSubsumption
(
ClauseSet
cs
,
Clause
clause
) {
for
(
int
i
=
0
;
i
<
cs
.
length
();
i
++) {
Clause
c
=
cs
.
get
(
i
);
if
(
subsumes
(
c
,
clause
))
return
true
;
}
return
false
;
}
/** ***************************************************************
* Remove all clauses that are subsumed by clause from set.
*/
public
static
int
backwardSubsumption
(
Clause
clause
,
ClauseSet
cs
) {
ArrayList
<
Clause
>
subsumed_set
=
new
ArrayList
<
Clause
>();
for
(
int
i
=
0
;
i
<
cs
.
length
();
i
++) {
Clause
c
=
cs
.
get
(
i
);
if
(
subsumes
(
clause
,
c
))
subsumed_set
.
add
(
c
);
}
int
res
=
subsumed_set
.
size
();
for
(
int
i
=
0
;
i
<
subsumed_set
.
size
();
i
++) {
Clause
c
=
subsumed_set
.
get
(
i
);
if
(
c
.
supportsClauses
.
size
() ==
0
)
// make sure that clauses that support others are not removed.
cs
.
extractClause
(
c
);
}
return
res
;
}
/** ***************************************************************
* ************ UNIT TESTS *****************
*/
public
static
Clause
c1
=
null
;
public
static
Clause
c2
=
null
;
public
static
Clause
c3
=
null
;
public
static
Clause
c4
=
null
;
public
static
Clause
c5
=
null
;
/** ***************************************************************
* Setup function for resolution testing
*/
public
static
void
setup
() {
String
spec
=
"cnf(axiom, c1, $false).
\n
"
+
"cnf(axiom, c2, p(a)).
\n
"
+
"cnf(axiom, c3, p(X)).
\n
"
+
"cnf(axiom, c4, p(a)|q(f(X))).
\n
"
+
"cnf(axiom, c5, p(a)|q(f(b))|p(X)).
\n
"
;
Lexer
lex
=
new
Lexer
(
spec
);
c1
=
Clause
.
parse
(
lex
);
System
.
out
.
println
(
c1
);
c2
=
Clause
.
parse
(
lex
);
System
.
out
.
println
(
c2
);
c3
=
Clause
.
parse
(
lex
);
System
.
out
.
println
(
c3
);
c4
=
Clause
.
parse
(
lex
);
System
.
out
.
println
(
c4
);
c5
=
Clause
.
parse
(
lex
);
System
.
out
.
println
(
c5
);
}
/** ***************************************************************
* Test subsumption.
*/
public
static
void
testSubsumption
() {
System
.
out
.
println
(
"---------------------"
);
System
.
out
.
println
(
"INFO in Subsumption.testSubsumption(): all should be true"
);
System
.
out
.
println
(
c1
+
" subsumes "
+
c1
+
" = "
+
subsumes
(
c1
,
c1
));
System
.
out
.
println
(
c2
+
" subsumes "
+
c2
+
" = "
+
subsumes
(
c2
,
c2
));
System
.
out
.
println
(
c3
+
" subsumes "
+
c3
+
" = "
+
subsumes
(
c3
,
c3
));
System
.
out
.
println
(
c4
+
" subsumes "
+
c4
+
" = "
+
subsumes
(
c4
,
c4
));
System
.
out
.
println
(
c1
+
" subsumes "
+
c2
+
" = "
+
subsumes
(
c1
,
c2
));
System
.
out
.
println
(
c2
+
" does not subsume "
+
c1
+
" = "
+ !
subsumes
(
c2
,
c1
));
System
.
out
.
println
(
c2
+
" does not subsume "
+
c3
+
" = "
+ !
subsumes
(
c2
,
c3
));
System
.
out
.
println
(
c3
+
" subsumes "
+
c2
+
" = "
+
subsumes
(
c3
,
c2
));
System
.
out
.
println
(
c4
+
" subsumes "
+
c5
+
" = "
+
subsumes
(
c4
,
c5
));
System
.
out
.
println
(
c5
+
" does not subsume "
+
c4
+
" = "
+ !
subsumes
(
c5
,
c4
));
}
/** ***************************************************************
* Test method for this class.
*/
public
static
void
main
(
String
[]
args
) {
setup
();
testSubsumption
();
}
}
Back
|
FazBrowse Home
|
New Git URL