1 package org.sat4j.sat.visu;
2
3 import info.monitorenter.gui.chart.Chart2D;
4 import info.monitorenter.gui.chart.IAxis.AxisTitle;
5 import info.monitorenter.gui.chart.ITrace2D;
6 import info.monitorenter.gui.chart.rangepolicies.RangePolicyHighestValues;
7 import info.monitorenter.gui.chart.traces.Trace2DLtd;
8 import info.monitorenter.gui.chart.traces.Trace2DSimple;
9 import info.monitorenter.gui.chart.traces.painters.TracePainterVerticalBar;
10
11 import java.awt.Color;
12 import java.awt.Container;
13 import java.awt.GridLayout;
14 import java.awt.event.WindowAdapter;
15 import java.awt.event.WindowEvent;
16
17 import javax.swing.JFrame;
18
19 public class JChartBasedSolverVisualisation implements SolverVisualisation {
20
21 private JFrame visuFrame;
22
23 private int nVar;
24
25 private Chart2D variablesEvaluationChart;
26 private Chart2D clausesEvaluationChart;
27 private Chart2D learnedClausesSizeChart;
28 private Chart2D decisionLevelWhenConflictChart;
29 private Chart2D trailLevelWhenConflictChart;
30 private Chart2D positiveDecisionVariableChart;
31 private Chart2D negativeDecisionVariableChart;
32 private Chart2D propagationPerSecondChart;
33
34
35 private MyChartPanel variablesEvaluationPanel;
36 private MyChartPanel clausesEvaluationPanel;
37 private MyChartPanel learnedClausesSizePanel;
38 private MyChartPanel decisionLevelWhenConflictPanel;
39 private MyChartPanel trailLevelWhenConflictPanel;
40 private MyChartPanel positiveDecisionVariablePanel;
41 private MyChartPanel negativeDecisionVariablePanel;
42 private MyChartPanel propagationPerSecondPanel;
43
44 private ITrace2D positiveDecisionTrace;
45 private ITrace2D negativeDecisionTrace;
46 private ITrace2D restartPosDecisionTrace;
47 private ITrace2D restartNegDecisionTrace;
48 private ITrace2D cleanPosDecisionTrace;
49 private ITrace2D cleanNegDecisionTrace;
50
51 private ITrace2D learnedClausesSizeTrace;
52 private ITrace2D learnedClausesSizeRestartTrace;
53 private ITrace2D learnedClausesSizeCleanTrace;
54
55 private ITrace2D conflictDepthTrace;
56 private ITrace2D conflictDepthRestartTrace;
57 private ITrace2D conflictDepthCleanTrace;
58
59 private ITrace2D clausesEvaluationTrace;
60
61 private ITrace2D conflictLevelTrace;
62 private ITrace2D conflictLevelRestartTrace;
63 private ITrace2D conflictLevelCleanTrace;
64
65 private ITrace2D heuristicsTrace;
66
67 private ITrace2D speedTrace;
68 private ITrace2D speedCleanTrace;
69 private ITrace2D speedRestartTrace;
70
71 private VisuPreferences pref;
72
73 public JChartBasedSolverVisualisation(VisuPreferences pref) {
74 this(pref, true);
75 }
76
77 public JChartBasedSolverVisualisation(VisuPreferences pref,
78 boolean isVisible) {
79
80 this.pref = pref;
81
82 init();
83
84 }
85
86 public void init() {
87 this.visuFrame = new JFrame("Visualisation");
88
89 Container c = this.visuFrame.getContentPane();
90
91 int nbGraphs = this.pref.getNumberOfDisplayedGraphs();
92 int[] nbLinesTab = new int[] { 1, 2, 3, 2 };
93
94 int nbLines = 3;
95 if (nbGraphs < 5) {
96 nbLines = nbLinesTab[nbGraphs - 1];
97 }
98
99 int nbCols = (nbGraphs - 1) / 3 + 1;
100
101 c.setLayout(new GridLayout(nbLines, nbCols, 5, 5));
102
103 initCharts();
104
105 addChartsToFrame();
106
107 initTraces();
108
109 this.visuFrame.setBackground(this.pref.getBackgroundColor());
110 this.visuFrame.setForeground(this.pref.getBorderColor());
111
112 this.visuFrame.setSize(800, 400);
113
114
115 this.visuFrame.addWindowListener(new WindowAdapter() {
116 @Override
117 public void windowClosing(WindowEvent e) {
118
119 }
120 });
121
122
123 }
124
125 public void initCharts() {
126 this.variablesEvaluationChart = new Chart2D();
127 this.clausesEvaluationChart = new Chart2D();
128 this.learnedClausesSizeChart = new Chart2D();
129 this.decisionLevelWhenConflictChart = new Chart2D();
130 this.trailLevelWhenConflictChart = new Chart2D();
131 this.positiveDecisionVariableChart = new Chart2D();
132 this.negativeDecisionVariableChart = new Chart2D();
133 this.propagationPerSecondChart = new Chart2D();
134
135
136 AxisTitle voidTitle = new AxisTitle("");
137 this.variablesEvaluationChart.getAxisX().setAxisTitle(voidTitle);
138 this.variablesEvaluationChart.getAxisY().setAxisTitle(voidTitle);
139 this.clausesEvaluationChart.getAxisX().setAxisTitle(voidTitle);
140 this.clausesEvaluationChart.getAxisY().setAxisTitle(voidTitle);
141 this.learnedClausesSizeChart.getAxisX().setAxisTitle(voidTitle);
142 this.learnedClausesSizeChart.getAxisY().setAxisTitle(voidTitle);
143 this.decisionLevelWhenConflictChart.getAxisX().setAxisTitle(voidTitle);
144 this.decisionLevelWhenConflictChart.getAxisY().setAxisTitle(voidTitle);
145 this.trailLevelWhenConflictChart.getAxisX().setAxisTitle(voidTitle);
146 this.trailLevelWhenConflictChart.getAxisY().setAxisTitle(voidTitle);
147 this.positiveDecisionVariableChart.getAxisX().setAxisTitle(voidTitle);
148 this.positiveDecisionVariableChart.getAxisY().setAxisTitle(voidTitle);
149 this.negativeDecisionVariableChart.getAxisX().setAxisTitle(voidTitle);
150 this.negativeDecisionVariableChart.getAxisY().setAxisTitle(voidTitle);
151 this.propagationPerSecondChart.getAxisX().setAxisTitle(voidTitle);
152 this.propagationPerSecondChart.getAxisY().setAxisTitle(voidTitle);
153
154
155 }
156
157 public void addChartsToFrame() {
158 this.variablesEvaluationPanel = new MyChartPanel(
159 this.variablesEvaluationChart, "Variables evaluation",
160 this.pref.getBackgroundColor(), this.pref.getBorderColor());
161 this.clausesEvaluationPanel = new MyChartPanel(
162 this.clausesEvaluationChart, "Clauses evaluation",
163 this.pref.getBackgroundColor(), this.pref.getBorderColor());
164 this.learnedClausesSizePanel = new MyChartPanel(
165 this.learnedClausesSizeChart, "Size of learned clauses",
166 this.pref.getBackgroundColor(), this.pref.getBorderColor());
167 this.decisionLevelWhenConflictPanel = new MyChartPanel(
168 this.decisionLevelWhenConflictChart,
169 "Decision level when conflict", this.pref.getBackgroundColor(),
170 this.pref.getBorderColor());
171 this.trailLevelWhenConflictPanel = new MyChartPanel(
172 this.trailLevelWhenConflictChart, "Trail level when conflict",
173 this.pref.getBackgroundColor(), this.pref.getBorderColor());
174 this.positiveDecisionVariablePanel = new MyChartPanel(
175 this.positiveDecisionVariableChart, "Positive decision phases",
176 this.pref.getBackgroundColor(), this.pref.getBorderColor());
177 this.negativeDecisionVariablePanel = new MyChartPanel(
178 this.negativeDecisionVariableChart, "Negative decision phases",
179 this.pref.getBackgroundColor(), this.pref.getBorderColor());
180 this.propagationPerSecondPanel = new MyChartPanel(
181 this.propagationPerSecondChart,
182 "Number of propagations per second",
183 this.pref.getBackgroundColor(), this.pref.getBorderColor());
184
185 if (this.pref.isDisplayClausesSize()) {
186 this.visuFrame.add(this.learnedClausesSizePanel);
187 }
188 if (this.pref.isDisplayClausesEvaluation()) {
189 this.visuFrame.add(this.clausesEvaluationPanel);
190 }
191 if (this.pref.isDisplayConflictsTrail()) {
192 this.visuFrame.add(this.trailLevelWhenConflictPanel);
193 }
194 if (this.pref.isDisplayDecisionIndexes()) {
195 this.visuFrame.add(this.negativeDecisionVariablePanel);
196 }
197 if (this.pref.isDisplayVariablesEvaluation()) {
198 this.visuFrame.add(this.variablesEvaluationPanel);
199 }
200 if (this.pref.isDisplayConflictsDecision()) {
201 this.visuFrame.add(this.decisionLevelWhenConflictPanel);
202 }
203 if (this.pref.isDisplayDecisionIndexes()) {
204 this.visuFrame.add(this.positiveDecisionVariablePanel);
205 }
206 if (this.pref.isDisplaySpeed()) {
207 this.visuFrame.add(this.propagationPerSecondPanel);
208
209 }
210 }
211
212 public void initTraces() {
213
214 this.positiveDecisionTrace = new Trace2DSimple("Positive decision");
215 this.positiveDecisionTrace.setTracePainter(new TracePainterPlus());
216 this.positiveDecisionTrace.setColor(new Color(0f, 0.78f, 0.09f));
217
218 this.negativeDecisionTrace = new Trace2DSimple("Negative decision");
219 this.negativeDecisionTrace.setTracePainter(new TracePainterPlus());
220 this.negativeDecisionTrace.setColor(Color.RED);
221
222 this.restartPosDecisionTrace = new Trace2DSimple("Restart");
223 this.restartPosDecisionTrace
224 .setTracePainter(new TracePainterVerticalBar(2,
225 this.positiveDecisionVariableChart));
226 this.restartPosDecisionTrace.setColor(Color.LIGHT_GRAY);
227
228 this.restartNegDecisionTrace = new Trace2DSimple("Restart");
229 this.restartNegDecisionTrace
230 .setTracePainter(new TracePainterVerticalBar(2,
231 this.negativeDecisionVariableChart));
232 this.restartNegDecisionTrace.setColor(Color.LIGHT_GRAY);
233
234 this.cleanPosDecisionTrace = new Trace2DSimple("Clean");
235 this.cleanPosDecisionTrace.setTracePainter(new TracePainterVerticalBar(
236 2, this.positiveDecisionVariableChart));
237 this.cleanPosDecisionTrace.setColor(Color.ORANGE);
238
239 this.cleanNegDecisionTrace = new Trace2DSimple("Clean");
240 this.cleanNegDecisionTrace.setTracePainter(new TracePainterVerticalBar(
241 2, this.negativeDecisionVariableChart));
242 this.cleanNegDecisionTrace.setColor(Color.ORANGE);
243
244 this.positiveDecisionVariableChart.addTrace(this.positiveDecisionTrace);
245 this.positiveDecisionVariableChart
246 .addTrace(this.restartPosDecisionTrace);
247 this.positiveDecisionVariableChart.addTrace(this.cleanPosDecisionTrace);
248
249 this.positiveDecisionTrace.setZIndex(ITrace2D.ZINDEX_MAX);
250
251
252
253
254
255 this.positiveDecisionVariableChart.getAxisX().setRangePolicy(
256 new RangePolicyHighestValues(8000));
257
258
259
260 this.negativeDecisionVariableChart
261 .addTrace(this.restartNegDecisionTrace);
262 this.negativeDecisionVariableChart.addTrace(this.cleanNegDecisionTrace);
263 this.negativeDecisionVariableChart.addTrace(this.negativeDecisionTrace);
264 this.negativeDecisionTrace.setZIndex(ITrace2D.ZINDEX_MAX);
265
266 this.negativeDecisionVariableChart.getAxisX().setRangePolicy(
267 this.positiveDecisionVariableChart.getAxisX().getRangePolicy());
268
269
270
271
272 this.conflictDepthTrace = new Trace2DLtd(15000, "Trail level");
273 this.conflictDepthTrace.setTracePainter(new TracePainterPlus());
274 this.conflictDepthTrace.setColor(Color.MAGENTA);
275 this.trailLevelWhenConflictChart
276 .setName("Trail level when the conflict occurs");
277 this.trailLevelWhenConflictChart.addTrace(this.conflictDepthTrace);
278 this.conflictDepthTrace.setZIndex(ITrace2D.ZINDEX_MAX);
279
280 this.conflictDepthRestartTrace = new Trace2DSimple("Restart");
281 this.conflictDepthRestartTrace
282 .setTracePainter(new TracePainterVerticalBar(2,
283 this.trailLevelWhenConflictChart));
284 this.conflictDepthRestartTrace.setColor(Color.LIGHT_GRAY);
285 this.trailLevelWhenConflictChart
286 .addTrace(this.conflictDepthRestartTrace);
287
288 this.conflictDepthCleanTrace = new Trace2DSimple("Clean");
289 this.conflictDepthCleanTrace
290 .setTracePainter(new TracePainterVerticalBar(2,
291 this.trailLevelWhenConflictChart));
292 this.conflictDepthCleanTrace.setColor(Color.ORANGE);
293 this.trailLevelWhenConflictChart.addTrace(this.conflictDepthCleanTrace);
294 this.trailLevelWhenConflictChart.getAxisX().setRangePolicy(
295 new RangePolicyHighestValues(2000));
296
297 this.conflictLevelTrace = new Trace2DSimple("Decision level");
298 this.conflictLevelTrace.setTracePainter(new TracePainterPlus());
299 this.conflictLevelTrace.setColor(Color.MAGENTA);
300 this.decisionLevelWhenConflictChart
301 .setName("Decision level chen the conflict occurs");
302 this.decisionLevelWhenConflictChart.addTrace(this.conflictLevelTrace);
303 this.conflictLevelTrace.setZIndex(ITrace2D.ZINDEX_MAX);
304
305 this.conflictLevelRestartTrace = new Trace2DSimple("Restart");
306 this.conflictLevelRestartTrace
307 .setTracePainter(new TracePainterVerticalBar(2,
308 this.decisionLevelWhenConflictChart));
309 this.conflictLevelRestartTrace.setColor(Color.LIGHT_GRAY);
310 this.decisionLevelWhenConflictChart
311 .addTrace(this.conflictLevelRestartTrace);
312
313 this.conflictLevelCleanTrace = new Trace2DSimple("Clean");
314 this.conflictLevelCleanTrace
315 .setTracePainter(new TracePainterVerticalBar(2,
316 this.decisionLevelWhenConflictChart));
317 this.conflictLevelCleanTrace.setColor(Color.ORANGE);
318 this.decisionLevelWhenConflictChart
319 .addTrace(this.conflictLevelCleanTrace);
320
321 this.decisionLevelWhenConflictChart.getAxisX().setRangePolicy(
322 new RangePolicyHighestValues(2000));
323
324 this.learnedClausesSizeTrace = new Trace2DSimple("Size");
325 this.learnedClausesSizeTrace.setTracePainter(new TracePainterPlus());
326 this.learnedClausesSizeTrace.setColor(Color.BLUE);
327 this.learnedClausesSizeChart.setName("Learned clauses size");
328 this.learnedClausesSizeChart.addTrace(this.learnedClausesSizeTrace);
329 this.learnedClausesSizeTrace.setZIndex(ITrace2D.ZINDEX_MAX);
330 this.learnedClausesSizeChart.getAxisX().setRangePolicy(
331 new RangePolicyHighestValues(2000));
332
333 this.learnedClausesSizeRestartTrace = new Trace2DSimple("Restart");
334 this.learnedClausesSizeRestartTrace
335 .setTracePainter(new TracePainterVerticalBar(2,
336 this.learnedClausesSizeChart));
337 this.learnedClausesSizeRestartTrace.setColor(Color.LIGHT_GRAY);
338 this.learnedClausesSizeChart
339 .addTrace(this.learnedClausesSizeRestartTrace);
340
341 this.learnedClausesSizeCleanTrace = new Trace2DSimple("Clean");
342 this.learnedClausesSizeCleanTrace
343 .setTracePainter(new TracePainterVerticalBar(2,
344 this.learnedClausesSizeChart));
345 this.learnedClausesSizeCleanTrace.setColor(Color.ORANGE);
346 this.learnedClausesSizeChart
347 .addTrace(this.learnedClausesSizeCleanTrace);
348
349 this.clausesEvaluationTrace = new Trace2DSimple("Evaluation");
350 this.clausesEvaluationTrace.setTracePainter(new TracePainterPlus());
351 this.clausesEvaluationTrace.setColor(Color.BLUE);
352 this.clausesEvaluationTrace.setName("Clauses evaluation");
353 this.clausesEvaluationChart.addTrace(this.clausesEvaluationTrace);
354
355 this.heuristicsTrace = new Trace2DSimple("Evaluation");
356 this.heuristicsTrace.setTracePainter(new TracePainterPlus());
357 this.heuristicsTrace.setColor(Color.ORANGE);
358 this.variablesEvaluationChart.setName("Variables evaluation");
359 this.variablesEvaluationChart.addTrace(this.heuristicsTrace);
360
361 this.speedTrace = new Trace2DSimple("Speed");
362 this.speedTrace.setColor(new Color(0.02f, .78f, .76f));
363 this.speedCleanTrace = new Trace2DSimple("Clean");
364 this.speedCleanTrace.setColor(Color.ORANGE);
365 this.speedCleanTrace.setTracePainter(new TracePainterVerticalBar(2,
366 this.propagationPerSecondChart));
367 this.speedRestartTrace = new Trace2DSimple("Restart");
368 this.speedRestartTrace.setColor(Color.LIGHT_GRAY);
369 this.speedRestartTrace.setTracePainter(new TracePainterVerticalBar(2,
370 this.propagationPerSecondChart));
371
372 this.propagationPerSecondChart.addTrace(this.speedCleanTrace);
373 this.propagationPerSecondChart.addTrace(this.speedRestartTrace);
374 this.propagationPerSecondChart.addTrace(this.speedTrace);
375 this.propagationPerSecondChart.getAxisX().setRangePolicy(
376 new RangePolicyHighestValues(30));
377
378 this.speedTrace.setZIndex(ITrace2D.ZINDEX_MAX);
379
380 }
381
382 public void setVisible(boolean b) {
383 this.visuFrame.setVisible(b);
384 }
385
386 public ITrace2D getPositiveDecisionTrace() {
387 return this.positiveDecisionTrace;
388 }
389
390 public void setPositiveDecisionTrace(ITrace2D positiveDecisionTrace) {
391 this.positiveDecisionTrace = positiveDecisionTrace;
392 }
393
394 public ITrace2D getNegativeDecisionTrace() {
395 return this.negativeDecisionTrace;
396 }
397
398 public void setNegativeDecisionTrace(ITrace2D negativeDecisionTrace) {
399 this.negativeDecisionTrace = negativeDecisionTrace;
400 }
401
402 public ITrace2D getRestartNegDecisionTrace() {
403 return this.restartNegDecisionTrace;
404 }
405
406 public void setRestartNegDecisionTrace(ITrace2D restartNegDecisionTrace) {
407 this.restartNegDecisionTrace = restartNegDecisionTrace;
408 }
409
410 public ITrace2D getRestartPosDecisionTrace() {
411 return this.restartPosDecisionTrace;
412 }
413
414 public void setRestartPosDecisionTrace(ITrace2D restartPosDecisionTrace) {
415 this.restartPosDecisionTrace = restartPosDecisionTrace;
416 }
417
418 public ITrace2D getConflictDepthTrace() {
419 return this.conflictDepthTrace;
420 }
421
422 public void setConflictDepthTrace(ITrace2D conflictDepthTrace) {
423 this.conflictDepthTrace = conflictDepthTrace;
424 }
425
426 public ITrace2D getLearnedClausesSizeTrace() {
427 return this.learnedClausesSizeTrace;
428 }
429
430 public void setLearnedClausesSizeTrace(ITrace2D learnedClausesSizeTrace) {
431 this.learnedClausesSizeTrace = learnedClausesSizeTrace;
432 }
433
434 public ITrace2D getClausesEvaluationTrace() {
435 return this.clausesEvaluationTrace;
436 }
437
438 public void setClausesEvaluationTrace(ITrace2D clausesEvaluationTrace) {
439 this.clausesEvaluationTrace = clausesEvaluationTrace;
440 }
441
442 public ITrace2D getConflictLevelTrace() {
443 return this.conflictLevelTrace;
444 }
445
446 public void setConflictLevelTrace(ITrace2D conflictLevelTrace) {
447 this.conflictLevelTrace = conflictLevelTrace;
448 }
449
450 public ITrace2D getConflictLevelRestartTrace() {
451 return this.conflictLevelRestartTrace;
452 }
453
454 public void setConflictLevelRestartTrace(ITrace2D conflictLevelRestartTrace) {
455 this.conflictLevelRestartTrace = conflictLevelRestartTrace;
456 }
457
458 public ITrace2D getHeuristicsTrace() {
459 return this.heuristicsTrace;
460 }
461
462 public void setHeuristicsTrace(ITrace2D heuristicsTrace) {
463 this.heuristicsTrace = heuristicsTrace;
464 }
465
466 public ITrace2D getSpeedTrace() {
467 return this.speedTrace;
468 }
469
470 public void setSpeedTrace(ITrace2D speedTrace) {
471 this.speedTrace = speedTrace;
472 }
473
474 public ITrace2D getSpeedCleanTrace() {
475 return this.speedCleanTrace;
476 }
477
478 public void setSpeedCleanTrace(ITrace2D speedCleanTrace) {
479 this.speedCleanTrace = speedCleanTrace;
480 }
481
482 public ITrace2D getSpeedRestartTrace() {
483 return this.speedRestartTrace;
484 }
485
486 public void setSpeedRestartTrace(ITrace2D speedRestartTrace) {
487 this.speedRestartTrace = speedRestartTrace;
488 }
489
490 public ITrace2D getConflictDepthRestartTrace() {
491 return this.conflictDepthRestartTrace;
492 }
493
494 public void setConflictDepthRestartTrace(ITrace2D conflictDepthRestartTrace) {
495 this.conflictDepthRestartTrace = conflictDepthRestartTrace;
496 }
497
498 public ITrace2D getLearnedClausesSizeRestartTrace() {
499 return this.learnedClausesSizeRestartTrace;
500 }
501
502 public void setLearnedClausesSizeRestartTrace(
503 ITrace2D learnedClausesSizeRestartTrace) {
504 this.learnedClausesSizeRestartTrace = learnedClausesSizeRestartTrace;
505 }
506
507 public ITrace2D getLearnedClausesSizeCleanTrace() {
508 return this.learnedClausesSizeCleanTrace;
509 }
510
511 public void setLearnedClausesSizeCleanTrace(
512 ITrace2D learnedClausesSizeCleanTrace) {
513 this.learnedClausesSizeCleanTrace = learnedClausesSizeCleanTrace;
514 }
515
516 public ITrace2D getConflictLevelCleanTrace() {
517 return this.conflictLevelCleanTrace;
518 }
519
520 public void setConflictLevelCleanTrace(ITrace2D conflictLevelCleanTrace) {
521 this.conflictLevelCleanTrace = conflictLevelCleanTrace;
522 }
523
524 public ITrace2D getConflictDepthCleanTrace() {
525 return this.conflictDepthCleanTrace;
526 }
527
528 public void setConflictDepthCleanTrace(ITrace2D conflictDepthCleanTrace) {
529 this.conflictDepthCleanTrace = conflictDepthCleanTrace;
530 }
531
532 public ITrace2D getCleanPosDecisionTrace() {
533 return this.cleanPosDecisionTrace;
534 }
535
536 public void setCleanPosDecisionTrace(ITrace2D cleanPosDecisionTrace) {
537 this.cleanPosDecisionTrace = cleanPosDecisionTrace;
538 }
539
540 public ITrace2D getCleanNegDecisionTrace() {
541 return this.cleanNegDecisionTrace;
542 }
543
544 public void setCleanNegDecisionTrace(ITrace2D cleanNegDecisionTrace) {
545 this.cleanNegDecisionTrace = cleanNegDecisionTrace;
546 }
547
548 public int getnVar() {
549 return this.nVar;
550 }
551
552 public void setnVar(int nVar) {
553 this.nVar = nVar;
554 }
555
556 public void start() {
557
558
559 this.visuFrame.setVisible(true);
560 }
561
562 public void end() {
563 this.visuFrame.setVisible(false);
564 }
565
566 }