Clover Coverage Report
Coverage timestamp: mer. juin 27 2007 07:27:16 CEST
37   157   6   2,64
8   95   0,51   14
14     1,36  
1    
 
  DotSearchListener       Line # 43 37 6 0% 0.0
 
No Tests
 
1    /*
2    * SAT4J: a SATisfiability library for Java Copyright (C) 2004-2006 Daniel Le Berre
3    *
4    * Based on the original minisat specification from:
5    *
6    * An extensible SAT solver. Niklas E?n and Niklas S?rensson. Proceedings of the
7    * Sixth International Conference on Theory and Applications of Satisfiability
8    * Testing, LNCS 2919, pp 502-518, 2003.
9    *
10    * This library is free software; you can redistribute it and/or modify it under
11    * the terms of the GNU Lesser General Public License as published by the Free
12    * Software Foundation; either version 2.1 of the License, or (at your option)
13    * any later version.
14    *
15    * This library is distributed in the hope that it will be useful, but WITHOUT
16    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17    * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
18    * details.
19    *
20    * You should have received a copy of the GNU Lesser General Public License
21    * along with this library; if not, write to the Free Software Foundation, Inc.,
22    * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23    *
24    */
25    package org.sat4j.minisat.core;
26   
27    import java.io.FileWriter;
28    import java.io.IOException;
29    import java.io.Writer;
30   
31    import org.sat4j.core.Vec;
32   
33    /**
34    * Class allowing to express the search as a tree in the dot language. The
35    * resulting file can be viewed in a tool like <a
36    * href="http://www.graphviz.org/">Graphviz</a>
37    *
38    * To use only on small benchmarks.
39    *
40    * @author daniel
41    *
42    */
 
43    public class DotSearchListener implements SearchListener {
44   
45    /**
46    *
47    */
48    private static final long serialVersionUID = 1L;
49   
50    private final Vec<String> pile;
51   
52    private String currentNodeName = null;
53   
54    private transient Writer out;
55   
56    private boolean estOrange = false;
57   
 
58  0 toggle public DotSearchListener(final String fileNameToSave) {
59  0 pile = new Vec<String>();
60  0 try {
61  0 out = new FileWriter(fileNameToSave);
62    } catch (IOException e) {
63  0 System.err.println("Problem when created file.");
64    }
65    }
66   
 
67  0 toggle public final void assuming(final int p) {
68  0 final Integer absP = Math.abs(p);
69  0 String newName;
70   
71  0 if (currentNodeName == null) {
72  0 newName = absP.toString();
73  0 pile.push(newName);
74  0 saveLine(lineTab("\"" + newName + "\"" + "[label=\"" + newName
75    + "\", shape=circle, color=blue, style=filled]"));
76    } else {
77  0 newName = currentNodeName;
78  0 pile.push(newName);
79  0 saveLine(lineTab("\"" + newName + "\"" + "[label=\""
80    + absP.toString()
81    + "\", shape=circle, color=blue, style=filled]"));
82    }
83  0 currentNodeName = newName;
84    }
85   
 
86  0 toggle public final void propagating(final int p) {
87  0 String newName = currentNodeName + "." + p;
88   
89  0 if (currentNodeName == null) {
90  0 saveLine(lineTab("\"null\" [label=\"\", shape=point]"));
91    }
92  0 final String couleur = estOrange ? "orange" : "green";
93   
94  0 saveLine(lineTab("\"" + newName + "\"" + "[label=\""
95    + Integer.toString(p) + "\",shape=point, color=black]"));
96  0 saveLine(lineTab("\"" + currentNodeName + "\"" + " -- " + "\""
97    + newName + "\"" + "[label=" + "\" " + Integer.toString(p)
98    + "\", fontcolor =" + couleur + ", color = " + couleur
99    + ", style = bold]"));
100  0 currentNodeName = newName;
101  0 estOrange = false;
102    }
103   
 
104  0 toggle public final void backtracking(final int p) {
105  0 final String temp = pile.last();
106  0 pile.pop();
107  0 saveLine("\"" + temp + "\"" + "--" + "\"" + currentNodeName + "\""
108    + "[label=\"\", color=red, style=dotted]");
109  0 currentNodeName = temp;
110    }
111   
 
112  0 toggle public final void adding(final int p) {
113  0 estOrange = true;
114    }
115   
 
116  0 toggle public final void learn(final Constr clause) {
117    }
118   
 
119  0 toggle public final void delete(final int[] clause) {
120    }
121   
 
122  0 toggle public final void conflictFound() {
123  0 saveLine(lineTab("\"" + currentNodeName
124    + "\" [label=\"\", shape=box, color=\"red\", style=filled]"));
125    }
126   
 
127  0 toggle public final void solutionFound() {
128  0 saveLine(lineTab("\"" + currentNodeName
129    + "\" [label=\"\", shape=box, color=\"green\", style=filled]"));
130    }
131   
 
132  0 toggle public final void beginLoop() {
133    }
134   
 
135  0 toggle public final void start() {
136  0 saveLine("graph G {");
137    }
138   
 
139  0 toggle public final void end(Lbool result) {
140  0 saveLine("}");
141    }
142   
 
143  0 toggle private final String lineTab(final String line) {
144  0 return "\t" + line;
145    }
146   
 
147  0 toggle private final void saveLine(final String line) {
148  0 try {
149  0 out.write(line + '\n');
150  0 if ("}".equals(line)) {
151  0 out.close();
152    }
153    } catch (IOException e) {
154  0 e.printStackTrace();
155    }
156    }
157    }