Esempio n. 1
0
void Utils::getDisjointLinks(Path *path1, Path *path2, std::list<StarLink*> &list, int nbLinks){
	std::vector<int> indexes(nbLinks);
	for (int i = 0; i < nbLinks; ++i) {
		indexes[i] = 0;
	}
	
	for (StarLinkIterator it = path1->begin(); it != path1->end(); ++it) {
		indexes[(*it)->getIndex()] = 1;
	}
	int index = -1;
	for (StarLinkIterator it = path2->begin(); it != path2->end(); ++it) {
		StarLink* link = *it;
		index = link->getIndex();
		if (indexes[index] == 0) {
			list.push_back(link);
		} else {
			indexes[index] = -1;
		}
	}
	for (StarLinkIterator it = path1->begin(); it != path1->end(); ++it) {
		StarLink* link = *it;
		if (indexes[link->getIndex()] == 1) {
			list.push_back(link);
		}
	}
	assert(!list.empty());
};
Esempio n. 2
0
FPType DAGraphBWithStep::calcFlowStep(Path* minPath, Path* maxPath) const{
	int nbLinks = net_->getNbLinks();
	std::vector<FPType> x(nbLinks);
	std::vector<FPType> y(nbLinks);
	std::vector<int> indexes(nbLinks);
	
	for(StarLinkIterator it = maxPath->begin(); it != maxPath->end(); ++it){
		y[(*it)->getIndex()] = 0.0;
	}
	for (StarLinkIterator it = minPath->begin(); it != minPath->end(); ++it) {
		y[(*it)->getIndex()] = 0.0;
	}
	
	int linkIndex = -1;
	int size = 0;
	
	// projecting path direction onto links
	FPType descDirection = minPath->getCurrCost() - maxPath->getCurrCost(); 

	FPType oFlow = 0.0;
	FPType maxPathFlow = std::numeric_limits<FPType>::infinity( ); 
	for(StarLinkIterator it = maxPath->begin(); it != maxPath->end(); ++it){
		StarLink* link = *it;
		linkIndex = link->getIndex();
		x[linkIndex] = link->getFlow();
		y[linkIndex] += descDirection;	
		indexes[size] = linkIndex;
		++size;
		oFlow = getOriginFlow(linkIndex);
		if (oFlow < maxPathFlow) maxPathFlow = oFlow;
	}
	if (maxPathFlow == 0.0) {
		return 0.0;
	}

	for (StarLinkIterator it = minPath->begin(); it != minPath->end(); ++it) {
		StarLink* link = *it;
		linkIndex = link->getIndex();
		x[linkIndex] = link->getFlow();
		y[linkIndex] -= descDirection; 
		indexes[size] = linkIndex;
		++size;
	}
	
	(lineSearch_->getDerivative())->setDataPointers(size, x, y, indexes);
	
	// calculating upper bound for line search
	FPType ub = -maxPathFlow / descDirection;
	assert(ub > 0.0);
	return (lineSearch_->execute(0.0, ub) * -descDirection);
};
Esempio n. 3
0
FPType PASWithStep::getFlowShift() {
    FPType x[nbLinks_];
    FPType y[nbLinks_];
    int indexes[nbLinks_];

    int size = 0;
    FPType dir[2];
    dir[cheapSegm_] = expCost_ - cheapCost_;
    dir[1 - cheapSegm_] = -dir[cheapSegm_];
    StarLink* link = NULL;
    int linkIndex = -1;
    for (int i = 0; i < 2; ++i) {
        for (std::list<StarLink*>::const_iterator it = segments_[i].begin();
                it != segments_[i].end(); ++it) {
            link = *it;
            linkIndex = link->getIndex();
            x[linkIndex] = link->getFlow();
            y[linkIndex] = dir[i];
            indexes[size] = linkIndex;
            ++size;
        }
    }
    (lineSearch_->getDerivative())->setDataPointers(size, x, y, indexes);
    return lineSearch_->execute(0.0, totalShift_ / dir[cheapSegm_]) * dir[cheapSegm_];

};
Esempio n. 4
0
bool DAGraph::explore(int vertex, bool *visited){
	
	visited[vertex] = true;
	preVisit(vertex);
	std::list<StarLink*> &linksList = (nodes_[vertex])->outLinks;
	int index = -1;
	bool backEdgeDetected = false;
	StarLink* link = NULL;
	for(std::list<StarLink*>::iterator it = linksList.begin(); it != linksList.end(); ++it){
		link = *it;
		index = link->getNodeToIndex();
		if (checkPositiveFlow(link->getIndex())) {
			handleExploredLink(link);
			if ((nodes_[index])->pre == 0) {
				backEdgeDetected = explore(index, visited);
				if (backEdgeDetected) return true;
			}
			if ((nodes_[index])->pre > 0 && (nodes_[index])->post == 0) {
				return handleBackEdge(link);
			}
		} 
	}
	postVisit(vertex);
	return false;
};
Esempio n. 5
0
void Utils::getCommonLinks(PathBasedFlowMove *paths, std::list<StarLink*> &list, int nbLinks){
	std::vector<int> indexes(nbLinks);
	std::vector<int> indexesTmp(nbLinks);
	std::vector<StarLink*> links(nbLinks);
	int size = 0;
	for (int i = 0; i < nbLinks; ++i) {
		indexes[i] = 0;
		indexesTmp[i] = 0;
		links[i] = NULL;
	}
	int index = -1;
	Path *path = NULL;
	int nbPaths = 0;
	for (PathAndDirection *pathDir = paths->beginPathDirection(); pathDir != NULL; 
			pathDir = paths->getNextPathDirection()) {
		path = pathDir->getPath();
		++nbPaths;
		for(StarLinkIterator it = path->begin(); it != path->end(); ++it){
			StarLink* link = *it;
			index = link->getIndex();
			if (indexes[index] == 0) {
				indexesTmp[size] = index;
				++size;
				links[index] = link;
			}
			++indexes[index];
		}
	}
	for (int i = 0; i < size; ++i) {
		index = indexesTmp[i];
		if (indexes[index] == nbPaths) {
			list.push_back(links[index]);
		}
	}
};
Esempio n. 6
0
int findLinkIndex(int tail, int head, StarNetwork* net, int guessIndex){
	StarLink* link = net->getLink(guessIndex);
	assert(link != NULL);
	if (link->getNodeFrom() == tail && link->getNodeTo() == head) {
		return link->getIndex();
	}
	return -1;
};
Esempio n. 7
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;
};
Esempio n. 8
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);
};
Esempio n. 9
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);
	}
};
Esempio n. 10
0
void LinkFlows::updateLinkFlows(){
	for (StarLink *link = net_->beginOnlyLink(); link != NULL; link = net_->getNextOnlyLink()) {
		link->setFlow(linkFlows_[link->getIndex()]);
		link->updateTime();
	}
};