Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
SAT4J
sat4j
Commits
f0332be6
Commit
f0332be6
authored
Sep 10, 2017
by
Daniel Le Berre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small examples showing how to use MaxHSLikeSolver.
parent
30eda6cc
Pipeline
#259
failed with stage
in 13 minutes and 13 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
0 deletions
+75
-0
org.sat4j.maxsat/src/test/java/org/sat4j/maxsat/TestMaxHSLikeSolver.java
...t/src/test/java/org/sat4j/maxsat/TestMaxHSLikeSolver.java
+75
-0
No files found.
org.sat4j.maxsat/src/test/java/org/sat4j/maxsat/TestMaxHSLikeSolver.java
0 → 100644
View file @
f0332be6
package
org.sat4j.maxsat
;
import
static
org
.
junit
.
Assert
.*;
import
java.math.BigInteger
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.sat4j.core.VecInt
;
import
org.sat4j.specs.ContradictionException
;
import
org.sat4j.specs.TimeoutException
;
public
class
TestMaxHSLikeSolver
{
private
MaxHSLikeSolver
pwms
;
@Before
public
void
init
()
{
this
.
pwms
=
new
MaxHSLikeSolver
(
org
.
sat4j
.
pb
.
SolverFactory
.
newDefault
(),
org
.
sat4j
.
minisat
.
SolverFactory
.
newDefault
());
}
@Test
public
void
testOnePMS
()
throws
ContradictionException
,
TimeoutException
{
pwms
.
newVar
(
4
);
pwms
.
addHardClause
(
new
VecInt
(
new
int
[]
{
1
,
2
,
3
,
4
}));
pwms
.
addSoftClause
(
new
VecInt
(
new
int
[]
{-
1
,-
2
}));
pwms
.
addSoftClause
(
new
VecInt
(
new
int
[]
{-
1
,
2
}));
pwms
.
addSoftClause
(
new
VecInt
(
new
int
[]
{
1
,-
3
}));
pwms
.
addSoftClause
(
new
VecInt
(
new
int
[]
{
1
,
3
}));
assertTrue
(
pwms
.
isSatisfiable
());
assertEquals
(
pwms
.
violatedWeight
(),
BigInteger
.
ONE
);
}
@Test
public
void
testAnotherPMS
()
throws
ContradictionException
,
TimeoutException
{
pwms
.
newVar
(
4
);
pwms
.
addHardClause
(
new
VecInt
(
new
int
[]
{
1
,
2
,
3
,
4
}));
pwms
.
addSoftClause
(
new
VecInt
(
new
int
[]
{-
1
,-
2
}));
pwms
.
addSoftClause
(
new
VecInt
(
new
int
[]
{
1
}));
pwms
.
addSoftClause
(
new
VecInt
(
new
int
[]
{
2
}));
pwms
.
addSoftClause
(
new
VecInt
(
new
int
[]
{-
1
,-
3
}));
pwms
.
addSoftClause
(
new
VecInt
(
new
int
[]
{
3
}));
assertTrue
(
pwms
.
isSatisfiable
());
assertEquals
(
pwms
.
violatedWeight
(),
BigInteger
.
ONE
);
}
@Test
public
void
testAnotherPMSRelaxingTwoConstraints
()
throws
ContradictionException
,
TimeoutException
{
pwms
.
newVar
(
4
);
pwms
.
addHardClause
(
new
VecInt
(
new
int
[]
{
1
,
2
,
3
,
4
}));
pwms
.
addSoftClause
(
new
VecInt
(
new
int
[]
{-
1
,-
2
}));
pwms
.
addSoftClause
(
new
VecInt
(
new
int
[]
{
1
}));
pwms
.
addSoftClause
(
new
VecInt
(
new
int
[]
{
2
}));
pwms
.
addSoftClause
(
new
VecInt
(
new
int
[]
{-
3
,-
4
}));
pwms
.
addSoftClause
(
new
VecInt
(
new
int
[]
{
3
}));
pwms
.
addSoftClause
(
new
VecInt
(
new
int
[]
{
4
}));
assertTrue
(
pwms
.
isSatisfiable
());
assertEquals
(
pwms
.
violatedWeight
(),
BigInteger
.
valueOf
(
2
));
}
@Test
public
void
testOneWPMS
()
throws
ContradictionException
,
TimeoutException
{
pwms
.
newVar
(
4
);
pwms
.
addHardClause
(
new
VecInt
(
new
int
[]
{
1
,
2
,
3
,
4
}));
pwms
.
addSoftClause
(
1000
,
new
VecInt
(
new
int
[]
{-
1
,-
2
}));
pwms
.
addSoftClause
(
500
,
new
VecInt
(
new
int
[]
{-
1
,
2
}));
pwms
.
addSoftClause
(
200
,
new
VecInt
(
new
int
[]
{
1
,-
3
}));
pwms
.
addSoftClause
(
100
,
new
VecInt
(
new
int
[]
{
1
,
3
}));
assertTrue
(
pwms
.
isSatisfiable
());
assertEquals
(
pwms
.
violatedWeight
(),
BigInteger
.
valueOf
(
100
));
}
}
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