View Javadoc

1   /*******************************************************************************
2    * SAT4J: a SATisfiability library for Java Copyright (C) 2004, 2012 Artois University and CNRS
3    *
4    * All rights reserved. This program and the accompanying materials
5    * are made available under the terms of the Eclipse Public License v1.0
6    * which accompanies this distribution, and is available at
7    *  http://www.eclipse.org/legal/epl-v10.html
8    *
9    * Alternatively, the contents of this file may be used under the terms of
10   * either the GNU Lesser General Public License Version 2.1 or later (the
11   * "LGPL"), in which case the provisions of the LGPL are applicable instead
12   * of those above. If you wish to allow use of your version of this file only
13   * under the terms of the LGPL, and not to allow others to use your version of
14   * this file under the terms of the EPL, indicate your decision by deleting
15   * the provisions above and replace them with the notice and other provisions
16   * required by the LGPL. If you do not delete the provisions above, a recipient
17   * may use your version of this file under the terms of the EPL or the LGPL.
18   *
19   * Based on the original MiniSat specification from:
20   *
21   * An extensible SAT solver. Niklas Een and Niklas Sorensson. Proceedings of the
22   * Sixth International Conference on Theory and Applications of Satisfiability
23   * Testing, LNCS 2919, pp 502-518, 2003.
24   *
25   * See www.minisat.se for the original solver in C++.
26   *
27   * Contributors:
28   *   CRIL - initial API and implementation
29   *******************************************************************************/
30  package org.sat4j.minisat.core;
31  
32  import java.io.PrintWriter;
33  import java.io.Serializable;
34  import java.lang.reflect.Field;
35  import java.util.HashMap;
36  import java.util.Map;
37  
38  /**
39   * Contains some statistics regarding the search.
40   * 
41   * @author daniel
42   * 
43   */
44  public class SolverStats implements Serializable {
45      private static final long serialVersionUID = 1L;
46  
47      public int starts;
48  
49      public long decisions;
50  
51      public long propagations;
52  
53      public long inspects;
54  
55      public long conflicts;
56  
57      public long learnedliterals;
58  
59      public long learnedbinaryclauses;
60  
61      public long learnedternaryclauses;
62  
63      public long learnedclauses;
64  
65      public long ignoredclauses;
66  
67      public long rootSimplifications;
68  
69      public long reducedliterals;
70  
71      public long changedreason;
72  
73      public int reduceddb;
74  
75      public int shortcuts;
76  
77      public long updateLBD;
78  
79      public int importedUnits;
80  
81      public void reset() {
82          this.starts = 0;
83          this.decisions = 0;
84          this.propagations = 0;
85          this.inspects = 0;
86          this.shortcuts = 0;
87          this.conflicts = 0;
88          this.learnedliterals = 0;
89          this.learnedclauses = 0;
90          this.ignoredclauses = 0;
91          this.learnedbinaryclauses = 0;
92          this.learnedternaryclauses = 0;
93          this.rootSimplifications = 0;
94          this.reducedliterals = 0;
95          this.changedreason = 0;
96          this.reduceddb = 0;
97          this.updateLBD = 0;
98          this.importedUnits = 0;
99      }
100 
101     public void printStat(PrintWriter out, String prefix) {
102         out.println(prefix + "starts\t\t: " + this.starts);
103         out.println(prefix + "conflicts\t\t: " + this.conflicts);
104         out.println(prefix + "decisions\t\t: " + this.decisions);
105         out.println(prefix + "propagations\t\t: " + this.propagations);
106         out.println(prefix + "inspects\t\t: " + this.inspects);
107         out.println(prefix + "shortcuts\t\t: " + this.shortcuts);
108         out.println(prefix + "learnt literals\t: " + this.learnedliterals);
109         out.println(prefix + "learnt binary clauses\t: "
110                 + this.learnedbinaryclauses);
111         out.println(prefix + "learnt ternary clauses\t: "
112                 + this.learnedternaryclauses);
113         out.println(prefix + "learnt constraints\t: " + this.learnedclauses);
114         out.println(prefix + "ignored constraints\t: " + this.ignoredclauses);
115         out.println(prefix + "root simplifications\t: "
116                 + this.rootSimplifications);
117         out.println(prefix + "removed literals (reason simplification)\t: "
118                 + this.reducedliterals);
119         out.println(prefix + "reason swapping (by a shorter reason)\t: "
120                 + this.changedreason);
121         out.println(prefix + "Calls to reduceDB\t: " + this.reduceddb);
122         out.println(prefix + "Number of update (reduction) of LBD\t: "
123                 + this.updateLBD);
124         out.println(prefix + "Imported unit clauses\t: "
125                 + this.importedUnits);
126     }
127 
128     public Map<String, Number> toMap() {
129         Map<String, Number> map = new HashMap<String, Number>();
130         for (Field f : this.getClass().getFields()) {
131             try {
132                 map.put(f.getName(), (Number) f.get(this));
133             } catch (IllegalArgumentException e) {
134                 // ignores silently
135             } catch (IllegalAccessException e) {
136                 // ignores silently
137             }
138         }
139         return map;
140     }
141 }