| 
 1 | 
  
 |  | 
| 
 2 | 
  
 |  | 
| 
 3 | 
  
 |  | 
| 
 4 | 
  
 |  | 
| 
 5 | 
  
 |  | 
| 
 6 | 
  
 |  | 
| 
 7 | 
  
 | package org.sat4j.minisat.orders; | 
| 
 8 | 
  
 |  | 
| 
 9 | 
  
 | import java.util.ArrayList; | 
| 
 10 | 
  
 | import java.util.Collections; | 
| 
 11 | 
  
 |  | 
| 
 12 | 
  
 | import org.sat4j.minisat.core.ILits; | 
| 
 13 | 
  
 | import org.sat4j.minisat.core.ILits2; | 
| 
 14 | 
  
 |  | 
| 
 15 | 
  
 |  | 
| 
 16 | 
  
 |  | 
| 
 17 | 
  
 |  | 
| 
 18 | 
  
 |  | 
| 
 19 | 
  
 | public class MyOrder extends VarOrder { | 
| 
 20 | 
  
 |  | 
| 
 21 | 
  
 |     private static final long serialVersionUID = 1L; | 
| 
 22 | 
  
 |  | 
| 
 23 | 
  
 |     private ILits2 lits; | 
| 
 24 | 
  
 |  | 
| 
 25 | 
  
 |     class Temp implements Comparable<Temp> { | 
| 
 26 | 
  
 |         private final int id; | 
| 
 27 | 
  
 |  | 
| 
 28 | 
  
 |         private final int count; | 
| 
 29 | 
  
 |  | 
| 
 30 | 
 90
 |         Temp(int id) {
 | 
| 
 31 | 
 90
 |             this.id = id;
 | 
| 
 32 | 
 90
 |             count = lits.nBinaryClauses(id) + lits.nBinaryClauses(id ^ 1);
 | 
| 
 33 | 
  
 |         } | 
| 
 34 | 
  
 |  | 
| 
 35 | 
 89
 |         public int compareTo(Temp t) {
 | 
| 
 36 | 
 89
 |             if (count == 0) {
 | 
| 
 37 | 
 0
 |                 return Integer.MAX_VALUE;
 | 
| 
 38 | 
  
 |             } | 
| 
 39 | 
 89
 |             if (t.count == 0) {
 | 
| 
 40 | 
 0
 |                 return -1;
 | 
| 
 41 | 
  
 |             } | 
| 
 42 | 
 89
 |             return count - t.count;
 | 
| 
 43 | 
  
 |         } | 
| 
 44 | 
  
 |  | 
| 
 45 | 
 0
 |         @Override
 | 
| 
 46 | 
  
 |         public String toString() { | 
| 
 47 | 
 0
 |             return "" + id + "(" + count + ")";  
 | 
| 
 48 | 
  
 |         } | 
| 
 49 | 
  
 |     } | 
| 
 50 | 
  
 |  | 
| 
 51 | 
  
 |      | 
| 
 52 | 
  
 |  | 
| 
 53 | 
  
 |  | 
| 
 54 | 
  
 |  | 
| 
 55 | 
  
 |  | 
| 
 56 | 
 1
 |     @Override
 | 
| 
 57 | 
  
 |     public void setLits(ILits lits) { | 
| 
 58 | 
 1
 |         super.setLits(lits);
 | 
| 
 59 | 
 1
 |         this.lits = (ILits2) lits;
 | 
| 
 60 | 
  
 |     } | 
| 
 61 | 
  
 |  | 
| 
 62 | 
  
 |      | 
| 
 63 | 
  
 |  | 
| 
 64 | 
  
 |  | 
| 
 65 | 
  
 |  | 
| 
 66 | 
  
 |  | 
| 
 67 | 
 1
 |     @Override
 | 
| 
 68 | 
  
 |     public void init() { | 
| 
 69 | 
 1
 |         super.init();
 | 
| 
 70 | 
 1
 |         ArrayList<Temp> v = new ArrayList<Temp>(order.length);
 | 
| 
 71 | 
  
 |  | 
| 
 72 | 
 1
 |         for (int i = 1; i < order.length; i++) {
 | 
| 
 73 | 
 90
 |             Temp t = new Temp(order[i]);
 | 
| 
 74 | 
 90
 |             v.add(t);
 | 
| 
 75 | 
  
 |         } | 
| 
 76 | 
 1
 |         Collections.sort(v);
 | 
| 
 77 | 
  
 |          | 
| 
 78 | 
 1
 |         for (int i = 0; i < v.size(); i++) {
 | 
| 
 79 | 
 90
 |             Temp t = v.get(i);
 | 
| 
 80 | 
 90
 |             order[i + 1] = t.id;
 | 
| 
 81 | 
 90
 |             int index = t.id >> 1;
 | 
| 
 82 | 
 90
 |             varpos[index] = i + 1;
 | 
| 
 83 | 
  
 |         } | 
| 
 84 | 
 1
 |         lastVar = 1;
 | 
| 
 85 | 
  
 |     } | 
| 
 86 | 
  
 |      | 
| 
 87 | 
 0
 |     @Override
 | 
| 
 88 | 
  
 |     public String toString() { | 
| 
 89 | 
 0
 |         return "Init VSIDS order using a POSIT-like static order on 2 and 3 clauses.";  
 | 
| 
 90 | 
  
 |     } | 
| 
 91 | 
  
 | } |