Esempio n. 1
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. 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
bool DAGraph::handleBackEdge(StarLink* link){
	std::cout << "Back egde detected in DAG Link = " <<  link->getIndex() << " oflow = " << 
		getOriginFlow(link->getIndex()) << link->toString() << std::endl;
	throw Error("Back egde detected in DAG"); 
	return true;
};