[algorithms] Updated frechet and hausdorff distance algorithm

This commit is contained in:
Yaghyavardhan singh khangarot 2018-07-06 03:51:02 +05:30
parent 13f12035c8
commit dde8666d16
4 changed files with 8 additions and 317 deletions

View File

@ -18,7 +18,6 @@
#include <utility>
#include <vector>
#include <limits>
#include <initializer_list>
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/geometries/linestring.hpp>
@ -103,7 +102,7 @@ struct linestring_linestring
(std::max)(coup_matrix(i-1,j),dis);
else if(i>0 && j>0)
coup_matrix(i,j)=
(std::max)((std::min)({coup_matrix(i,j-1),coup_matrix(i-1,j),coup_matrix(i-1,j-1)}),dis);
(std::max)((std::min)(coup_matrix(i,j-1),(std::min)(coup_matrix(i-1,j),coup_matrix(i-1,j-1))),dis);
else
coup_matrix(i,j)=not_feasible;
}
@ -178,4 +177,4 @@ frechet_distance(Geometry1 const& g1, Geometry2 const& g2)
return frechet_distance(g1, g2, strategy_type());
}
}} // namespace boost::geometry
}} // namespace boost::geometry

View File

@ -140,12 +140,12 @@ struct range_multi_range
result_type dis_max=0;
for(size_type j=0;j<b;j++)
{
result_type dis_min;
dis_max =range_range::apply(rng,range::at(mrng,j),strategy);
if(dis_max > haus_dis)
{
haus_dis=dis_max;
}
result_type dis_min;
dis_max =range_range::apply(rng,range::at(mrng,j),strategy);
if(dis_max > haus_dis)
{
haus_dis=dis_max;
}
}
@ -275,4 +275,3 @@ hausdorff_distance(Geometry1 const& g1, Geometry2 const& g2)
}
}} // namespace boost::geometry

View File

