Fast SAT Solver (C++, GAlib)
File detail
Source code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Fast SAT Solver: SatSolverObserver.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.4 -->
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main Page</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li class="current"><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<h1>SatSolverObserver.cpp</h1><a href="SatSolverObserver_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * Copyright (C) 2008 Kamil Dudka <xdudka00@stud.fit.vutbr.cz></span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> * This file is part of fss (Fast SAT Solver).</span>
<a name="l00005"></a>00005 <span class="comment"> *</span>
<a name="l00006"></a>00006 <span class="comment"> * fss is free software: you can redistribute it and/or modify</span>
<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation, either version 3 of the License, or</span>
<a name="l00009"></a>00009 <span class="comment"> * any later version.</span>
<a name="l00010"></a>00010 <span class="comment"> *</span>
<a name="l00011"></a>00011 <span class="comment"> * fss is distributed in the hope that it will be useful,</span>
<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
<a name="l00015"></a>00015 <span class="comment"> *</span>
<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
<a name="l00017"></a>00017 <span class="comment"> * along with fss. If not, see <http://www.gnu.org/licenses/>.</span>
<a name="l00018"></a>00018 <span class="comment"> */</span>
<a name="l00019"></a>00019
<a name="l00020"></a>00020 <span class="preprocessor">#include <iostream></span>
<a name="l00021"></a>00021 <span class="preprocessor">#include <iomanip></span>
<a name="l00022"></a>00022 <span class="preprocessor">#include <ga/GAStatistics.h></span>
<a name="l00023"></a>00023 <span class="preprocessor">#include "<a class="code" href="fssIO_8h.html" title="I/O module.">fssIO.h</a>"</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include "<a class="code" href="SatSolver_8h.html" title="ISatItem, IObserver and AbstractSatSolver with its base classes.">SatSolver.h</a>"</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include "<a class="code" href="GaSatSolver_8h.html" title="GaSatSolver class using GAlib library to solve SAT problem.">GaSatSolver.h</a>"</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include "<a class="code" href="SatSolverObserver_8h.html" title="Set of useful observers attachable to AbstractSatSolver or its base classes.">SatSolverObserver.h</a>"</span>
<a name="l00027"></a>00027
<a name="l00028"></a>00028 <span class="keyword">namespace </span>FastSatSolver {
<a name="l00029"></a>00029
<a name="l00030"></a>00030 <span class="comment">// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</span>
<a name="l00031"></a>00031 <span class="comment">// SolutionsCountStop implementation</span>
<a name="l00032"></a><a class="code" href="structFastSatSolver_1_1SolutionsCountStop_1_1Private.html">00032</a> <span class="keyword">struct </span><a class="code" href="structFastSatSolver_1_1SolutionsCountStop_1_1Private.html">SolutionsCountStop::Private</a> {
<a name="l00033"></a><a class="code" href="structFastSatSolver_1_1SolutionsCountStop_1_1Private.html#6037497b3b68fb4ca97f9826788558f7">00033</a> <a class="code" href="classFastSatSolver_1_1AbstractSatSolver.html" title="SAT Solver base class.">AbstractSatSolver</a> *<a class="code" href="structFastSatSolver_1_1SolutionsCountStop_1_1Private.html#6037497b3b68fb4ca97f9826788558f7">solver</a>;
<a name="l00034"></a><a class="code" href="structFastSatSolver_1_1SolutionsCountStop_1_1Private.html#0bb4514de6d8afc32e651237e923cf02">00034</a> <span class="keywordtype">int</span> <a class="code" href="structFastSatSolver_1_1SolutionsCountStop_1_1Private.html#0bb4514de6d8afc32e651237e923cf02">minCountOfSolutions</a>;
<a name="l00035"></a>00035 };
<a name="l00036"></a><a class="code" href="classFastSatSolver_1_1SolutionsCountStop.html#22aa639cca1856e0b131b89fd0eea59f">00036</a> <a class="code" href="classFastSatSolver_1_1SolutionsCountStop.html#22aa639cca1856e0b131b89fd0eea59f">SolutionsCountStop::SolutionsCountStop</a>(<a class="code" href="classFastSatSolver_1_1AbstractSatSolver.html" title="SAT Solver base class.">AbstractSatSolver</a> *solver, <span class="keywordtype">int</span> minCountOfSolutions):
<a name="l00037"></a>00037 d(new <a class="code" href="structFastSatSolver_1_1SolutionsCountStop_1_1Private.html">Private</a>)
<a name="l00038"></a>00038 {
<a name="l00039"></a>00039 d-><a class="code" href="structFastSatSolver_1_1SolutionsCountStop_1_1Private.html#6037497b3b68fb4ca97f9826788558f7">solver</a> = solver;
<a name="l00040"></a>00040 d-><a class="code" href="structFastSatSolver_1_1SolutionsCountStop_1_1Private.html#0bb4514de6d8afc32e651237e923cf02">minCountOfSolutions</a> = minCountOfSolutions;
<a name="l00041"></a>00041 }
<a name="l00042"></a><a class="code" href="classFastSatSolver_1_1SolutionsCountStop.html#24c5bffeebdc7451f16a053c79302c0c">00042</a> SolutionsCountStop::~SolutionsCountStop() {
<a name="l00043"></a>00043 <span class="keyword">delete</span> d;
<a name="l00044"></a>00044 }
<a name="l00045"></a><a class="code" href="classFastSatSolver_1_1SolutionsCountStop.html#7ff19734eb024bd6f3e2ad95647b1b27">00045</a> <span class="keywordtype">void</span> <a class="code" href="classFastSatSolver_1_1SolutionsCountStop.html#7ff19734eb024bd6f3e2ad95647b1b27" title="Event notification, usually called by object implementing ISubject interface.">SolutionsCountStop::notify</a>() {
<a name="l00046"></a>00046 <span class="keyword">const</span> <span class="keywordtype">int</span> nSolutions= d-><a class="code" href="structFastSatSolver_1_1SolutionsCountStop_1_1Private.html#6037497b3b68fb4ca97f9826788558f7">solver</a>-><a class="code" href="classFastSatSolver_1_1AbstractSatSolver.html#f70c2c7822e8a563a1685c9b68d5cc4a" title="Returns current count solutions founded by solver.">getSolutionsCount</a>();
<a name="l00047"></a>00047 <span class="keywordflow">if</span> (nSolutions >= d-><a class="code" href="structFastSatSolver_1_1SolutionsCountStop_1_1Private.html#0bb4514de6d8afc32e651237e923cf02">minCountOfSolutions</a>)
<a name="l00048"></a>00048 d-><a class="code" href="structFastSatSolver_1_1SolutionsCountStop_1_1Private.html#6037497b3b68fb4ca97f9826788558f7">solver</a>-><a class="code" href="classFastSatSolver_1_1AbstractProcessWatched.html#8c528baf37154d347366083f0f816846" title="Stop currently executed process as soon as possible.">stop</a>();
<a name="l00049"></a>00049 }
<a name="l00050"></a>00050
<a name="l00051"></a>00051
<a name="l00052"></a>00052 <span class="comment">// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</span>
<a name="l00053"></a>00053 <span class="comment">// TimedStop implementation</span>
<a name="l00054"></a><a class="code" href="structFastSatSolver_1_1TimedStop_1_1Private.html">00054</a> <span class="keyword">struct </span><a class="code" href="structFastSatSolver_1_1TimedStop_1_1Private.html">TimedStop::Private</a> {
<a name="l00055"></a><a class="code" href="structFastSatSolver_1_1TimedStop_1_1Private.html#2f61d47177f68c26f7a844334d9b7584">00055</a> <a class="code" href="classFastSatSolver_1_1AbstractProcessWatched.html" title="Multi-step process with time-watch extension.">AbstractProcessWatched</a> *process;
<a name="l00056"></a><a class="code" href="structFastSatSolver_1_1TimedStop_1_1Private.html#15d8a2a8c2da682b1a60c8479a763081">00056</a> <span class="keywordtype">long</span> msec;
<a name="l00057"></a>00057 };
<a name="l00058"></a><a class="code" href="classFastSatSolver_1_1TimedStop.html#5d6de079315b84063c4deec32eef6013">00058</a> <a class="code" href="classFastSatSolver_1_1TimedStop.html#5d6de079315b84063c4deec32eef6013">TimedStop::TimedStop</a>(<a class="code" href="classFastSatSolver_1_1AbstractProcessWatched.html" title="Multi-step process with time-watch extension.">AbstractProcessWatched</a> *process, <span class="keywordtype">long</span> msec):
<a name="l00059"></a>00059 d(new <a class="code" href="structFastSatSolver_1_1TimedStop_1_1Private.html">Private</a>)
<a name="l00060"></a>00060 {
<a name="l00061"></a>00061 d-><a class="code" href="structFastSatSolver_1_1TimedStop_1_1Private.html#2f61d47177f68c26f7a844334d9b7584">process</a> = process;
<a name="l00062"></a>00062 d-><a class="code" href="structFastSatSolver_1_1TimedStop_1_1Private.html#15d8a2a8c2da682b1a60c8479a763081">msec</a> = msec;
<a name="l00063"></a>00063 }
<a name="l00064"></a><a class="code" href="classFastSatSolver_1_1TimedStop.html#ba52ba759531af1cb8143ab87b52ddb0">00064</a> <a class="code" href="classFastSatSolver_1_1TimedStop.html#ba52ba759531af1cb8143ab87b52ddb0">TimedStop::~TimedStop</a>() {
<a name="l00065"></a>00065 <span class="keyword">delete</span> d;
<a name="l00066"></a>00066 }
<a name="l00067"></a><a class="code" href="classFastSatSolver_1_1TimedStop.html#7ff19734eb024bd6f3e2ad95647b1b27">00067</a> <span class="keywordtype">void</span> <a class="code" href="classFastSatSolver_1_1TimedStop.html#7ff19734eb024bd6f3e2ad95647b1b27" title="Event notification, usually called by object implementing ISubject interface.">TimedStop::notify</a>() {
<a name="l00068"></a>00068 <span class="keywordtype">long</span> elapsed = d-><a class="code" href="structFastSatSolver_1_1TimedStop_1_1Private.html#2f61d47177f68c26f7a844334d9b7584">process</a>-><a class="code" href="classFastSatSolver_1_1AbstractProcessWatched.html#57e2ab43bf94f9adc686e788f8771681" title="Returns time elapsed by activity.">getTimeElapsed</a>();
<a name="l00069"></a>00069 <span class="keywordflow">if</span> (elapsed > d-><a class="code" href="structFastSatSolver_1_1TimedStop_1_1Private.html#15d8a2a8c2da682b1a60c8479a763081">msec</a>)
<a name="l00070"></a>00070 d-><a class="code" href="structFastSatSolver_1_1TimedStop_1_1Private.html#2f61d47177f68c26f7a844334d9b7584">process</a>-><a class="code" href="classFastSatSolver_1_1AbstractProcessWatched.html#8c528baf37154d347366083f0f816846" title="Stop currently executed process as soon as possible.">stop</a>();
<a name="l00071"></a>00071 }
<a name="l00072"></a>00072
<a name="l00073"></a>00073
<a name="l00074"></a>00074 <span class="comment">// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</span>
<a name="l00075"></a>00075 <span class="comment">// FitnessWatch implementation</span>
<a name="l00076"></a><a class="code" href="structFastSatSolver_1_1FitnessWatch_1_1Private.html">00076</a> <span class="keyword">struct </span><a class="code" href="structFastSatSolver_1_1FitnessWatch_1_1Private.html">FitnessWatch::Private</a> {
<a name="l00077"></a><a class="code" href="structFastSatSolver_1_1FitnessWatch_1_1Private.html#6037497b3b68fb4ca97f9826788558f7">00077</a> <a class="code" href="classFastSatSolver_1_1AbstractSatSolver.html" title="SAT Solver base class.">AbstractSatSolver</a> *solver;
<a name="l00078"></a><a class="code" href="structFastSatSolver_1_1FitnessWatch_1_1Private.html#eacb68b8c7e9ae9b97ab9c6ab41940cb">00078</a> std::ostream &stream;
<a name="l00079"></a><a class="code" href="structFastSatSolver_1_1FitnessWatch_1_1Private.html#c1dfa1e4f4ce3522765951e4bb1c8902">00079</a> <span class="keywordtype">float</span> maxFitness;
<a name="l00080"></a>00080
<a name="l00081"></a><a class="code" href="structFastSatSolver_1_1FitnessWatch_1_1Private.html#07986f4a8a47d0b9b7fb0caefcaa2fce">00081</a> <a class="code" href="structFastSatSolver_1_1FitnessWatch_1_1Private.html">Private</a>(std::ostream &streamTo): stream(streamTo) { }
<a name="l00082"></a>00082 };
<a name="l00083"></a><a class="code" href="classFastSatSolver_1_1FitnessWatch.html#0d1f0664e9719faf63fef42d76e92ffc">00083</a> <a class="code" href="classFastSatSolver_1_1FitnessWatch.html#0d1f0664e9719faf63fef42d76e92ffc">FitnessWatch::FitnessWatch</a>(<a class="code" href="classFastSatSolver_1_1AbstractSatSolver.html" title="SAT Solver base class.">AbstractSatSolver</a> *solver, std::ostream &streamTo):
<a name="l00084"></a>00084 d(new <a class="code" href="structFastSatSolver_1_1FitnessWatch_1_1Private.html">Private</a>(streamTo))
<a name="l00085"></a>00085 {
<a name="l00086"></a>00086 d-><a class="code" href="structFastSatSolver_1_1FitnessWatch_1_1Private.html#6037497b3b68fb4ca97f9826788558f7">solver</a> = solver;
<a name="l00087"></a>00087 d-><a class="code" href="structFastSatSolver_1_1FitnessWatch_1_1Private.html#c1dfa1e4f4ce3522765951e4bb1c8902">maxFitness</a> = 0.0;
<a name="l00088"></a>00088 }
<a name="l00089"></a><a class="code" href="classFastSatSolver_1_1FitnessWatch.html#692c368d6c771d6cd37e78ea66776748">00089</a> <a class="code" href="classFastSatSolver_1_1FitnessWatch.html#692c368d6c771d6cd37e78ea66776748">FitnessWatch::~FitnessWatch</a>() {
<a name="l00090"></a>00090 <span class="keyword">delete</span> d;
<a name="l00091"></a>00091 }
<a name="l00092"></a><a class="code" href="classFastSatSolver_1_1FitnessWatch.html#7ff19734eb024bd6f3e2ad95647b1b27">00092</a> <span class="keywordtype">void</span> <a class="code" href="classFastSatSolver_1_1FitnessWatch.html#7ff19734eb024bd6f3e2ad95647b1b27" title="Event notification, usually called by object implementing ISubject interface.">FitnessWatch::notify</a>() {
<a name="l00093"></a>00093 <a class="code" href="classFastSatSolver_1_1AbstractSatSolver.html" title="SAT Solver base class.">AbstractSatSolver</a> *solver= d-><a class="code" href="structFastSatSolver_1_1FitnessWatch_1_1Private.html#6037497b3b68fb4ca97f9826788558f7">solver</a>;
<a name="l00094"></a>00094 <span class="keywordtype">float</span> maxFitness = solver-><a class="code" href="classFastSatSolver_1_1AbstractSatSolver.html#5f493f0ddbb31c2e3fa53153b67501e6" title="Returns the Best fitness founded by solver.">maxFitness</a>();
<a name="l00095"></a>00095 <span class="keywordflow">if</span> (maxFitness <= d->maxFitness)
<a name="l00096"></a>00096 <span class="comment">// Fitness not changed</span>
<a name="l00097"></a>00097 <span class="keywordflow">return</span>;
<a name="l00098"></a>00098
<a name="l00099"></a>00099 <span class="keywordtype">int</span> generation = 0;
<a name="l00100"></a>00100 <a class="code" href="classFastSatSolver_1_1GaSatSolver.html" title="Solver using GAlib library to solve SAT problem.">GaSatSolver</a> *gaSolver= <span class="keyword">dynamic_cast<</span><a class="code" href="classFastSatSolver_1_1GaSatSolver.html" title="Solver using GAlib library to solve SAT problem.">GaSatSolver</a> *<span class="keyword">></span>(solver);
<a name="l00101"></a>00101 <span class="keywordflow">if</span> (gaSolver) {
<a name="l00102"></a>00102 GAStatistics stats= gaSolver-><a class="code" href="classFastSatSolver_1_1GaSatSolver.html#a7b4044638ce63985c719e6f456a8ea5" title="Returns useful statistic data managed by GAStatistics class.">getStatistics</a>();
<a name="l00103"></a>00103 generation = stats.generation();
<a name="l00104"></a>00104 <span class="keywordflow">if</span> (0 == generation)
<a name="l00105"></a>00105 <span class="keywordflow">return</span>;
<a name="l00106"></a>00106 }
<a name="l00107"></a>00107
<a name="l00108"></a>00108 <span class="comment">// Save maxFitness for next call</span>
<a name="l00109"></a>00109 d-><a class="code" href="structFastSatSolver_1_1FitnessWatch_1_1Private.html#c1dfa1e4f4ce3522765951e4bb1c8902">maxFitness</a> = maxFitness;
<a name="l00110"></a>00110
<a name="l00111"></a>00111 <span class="comment">// Read other statistics</span>
<a name="l00112"></a>00112 <span class="keyword">const</span> <span class="keywordtype">float</span> minFitness= solver-><a class="code" href="classFastSatSolver_1_1AbstractSatSolver.html#d1d0057d2029d7bfbf25323ab7c3b6ec" title="Returns fitness of the Worst solution managed by solver.">minFitness</a>();
<a name="l00113"></a>00113 <span class="keyword">const</span> <span class="keywordtype">float</span> avgFitness= solver-><a class="code" href="classFastSatSolver_1_1AbstractSatSolver.html#1d214769e7d45e9fd04601b31adb8c70" title="Returns average fitness computed by solver.">avgFitness</a>();
<a name="l00114"></a>00114 <span class="keyword">const</span> <span class="keywordtype">float</span> timeElapsed= d-><a class="code" href="structFastSatSolver_1_1FitnessWatch_1_1Private.html#6037497b3b68fb4ca97f9826788558f7">solver</a>-><a class="code" href="classFastSatSolver_1_1AbstractProcessWatched.html#57e2ab43bf94f9adc686e788f8771681" title="Returns time elapsed by activity.">getTimeElapsed</a>()/1000.0;
<a name="l00115"></a>00115
<a name="l00116"></a>00116 <span class="keyword">using</span> <a class="code" href="classFastSatSolver_1_1StreamDecorator_1_1FixedFloat.html" title="High-level stream manipulator for fixed floats.">StreamDecorator::FixedFloat</a>;
<a name="l00117"></a>00117 d-><a class="code" href="structFastSatSolver_1_1FitnessWatch_1_1Private.html#eacb68b8c7e9ae9b97ab9c6ab41940cb">stream</a>
<a name="l00118"></a>00118 << <span class="stringliteral">"--- satisfaction:"</span> << FixedFloat(3,1) << maxFitness*100.0 << <span class="stringliteral">"%"</span>
<a name="l00119"></a>00119 << <span class="stringliteral">"(avg:"</span> << FixedFloat(3,1) << avgFitness*100.0
<a name="l00120"></a>00120 << <span class="stringliteral">", min:"</span> << FixedFloat(3,1) << minFitness*100.0 << <span class="stringliteral">")"</span>
<a name="l00121"></a>00121 << <span class="stringliteral">", generation "</span> << std::setw(5) << generation
<a name="l00122"></a>00122 << <span class="stringliteral">", time elapsed: "</span> << FixedFloat(5,2) << timeElapsed << <span class="stringliteral">" s"</span>
<a name="l00123"></a>00123 << std::endl;
<a name="l00124"></a>00124 }
<a name="l00125"></a><a class="code" href="classFastSatSolver_1_1FitnessWatch.html#d20897c5c8bd47f5d4005989bead0e55">00125</a> <span class="keywordtype">void</span> <a class="code" href="classFastSatSolver_1_1FitnessWatch.html#d20897c5c8bd47f5d4005989bead0e55">FitnessWatch::reset</a>() {
<a name="l00126"></a>00126 d-><a class="code" href="structFastSatSolver_1_1FitnessWatch_1_1Private.html#c1dfa1e4f4ce3522765951e4bb1c8902">maxFitness</a> = 0.0;
<a name="l00127"></a>00127 }
<a name="l00128"></a>00128
<a name="l00129"></a>00129 <span class="comment">// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</span>
<a name="l00130"></a>00130 <span class="comment">// ResultsWatch implementation</span>
<a name="l00131"></a><a class="code" href="structFastSatSolver_1_1ResultsWatch_1_1Private.html">00131</a> <span class="keyword">struct </span><a class="code" href="structFastSatSolver_1_1ResultsWatch_1_1Private.html">ResultsWatch::Private</a> {
<a name="l00132"></a><a class="code" href="structFastSatSolver_1_1ResultsWatch_1_1Private.html#6037497b3b68fb4ca97f9826788558f7">00132</a> <a class="code" href="classFastSatSolver_1_1AbstractSatSolver.html" title="SAT Solver base class.">AbstractSatSolver</a> *solver;
<a name="l00133"></a><a class="code" href="structFastSatSolver_1_1ResultsWatch_1_1Private.html#eacb68b8c7e9ae9b97ab9c6ab41940cb">00133</a> std::ostream &stream;
<a name="l00134"></a><a class="code" href="structFastSatSolver_1_1ResultsWatch_1_1Private.html#1e70014c1e6b2fc3cd76f48b0cc2f40b">00134</a> <span class="keywordtype">int</span> nResults;
<a name="l00135"></a>00135
<a name="l00136"></a><a class="code" href="structFastSatSolver_1_1ResultsWatch_1_1Private.html#07986f4a8a47d0b9b7fb0caefcaa2fce">00136</a> <a class="code" href="structFastSatSolver_1_1ResultsWatch_1_1Private.html">Private</a>(std::ostream &streamTo): stream(streamTo) { }
<a name="l00137"></a>00137 };
<a name="l00138"></a><a class="code" href="classFastSatSolver_1_1ResultsWatch.html#f921d2c5a2ab1812697c3ba133f3a6aa">00138</a> <a class="code" href="classFastSatSolver_1_1ResultsWatch.html#f921d2c5a2ab1812697c3ba133f3a6aa">ResultsWatch::ResultsWatch</a>(<a class="code" href="classFastSatSolver_1_1AbstractSatSolver.html" title="SAT Solver base class.">AbstractSatSolver</a> *solver, std::ostream &streamTo):
<a name="l00139"></a>00139 d(new <a class="code" href="structFastSatSolver_1_1ResultsWatch_1_1Private.html">Private</a>(streamTo))
<a name="l00140"></a>00140 {
<a name="l00141"></a>00141 d-><a class="code" href="structFastSatSolver_1_1ResultsWatch_1_1Private.html#6037497b3b68fb4ca97f9826788558f7">solver</a> = solver;
<a name="l00142"></a>00142 d-><a class="code" href="structFastSatSolver_1_1ResultsWatch_1_1Private.html#1e70014c1e6b2fc3cd76f48b0cc2f40b">nResults</a> = 0;
<a name="l00143"></a>00143 }
<a name="l00144"></a><a class="code" href="classFastSatSolver_1_1ResultsWatch.html#2c8aa4e33454d8ac246f3fecf18a0e4e">00144</a> <a class="code" href="classFastSatSolver_1_1ResultsWatch.html#2c8aa4e33454d8ac246f3fecf18a0e4e">ResultsWatch::~ResultsWatch</a>() {
<a name="l00145"></a>00145 <span class="keyword">delete</span> d;
<a name="l00146"></a>00146 }
<a name="l00147"></a><a class="code" href="classFastSatSolver_1_1ResultsWatch.html#7ff19734eb024bd6f3e2ad95647b1b27">00147</a> <span class="keywordtype">void</span> <a class="code" href="classFastSatSolver_1_1ResultsWatch.html#7ff19734eb024bd6f3e2ad95647b1b27" title="Event notification, usually called by object implementing ISubject interface.">ResultsWatch::notify</a>() {
<a name="l00148"></a>00148 <span class="keyword">using namespace </span>StreamDecorator;
<a name="l00149"></a>00149 <a class="code" href="classFastSatSolver_1_1AbstractSatSolver.html" title="SAT Solver base class.">AbstractSatSolver</a> *solver= d-><a class="code" href="structFastSatSolver_1_1ResultsWatch_1_1Private.html#6037497b3b68fb4ca97f9826788558f7">solver</a>;
<a name="l00150"></a>00150 <span class="keyword">const</span> <span class="keywordtype">int</span> nResults= solver-><a class="code" href="classFastSatSolver_1_1AbstractSatSolver.html#f70c2c7822e8a563a1685c9b68d5cc4a" title="Returns current count solutions founded by solver.">getSolutionsCount</a>();
<a name="l00151"></a>00151 <span class="keywordflow">if</span> (nResults <= d->nResults)
<a name="l00152"></a>00152 <span class="keywordflow">return</span>;
<a name="l00153"></a>00153 d-><a class="code" href="structFastSatSolver_1_1ResultsWatch_1_1Private.html#1e70014c1e6b2fc3cd76f48b0cc2f40b">nResults</a> = nResults;
<a name="l00154"></a>00154
<a name="l00155"></a>00155 <span class="keyword">const</span> <span class="keywordtype">float</span> timeElapsed= solver-><a class="code" href="classFastSatSolver_1_1AbstractProcessWatched.html#57e2ab43bf94f9adc686e788f8771681" title="Returns time elapsed by activity.">getTimeElapsed</a>()/1000.0;
<a name="l00156"></a>00156 d-><a class="code" href="structFastSatSolver_1_1ResultsWatch_1_1Private.html#eacb68b8c7e9ae9b97ab9c6ab41940cb">stream</a>
<a name="l00157"></a>00157 << Color(<a class="code" href="group__fssIO.html#ggc31db05c6cb5891c704eae374f6926a8d627db49c0f44dcd2a17519757cabc6e">C_LIGHT_BLUE</a>) << <span class="stringliteral">"--- "</span> << nResults
<a name="l00158"></a>00158 << <span class="stringliteral">". solution found in "</span> << FixedFloat(5,2) << timeElapsed << <span class="stringliteral">" s"</span>
<a name="l00159"></a>00159 << Color() << std::endl;
<a name="l00160"></a>00160 }
<a name="l00161"></a>00161
<a name="l00162"></a><a class="code" href="structFastSatSolver_1_1ProgressWatch_1_1Private.html">00162</a> <span class="keyword">struct </span><a class="code" href="structFastSatSolver_1_1ProgressWatch_1_1Private.html">ProgressWatch::Private</a> {
<a name="l00163"></a><a class="code" href="structFastSatSolver_1_1ProgressWatch_1_1Private.html#d957b3ab55b0372e52f503b57a0d17ed">00163</a> <a class="code" href="classFastSatSolver_1_1AbstractProcess.html" title="Base class of simple multi-step process.">AbstractProcess</a> *process;
<a name="l00164"></a><a class="code" href="structFastSatSolver_1_1ProgressWatch_1_1Private.html#5f416f37089c19cf5a750ed7eb9c725d">00164</a> <span class="keywordtype">int</span> stepsTotal;
<a name="l00165"></a><a class="code" href="structFastSatSolver_1_1ProgressWatch_1_1Private.html#72e27dee31b1c4c6a504fbed29542d97">00165</a> <span class="keywordtype">int</span> last;
<a name="l00166"></a><a class="code" href="structFastSatSolver_1_1ProgressWatch_1_1Private.html#eacb68b8c7e9ae9b97ab9c6ab41940cb">00166</a> std::ostream &stream;
<a name="l00167"></a>00167
<a name="l00168"></a><a class="code" href="structFastSatSolver_1_1ProgressWatch_1_1Private.html#07986f4a8a47d0b9b7fb0caefcaa2fce">00168</a> <a class="code" href="structFastSatSolver_1_1ProgressWatch_1_1Private.html">Private</a>(std::ostream &streamTo): stream(streamTo) { }
<a name="l00169"></a>00169 };
<a name="l00170"></a><a class="code" href="classFastSatSolver_1_1ProgressWatch.html#41ab01b3b0a796939656e0a7f58a9895">00170</a> <a class="code" href="classFastSatSolver_1_1ProgressWatch.html#41ab01b3b0a796939656e0a7f58a9895">ProgressWatch::ProgressWatch</a>(<a class="code" href="classFastSatSolver_1_1AbstractProcess.html" title="Base class of simple multi-step process.">AbstractProcess</a> *process, <span class="keywordtype">int</span> stepsTotal, std::ostream &streamTo):
<a name="l00171"></a>00171 d(new <a class="code" href="structFastSatSolver_1_1ProgressWatch_1_1Private.html">Private</a>(streamTo))
<a name="l00172"></a>00172 {
<a name="l00173"></a>00173 d-><a class="code" href="structFastSatSolver_1_1ProgressWatch_1_1Private.html#d957b3ab55b0372e52f503b57a0d17ed">process</a> = process;
<a name="l00174"></a>00174 d-><a class="code" href="structFastSatSolver_1_1ProgressWatch_1_1Private.html#5f416f37089c19cf5a750ed7eb9c725d">stepsTotal</a> = stepsTotal;
<a name="l00175"></a>00175 d-><a class="code" href="structFastSatSolver_1_1ProgressWatch_1_1Private.html#72e27dee31b1c4c6a504fbed29542d97">last</a> = 0;
<a name="l00176"></a>00176 }
<a name="l00177"></a><a class="code" href="classFastSatSolver_1_1ProgressWatch.html#5c47526a1f7ded8f3bbd6fbee5c7c900">00177</a> <a class="code" href="classFastSatSolver_1_1ProgressWatch.html#5c47526a1f7ded8f3bbd6fbee5c7c900">ProgressWatch::~ProgressWatch</a>() {
<a name="l00178"></a>00178 <span class="keyword">delete</span> d;
<a name="l00179"></a>00179 }
<a name="l00180"></a><a class="code" href="classFastSatSolver_1_1ProgressWatch.html#7ff19734eb024bd6f3e2ad95647b1b27">00180</a> <span class="keywordtype">void</span> <a class="code" href="classFastSatSolver_1_1ProgressWatch.html#7ff19734eb024bd6f3e2ad95647b1b27" title="Event notification, usually called by object implementing ISubject interface.">ProgressWatch::notify</a>() {
<a name="l00181"></a>00181 <span class="keyword">using namespace </span>StreamDecorator;
<a name="l00182"></a>00182
<a name="l00183"></a>00183 <span class="comment">// Check percentage value</span>
<a name="l00184"></a>00184 <span class="keyword">const</span> <span class="keywordtype">int</span> currentStep= d-><a class="code" href="structFastSatSolver_1_1ProgressWatch_1_1Private.html#d957b3ab55b0372e52f503b57a0d17ed">process</a>-><a class="code" href="classFastSatSolver_1_1AbstractProcess.html#14fa4258dc9ab261c5d4026ae3dfc882" title="Returns current step number.">getStepsCount</a>();
<a name="l00185"></a>00185 <span class="keyword">const</span> <span class="keywordtype">int</span> percents=
<a name="l00186"></a>00186 currentStep*100 /
<a name="l00187"></a>00187 d-><a class="code" href="structFastSatSolver_1_1ProgressWatch_1_1Private.html#5f416f37089c19cf5a750ed7eb9c725d">stepsTotal</a>;
<a name="l00188"></a>00188 <span class="keywordflow">if</span> (percents == d-><a class="code" href="structFastSatSolver_1_1ProgressWatch_1_1Private.html#72e27dee31b1c4c6a504fbed29542d97">last</a>)
<a name="l00189"></a>00189 <span class="keywordflow">return</span>;
<a name="l00190"></a>00190 d-><a class="code" href="structFastSatSolver_1_1ProgressWatch_1_1Private.html#72e27dee31b1c4c6a504fbed29542d97">last</a> = percents;
<a name="l00191"></a>00191
<a name="l00192"></a>00192 <span class="comment">// Write out message</span>
<a name="l00193"></a>00193 d-><a class="code" href="structFastSatSolver_1_1ProgressWatch_1_1Private.html#eacb68b8c7e9ae9b97ab9c6ab41940cb">stream</a>
<a name="l00194"></a>00194 << Color(<a class="code" href="group__fssIO.html#ggc31db05c6cb5891c704eae374f6926a83480f1b50ebb454abb68e97ef2fc7035">C_GREEN</a>) << <span class="stringliteral">"--- Progress:"</span>
<a name="l00195"></a>00195 << std::setw(3) << percents << <span class="stringliteral">"%"</span>
<a name="l00196"></a>00196 << Color() << std::endl;
<a name="l00197"></a>00197 }
<a name="l00198"></a>00198
<a name="l00199"></a>00199 } <span class="comment">// namespace FastSatSolver</span>
<a name="l00200"></a>00200
</pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Wed Nov 5 22:30:22 2008 for Fast SAT Solver by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.4 </small></address>
</body>
</html>