An initial benchmark program

This commit is contained in:
Andreas Fabri 2009-11-22 22:24:08 +00:00
parent 2dcfd2e49c
commit 679933b028
5 changed files with 40849 additions and 0 deletions

1
.gitattributes vendored
View File

@ -2935,6 +2935,7 @@ SearchStructures/doc_tex/SearchStructures_ref/segment_ex2.gif -text svneol=unset
SearchStructures/doc_tex/SearchStructures_ref/segment_ex2.pdf -text svneol=unset#application/pdf
SearchStructures/doc_tex/SearchStructures_ref/segment_ex4.gif -text svneol=unset#image/gif
SearchStructures/doc_tex/SearchStructures_ref/segment_ex4.pdf -text svneol=unset#application/pdf
Segment_Delaunay_graph_2/benchmark/Segment_Delaunay_graph_2/data/norway.cin -text
Segment_Delaunay_graph_2/doc_tex/Segment_Delaunay_graph_2/fig/norway.png -text
Segment_Delaunay_graph_2/doc_tex/Segment_Delaunay_graph_2/fig/svd.png -text
Segment_Delaunay_graph_2/doc_tex/Segment_Delaunay_graph_2/sdg-rep.fig -text svneol=unset#application/octet-stream

View File

@ -0,0 +1,32 @@
# Created by the script cgal_create_cmake_script
# This is the CMake script for compiling a CGAL application.
project( Segment_Delaunay_graph_2_example )
CMAKE_MINIMUM_REQUIRED(VERSION 2.4.5)
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
if ( COMMAND cmake_policy )
cmake_policy( SET CMP0003 NEW )
endif()
find_package(CGAL QUIET COMPONENTS Core )
if ( CGAL_FOUND )
include( ${CGAL_USE_FILE} )
include( CGAL_CreateSingleSourceCGALProgram )
# include_directories (BEFORE ../../include)
create_single_source_cgal_program( "benchmark.cpp" )
else()
message(STATUS "This program requires the CGAL library, and will not be compiled.")
endif()

View File