@ -1,153 +0,0 @@
// Boost.Geometry
// Copyright (c) 2018 Yaghyavardhan Singh Khangarot, Hyderabad, India.
// Contributed and/or modified by Yaghyavardhan Singh Khangarot, as part of Google Summer of Code 2018 program.
// Use, modification and distribution is subject to 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)
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#ifndef BOOST_GEOMETRY_TEST_frechet_DISTANCE_HPP
#define BOOST_GEOMETRY_TEST_frechet_DISTANCE_HPP
#define BOOST_GEOMETRY_TEST_DEBUG
//#include <boost/test/unit_test.hpp>
#include <boost/test/floating_point_comparison.hpp>
#include "../../../include/boost/geometry/algorithms/frechet_distance.hpp"
#include <boost/geometry/io/wkt/wkt.hpp>
#include <boost/geometry/strategies/strategies.hpp>
#include <boost/variant/variant.hpp>
namespace bg = boost::geometry;
template <typename Geometry1,typename Geometry2>
void test_frechet_distance(Geometry1 const& geometry1,Geometry2 const& geometry2,
typename bg::distance_result
<
typename bg::point_type<Geometry1>::type,
typename bg::point_type<Geometry2>::type
>::type expected_frechet_distance )
{
using namespace bg;
typedef typename distance_result
<
typename point_type<Geometry1>::type,
typename point_type<Geometry2>::type
>::type result_type;
long double h_distance = bg::frechet_distance(geometry1,geometry2);
#ifdef BOOST_GEOMETRY_TEST_DEBUG
std::ostringstream out;
out << typeid(typename bg::coordinate_type<Geometry1>::type).name()
<< std::endl
<< typeid(typename bg::coordinate_type<Geometry2>::type).name()
<< std::endl
<< typeid(h_distance).name()
<< std::endl
<< "frechet_distance : " << bg::frechet_distance(geometry1,geometry2)
<< std::endl;
std::cout << out.str();
#endif
// BOOST_CHECK_CLOSE(h_distance, expected_frechet_distance, 0.0001);
}
template <typename Geometry1,typename Geometry2>
void test_geometry(std::string const& wkt1,std::string const& wkt2,
typename bg::distance_result
<
typename bg::point_type<Geometry1>::type,
typename bg::point_type<Geometry2>::type
>::type expected_frechet_distance)
{
Geometry1 geometry1;
bg::read_wkt(wkt1, geometry1);
Geometry2 geometry2;
bg::read_wkt(wkt2, geometry2);
test_frechet_distance(geometry1,geometry2,expected_frechet_distance);
#if !defined(BOOST_GEOMETRY_TEST_DEBUG)
test_hausdorff_distance(boost::variant<Geometry1>(geometry1),boost::variant<Geometry2>(geometry2), expected_hausdorff_distance);
#endif
}
template <typename Geometry1,typename Geometry2 ,typename Strategy>
void test_frechet_distance(Geometry1 const& geometry1,Geometry2 const& geometry2,Strategy strategy,
typename bg::distance_result
<
typename bg::point_type<Geometry1>::type,
typename bg::point_type<Geometry2>::type,
Strategy
>::type expected_frechet_distance )
{
using namespace bg;
typedef typename distance_result
<
typename point_type<Geometry1>::type,
typename point_type<Geometry2>::type,
Strategy
>::type result_type;
long double h_distance = bg::frechet_distance(geometry1,geometry2,strategy);
#ifdef BOOST_GEOMETRY_TEST_DEBUG
std::ostringstream out;
out << typeid(typename bg::coordinate_type<Geometry1>::type).name()
<< std::endl
<< typeid(typename bg::coordinate_type<Geometry2>::type).name()
<< std::endl
<< typeid(h_distance).name()
<< std::endl
<< "frechet_distance : " << bg::frechet_distance(geometry1,geometry2,strategy)
<< std::endl;
std::cout << out.str();
#endif
//BOOST_CHECK_CLOSE(h_distance, expected_frechet_distance, 0.0001);
}
template <typename Geometry1,typename Geometry2,typename Strategy>
void test_geometry(std::string const& wkt1,std::string const& wkt2,Strategy strategy,
typename bg::distance_result
<
typename bg::point_type<Geometry1>::type,
typename bg::point_type<Geometry2>::type,
Strategy
>::type expected_frechet_distance)
{
Geometry1 geometry1;
bg::read_wkt(wkt1, geometry1);
Geometry2 geometry2;
bg::read_wkt(wkt2, geometry2);
test_frechet_distance(geometry1,geometry2,strategy,expected_frechet_distance);
#if !defined(BOOST_GEOMETRY_TEST_DEBUG)
test_frechet_distance(boost::variant<Geometry1>(geometry1),boost::variant<Geometry2>(geometry2),strategy, expected_hausdorff_distance);
#endif
}
template <typename Geometry1,typename Geometry2>
void test_empty_input(Geometry1 const& geometry1,Geometry2 const& geometry2)
{
try
{
bg::frechet_distance(geometry1,geometry2);
}
catch(bg::empty_input_exception const& )
{
return;
}
//BOOST_CHECK_MESSAGE(false, "A empty_input_exception should have been thrown" );
}
#endif

View File

@ -1,154 +0,0 @@
// Boost.Geometry
// Copyright (c) 2018 Yaghyavardhan Singh Khangarot, Hyderabad, India.
// Contributed and/or modified by Yaghyavardhan Singh Khangarot, as part of Google Summer of Code 2018 program.
// Use, modification and distribution is subject to 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)
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#ifndef BOOST_GEOMETRY_TEST_HAUSDORFF_DISTANCE_HPP
#define BOOST_GEOMETRY_TEST_HAUSDORFF_DISTANCE_HPP
//#include <boost/test/unit_test.hpp>
#include <boost/test/floating_point_comparison.hpp>
#include "../../../include/boost/geometry/algorithms/hausdorff_distance.hpp"
#include <boost/geometry/io/wkt/wkt.hpp>
#include <boost/geometry/strategies/strategies.hpp>
#include <boost/variant/variant.hpp>
#include <boost/mpl/if.hpp>
namespace bg = boost::geometry;
template <typename Geometry1,typename Geometry2>
void test_hausdorff_distance(Geometry1 const& geometry1,Geometry2 const& geometry2,
typename bg::distance_result
<
typename bg::point_type<Geometry1>::type,
typename bg::point_type<Geometry2>::type
>::type expected_hausdorff_distance )
{
using namespace bg;
typedef typename distance_result
<
typename point_type<Geometry1>::type,
typename point_type<Geometry2>::type
>::type result_type;
long double h_distance = bg::hausdorff_distance(geometry1,geometry2);
#ifdef BOOST_GEOMETRY_TEST_DEBUG
std::ostringstream out;
out << typeid(typename bg::coordinate_type<Geometry1>::type).name()
<< std::endl
<< typeid(typename bg::coordinate_type<Geometry2>::type).name()
<< std::endl
<< typeid(h_distance).name()
<< std::endl
<< "hausdorff_distance : " << bg::hausdorff_distance(geometry1,geometry2)
<< std::endl;
std::cout << out.str();
#endif
// BOOST_CHECK_CLOSE(h_distance, expected_hausdorff_distance, 0.0001);
}
template <typename Geometry1,typename Geometry2>
void test_geometry(std::string const& wkt1,std::string const& wkt2,
typename bg::distance_result
<
typename bg::point_type<Geometry1>::type,
typename bg::point_type<Geometry2>::type
>::type expected_hausdorff_distance)
{
Geometry1 geometry1;
bg::read_wkt(wkt1, geometry1);
Geometry2 geometry2;
bg::read_wkt(wkt2, geometry2);
test_hausdorff_distance(geometry1,geometry2,expected_hausdorff_distance);
#if !defined(BOOST_GEOMETRY_TEST_DEBUG)
test_hausdorff_distance(boost::variant<Geometry1>(geometry1),boost::variant<Geometry2>(geometry2), expected_hausdorff_distance);
#endif
}
template <typename Geometry1,typename Geometry2 ,typename Strategy>
void test_hausdorff_distance(Geometry1 const& geometry1,Geometry2 const& geometry2,Strategy strategy,
typename bg::distance_result
<
typename bg::point_type<Geometry1>::type,
typename bg::point_type<Geometry2>::type,
Strategy
>::type expected_hausdorff_distance )
{
using namespace bg;
typedef typename distance_result
<
typename point_type<Geometry1>::type,
typename point_type<Geometry2>::type,
Strategy
>::type result_type;
long double h_distance = bg::hausdorff_distance(geometry1,geometry2,strategy);
#ifdef BOOST_GEOMETRY_TEST_DEBUG
std::ostringstream out;
out << typeid(typename bg::coordinate_type<Geometry1>::type).name()
<< std::endl
<< typeid(typename bg::coordinate_type<Geometry2>::type).name()
<< std::endl
<< typeid(h_distance).name()
<< std::endl
<< "hausdorff_distance : " << bg::hausdorff_distance(geometry1,geometry2,strategy)
<< std::endl;
std::cout << out.str();
#endif
//BOOST_CHECK_CLOSE(h_distance, expected_hausdorff_distance, 0.0001);
}
template <typename Geometry1,typename Geometry2,typename Strategy>
void test_geometry(std::string const& wkt1,std::string const& wkt2,Strategy strategy,
typename bg::distance_result
<
typename bg::point_type<Geometry1>::type,
typename bg::point_type<Geometry2>::type,
Strategy
>::type expected_hausdorff_distance)
{
Geometry1 geometry1;
bg::read_wkt(wkt1, geometry1);
Geometry2 geometry2;
bg::read_wkt(wkt2, geometry2);
test_hausdorff_distance(geometry1,geometry2,strategy,expected_hausdorff_distance);
#if !defined(BOOST_GEOMETRY_TEST_DEBUG)
test_hausdorff_distance(boost::variant<Geometry1>(geometry1),boost::variant<Geometry2>(geometry2),strategy, expected_hausdorff_distance);
#endif
}
template <typename Geometry1,typename Geometry2>
void test_empty_input(Geometry1 const& geometry1,Geometry2 const& geometry2)
{
try
{
bg::hausdorff_distance(geometry1,geometry2);
}
catch(bg::empty_input_exception const& )
{
return;
}
//BOOST_CHECK_MESSAGE(false, "A empty_input_exception should have been thrown" );
}
#endif