brute_force.cpp
Go to the documentation of this file.
1 //=============================================================================
2 // Copyright (C) 2021-2024 Wageningen University - All Rights Reserved
3 // Author: Gonzalo Mier
4 // BSD-3 License
5 //=============================================================================
6 
7 #include <algorithm>
8 #ifdef ALLOW_PARALLELIZATION
9 #include <execution>
10 #endif
11 #include <vector>
12 #include <utility>
13 #include <limits>
15 
16 namespace f2c::sg {
17 
18 double BruteForce::getStepAngle() const {
19  return this->step_angle;
20 }
21 
22 void BruteForce::setStepAngle(double d) {
23  this->step_angle = d;
24 }
25 
27  double op_width, const F2CCell& poly) {
28  int n = static_cast<int>(
29  boost::math::constants::two_pi<double>() / step_angle);
30  std::vector<double> costs(n);
31  std::vector<int> ids(n);
32  std::iota(ids.begin(), ids.end(), 0);
33 
34  auto getCostSwaths = [this, op_width, &poly, &obj] (const int& i) {
35  return computeCostOfAngle(obj, i * step_angle, op_width, poly);
36  };
37 
38  #ifdef ALLOW_PARALLELIZATION
39  std::transform(std::execution::par_unseq, ids.begin(), ids.end(),
40  costs.begin(), getCostSwaths);
41  #else
42  std::transform(ids.begin(), ids.end(), costs.begin(), getCostSwaths);
43  #endif
44 
45  return ids[std::min_element(
46  costs.begin(), costs.end()) - costs.begin()] * step_angle;
47 }
48 
49 } // namespace f2c::sg
50 
f2c::sg::BruteForce::setStepAngle
void setStepAngle(double d)
Definition: brute_force.cpp:22
brute_force.h
f2c::obj::SGObjective
Base class for objective functions of swath generators.
Definition: sg_objective.h:21
f2c::types::Cell
Definition: Cell.h:32
7_decomposition.obj
obj
Definition: 7_decomposition.py:32
f2c::sg::BruteForce::computeBestAngle
double computeBestAngle(f2c::obj::SGObjective &obj, double op_width, const F2CCell &poly) override
Definition: brute_force.cpp:26
f2c::sg
Swath generator algorithms' namespace.
Definition: brute_force.h:18
f2c::sg::SwathGeneratorBase::computeCostOfAngle
virtual double computeCostOfAngle(f2c::obj::SGObjective &obj, double ang, double op_width, const F2CCell &poly)
Definition: swath_generator_base.cpp:65
f2c::sg::BruteForce::step_angle
double step_angle
Definition: brute_force.h:29
f2c::sg::BruteForce::getStepAngle
double getStepAngle() const
Definition: brute_force.cpp:18


fields2cover
Author(s):
autogenerated on Fri Apr 25 2025 02:18:31