00001 #ifndef _VERIFICATION_HPP
00002 #define _VERIFICATION_HPP
00003
00004 #include <iostream>
00005 #include <assert.h>
00006 #include "geometry.hpp"
00007 #include "random.hpp"
00008 #include "coloring.hpp"
00009
00010 namespace Arak {
00011
00029 class CriticalStatsEstimator {
00030
00031 protected:
00032
00036 unsigned long int n;
00037
00041 unsigned long int sumIntVertices;
00042
00046 unsigned long int sumIntEdges;
00047
00055 unsigned long int sumBdVertices[4];
00056
00061 std::vector<Geometry::Segment> testSegments;
00062
00067 std::vector<unsigned long int> sumCrossings;
00068
00069 public:
00070
00074 CriticalStatsEstimator()
00075 : n(0), sumIntVertices(0), sumIntEdges(0) {
00076 sumBdVertices[0] =
00077 sumBdVertices[1] =
00078 sumBdVertices[2] =
00079 sumBdVertices[3] = 0;
00080 }
00081
00089 CriticalStatsEstimator(int k, const Coloring& c,
00090 Arak::Util::Random& random =
00091 Arak::Util::default_random)
00092 : n(0), sumIntVertices(0), sumIntEdges(0), sumCrossings(k, 0) {
00093 sumBdVertices[0] =
00094 sumBdVertices[1] =
00095 sumBdVertices[2] =
00096 sumBdVertices[3] = 0;
00097 for (int i = 0; i < k; i++) {
00098 Geometry::Point p = c.randomPoint(random);
00099 Geometry::Point q = c.randomPoint(random);
00100 testSegments.push_back(Geometry::Segment(p, q));
00101 }
00102 }
00103
00109 void update(const Coloring& c);
00110
00118 template<typename charT, typename traits>
00119 void report(const Geometry::Rectangle& boundary,
00120 double scale,
00121 std::basic_ostream<charT,traits>& out) const {
00122
00123 assert(boundary.xmax() - boundary.xmin() ==
00124 boundary.ymax() - boundary.ymin());
00125 double side = CGAL::to_double(boundary.xmax() - boundary.xmin());
00126 double expNumIntVertices = 4.0 * M_PI * pow(side * scale, 2);
00127 double avgNumIntVertices = double(sumIntVertices) / double(n);
00128 double expNumIntEdges = 4.0 * side * scale + expNumIntVertices;
00129 double avgNumIntEdges = double(sumIntEdges) / double(n);
00130 out << std::setw(28) << "statistic"
00131 << std::setw(12) << "average"
00132 << std::setw(12) << "expectation"
00133 << std::endl;
00134 out << std::setw(28) << "----------------------------"
00135 << std::setw(12) << "-----------"
00136 << std::setw(12) << "-----------"
00137 << std::endl;
00138 out << std::setw(28) << "# interior vertices"
00139 << std::setw(12) << avgNumIntVertices
00140 << std::setw(12) << expNumIntVertices
00141 << std::endl;
00142 out << std::setw(28) << "# interior edges"
00143 << std::setw(12) << avgNumIntEdges
00144 << std::setw(12) << expNumIntEdges
00145 << std::endl;
00146 for (int i = 0; i < 4; i++) {
00147 double expNumBdVertices = 2.0 * scale * side;
00148 double avgNumBdVertices = double(sumBdVertices[i]) / double(n);
00149 out << std::setw(26) << "# boundary vertices ("
00150 << std::setw(0) << i << ")"
00151 << std::setw(12) << avgNumBdVertices
00152 << std::setw(12) << expNumBdVertices
00153 << std::endl;
00154 }
00155 for (unsigned int i = 0; i < testSegments.size(); i++) {
00156 const Geometry::Segment& s = testSegments[i];
00157 double length = sqrt(CGAL::to_double(s.squared_length()));
00158 double expNumCrossings = 2.0 * scale * length;
00159 double avgNumCrossings = double(sumCrossings[i]) / double(n);
00160 out << std::setw(26) << "# crossings of test edge ("
00161 << std::setw(0) << i << ")"
00162 << std::setw(12) << avgNumCrossings
00163 << std::setw(12) << expNumCrossings
00164 << std::endl;
00165 }
00166 }
00167
00168 };
00169
00170 }
00171
00172 #endif