Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r78298 - in sandbox/gtl/libs/polygon: benchmark test
From: sydorchuk.andriy_at_[hidden]
Date: 2012-05-01 15:53:59


Author: asydorchuk
Date: 2012-05-01 15:53:57 EDT (Tue, 01 May 2012)
New Revision: 78298
URL: http://svn.boost.org/trac/boost/changeset/78298

Log:
Syncing gtl test with trunk.
Moving voronoi benchmark test to benchmarks directory.
Added:
   sandbox/gtl/libs/polygon/benchmark/voronoi_benchmark.cpp (contents, props changed)
Removed:
   sandbox/gtl/libs/polygon/test/voronoi_benchmark_test.cpp
Text files modified:
   sandbox/gtl/libs/polygon/benchmark/Jamfile.v2 | 5 +
   sandbox/gtl/libs/polygon/test/Jamfile.v2 | 5 -
   sandbox/gtl/libs/polygon/test/gtl_boost_unit_test.cpp | 102 ++++++++++++++++++++++++++++++++++++---
   3 files changed, 97 insertions(+), 15 deletions(-)

Modified: sandbox/gtl/libs/polygon/benchmark/Jamfile.v2
==============================================================================
--- sandbox/gtl/libs/polygon/benchmark/Jamfile.v2 (original)
+++ sandbox/gtl/libs/polygon/benchmark/Jamfile.v2 2012-05-01 15:53:57 EDT (Tue, 01 May 2012)
@@ -38,6 +38,11 @@
         <library>$(SHULL_ROOT)/s_hull.so
     ;
 
+alias "benchmark-general"
+ :
+ [ run voronoi_benchmark.cpp ]
+ ;
+
 alias "benchmark-points"
     :
         [ run voronoi_benchmark_points.cpp ]

