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
39
40 private static final long serialVersionUID = 1L;
41
42 private final IVisualizationTool visuTool;
43 private final IVisualizationTool cleanVisuTool;
44 private final IVisualizationTool restartVisuTool;
45
46 private long begin, end;
47 private int counter;
48 private long index;
49
50 private int nVar;
51
52 private double maxY;
53
54 public SpeedTracing(IVisualizationTool visuTool,
55 IVisualizationTool cleanVisuTool, IVisualizationTool restartVisuTool) {
56 this.visuTool = visuTool;
57 this.cleanVisuTool = cleanVisuTool;
58 this.restartVisuTool = restartVisuTool;
59
60 visuTool.init();
61 cleanVisuTool.init();
62 restartVisuTool.init();
63
64 this.begin = System.currentTimeMillis();
65 this.counter = 0;
66 this.index = 0;
67 this.maxY = 0;
68 }
69
70 @Override
71 public void propagating(int p, IConstr reason) {
72 this.end = System.currentTimeMillis();
73 double y;
74 if (this.end - this.begin >= 2000) {
75 long tmp = this.end - this.begin;
76 this.index += tmp;
77 y = this.counter / tmp * 1000;
78 if (y > this.maxY) {
79 this.maxY = y;
80 }
81 this.visuTool.addPoint(this.index / 1000.0, y);
82 this.cleanVisuTool.addPoint(this.index / 1000.0, 0);
83 this.restartVisuTool.addPoint(this.index / 1000.0, 0);
84 this.begin = System.currentTimeMillis();
85 this.counter = 0;
86 }
87 this.counter++;
88 }
89
90 @Override
91 public void end(Lbool result) {
92 this.visuTool.end();
93 this.cleanVisuTool.end();
94 this.restartVisuTool.end();
95 }
96
97 @Override
98 public void cleaning() {
99 this.end = System.currentTimeMillis();
100 long indexClean = this.index + this.end - this.begin;
101 this.visuTool.addPoint(indexClean / 1000.0, this.counter
102 / (this.end - this.begin) * 1000);
103 this.cleanVisuTool.addPoint(indexClean / 1000.0, this.maxY);
104 this.restartVisuTool.addInvisiblePoint(indexClean, 0);
105
106 }
107
108 @Override
109 public void restarting() {
110 this.end = System.currentTimeMillis();
111 long indexRestart = this.index + this.end - this.begin;
112 double y = this.counter / (this.end - this.begin) * 1000;
113 this.visuTool.addPoint(indexRestart / 1000.0, y);
114 if (y > this.maxY) {
115 this.maxY = y;
116 }
117 this.restartVisuTool.addPoint(indexRestart / 1000.0, this.maxY);
118 this.cleanVisuTool.addInvisiblePoint(indexRestart, 0);
119 }
120
121 @Override
122 public void start() {
123 this.visuTool.init();
124 this.cleanVisuTool.init();
125 this.restartVisuTool.init();
126
127 this.begin = System.currentTimeMillis();
128 this.counter = 0;
129 this.index = 0;
130 }
131
132 @Override
133 public void init(ISolverService solverService) {
134 this.nVar = solverService.nVars();
135 }
136 }