33 #ifndef COSTS_EVALUATOR_H 34 #define COSTS_EVALUATOR_H 43 #include <eigen3/Eigen/Core> 57 template <
typename Lattice>
82 virtual void loadCostFunctions() = 0;
85 virtual void init(std::vector<std::shared_ptr<Lattice>>& _lattPtr) = 0;
91 virtual bool evalValidCostStep(
const CostEvaluatorCostType& _arrayType,
double _arcNow,
size_t& _violatingLatIdx,
95 virtual void computeScalarCost(
double& _f) = 0;
98 virtual void computeArrayCost(std::vector<double>& _arr,
const CostEvaluatorCostType& _arrayType) = 0;
103 computeScalarCost(f);
121 computeScalarCost(f);
129 if ((f > FLT_MAX) || (std::isnan(f)))
133 for (
const auto& hI : h)
144 bool gIsValid(
const double& _boxBound = 1e-2)
const 146 for (
const auto& gI : g)
148 if (fabs(gI) >= _boxBound)
157 bool gIsValid(
const size_t _Idx,
const double& _boxBound = 1e-2)
const 159 if (fabs(g[_Idx]) >= _boxBound)
170 std::vector<double>
h;
173 std::vector<double>
g;
185 template <
typename Lattice,
typename MapData>
210 void init(std::vector<std::shared_ptr<Lattice>>& _lattPtr)
override 212 for (
auto& partialCostsArrayI : partialCostsArray_)
214 partialCostsArrayI.clear();
216 this->loadCostFunctions();
217 for (
auto& funcI : partialCostsArray_)
219 for (
auto& partFuncI : funcI)
221 partFuncI->initLatticeMap(_lattPtr, mapDataPtr_);
231 for (
auto& partFuncI : funcI)
234 partFuncI->calcCostsFull();
241 for (
size_t k = 0; k < partFuncI->costsSize(); ++k)
243 _f += partFuncI->cost(k);
252 auto& funcI = partialCostsArray_[
asInt(_arrayType)];
253 for (
auto& partFuncI : funcI)
256 partFuncI->calcCostsFull();
261 for (
auto& partFuncI : partialCostsArray_[
asInt(_arrayType)])
263 arrSize += partFuncI->costsSize();
265 _arr.resize(arrSize);
269 for (; iP < partialCostsArray_[
asInt(_arrayType)].size(); ++iP)
271 for (
size_t k = 0; k < partialCostsArray_[
asInt(_arrayType)][iP]->costsSize(); ++k, ++iH)
273 _arr[iH] = partialCostsArray_[
asInt(_arrayType)][iP]->cost(k);
282 auto& funcI = partialCostsArray_[
asInt(_arrayType)];
283 for (
auto& partFuncI : funcI)
288 firstAfterReset_ =
true;
293 double& _arcMax)
override 295 if (firstAfterReset_)
298 auto& funcI = partialCostsArray_[
asInt(_arrayType)];
299 for (
auto& partFuncI : funcI)
303 firstAfterReset_ =
false;
307 auto& funcI = partialCostsArray_[
asInt(_arrayType)];
308 for (
auto& partFuncI : funcI)
310 partFuncI->resetNew();
313 double minCost = FLT_MAX;
314 double arcMin = FLT_MAX;
316 auto& funcI = partialCostsArray_[
asInt(_arrayType)];
317 for (
auto& partFuncI : funcI)
319 size_t k = partFuncI->iterIdxPartBegin_;
320 partFuncI->calcCosts1KnotStep(_arcNow);
321 size_t kend = std::min(k + 1, partFuncI->costsSize());
322 for (; k < kend; ++k)
324 const double& costK = partFuncI->cost(k);
327 double violLatNew = partFuncI->arcAtLattIdxPrev();
328 if ((minCost >= 0) || (violLatNew < arcMin))
332 _violatingLatIdx = partFuncI->knotLatIdx();
333 _arcMax = partFuncI->arcAtLattIdxPrev();
343 std::vector<std::vector<std::unique_ptr<cost_functions::CostsArrayLatBase<Lattice, MapData>>>>
partialCostsArray_;
359 #endif // COSTS_EVALUATOR_H
std::shared_ptr< MapData > mapDataPtr_
void init(std::vector< std::shared_ptr< Lattice >> &_lattPtr) override
bool evalValidCostStep(const CostEvaluatorCostType &_arrayType, double _arcNow, size_t &_violatingLatIdx, double &_arcMax) override
void resetCostFunctions(const CostEvaluatorCostType &_arrayType) override
void computeArrayCost(std::vector< double > &_arr, const CostEvaluatorCostType &_arrayType) override
constexpr auto asInt(Enumeration const value) -> typename std::underlying_type< Enumeration >::type
std::vector< std::vector< std::unique_ptr< cost_functions::CostsArrayLatBase< Lattice, MapData > > > > partialCostsArray_
std::shared_ptr< MapData > & mapDataPtr()
bool gIsValid(const double &_boxBound=1e-2) const
void computeScalarCost(double &_f)
bool gIsValid(const size_t _Idx, const double &_boxBound=1e-2) const
std::vector< double > gradF
CostsEvaluator(std::shared_ptr< MapData > &_mapDataPtr)