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