Added: sandbox/gtl/libs/polygon/benchmark/voronoi_benchmark.cpp
==============================================================================
--- (empty file)
+++ sandbox/gtl/libs/polygon/benchmark/voronoi_benchmark.cpp 2012-05-01 15:53:57 EDT (Tue, 01 May 2012)
@@ -0,0 +1,156 @@
+// Boost.Polygon library voronoi_benchmark.cpp file
+
+// Copyright Andrii Sydorchuk 2010-2012.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#include <iomanip>
+#include <iostream>
+#include <fstream>
+#include <numeric>
+#include <vector>
+
+#define BOOST_TEST_MODULE benchmark_test
+#include <boost/mpl/list.hpp>
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/test/test_case_template.hpp>
+#include <boost/timer.hpp>
+
+#include <boost/polygon/polygon.hpp>
+#include <boost/polygon/voronoi.hpp>
+using namespace boost::polygon;
+
+typedef boost::mpl::list<int> test_types;
+const char *BENCHMARK_FILE = "voronoi_benchmark.txt";
+const char *POINT_INPUT_FILE = "voronoi_input_data/voronoi_point.txt";
+const char *SEGMENT_INPUT_FILE = "voronoi_input_data/voronoi_segment.txt";
+const int POINT_RUNS = 10;
+const int SEGMENT_RUNS = 10;
+
+boost::mt19937 gen(static_cast<unsigned int>(time(NULL)));
+boost::timer timer;
+
+BOOST_AUTO_TEST_CASE_TEMPLATE(benchmark_test_random, T, test_types) {
+ typedef T coordinate_type;
+ typedef point_data<coordinate_type> point_type;
+ voronoi_diagram<double> test_output;
+
+ std::ofstream bench_file(BENCHMARK_FILE, std::ios_base::out | std::ios_base::app);
+ bench_file << "Voronoi Benchmark Test (time in seconds):" << std::endl;
+ bench_file << "| Number of points | Number of tests | Time per one test |" << std::endl;
+ bench_file << std::setiosflags(std::ios::right | std::ios::fixed) << std::setprecision(6);
+
+#ifdef NDEBUG
+ int max_points = 100000;
+#else
+ int max_points = 100;
+#endif
+
+ std::vector<point_type> points;
+ coordinate_type x, y;
+ for (int num_points = 10; num_points <= max_points; num_points *= 10) {
+ points.resize(num_points);
+ timer.restart();
+ int num_tests = max_points / num_points;
+ for (int cur = 0; cur < num_tests; cur++) {
+ test_output.clear();
+ for (int cur_point = 0; cur_point < num_points; cur_point++) {
+ x = static_cast<coordinate_type>(gen());
+ y = static_cast<coordinate_type>(gen());
+ points[cur_point] = point_type(x, y);
+ }
+ construct_voronoi(points.begin(), points.end(), &test_output);
+ }
+ double elapsed_time = timer.elapsed();
+ double time_per_test = elapsed_time / num_tests;
+
+ bench_file << "| " << std::setw(16) << num_points << " ";
+ bench_file << "| " << std::setw(15) << num_tests << " ";
+ bench_file << "| " << std::setw(17) << time_per_test << " ";
+ bench_file << "| " << std::endl;
+ }
+ bench_file.close();
+}
+
+#ifdef NDEBUG
+BOOST_AUTO_TEST_CASE_TEMPLATE(benchmark_test_points, T, test_types) {
+ typedef T coordinate_type;
+ typedef point_data<coordinate_type> point_type;
+
+ std::vector<point_type> points;
+ {
+ std::ifstream input_file(POINT_INPUT_FILE);
+ int num_points;
+ coordinate_type x, y;
+ input_file >> num_points;
+ points.reserve(num_points);
+ for (int i = 0; i < num_points; ++i) {
+ input_file >> x >> y;
+ points.push_back(point_type(x, y));
+ }
+ input_file.close();
+ }
+
+ std::vector<double> periods;
+ {
+ for (int i = 0; i < POINT_RUNS; ++i) {
+ voronoi_diagram<double> test_output;
+ timer.restart();
+ construct_voronoi(points.begin(), points.end(), &test_output);
+ periods.push_back(timer.elapsed());
+ }
+ }
+ std::sort(periods.begin(), periods.end());
+ // Using olympic system to evaluate average time.
+ double elapsed_time = std::accumulate(periods.begin() + 2, periods.end() - 2, 0.0);
+ elapsed_time /= (periods.size() - 4);
+
+ std::ofstream bench_file(BENCHMARK_FILE, std::ios_base::out | std::ios_base::app);
+ bench_file << std::setiosflags(std::ios::right | std::ios::fixed) << std::setprecision(6);
+ bench_file << "Static test of " << points.size() << " points: " << elapsed_time << std::endl;
+ bench_file.close();
+}
+
+BOOST_AUTO_TEST_CASE_TEMPLATE(benchmark_test_segments, T, test_types) {
+ typedef T coordinate_type;
+ typedef point_data<coordinate_type> point_type;
+ typedef segment_data<coordinate_type> segment_type;
+
+ std::vector<segment_type> segments;
+ {
+ std::ifstream input_file(SEGMENT_INPUT_FILE);
+ int num_segments;
+ coordinate_type x0, y0, x1, y1;
+ input_file >> num_segments;
+ segments.reserve(num_segments);
+ for (int i = 0; i < num_segments; ++i) {
+ input_file >> x0 >> y0 >> x1 >> y1;
+ point_type p0(x0, y0), p1(x1, y1);
+ segments.push_back(segment_type(p0, p1));
+ }
+ input_file.close();
+ }
+
+ std::vector<double> periods;
+ {
+ for (int i = 0; i < SEGMENT_RUNS; ++i) {
+ voronoi_diagram<double> test_output;
+ timer.restart();
+ construct_voronoi(segments.begin(), segments.end(), &test_output);
+ periods.push_back(timer.elapsed());
+ }
+ }
+ std::sort(periods.begin(), periods.end());
+ // Using olympic system to evaluate average time.
+ double elapsed_time = std::accumulate(periods.begin() + 2, periods.end() - 2, 0.0);
+ elapsed_time /= (periods.size() - 4);
+
+ std::ofstream bench_file(BENCHMARK_FILE, std::ios_base::out | std::ios_base::app);
+ bench_file << std::setiosflags(std::ios::right | std::ios::fixed) << std::setprecision(6);
+ bench_file << "Static test of " << segments.size() << " segments: " << elapsed_time << std::endl;
+ bench_file.close();
+}
+#endif

Modified: sandbox/gtl/libs/polygon/test/Jamfile.v2
==============================================================================
--- sandbox/gtl/libs/polygon/test/Jamfile.v2 (original)
+++ sandbox/gtl/libs/polygon/test/Jamfile.v2 2012-05-01 15:53:57 EDT (Tue, 01 May 2012)
@@ -22,11 +22,6 @@
         [ run gtl_boost_unit_test.cpp ]
     ;
 
-alias "voronoi-benchmark"
- :
- [ run voronoi_benchmark_test.cpp ]
- ;
-
 alias "voronoi-unit"
     :
         [ run voronoi_builder_test.cpp ]

Modified: sandbox/gtl/libs/polygon/test/gtl_boost_unit_test.cpp
==============================================================================
--- sandbox/gtl/libs/polygon/test/gtl_boost_unit_test.cpp (original)
+++ sandbox/gtl/libs/polygon/test/gtl_boost_unit_test.cpp 2012-05-01 15:53:57 EDT (Tue, 01 May 2012)
@@ -12,18 +12,26 @@
 #include <time.h>
 #include <stdlib.h>
 
+void assert_s(bool c, std::string msg) {
+ if(!c) {
+ std::cout << msg << std::endl;
+ exit( 1);
+ }
+}
+
 namespace boost { namespace polygon{
- void addpoly(polygon_45_set_data<int>& pset,
- int* pts, int numpts) {
- std::vector<point_data<int> > mppts;
- for(unsigned int i = 0; i < numpts*2; i += 2) {
- point_data<int> pt(pts[i], pts[i+1]);
- mppts.push_back(pt);
+ void addpoly(polygon_45_set_data<int>& pset,
+ int* pts, int numpts) {
+ std::vector<point_data<int> > mppts;
+ for(unsigned int i = 0; i < numpts*2; i += 2) {
+ point_data<int> pt(pts[i], pts[i+1]);
+ mppts.push_back(pt);
+ }
+ polygon_45_data<int> poly;
+ poly.set(mppts.begin(), mppts.end());
+ pset += poly;
     }
- polygon_45_data<int> poly;
- poly.set(mppts.begin(), mppts.end());
- pset += poly;
- }
+
 
   template <class T>
   std::ostream& operator << (std::ostream& o, const interval_data<T>& i)
@@ -185,6 +193,11 @@
   {
     return o << r.get(HORIZONTAL) << ' ' << r.get(VERTICAL);
   }
+ template <class T>
+ std::ostream& operator << (std::ostream& o, const directed_line_segment_data<T>& r)
+ {
+ return o << r.get(LOW) << ' ' << r.get(HIGH);
+ }
 
 
   template <typename T>
@@ -3633,6 +3646,75 @@
       }
     }
   }
