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 package org.sat4j.minisat.orders;
26
27 import static org.sat4j.minisat.core.LiteralsUtils.neg;
28 import static org.sat4j.minisat.core.LiteralsUtils.var;
29
30 import java.math.BigInteger;
31
32 import org.sat4j.minisat.core.ILits;
33 import org.sat4j.opt.ObjectiveFunction;
34 import org.sat4j.specs.IVec;
35 import org.sat4j.specs.IVecInt;
36
37 public class VarOrderHeapObjective extends VarOrderHeap<ILits> {
38
39
40
41
42 private static final long serialVersionUID = 1L;
43
44 private ObjectiveFunction obj;
45
46 public void setObjectiveFunction(ObjectiveFunction obj) {
47 this.obj = obj;
48 }
49
50 @Override
51 public void init() {
52 super.init();
53 if (obj != null) {
54 IVecInt vars = obj.getVars();
55 IVec<BigInteger> coefs = obj.getCoeffs();
56 for (int i = 0; i < vars.size(); i++) {
57 int p = lits.getFromPool(vars.get(i));
58 BigInteger c = coefs.get(i);
59 if (c.signum() < 0) {
60 p = neg(p);
61 }
62 int var = var(p);
63 activity[var] = c.abs().doubleValue();
64 if (heap.inHeap(var))
65 heap.increase(var);
66 phase[var] = neg(p);
67 }
68 }
69 }
70
71 @Override
72 public void updateVar(int p) {
73 int var = p >> 1;
74 updateActivity(var);
75 if (heap.inHeap(var))
76 heap.increase(var);
77 }
78
79 @Override
80 public void assignLiteral(int p) {
81 phase[p>>1] = p;
82 }
83 }