/* ============================================================================= * coordinate_comparePair * -- For sorting in list of source/destination pairs * -- Route longer paths first so they are more likely to succeed * ============================================================================= */ long coordinate_comparePair (const void* aPtr, const void* bPtr) { double aDistance = getPairDistance((pair_t*)aPtr); double bDistance = getPairDistance((pair_t*)bPtr); if (aDistance < bDistance) { return 1; } else if (aDistance > bDistance) { return -1; } return 0; }
void IntervalManager::memorizeAction(std::pair<int, int>& pair, int costDiff) { int distance = getPairDistance(pair, dimension); for (Interval* interval : intervals) { if (distance < interval->getMaxDistance() && distance >= interval->getMinDistance()) { Action* action = new Action(pair, costDiff); interval->addAction(action); lastAction = action; } // Note: don't break, more than one interval might qualify } }
std::ostream& IntervalManager::outputDataCSV(std::ostream& out) { // prefix out << relation->getType() << "," << strategy->getType() << ","; // either 1st line data or current data if (!startedCSVOutput) { startedCSVOutput = true; // Interval data headers for (Interval* interval : intervals) { out << "[" << interval->getMinDistance() << ";" << interval->getMaxDistance() << "[,"; } // Last action headers out << "Last Action, ,"; out << "Range,"; out << "Cost diff,"; // Actions considered headers out << "Stats,"; out << "# of improving actions,"; out << "# of degrading actions,"; out << "ratio,"; } else { // Interval data for (Interval* interval : intervals) { out << interval->getActions().size() << ","; } // Last action data out << "Action:,"; const std::pair<int, int>& pair = lastAction->getPair(); out << "[" << pair.first << " <-> " << pair.second << "],"; out << getPairDistance(pair, dimension) << ","; out << lastAction->getCostDiff() << ","; // Actions considered stats out << "Stats:,"; out << strategicMemory->getNumberOfGoodActions() << ","; out << strategicMemory->getNumberOfBadActions() << ","; out << strategicMemory->getGoodToBadRatio() << ","; } out << std::endl; return out; }
Interval* IntervalManager::getInterval(const std::pair<int, int>& pair) { int distance = getPairDistance(pair, dimension); return getInterval(distance); }