Ejemplo n.º 1
0
void assignRndTolls(ShortestPath* shPath, int destIndex, TollContainerType& tolls, 
		FPType probabylity, TollType maxToll){
	StarLink *link = shPath->getInComeLink(destIndex);
	int nextDest = link->getNodeFromIndex();
	int linkIndex = -1;
	while (link != NULL) {
		linkIndex = link->getIndex();
		tolls[linkIndex] = getRndNumberWithProbability(tolls[linkIndex], probabylity, maxToll);
		nextDest = link->getNodeFromIndex();
		link = shPath->getInComeLink(nextDest);
	}
};
Ejemplo n.º 2
0
FPType Utils::checkFeasibility(StarNetwork *net, ODMatrix *mat){
	std::vector<FPType> total(net->getNbNodes());
	for (int i = 0; i < net->getNbNodes(); ++i) {
		total[i] = 0.0;
	}
	// load demands
	for (OriginIterator it = mat->begin(); it != mat->end(); ++it){
		Origin* origin = *it;
		for (PairODIterator jt = origin->begin(); jt != origin->end(); ++jt) {
			PairOD* dest = *jt;
			total[origin->getIndex()] += dest->getDemand();
			total[dest->getIndex()] -= dest->getDemand();
		}
	}
	
	//travers network and check
	for (StarLink *link = net->beginOnlyLink(); link != NULL; link = net->getNextOnlyLink()) {
		total[link->getNodeFromIndex()] -= link->getFlow();
		total[link->getNodeToIndex()] += link->getFlow();
	}
	FPType maxVal = 0.0;
	for (int i = 0; i < net->getNbNodes(); ++i) {
		if (fabs(total[i]) > maxVal) maxVal = fabs(total[i]);
	}
	return maxVal;
};
Ejemplo n.º 3
0
void KMLNetOutput::createKML(const std::string& fileWithNodes, const std::string& kmlFileName){

	std::cout << "KML will be written to: " << kmlFileName << std::endl;
	int nbNodes = net_->getNbNodes();
	std::vector<FPType> xCoord(nbNodes, 0);
	std::vector<FPType> yCoord(nbNodes, 0);
	std::vector<int> nodeID(nbNodes, 0);
	
	readCoord(fileWithNodes, xCoord, yCoord, nodeID);

	FileWriter writeKml(kmlFileName);
	writeKml.writeLine(createKmlHeader());
	
	for (StarLink* link = net_->beginOnlyLink(); link != NULL; link = net_->getNextOnlyLink()) {
		if (shouldCreatePlacemark(link)) {
			int tail = link->getNodeFromIndex();
			int head = link->getNodeToIndex();
			FPType x1 = xCoord[tail];
			FPType y1 = yCoord[tail];
			FPType x2 = xCoord[head];
			FPType y2 = yCoord[head];
			if (x1 == 0 && y1 == 0) std::cout << "Missing node coordinate: " << link->getNodeFrom() << 
								" link: " << link->toString() << std::endl; 
			if (x2 == 0 && y2 == 0) std::cout << "Missing node coordinate: " << link->getNodeTo() << 
								" link: " << link->toString() << std::endl;
			if (x1 != 0 && y1 != 0 && x2 != 0 && y2 != 0) 
				writeKml.writeLine(createPlacemark(x1, y1, x2, y2, link)); 
		}
	}

	writeKml.writeLine(createKmlFooter());
};
Ejemplo n.º 4
0
bool ODSet::improveSet(){
	shPath_->calculate(originIndex_, destIndex_, index_);
	FPType minDist = shPath_->getCost(destIndex_);
	if (minDist - minDist_ < -zeroFlow_) { // if we add link costs in different order path 
											// costs might not be the same
		Path *path = new Path();
		path->setCurrCost(minDist);
		StarLink *link = shPath_->getInComeLink(destIndex_);
		int nextDest = link->getNodeFromIndex();
		while (link != NULL) {
			path->addLinkToPath(link);
			nextDest = link->getNodeFromIndex();
			link = shPath_->getInComeLink(nextDest);
		}
		addPath(path);
		return true;
	}
	return false;
};
Ejemplo n.º 5
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.º 6
0
FPType DAGraph::checkOFlowsFeasibility(){
	int nbNodes = net_->getNbNodes(); 
	FPType total[nbNodes];
	for (int i = 0; i < nbNodes; ++i) {
		total[i] = 0.0;
	}
	// load demands
	for (OriginIterator it = mat_->begin(); it != mat_->end(); ++it){
		Origin* origin = *it;
		if (origin->getIndex() == originIndex_){
			for (PairODIterator jt = origin->begin(); jt != origin->end(); ++jt) {
				PairOD* dest = *jt;
				FPType demand = dest->getDemand();
				total[origin->getIndex()] += demand;
				total[dest->getIndex()] -= demand;
			}
			break;
		}
	}
	//travers network and check
	
	int i = -1;
	StarLink* link = NULL;
	std::list<StarLink*> inLinks;
	for (int j = 0; j < nodeSize_; ++j) {
    	i = nodeIndexes_[j];
    	getInLinks(i, inLinks);
    	for (std::list<StarLink*>::iterator it = inLinks.begin(); it != inLinks.end(); ++it){
      		link = *it;
			total[link->getNodeFromIndex()] -= getOriginFlow(link->getIndex());
			total[link->getNodeToIndex()] += getOriginFlow(link->getIndex());
		}
	
	}
	
	FPType max = 0.0;
		
	for (int i = 0; i < net_->getNbNodes(); ++i) {
		if (fabs(total[i]) > max) {	
			max = fabs(total[i]);
		}
	}
	return max;
};
Ejemplo n.º 7
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;
	}
};