12 #include <tracking/trackFindingCDC/numerics/Weight.h>
16 #include <type_traits>
24 namespace TrackFindingCDC {
27 template <
class AFrom,
class ATo = AFrom>
28 class WeightedRelation :
public std::pair<std::pair<AFrom*, Weight>, ATo*> {
31 using Super = std::pair<std::pair<AFrom*, Weight>, ATo*>;
50 bool operator<(
const WeightedRelation<From, To>& rhs)
const
52 return (
getFrom() < rhs.getFrom() or
57 (
getTo() < rhs.getTo())))));
61 friend bool operator<(
const std::pair<From*, Weight>& weightedPtr,
64 return (weightedPtr.first < weightedRelation.getFrom() or
65 (not(weightedRelation.getFrom() < weightedPtr.first) and
67 (weightedPtr.second > weightedRelation.getWeight())));
72 const std::pair<From*, Weight>& weightedPtr)
74 return (weightedRelation.getFrom() < weightedPtr.first or
75 (not(weightedPtr.first < weightedRelation.getFrom()) and
77 (weightedRelation.getWeight() > weightedPtr.second)));
83 return ptrFrom < weightedRelation.getFrom();
89 return weightedRelation.getFrom() < ptrFrom;
107 this->first.second = weight;
131 template <
class AFrom,
class ATo = AFrom>
138 template <
class AWeightedRelations>
139 static bool areSymmetric(
const AWeightedRelations& weightedRelations)
141 static_assert(std::is_same<AFrom, ATo>::value,
"Symmetric check requires some types in From and To");
142 assert(std::is_sorted(std::begin(weightedRelations), std::end(weightedRelations)));
143 auto reversedRelationExists =
145 auto reversedRelations = std::equal_range(std::begin(weightedRelations),
146 std::end(weightedRelations),
147 weightedRelation.reversed());
148 return reversedRelations.first != reversedRelations.second;
150 return std::all_of(std::begin(weightedRelations),
151 std::end(weightedRelations),
152 reversedRelationExists);