generate-shapes/src/pfaedle/router/RoutingAttrs.h

68 lines
1.9 KiB
C
Raw Normal View History

2018-06-09 17:14:08 +02:00
// Copyright 2018, University of Freiburg,
// Chair of Algorithms and Data Structures.
// Authors: Patrick Brosi <brosi@informatik.uni-freiburg.de>
#ifndef PFAEDLE_ROUTER_ROUTINGATTRS_H_
#define PFAEDLE_ROUTER_ROUTINGATTRS_H_
#include <map>
#include <string>
#include "pfaedle/trgraph/EdgePL.h"
using pfaedle::trgraph::TransitEdgeLine;
namespace pfaedle {
namespace router {
struct RoutingAttrs {
RoutingAttrs() : fromString(""), toString(""), shortName(""), _simiCache() {}
std::string fromString;
std::string toString;
std::string shortName;
mutable std::map<const TransitEdgeLine*, double> _simiCache;
2019-02-03 12:48:48 +01:00
// carfull: lower return value = higher similarity
2018-06-09 17:14:08 +02:00
double simi(const TransitEdgeLine* line) const {
auto i = _simiCache.find(line);
if (i != _simiCache.end()) return i->second;
double cur = 1;
2019-02-03 12:48:48 +01:00
if (shortName.empty() || router::lineSimi(line->shortName, shortName) > 0.5)
cur -= 0.333333333;
2018-06-09 17:14:08 +02:00
2019-02-03 12:48:48 +01:00
if (toString.empty() || line->toStr.empty() ||
router::statSimi(line->toStr, toString) > 0.5)
cur -= 0.333333333;
2018-06-09 17:14:08 +02:00
2019-02-03 12:48:48 +01:00
if (fromString.empty() || line->fromStr.empty() ||
2018-06-09 17:14:08 +02:00
router::statSimi(line->fromStr, fromString) > 0.5)
2019-02-03 12:48:48 +01:00
cur -= 0.333333333;
2018-06-09 17:14:08 +02:00
_simiCache[line] = cur;
return cur;
}
};
inline bool operator==(const RoutingAttrs& a, const RoutingAttrs& b) {
return a.shortName == b.shortName && a.toString == b.toString &&
a.fromString == b.fromString;
}
inline bool operator!=(const RoutingAttrs& a, const RoutingAttrs& b) {
return !(a == b);
}
inline bool operator<(const RoutingAttrs& a, const RoutingAttrs& b) {
return a.fromString < b.fromString ||
(a.fromString == b.fromString && a.toString < b.toString) ||
(a.fromString == b.fromString && a.toString == b.toString &&
a.shortName < b.shortName);
}
} // namespace router
} // namespace pfaedle
#endif // PFAEDLE_ROUTER_ROUTINGATTRS_H_