1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| package org.sat4j.opt; |
8 |
| |
9 |
| import java.math.BigInteger; |
10 |
| |
11 |
| import org.sat4j.reader.ObjectiveFunction; |
12 |
| import org.sat4j.specs.ContradictionException; |
13 |
| import org.sat4j.specs.IOptimizationProblem; |
14 |
| import org.sat4j.specs.ISolver; |
15 |
| import org.sat4j.specs.TimeoutException; |
16 |
| import org.sat4j.tools.SolverDecorator; |
17 |
| |
18 |
| public class PseudoOptDecorator extends SolverDecorator implements |
19 |
| IOptimizationProblem { |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| private static final long serialVersionUID = 1L; |
25 |
| |
26 |
| private ObjectiveFunction objfct; |
27 |
| |
28 |
| private int[] prevmodel; |
29 |
| |
30 |
0
| public PseudoOptDecorator(ISolver solver) {
|
31 |
0
| super(solver);
|
32 |
| } |
33 |
| |
34 |
0
| public void setObjectTiveFunction(ObjectiveFunction objf) {
|
35 |
0
| objfct = objf;
|
36 |
| } |
37 |
| |
38 |
0
| public boolean admitABetterSolution() throws TimeoutException {
|
39 |
0
| boolean result = super.isSatisfiable();
|
40 |
0
| if (result)
|
41 |
0
| prevmodel = super.model();
|
42 |
0
| return result;
|
43 |
| } |
44 |
| |
45 |
0
| public boolean hasNoObjectiveFunction() {
|
46 |
0
| return objfct == null;
|
47 |
| } |
48 |
| |
49 |
0
| public boolean nonOptimalMeansSatisfiable() {
|
50 |
0
| return true;
|
51 |
| } |
52 |
| |
53 |
0
| public Number calculateObjective() {
|
54 |
0
| return objfct.calculateDegree(prevmodel);
|
55 |
| } |
56 |
| |
57 |
0
| public void discard() throws ContradictionException {
|
58 |
0
| super.addPseudoBoolean(objfct.getVars(), objfct.getCoeffs(), false,
|
59 |
| objfct.calculateDegree(prevmodel).subtract(BigInteger.ONE)); |
60 |
| } |
61 |
| |
62 |
0
| @Override
|
63 |
| public int[] model() { |
64 |
0
| return prevmodel;
|
65 |
| } |
66 |
| |
67 |
| } |