Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SAT4J
sat4j
Commits
d3266770
Commit
d3266770
authored
Sep 20, 2021
by
Anthony Blomme
Browse files
Delete Anthony2.java
parent
ced102ef
Pipeline
#15927
passed with stages
in 55 minutes and 4 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
org.sat4j.core/src/main/java/org/sat4j/Anthony2.java
deleted
100644 → 0
View file @
ced102ef
package
org.sat4j
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Iterator
;
import
java.util.stream.Collectors
;
import
org.sat4j.core.LiteralsUtils
;
import
org.sat4j.core.VecInt
;
import
org.sat4j.minisat.SolverFactory
;
import
org.sat4j.minisat.core.ICDCL
;
import
org.sat4j.minisat.core.ILits
;
import
org.sat4j.minisat.core.IOrder
;
import
org.sat4j.minisat.core.Solver
;
import
org.sat4j.reader.DimacsReader
;
import
org.sat4j.reader.ParseFormatException
;
import
org.sat4j.reader.Reader
;
import
org.sat4j.specs.ContradictionException
;
import
org.sat4j.specs.ISolver
;
import
org.sat4j.specs.IVecInt
;
import
org.sat4j.specs.IteratorInt
;
import
org.sat4j.specs.TimeoutException
;
import
org.sat4j.tools.Backbone
;
public
class
Anthony2
{
static
class
Decision
{
private
final
Integer
d
;
private
final
IVecInt
propagations
;
Decision
(
Integer
d
,
IVecInt
propagations
)
{
this
.
d
=
d
;
this
.
propagations
=
propagations
;
}
Decision
(
Decision
decisions
)
{
this
.
d
=
decisions
.
d
;
this
.
propagations
=
decisions
.
propagations
;
}
@Override
public
String
toString
()
{
return
"("
+
d
+
"|"
+
propagations
+
")"
;
}
}
static
class
Model
{
private
final
Collection
<
Decision
>
decisions
;
Model
(
Collection
<
Decision
>
decisions
)
{
this
.
decisions
=
decisions
;
}
@Override
public
String
toString
()
{
return
this
.
decisions
.
toString
();
}
}
private
static
IVecInt
findPropagated
(
IVecInt
implied
,
IVecInt
assumptions
)
{
IVecInt
propagated
=
new
VecInt
();
for
(
IteratorInt
it
=
implied
.
iterator
();
it
.
hasNext
();)
{
int
l
=
it
.
next
();
if
(!
assumptions
.
contains
(
l
))
{
propagated
.
push
(
l
);
assumptions
.
push
(
l
);
}
}
return
propagated
;
}
private
static
int
decide
(
IVecInt
implied
,
ILits
lits
,
IOrder
order
)
{
for
(
IteratorInt
it
=
implied
.
iterator
();
it
.
hasNext
();)
{
int
l
=
it
.
next
();
lits
.
satisfies
(
LiteralsUtils
.
toInternal
(
l
));
}
return
LiteralsUtils
.
toDimacs
(
order
.
select
());
}
private
static
void
unassign
(
IVecInt
literals
,
ILits
lits
)
{
for
(
IteratorInt
it
=
literals
.
iterator
();
it
.
hasNext
();)
{
int
l
=
it
.
next
();
lits
.
unassign
(
LiteralsUtils
.
toInternal
(
l
));
}
}
private
static
Collection
<
Decision
>
cloneDecisions
(
Collection
<
Decision
>
decisions
)
{
return
decisions
.
stream
().
map
(
Decision:
:
new
)
.
collect
(
Collectors
.
toList
());
}
private
static
void
applyAndDecide
(
Integer
d
,
Collection
<
Decision
>
decisions
,
Collection
<
Model
>
models
,
IVecInt
assumptions
,
ISolver
solver
,
ILits
lits
,
IOrder
order
)
throws
TimeoutException
,
ParseFormatException
,
IOException
,
ContradictionException
{
if
(
d
!=
null
)
{
assumptions
.
push
(
d
);
}
solver
.
clearLearntClauses
();
IVecInt
implied
=
Backbone
.
instance
().
compute
(
solver
,
assumptions
);
IVecInt
propagated
=
findPropagated
(
implied
,
assumptions
);
decisions
.
add
(
new
Decision
(
d
,
propagated
));
if
(
assumptions
.
size
()
<
solver
.
realNumberOfVariables
())
{
int
nextDecision
=
decide
(
implied
,
lits
,
order
);
applyAndDecide
(
nextDecision
,
cloneDecisions
(
decisions
),
models
,
assumptions
.
clone
(),
solver
,
lits
,
order
);
lits
.
unassign
(
LiteralsUtils
.
toInternal
(
nextDecision
));
applyAndDecide
(-
nextDecision
,
cloneDecisions
(
decisions
),
models
,
assumptions
.
clone
(),
solver
,
lits
,
order
);
lits
.
unassign
(
LiteralsUtils
.
toInternal
(-
nextDecision
));
}
else
{
models
.
add
(
new
Model
(
decisions
));
}
unassign
(
propagated
,
lits
);
}
public
static
void
main
(
String
[]
args
)
throws
TimeoutException
,
ParseFormatException
,
IOException
,
ContradictionException
{
if
(
args
.
length
==
1
)
{
String
filename
=
args
[
0
];
ISolver
solver
=
SolverFactory
.
newDefault
();
ILits
lits
=
((
Solver
)
solver
).
getVocabulary
();
IOrder
order
=
((
ICDCL
<?>)
solver
).
getOrder
();
Reader
reader
=
new
DimacsReader
(
solver
);
reader
.
parseInstance
(
filename
);
IVecInt
assumptions
=
new
VecInt
();
Collection
<
Decision
>
decisions
=
new
ArrayList
<>();
Collection
<
Model
>
models
=
new
ArrayList
<>();
applyAndDecide
(
null
,
decisions
,
models
,
assumptions
,
solver
,
lits
,
order
);
for
(
Iterator
<
Model
>
i
=
models
.
iterator
();
i
.
hasNext
();)
{
System
.
out
.
println
(
i
.
next
());
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment