modified benchmarking function to support .environment files

This commit is contained in:
Francisc 2013-08-08 19:24:02 +03:00
parent 84ccb4ae7e
commit 2d210329f2
2 changed files with 64 additions and 104 deletions

View File

@ -27,13 +27,14 @@
#include <CGAL/Arrangement_2.h>
#include <CGAL/Simple_polygon_visibility_2.h>
#include <CGAL/Naive_visibility_2.h>
#include <CGAL/Triangular_expansion_visibility_2_.h>
#include <CGAL/test_model_methods.h>
#include <CGAL/test_utils.h>
#include <iostream>
#include <fstream>
int main() {
int main(int argc, char* argv[]) {
{
typedef CGAL::Gmpq Number_type;
typedef CGAL::Cartesian<Number_type> Kernel;
@ -45,12 +46,25 @@ int main() {
Simple_polygon_visibility_2;
typedef CGAL::Naive_visibility_2<Arrangement_2, CGAL::Tag_false>
Naive_visibility_2;
typedef CGAL::Triangular_expansion_visibility_2<Arrangement_2, CGAL::Tag_false>
Triangular_expansion_visibility_2;
Simple_polygon_visibility_2 simple_visibility;
Naive_visibility_2 naive_visibility;
const CGAL::Query_choice qchoice = CGAL::FACE;
CGAL::benchmark<Simple_polygon_visibility_2, Naive_visibility_2>
(simple_visibility, naive_visibility, qchoice, 1, 0);
if (argc == 2) {
Simple_polygon_visibility_2 simple_visibility;
Naive_visibility_2 naive_visibility;
Triangular_expansion_visibility_2 triangular_visibility;
const CGAL::Query_choice qchoice = CGAL::FACE;
std::string input_arr_file(argv[1]);
std::ifstream input(input_arr_file.c_str());
CGAL::benchmark<Naive_visibility_2, Triangular_expansion_visibility_2>
(naive_visibility, triangular_visibility, qchoice, input);
// CGAL::benchmark<Simple_polygon_visibility_2, Triangular_expansion_visibility_2>
// (simple_visibility, triangular_visibility, qchoice, input);
}
else {
std::cout << "Usage: ./benchmark [filename]\n";
exit(0);
}
}
return 0;
}

View File

@ -351,7 +351,8 @@ void run_tests(int case_number_simple, int case_number_non_simple) {
Visibility_2 visibility;
bool one_failed = false;
if (Visibility_2::Supports_simple_polygon_tag::value) {
if (Visibility_2::Supports_simple_polygon_tag::value
&& case_number_simple >= 1) {
int cnt = 0;
int cnt_passed = 0;
std::cout << " Running simple polygon test cases...\n";
@ -385,10 +386,12 @@ void run_tests(int case_number_simple, int case_number_non_simple) {
}
std::cout << ")" << std::endl;
}
if (Visibility_2::Supports_general_polygon_tag::value) {
if (Visibility_2::Supports_general_polygon_tag::value
&& case_number_non_simple >= 1) {
int cnt = 0;
int cnt_passed = 0;
std::cout << " Running non-simple polygon test cases...\n";
std::cout << " Running non-simple polygon test cases...\n";
for (int i = 1 ; i <= case_number_non_simple ; i++) {
std::string input_arr_file("data/test_non_simple_polygon_");
input_arr_file += num2string<int>(i);
@ -466,9 +469,9 @@ void create_arrangement_from_file(_Arrangement_2 &arr, std::ifstream& input) {
}
template <class _Arrangement_2>
void create_polygons_from_file(_Arrangement_2 &arr, std::ifstream& input) {
typedef _Arrangement_2 Arrangement_2;
typedef typename Arrangement_2::Geometry_traits_2 Geometry_traits_2;
void create_arrangement_from_env_file(_Arrangement_2 &arr, std::ifstream& input) {
typedef _Arrangement_2 Arrangement_2;
typedef typename Arrangement_2::Geometry_traits_2 Geometry_traits_2;
typedef typename Geometry_traits_2::Segment_2 Segment_2;
typedef typename Geometry_traits_2::Point_2 Point_2;
typedef typename Geometry_traits_2::FT Number_type;
@ -481,12 +484,15 @@ void create_polygons_from_file(_Arrangement_2 &arr, std::ifstream& input) {
std::stringstream convert(line);
int number_of_polygons;
convert >> number_of_polygons;
for (int i = 0; i != number_of_polygons; i++) {
for (int i = 0 ; i < number_of_polygons ; i++) {
std::vector<Point_2> points;
std::vector<Segment_2> segments;
int number_of_vertex;
input >> number_of_vertex;
for (int j = 0; j != number_of_vertex-1; j++) {
std::getline(input, line);
std::stringstream convert(line);
int number_of_vertices;
convert >> number_of_vertices;
for (int j = 0; j < number_of_vertices; j++) {
std::getline(input, line);
std::string n1, n2;
std::istringstream iss(line);
@ -494,14 +500,12 @@ void create_polygons_from_file(_Arrangement_2 &arr, std::ifstream& input) {
points.push_back(Point_2(string2num<Number_type>(n1),
string2num<Number_type>(n2)));
}
for (int j = 0; j != number_of_vertex-1; j++) {
for (int j = 0; j < number_of_vertices-1 ; j++) {
segments.push_back(Segment_2(points[j], points[j+1]));
}
segments.push_back(Segment_2(points.front(), points.back()));
CGAL::insert(arr, segments.begin(), segments.end());
}
}
else {
std::cout<<"Can't open the file. Check the file name.";
@ -604,14 +608,14 @@ void benchmark_one_unit(Visibility_2_fst visibility_fst,
timer.start();
visibility_fst.attach(arr);
timer.stop();
std::cout << " Time to attach to first object: "
std::cout << "Time to attach to first object: "
<< GREEN << timer.time() << " sec" << RESET << std::endl;
timer.reset();
timer.start();
visibility_snd.attach(arr);
timer.stop();
std::cout << " Time to attach to second object: "
std::cout << "Time to attach to second object: "
<< GREEN << timer.time() << " sec" << RESET << std::endl;
typename Input_arrangement_2::Face_const_iterator fit;
@ -638,7 +642,8 @@ void benchmark_one_unit(Visibility_2_fst visibility_fst,
(he->source()->point(), he->target()->point());
break;
case FACE:
Ccb_halfedge_const_circulator curr_next = circ;
Ccb_halfedge_const_circulator curr_next = curr;
curr_next++;
Halfedge_const_handle he_next = curr_next;
Point_2 p1 = he->source()->point();
Point_2 p2 = he->target()->point();
@ -656,7 +661,7 @@ void benchmark_one_unit(Visibility_2_fst visibility_fst,
curr++;
continue;
}
std::cout << " Running with qpoint: "
std::cout << "Running with qpoint: "
<< RED << curr_query_pt << RESET << std::endl;
Input_arrangement_2 out_arr_fst, out_arr_snd;
timer.reset();
@ -670,7 +675,7 @@ void benchmark_one_unit(Visibility_2_fst visibility_fst,
}
timer.stop();
std::cout << " Time to compute visibility region using first object: "
std::cout << " Time to compute visibility region using first object: "
<< GREEN << timer.time() << " sec" << RESET << std::endl;
timer.reset();
@ -683,103 +688,44 @@ void benchmark_one_unit(Visibility_2_fst visibility_fst,
}
timer.stop();
std::cout << " Time to compute visibility region using second object: "
std::cout << " Time to compute visibility region using second object: "
<< GREEN << timer.time() << " sec" << RESET << std::endl;
// visibility_fst.print_arrangement(out_arr_fst);
// visibility_fst.print_arrangement(out_arr_snd);
assert(true == (CGAL::test_are_equal<Output_arrangement_2>
(out_arr_fst, out_arr_snd)));
} while (++curr != circ);
}
template<class Visibility_2_fst, class Visibility_2_snd>
void benchmark(Visibility_2_fst &visibility_fst,
Visibility_2_snd &visibility_snd,
const Query_choice &choice,
int case_number_simple,
int case_number_non_simple) {
Visibility_2_snd &visibility_snd,
const Query_choice &choice,
std::ifstream &input) {
typedef typename Visibility_2_fst::Input_arrangement_2
Input_arrangement_2;
typedef typename Input_arrangement_2::Halfedge_handle Halfedge_handle;
typedef typename Input_arrangement_2::Geometry_traits_2 Geometry_traits_2;
typedef typename Input_arrangement_2::Ccb_halfedge_circulator
Ccb_halfedge_circulator;
typedef typename Input_arrangement_2::Edge_iterator Edge_iterator;
typedef typename Geometry_traits_2::Point_2 Point_2;
typedef typename Geometry_traits_2::FT Number_type;
typedef typename Geometry_traits_2::Segment_2 Segment_2;
bool one_failed = false;
if (Visibility_2_fst::Supports_simple_polygon_tag::value
&& Visibility_2_snd::Supports_simple_polygon_tag::value) {
Input_arrangement_2 arr;
create_arrangement_from_env_file<Input_arrangement_2>(arr, input);
if (Visibility_2_fst::Supports_general_polygon_tag::value
&& Visibility_2_snd::Supports_general_polygon_tag::value) {
std::cout << "Benchmarking simple polygon test cases...\n";
for (int i = 1 ; i <= case_number_simple ; i++) {
std::string input_arr_file("data/test_simple_polygon_");
input_arr_file += num2string<int>(i);
input_arr_file += ".dat";
std::cout << " Benchmarking test "
<< GREEN << input_arr_file << RESET << std::endl;
std::ifstream input(input_arr_file.c_str());
std::string curr_line;
while (std::getline(input, curr_line)) {
if (curr_line[0] != '#' && curr_line[0] != '/')
break;
}
std::stringstream convert(curr_line);
std::string x, y;
convert >> x >> y;
Point_2 query_pt(string2num<Number_type>(x),
string2num<Number_type>(y));
std::getline(input, curr_line);
std::string x1, y1;
std::istringstream iss(curr_line);
iss >> x1 >> y1;
Point_2 reference_pt(string2num<Number_type>(x1),
string2num<Number_type>(y1));
std::getline(input, curr_line);
Input_arrangement_2 arr;
create_arrangement_from_dat_file<Input_arrangement_2>(input, arr);
// CGAL::Visibility_2::print_arrangement<Input_arrangement_2>(arr);
benchmark_one_unit<Visibility_2_fst, Visibility_2_snd>(visibility_fst,
visibility_snd,
arr,
choice);
}
benchmark_one_unit<Visibility_2_fst, Visibility_2_snd>(visibility_fst,
visibility_snd,
arr,
choice);
}
if (Visibility_2_fst::Supports_general_polygon_tag::value
&& Visibility_2_snd::Supports_general_polygon_tag::value) {
std::cout << "Benchmarking non-simple polygon test cases...\n";
for (int i = 1 ; i <= case_number_non_simple ; i++) {
std::string input_arr_file("data/test_non_simple_polygon_");
input_arr_file += num2string<int>(i);
input_arr_file += ".dat";
std::cout << " Running test "
<< GREEN << input_arr_file << RESET << std::endl;
std::ifstream input(input_arr_file.c_str());
std::string curr_line;
while (std::getline(input, curr_line)) {
if (curr_line[0] != '#' && curr_line[0] != '/')
break;
}
std::stringstream convert(curr_line);
std::string x, y;
convert >> x >> y;
Point_2 query_pt(string2num<Number_type>(x),
string2num<Number_type>(y));
std::getline(input, curr_line);
std::string x1, y1;
std::istringstream iss(curr_line);
iss >> x1 >> y1;
Point_2 reference_pt(string2num<Number_type>(x1),
string2num<Number_type>(y1));
std::getline(input, curr_line);
Input_arrangement_2 arr;
create_arrangement_from_dat_file<Input_arrangement_2>(input, arr);
benchmark_one_unit<Visibility_2_fst, Visibility_2_snd>(visibility_fst,
visibility_snd,
arr,
choice);
else { // Only run the benchmark on the outter loop of the arrangement
Edge_iterator eit;
Input_arrangement_2 arr_trimmed;
for (eit = arr.edges_end() ; eit != arr.edges_end() ; eit++) {
// Segment_2 seg =
}
}
}