Ejemplo n.º 1
0
FPType NonAdditivePC::calculate(Path *path, int odIndex) const{
	assert(path != NULL && odIndex >=0);
	TollType totalToll = 0;
	FPType totalTime = 0.0;
	for (StarLinkIterator it = path->begin(); it != path->end(); ++it) {
		StarLink* link = *it;
		totalTime += link->getTime();
		totalToll += tolls_[link->getIndex()];
	}
	return calculate(totalTime, totalToll, odIndex);
};
Ejemplo n.º 2
0
void DAGraph::printMaxShPath(int node){
	StarLink *prevMax = (nodes_[node])->maxLink;
	int prevNode = -1; 
	std::cout << "Cost = " << (nodes_[node])->maxDist << std::endl;
	FPType cost = 0.0;
	while (prevMax != NULL){
		prevNode = prevMax->getNodeFromIndex();
		cost += prevMax->getFlow() * prevMax->getTime();
		std::cout << "[" << prevMax->getNodeToIndex() << ", " << prevNode << "] " 
					<< prevMax->getFlow() << " - ";
		prevMax = (nodes_[prevNode])->maxLink;
	}
	std::cout << std::endl;
};	
Ejemplo n.º 3
0
void DAGraph::buildMinMaxTrees(int destIndex){
	int index = -1;

	for (int i = 0; i < nodeSize_; ++i) {
		index = nodeIndexes_[i];
		nodes_[index]->minDist = std::numeric_limits<FPType>::infinity( );
		nodes_[index]->maxDist = 0.0;
	}
	nodes_[originIndex_]->minDist = 0.0; // set to zero for origin 
	
	// find shortest and longest paths with positive flow
	FPType dist = 0.0;
	FPType time = 0.0;
	int i = beginAscPass();
	
	assert(originIndex_ == i); //-- TODO: theoretically there might be 
					// an alternative top order that starts with another node -- 
					// not clear what to do in this case
	StarLink* link = NULL;
	for (; i != -1; i = getNextAscPass()) {
		std::list<StarLink*> &linksList = nodes_[i]->incomeLinks;
		for (std::list<StarLink*>::iterator it = linksList.begin(); it != linksList.end(); ++it) {
			link = *it;
			index = link->getNodeFromIndex();
			assert(nodes_[index] != NULL);
			time = link->getTime();
			dist = nodes_[index]->minDist + time; // min dist
			if (dist < nodes_[i]->minDist) {
				nodes_[i]->minDist = dist;
				nodes_[i]->minLink = link; 
			}
			dist = nodes_[index]->maxDist + time; // max dist
			if (dist >= nodes_[i]->maxDist) {
				nodes_[i]->maxDist = dist;
				nodes_[i]->maxLink = link; 
			}
		}
		
		if (i == destIndex) break;
	}
};