View Javadoc

1   /*******************************************************************************
2   * SAT4J: a SATisfiability library for Java Copyright (C) 2004-2008 Daniel Le Berre
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  *******************************************************************************/
28  package org.sat4j.minisat.core;
29  
30  import java.io.PrintWriter;
31  import java.io.Serializable;
32  import java.lang.reflect.Field;
33  import java.util.HashMap;
34  import java.util.Map;
35  
36  /**
37   * Contains some statistics regarding the search.
38   * 
39   * @author daniel
40   * 
41   */
42  public class SolverStats implements Serializable {
43      private static final long serialVersionUID = 1L;
44  
45      public int starts;
46  
47      public long decisions;
48  
49      public long propagations;
50  
51      public long inspects;
52  
53      public long conflicts;
54  
55      public long learnedliterals;
56  
57      public long learnedbinaryclauses;
58  
59      public long learnedternaryclauses;
60  
61      public long learnedclauses;
62      
63      public long ignoredclauses;
64  
65      public long rootSimplifications;
66  
67      public long reducedliterals;
68  
69      public long changedreason;
70  
71      public int reduceddb;
72  
73      public void reset() {
74          starts = 0;
75          decisions = 0;
76          propagations = 0;
77          inspects = 0;
78          conflicts = 0;
79          learnedliterals = 0;
80          learnedclauses = 0;
81          ignoredclauses = 0;
82          learnedbinaryclauses = 0;
83          learnedternaryclauses = 0;
84          rootSimplifications = 0;
85          reducedliterals = 0;
86          changedreason = 0;
87          reduceddb = 0;
88      }
89  
90      public void printStat(PrintWriter out, String prefix) {
91          out.println(prefix + "starts\t\t: " + starts);
92          out.println(prefix + "conflicts\t\t: " + conflicts);
93          out.println(prefix + "decisions\t\t: " + decisions);
94          out.println(prefix + "propagations\t\t: " + propagations);
95          out.println(prefix + "inspects\t\t: " + inspects);
96          out.println(prefix + "learnt literals\t: " + learnedliterals);
97          out
98                  .println(prefix + "learnt binary clauses\t: "
99                          + learnedbinaryclauses);
100         out.println(prefix + "learnt ternary clauses\t: "
101                 + learnedternaryclauses);
102         out.println(prefix + "learnt clauses\t: " + learnedclauses);
103         out.println(prefix + "ignored clauses\t: " + ignoredclauses);
104         out.println(prefix + "root simplifications\t: " + rootSimplifications);
105         out.println(prefix + "removed literals (reason simplification)\t: "
106                 + reducedliterals);
107         out.println(prefix + "reason swapping (by a shorter reason)\t: "
108                 + changedreason);
109         out.println(prefix + "Calls to reduceDB\t: " + reduceddb);
110     }
111 
112     public Map<String, Number> toMap() {
113         Map<String, Number> map = new HashMap<String, Number>();
114         for (Field f : this.getClass().getDeclaredFields()) {
115             try {
116                 map.put(f.getName(), (Number) f.get(this));
117             } catch (IllegalArgumentException e) {
118                 e.printStackTrace();
119             } catch (IllegalAccessException e) {
120                 e.printStackTrace();
121             }
122         }
123         return map;
124     }
125 }