@ -0,0 +1,230 @@
// standard includes
#include <iostream>
#include <fstream>
#include <cassert>
#define USE_FILTERED_TRAITS
//#define USE_HIERARCHY
//#undef CGAL_USE_CORE
// choose the kernel
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Timer.h>
#ifdef CGAL_USE_CORE
# include <CGAL/CORE_Expr.h>
#endif
typedef CGAL::Simple_cartesian<double> K;
typedef K::Point_2 Point_2;
// typedefs for the traits and the algorithm
#include <CGAL/Segment_Delaunay_graph_hierarchy_2.h>
#include <CGAL/Segment_Delaunay_graph_filtered_traits_2.h>
#ifdef USE_FILTERED_TRAITS
#ifdef CGAL_USE_CORE
typedef CGAL::Field_with_sqrt_tag MTag;
typedef CGAL::Field_with_sqrt_tag EMTag;
typedef CGAL::Simple_cartesian<CORE::Expr> EK;
typedef CGAL::Segment_Delaunay_graph_filtered_traits_2<K, MTag, EK, EMTag> Gt;
#else
typedef CGAL::Segment_Delaunay_graph_filtered_traits_2<K> Gt;
//typedef CGAL::Segment_Delaunay_graph_filtered_traits_without_intersections_2<K> Gt;
#endif
#else
typedef CGAL::Segment_Delaunay_graph_traits_2<K,CGAL::Field_tag>Gt;
#endif
#ifdef USE_HIERARCHY
typedef CGAL::Segment_Delaunay_graph_hierarchy_2<Gt> SDG2;
#else
typedef CGAL::Segment_Delaunay_graph_2<Gt> SDG2;
#endif
typedef std::vector<Point_2> Points_container;
typedef Points_container::size_type Index_type;
typedef std::pair<Index_type,Index_type> Constraint;
typedef std::vector<Constraint> Constraints_container;
Points_container points;
Constraints_container constraints;
SDG2 sdg;
std::vector<SDG2::Site_2> sites;
template <typename Kernel, typename Iterator>
struct Sort_traits_2 {
Kernel k;
Sort_traits_2 (const Kernel &kernel = Kernel())
: k (kernel)
{}
typedef Iterator Point_2;
struct Less_x_2 {
Kernel k;
Less_x_2 (const Kernel &kernel = Kernel())
: k (kernel)
{}
bool operator() (const Point_2 &p, const Point_2 &q) const
{
return k.less_x_2_object() (*p, *q);
}
};
Less_x_2
less_x_2_object() const
{
return Less_x_2(k);
}
struct Less_y_2 {
Kernel k;
Less_y_2 (const Kernel &kernel = Kernel())
: k (kernel)
{}
bool operator() (const Point_2 &p, const Point_2 &q) const
{
return k.less_y_2_object() (*p, *q);
}
};
Less_y_2
less_y_2_object() const
{
return Less_y_2(k);
}
};
template <typename SDG>
void
insert_constraints_using_spatial_sort(SDG& sdg)
{
typedef typename Points_container::const_iterator Points_iterator;
typedef std::vector<Points_iterator> Indices;
typedef std::vector<typename SDG::Vertex_handle> Vertices;
Sort_traits_2<K, Points_iterator> sort_traits;
Indices indices;
indices.reserve(points.size());
for(Points_iterator it = points.begin(); it != points.end(); ++it) {
indices.push_back(it);
}
std::random_shuffle(indices.begin(), indices.end());
CGAL::spatial_sort(indices.begin(), indices.end(),
sort_traits);
std::cerr << "Inserting points...";
CGAL::Timer timer;
timer.start();
Vertices vertices;
vertices.resize(points.size());
typename SDG::Vertex_handle hint;
for(typename Indices::const_iterator
pt_it_it = indices.begin(), end = indices.end();
pt_it_it != end; ++pt_it_it) {
typename SDG::Vertex_handle vh = sdg.insert(**pt_it_it, hint);
hint = vh;
vertices[*pt_it_it - points.begin()] = vh;
}
timer.stop();
std::cerr << " done (" << timer.time() << "s)\n";
std::cerr << "Inserting constraints...\n";
timer.reset();
timer.start();
for(typename Constraints_container::const_iterator
cit = constraints.begin(), end = constraints.end();
cit != end; ++cit) {
const typename SDG::Vertex_handle& v1 = vertices[cit->first];
const typename SDG::Vertex_handle& v2 = vertices[cit->second];
if(v1 != v2)
sdg.insert(v1, v2);
}
timer.stop();
std::cerr << " done (" << timer.time() << "s)\n";
}
bool
load_cin_file(std::istream& ifs) {
std::cerr << "Loading file... ";
CGAL::Timer timer;
timer.start();
bool not_first = false;
int n;
ifs >> n;
if(!ifs.good())
return false;
Point_2 p, q, qold;
char c;
int point_counter = 0;
while(ifs >> c >> p >> q) {
if(not_first && p == q) {
continue;
}
if(p == qold) {
points.push_back(q);
constraints.push_back(std::make_pair(point_counter-1, point_counter));
++point_counter;
}
else {
points.push_back(p);
points.push_back(q);
constraints.push_back(std::make_pair(point_counter, point_counter+1));
point_counter += 2;
}
qold = q;
not_first = true;
}
std::cerr << "done (" << timer.time() << "s)" << std::endl;
insert_constraints_using_spatial_sort(sdg);
return true;
}
void
load_sites(std::istream& ifs)
{
std::cerr << "Loading file... ";
SDG2::Site_2 site;
int n;
std::cin >> n;
// read the sites and insert them in the segment Delaunay graph
while ( std::cin >> site ) {
sites.push_back(site);
}
CGAL::Timer timer;
timer.start();
for(int i=0; i < sites.size(); i++){
sdg.insert(sites[i]);
}
timer.stop();
std::cerr << timer.time() << " sec.\nvalidity test:" << std::endl;
}
int main()
{
load_cin_file(std::cin);
// load_sites(std::cin);
if(! sdg.is_valid(true, 1) ){
std::cerr << "invalid data structure" << std::endl;
} else {
std::cerr << "valid data structure" << std::endl;
}
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
norway
17.5 sec Core, Filtered traits, hierarchy, intersections
8 sec Filtered traits, no hierarchy, spatial sort, intersections
It gets slower when I use the traits class without intersections,
probably because I don't know which kernel to choose.