void ROLogitCalculator::calculateProbabilities(std::vector<RORoute*> alternatives, const ROVehicle* const veh, const SUMOTime time) { const SUMOReal theta = myTheta >= 0 ? myTheta : getThetaForCLogit(alternatives); const SUMOReal beta = myBeta >= 0 ? myBeta : getBetaForCLogit(alternatives); if (beta > 0) { // calculate commonalities for (std::vector<RORoute*>::const_iterator i = alternatives.begin(); i != alternatives.end(); i++) { const RORoute* pR = *i; SUMOReal lengthR = 0; const std::vector<const ROEdge*>& edgesR = pR->getEdgeVector(); for (std::vector<const ROEdge*>::const_iterator edge = edgesR.begin(); edge != edgesR.end(); ++edge) { //@todo we should use costs here lengthR += (*edge)->getTravelTime(veh, STEPS2TIME(time)); } SUMOReal overlapSum = 0; for (std::vector<RORoute*>::const_iterator j = alternatives.begin(); j != alternatives.end(); j++) { const RORoute* pS = *j; SUMOReal overlapLength = 0.; SUMOReal lengthS = 0; const std::vector<const ROEdge*>& edgesS = pS->getEdgeVector(); for (std::vector<const ROEdge*>::const_iterator edge = edgesS.begin(); edge != edgesS.end(); ++edge) { lengthS += (*edge)->getTravelTime(veh, STEPS2TIME(time)); if (std::find(edgesR.begin(), edgesR.end(), *edge) != edgesR.end()) { overlapLength += (*edge)->getTravelTime(veh, STEPS2TIME(time)); } } overlapSum += pow(overlapLength / sqrt(lengthR * lengthS), myGamma); } myCommonalities[pR] = beta * log(overlapSum); } } for (std::vector<RORoute*>::iterator i = alternatives.begin(); i != alternatives.end(); i++) { RORoute* pR = *i; SUMOReal weightedSum = 0; for (std::vector<RORoute*>::iterator j = alternatives.begin(); j != alternatives.end(); j++) { RORoute* pS = *j; weightedSum += exp(theta * (pR->getCosts() - pS->getCosts() + myCommonalities[pR] - myCommonalities[pS])); } pR->setProbability(1. / weightedSum); } }
void ROGawronCalculator::calculateProbabilities(std::vector<RORoute*> alternatives, const ROVehicle* const /* veh */, const SUMOTime /* time */) { for (std::vector<RORoute*>::iterator i = alternatives.begin(); i != alternatives.end() - 1; i++) { RORoute* pR = *i; for (std::vector<RORoute*>::iterator j = i + 1; j != alternatives.end(); j++) { RORoute* pS = *j; // see [Gawron, 1998] (4.2) const SUMOReal delta = (pS->getCosts() - pR->getCosts()) / (pS->getCosts() + pR->getCosts()); // see [Gawron, 1998] (4.3a, 4.3b) SUMOReal newPR = gawronF(pR->getProbability(), pS->getProbability(), delta); SUMOReal newPS = pR->getProbability() + pS->getProbability() - newPR; if (ISNAN(newPR) || ISNAN(newPS)) { newPR = pS->getCosts() > pR->getCosts() ? (SUMOReal) 1. : 0; newPS = pS->getCosts() > pR->getCosts() ? 0 : (SUMOReal) 1.; } newPR = MIN2((SUMOReal) MAX2(newPR, (SUMOReal) 0), (SUMOReal) 1); newPS = MIN2((SUMOReal) MAX2(newPS, (SUMOReal) 0), (SUMOReal) 1); pR->setProbability(newPR); pS->setProbability(newPS); } } }