1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package org.sat4j.tools;
31
32 import org.sat4j.specs.IConstr;
33 import org.sat4j.specs.ISolverService;
34 import org.sat4j.specs.Lbool;
35
36 public class SpeedTracing extends SearchListenerAdapter<ISolverService> {
37
38 private static final long serialVersionUID = 1L;
39
40 private final IVisualizationTool visuTool;
41 private final IVisualizationTool cleanVisuTool;
42 private final IVisualizationTool restartVisuTool;
43
44 private long begin, end;
45 private int counter;
46 private long index;
47
48 private double maxY;
49
50 public SpeedTracing(IVisualizationTool visuTool,
51 IVisualizationTool cleanVisuTool, IVisualizationTool restartVisuTool) {
52 this.visuTool = visuTool;
53 this.cleanVisuTool = cleanVisuTool;
54 this.restartVisuTool = restartVisuTool;
55
56 visuTool.init();
57 cleanVisuTool.init();
58 restartVisuTool.init();
59
60 this.begin = System.currentTimeMillis();
61 this.counter = 0;
62 this.index = 0;
63 this.maxY = 0;
64 }
65
66 @Override
67 public void propagating(int p, IConstr reason) {
68 this.end = System.currentTimeMillis();
69 double y;
70 if (this.end - this.begin >= 2000) {
71 long tmp = this.end - this.begin;
72 this.index += tmp;
73 y = this.counter / tmp * 1000;
74 if (y > this.maxY) {
75 this.maxY = y;
76 }
77 this.visuTool.addPoint(this.index / 1000.0, y);
78 this.cleanVisuTool.addPoint(this.index / 1000.0, 0);
79 this.restartVisuTool.addPoint(this.index / 1000.0, 0);
80 this.begin = System.currentTimeMillis();
81 this.counter = 0;
82 }
83 this.counter++;
84 }
85
86 @Override
87 public void end(Lbool result) {
88 this.visuTool.end();
89 this.cleanVisuTool.end();
90 this.restartVisuTool.end();
91 }
92
93 @Override
94 public void cleaning() {
95 this.end = System.currentTimeMillis();
96 long indexClean = this.index + this.end - this.begin;
97 this.visuTool.addPoint(indexClean / 1000.0, this.counter
98 / (this.end - this.begin) * 1000);
99 this.cleanVisuTool.addPoint(indexClean / 1000.0, this.maxY);
100 this.restartVisuTool.addInvisiblePoint(indexClean, 0);
101 }
102
103 @Override
104 public void restarting() {
105 this.end = System.currentTimeMillis();
106 long indexRestart = this.index + this.end - this.begin;
107 double y = this.counter / (this.end - this.begin) * 1000;
108 this.visuTool.addPoint(indexRestart / 1000.0, y);
109 if (y > this.maxY) {
110 this.maxY = y;
111 }
112 this.restartVisuTool.addPoint(indexRestart / 1000.0, this.maxY);
113 this.cleanVisuTool.addInvisiblePoint(indexRestart, 0);
114 }
115
116 @Override
117 public void start() {
118 this.visuTool.init();
119 this.cleanVisuTool.init();
120 this.restartVisuTool.init();
121
122 this.begin = System.currentTimeMillis();
123 this.counter = 0;
124 this.index = 0;
125 }
126 }