+ {
+ using namespace gtl;
+ typedef point_data<int> Point;
+ typedef directed_line_segment_data<int> Dls;
+ Point pt1(0, 0);
+ Point pt2(10, 10);
+ Point pt3(20, 20);
+ Point pt4(20, 0);
+ Dls dls1(pt1, pt2);
+ Dls dls2(pt1, pt3);
+ Dls dls3(pt1, pt4);
+ Dls dls4(pt2, pt1);
+ bool b1 = equivalence(dls1, dls1);
+ bool b2 = equivalence(dls1, dls2);
+ bool b3 = equivalence(dls1, dls3);
+ bool b4 = equivalence(dls1, dls4);
+ if(!b1 || b2 || b3 || b4) {
+ std::cout << "fail1\n";
+ return 1;
+ }
+ low(dls1, pt1);
+ if(!equivalence(low(dls1), pt1)) {
+ std::cout << "fail2\n";
+ return 1;
+ }
+ high(dls1, pt2);
+ assert_s(equivalence(high(dls1), pt2), "fail3");
+ assign(dls1, dls4);
+ assert_s(equivalence(dls1, dls4), "fail4");
+ assert_s(!contains(dls1, dls2), "fail5");
+ assert_s(contains(dls2, dls1), "fail5");
+ assert_s(!contains(dls2, dls1, false), "fail6");
+ assert_s(center(dls1) == Point(5, 5), "center");
+ assert_s(length(dls3) == 20, "length");
+ scale_up(dls3, 10);
+ assert_s(length(dls3) == 200, "length2");
+ scale_down(dls3, 10);
+ assert_s(length(dls3) == 20, "length3");
+ scale(dls3, anisotropic_scale_factor<double>(1.5, 1.5, 1.5));
+ assert_s(length(dls3) == 30, "length4");
+ axis_transformation atr(axis_transformation::WS);
+ transform(dls3, atr);
+ assert_s(equivalence(high(dls3), Point(-30, 0)), "transform");
+ move(dls3, HORIZONTAL, 30);
+ assert_s(equivalence(high(dls3), pt1), "move");
+ convolve(dls3, pt2);
+ assert_s(equivalence(high(dls3), pt2), "convolve");
+ deconvolve(dls3, pt2);
+ assert_s(equivalence(high(dls3), pt1), "deconvolve");
+ assert_s(euclidean_distance(dls3, pt1) == 0.0, "distance1");
+ assert_s(euclidean_distance(dls3, pt2) == 10.0, "distance2");
+ std::cout << euclidean_distance(dls3, Point(5, 5)) << std::endl;
+ std::cout << dls1 << std::endl;
+ std::cout << euclidean_distance(dls1, Point(5, 5)) << std::endl;
+ std::cout << euclidean_distance(dls1, Point(15, 15)) << std::endl;
+ std::cout << euclidean_distance(dls1, Point(5, 6)) << std::endl;
+ std::cout << euclidean_distance(dls1, Point(5, 3)) << std::endl;
+ std::cout << euclidean_distance(dls1, dls3) << std::endl;
+ std::cout << euclidean_distance(dls1, directed_line_segment_data<int>(Point(2, 0), Point(3, 0))) << std::endl;
+ assert_s(intersects(dls1, dls3), "intersects1");
+ assert_s(!intersects(dls1, directed_line_segment_data<int>(Point(2, 0), Point(3, 0))), "intersects2");
+ assert_s(boundaries_intersect(dls1, dls2), "bi");
+ assert_s(abuts(dls1, dls2), "abuts");
+ Point p;
+ bool ir = intersection(p, dls1, dls2);
+ std::cout << ir << " " << p << std::endl;
+ }
+
   std::cout << "ALL TESTS COMPLETE\n";
   return 0;
 }
+

