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 void reset() {
80          this.starts = 0;
81          this.decisions = 0;
82          this.propagations = 0;
83          this.inspects = 0;
84          this.shortcuts = 0;
85          this.conflicts = 0;
86          this.learnedliterals = 0;
87          this.learnedclauses = 0;
88          this.ignoredclauses = 0;
89          this.learnedbinaryclauses = 0;
90          this.learnedternaryclauses = 0;
91          this.rootSimplifications = 0;
92          this.reducedliterals = 0;
93          this.changedreason = 0;
94          this.reduceddb = 0;
95          this.updateLBD = 0;
96      }
97  
98      public void printStat(PrintWriter out, String prefix) {
99          out.println(prefix + "starts\t\t: " + this.starts);
100         out.println(prefix + "conflicts\t\t: " + this.conflicts);
101         out.println(prefix + "decisions\t\t: " + this.decisions);
102         out.println(prefix + "propagations\t\t: " + this.propagations);
103         out.println(prefix + "inspects\t\t: " + this.inspects);
104         out.println(prefix + "shortcuts\t\t: " + this.shortcuts);
105         out.println(prefix + "learnt literals\t: " + this.learnedliterals);
106         out.println(prefix + "learnt binary clauses\t: "
107                 + this.learnedbinaryclauses);
108         out.println(prefix + "learnt ternary clauses\t: "
109                 + this.learnedternaryclauses);
110         out.println(prefix + "learnt constraints\t: " + this.learnedclauses);
111         out.println(prefix + "ignored constraints\t: " + this.ignoredclauses);
112         out.println(prefix + "root simplifications\t: "
113                 + this.rootSimplifications);
114         out.println(prefix + "removed literals (reason simplification)\t: "
115                 + this.reducedliterals);
116         out.println(prefix + "reason swapping (by a shorter reason)\t: "
117                 + this.changedreason);
118         out.println(prefix + "Calls to reduceDB\t: " + this.reduceddb);
119         out.println(prefix + "Number of update (reduction) of LBD\t: "
120                 + this.updateLBD);
121     }
122 
123     public Map<String, Number> toMap() {
124         Map<String, Number> map = new HashMap<String, Number>();
125         for (Field f : this.getClass().getFields()) {
126             try {
127                 map.put(f.getName(), (Number) f.get(this));
128             } catch (IllegalArgumentException e) {
129                 // ignores silently
130             } catch (IllegalAccessException e) {
131                 // ignores silently
132             }
133         }
134         return map;
135     }
136 }