12 void FrechetViewApplication::cli_setup(QString inputFile,
Algorithm algo)
15 std::cout <<
">>> Debug Build (don't use for serious benchmarks)." << std::endl;
19 QFileInfo file(inputFile);
20 reader.readAll(file.absoluteFilePath());
21 if (!reader.errorMessage().isEmpty()) {
22 std::string message = reader.errorMessage().toStdString();
23 throw std::runtime_error(message);
25 if (reader.getResults().size() < 2)
26 throw std::runtime_error(
"Input file with two curves expected.");
28 P = reader.getResults()[0].toCurve();
29 Q = reader.getResults()[1].toCurve();
31 auto fstring = inputFile.toLocal8Bit();
32 std::cout <<
" Input: " << fstring.data() << std::endl
33 <<
" Data: P=" << P.size() <<
" vertices. Q=" << Q.size() <<
" vertices. " << std::endl;
38 int FrechetViewApplication::cli_decideKFrechet(
double epsilon)
43 freeSpace->calculateFreeSpace(epsilon);
44 freeSpace->calculateBounds(epsilon);
55 return kAlgorithm::NO_SOLUTION;
61 std::cout <<
" Greedy Result: " 68 int FrechetViewApplication::commandLineInterface(QString inputFile,
70 double accuracy,
double epsilon)
throw(std::exception)
73 cli_setup(inputFile, algo);
84 std::cout <<
" Algorithm: Fréchet Distance for Curves. " <<std::endl;
87 polyAlgorithm->setup(P,Q,
true);
90 std::cout <<
" "<<
"Optimisation variant. "<<std::endl;
91 d_F = polyAlgorithm->optimiseCurve(0.0);
93 else if (accuracy > 0.0) {
94 std::cout <<
" "<<
"Approximation to "<<accuracy<<std::endl;
95 d_F = polyAlgorithm->optimiseCurve(accuracy);
97 else if (std::isnan(accuracy)) {
98 std::cout <<
" "<<
"Decision variant. Is d_F <= "<<epsilon<<
" ?"<<std::endl;
100 freeSpace->calculateFreeSpace(epsilon);
101 yes = (bool)polyAlgorithm->decideCurve(freeSpace,noPath,NAN,
true);
104 throw std::runtime_error(
"unexpected accuracy");
107 case ALGORITHM_POLYGON:
109 std::cout <<
" Algorithm: Fréchet Distance for Simple Polygons. "<<std::endl;
111 std::cout <<
" "<<
"Optimisation variant." << std::endl;
112 else if (accuracy > 0.0)
113 std::cout <<
" "<<
"Approximation to " << accuracy << std::endl;
114 else if (std::isnan(accuracy))
115 std::cout <<
" "<<
"Decision variant. Is d_F <= " << epsilon <<
" ?" << std::endl;
121 std::cout <<
" Info: Using extended floating point arithmetic " 122 <<
"("<< std::numeric_limits<accurate_float>::digits <<
" digits mantissa) for intermediate results." 126 switch(polyAlgorithm->status())
131 throw std::runtime_error(
"unexpected status "+polyAlgorithm->status());
135 throw std::runtime_error(
"Polygons must not be empty.");
139 throw std::runtime_error(
"Polygons must be closed. Use -curve instead.");
143 throw std::runtime_error(
"Polygons are not simple. Use -curve instead.");
147 throw std::runtime_error(
"Polygons are not counter-clockwise. This is a bug !");
151 throw std::runtime_error(
"One of the polyons is convex. Use -curve instead.");
155 d_F = polyAlgorithm->optimisePolygon(noPath);
157 else if (accuracy > 0.0) {
158 d_F = polyAlgorithm->optimisePolygon(noPath,accuracy);
160 else if (std::isnan(accuracy)) {
162 freeSpace->calculateFreeSpace(epsilon);
163 yes = (bool)polyAlgorithm->decidePolygon(freeSpace,noPath,epsilon,
true);
166 throw std::runtime_error(
"Unexpected accuracy");
169 case ALGORITHM_K_FRECHET:
170 if (!std::isnan(accuracy))
171 throw std::runtime_error(
"Optimisation variant not implemented for k-Fréchet algorithm.");
173 std::cout <<
" Algorithm: k-Fréchet Distance."<<std::endl
174 <<
" Calculate k for epsilon="<<epsilon << std::endl;
176 int k = cli_decideKFrechet(epsilon);
177 std::cout <<
" Result: ";
179 std::cout <<
"k = "<<k<<std::endl;
181 std::cout <<
"no solution."<<std::endl;
187 if (algo != ALGORITHM_K_FRECHET)
189 std::cout << std::fixed << std::setprecision(std::numeric_limits<double>::digits10);
190 if (!std::isnan(accuracy)) {
191 std::cout <<
" Result: d_F = " << d_F << std::endl;
194 std::cout <<
" Decision: YES. d_F <= " << epsilon << std::endl;
197 std::cout <<
" Decision: NO. d_F > " << epsilon << std::endl;
input data are faulty. Q is not a closed curve.
time_point printTimer(std::string label, bool do_print=true)
clock benchmark
const struct BruteForce & optimalResult() const
const fs::Components & components
connected components of the free-space diagram
input data have been successfully processed, the algorithm is now ready to execute
int k_optimal
optimal value so far
global definitions for all algorithms.
input data are faulty. P is convex.
Algorithm::ptr newPolyAlgorithm(bool topo)
factory method for creating a new algorithm object. Choose the appropriate implementation based on av...
Clock::time_point time_point
timestamp with high resolution
input data are faulty. P is not a oriented counter-clockwise.
input data are faulty. Q is not a simple polygon.
input data are faulty. P is not a simple polygon.
Algorithm
we have three Fréchet Distance algorithms
int runBruteForce(volatile bool *cancelFlag=0)
run the brute force algorithm. The greedy algorithm must have been run before!
int runGreedy()
run the greedy algorithm
long double accurate_float
time_point popTimer(std::string label, bool do_print=true)
clock benchmark and remove from stack
boost::shared_ptr< FSPath > ptr
smart pointer to an FSPath object
void calculateComponents(FreeSpace &fs)
calculate connected components
int k_max
upper bound derived from greedy results. k_max = min{greedy.k_xy,greedy.k_yx}
input data are faulty. Q is an empty curve.
The FreeSpace class models the Free-Space Diagram calculated from two curves.
input data are faulty. Q is not a oriented counter-clockwise.
input data are faulty. P is an empty curve.
int k_min
lower bound derived from greedy results. k_min = max{greedy.k_x,greedy.k_y}
input data are faulty. P is not a closed curve.
input data are faulty. Q is convex.
boost::shared_ptr< FreeSpace > ptr
smart pointer to FreeSpace object
void pushTimer()
start a new benchmark timer and push it to stack