Deleted: sandbox/gtl/libs/polygon/test/voronoi_benchmark_test.cpp
==============================================================================
--- sandbox/gtl/libs/polygon/test/voronoi_benchmark_test.cpp 2012-05-01 15:53:57 EDT (Tue, 01 May 2012)
+++ (empty file)
@@ -1,156 +0,0 @@
-// Boost.Polygon library voronoi_benchmark_test.cpp file
-
-// Copyright Andrii Sydorchuk 2010-2012.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-// See http://www.boost.org for updates, documentation, and revision history.
-
-#include <iomanip>
-#include <iostream>
-#include <fstream>
-#include <numeric>
-#include <vector>
-
-#define BOOST_TEST_MODULE benchmark_test
-#include <boost/mpl/list.hpp>
-#include <boost/random/mersenne_twister.hpp>
-#include <boost/test/test_case_template.hpp>
-#include <boost/timer.hpp>
-
-#include <boost/polygon/polygon.hpp>
-#include <boost/polygon/voronoi.hpp>
-using namespace boost::polygon;
-
-typedef boost::mpl::list<int> test_types;
-const char *BENCHMARK_FILE = "voronoi_benchmark.txt";
-const char *POINT_INPUT_FILE = "voronoi_input_data/voronoi_point.txt";
-const char *SEGMENT_INPUT_FILE = "voronoi_input_data/voronoi_segment.txt";
-const int POINT_RUNS = 10;
-const int SEGMENT_RUNS = 10;
-
-boost::mt19937 gen(static_cast<unsigned int>(time(NULL)));
-boost::timer timer;
-
-BOOST_AUTO_TEST_CASE_TEMPLATE(benchmark_test_random, T, test_types) {
- typedef T coordinate_type;
- typedef point_data<coordinate_type> point_type;
- voronoi_diagram<double> test_output;
-
- std::ofstream bench_file(BENCHMARK_FILE, std::ios_base::out | std::ios_base::app);
- bench_file << "Voronoi Benchmark Test (time in seconds):" << std::endl;
- bench_file << "| Number of points | Number of tests | Time per one test |" << std::endl;
- bench_file << std::setiosflags(std::ios::right | std::ios::fixed) << std::setprecision(6);
-
-#ifdef NDEBUG
- int max_points = 100000;
-#else
- int max_points = 100;
-#endif
-
- std::vector<point_type> points;
- coordinate_type x, y;
- for (int num_points = 10; num_points <= max_points; num_points *= 10) {
- points.resize(num_points);
- timer.restart();
- int num_tests = max_points / num_points;
- for (int cur = 0; cur < num_tests; cur++) {
- test_output.clear();
- for (int cur_point = 0; cur_point < num_points; cur_point++) {
- x = static_cast<coordinate_type>(gen());
- y = static_cast<coordinate_type>(gen());
- points[cur_point] = point_type(x, y);
- }
- construct_voronoi(points.begin(), points.end(), &test_output);
- }
- double elapsed_time = timer.elapsed();
- double time_per_test = elapsed_time / num_tests;
-
- bench_file << "| " << std::setw(16) << num_points << " ";
- bench_file << "| " << std::setw(15) << num_tests << " ";
- bench_file << "| " << std::setw(17) << time_per_test << " ";
- bench_file << "| " << std::endl;
- }
- bench_file.close();
-}
-
-#ifdef NDEBUG
-BOOST_AUTO_TEST_CASE_TEMPLATE(benchmark_test_points, T, test_types) {
- typedef T coordinate_type;
- typedef point_data<coordinate_type> point_type;
-
- std::vector<point_type> points;
- {
- std::ifstream input_file(POINT_INPUT_FILE);
- int num_points;
- coordinate_type x, y;
- input_file >> num_points;
- points.reserve(num_points);
- for (int i = 0; i < num_points; ++i) {
- input_file >> x >> y;
- points.push_back(point_type(x, y));
- }
- input_file.close();
- }
-
- std::vector<double> periods;
- {
- for (int i = 0; i < POINT_RUNS; ++i) {
- voronoi_diagram<double> test_output;
- timer.restart();
- construct_voronoi(points.begin(), points.end(), &test_output);
- periods.push_back(timer.elapsed());
- }
- }
- std::sort(periods.begin(), periods.end());
- // Using olympic system to evaluate average time.
- double elapsed_time = std::accumulate(periods.begin() + 2, periods.end() - 2, 0.0);
- elapsed_time /= (periods.size() - 4);
-
- std::ofstream bench_file(BENCHMARK_FILE, std::ios_base::out | std::ios_base::app);
- bench_file << std::setiosflags(std::ios::right | std::ios::fixed) << std::setprecision(6);
- bench_file << "Static test of " << points.size() << " points: " << elapsed_time << std::endl;
- bench_file.close();
-}
-
-BOOST_AUTO_TEST_CASE_TEMPLATE(benchmark_test_segments, T, test_types) {
- typedef T coordinate_type;
- typedef point_data<coordinate_type> point_type;
- typedef segment_data<coordinate_type> segment_type;
-
- std::vector<segment_type> segments;
- {
- std::ifstream input_file(SEGMENT_INPUT_FILE);
- int num_segments;
- coordinate_type x0, y0, x1, y1;
- input_file >> num_segments;
- segments.reserve(num_segments);
- for (int i = 0; i < num_segments; ++i) {
- input_file >> x0 >> y0 >> x1 >> y1;
- point_type p0(x0, y0), p1(x1, y1);
- segments.push_back(segment_type(p0, p1));
- }
- input_file.close();
- }
-
- std::vector<double> periods;
- {
- for (int i = 0; i < SEGMENT_RUNS; ++i) {
- voronoi_diagram<double> test_output;
- timer.restart();
- construct_voronoi(segments.begin(), segments.end(), &test_output);
- periods.push_back(timer.elapsed());
- }
- }
- std::sort(periods.begin(), periods.end());
- // Using olympic system to evaluate average time.
- double elapsed_time = std::accumulate(periods.begin() + 2, periods.end() - 2, 0.0);
- elapsed_time /= (periods.size() - 4);
-
- std::ofstream bench_file(BENCHMARK_FILE, std::ios_base::out | std::ios_base::app);
- bench_file << std::setiosflags(std::ios::right | std::ios::fixed) << std::setprecision(6);
- bench_file << "Static test of " << segments.size() << " segments: " << elapsed_time << std::endl;
- bench_file.close();
-}
-#endif


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk