Exemple #1
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;
};
Exemple #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);
};
Exemple #3
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;
};	
Exemple #4
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_];

};
FPType DescDirectionPathISP::calculateDerivative(Path* path) const{
	FPType der = 0.0;
	FPType flow = 0.0;
	for (StarLinkIterator it = path->begin(); it != path->end(); ++it) {
    StarLink* link = *it;
		flow = link->getFlow();
		if (flow < slope_) {
			flow = slope_;
		} 
		der +=  link->getDerivative();
	}
	return der;
};
Exemple #6
0
void ODSet::projectPathFlowOnLinks(){
	
	FPType flow = 0.0;
	for (PathIterator pathIt = begin(); pathIt != end(); ++pathIt) {
		Path* path = *pathIt;
		flow = path->getFlow() - path->getPrevFlow();
		if (fabs(flow) > zeroFlow_) {
			for (StarLinkIterator it = path->begin(); it != path->end(); ++it) {
				(*it)->addFlow(flow);
			}
		}
	}
	for (PathIterator pathIt = begin(); pathIt != end(); ++pathIt) {
		Path* path = *pathIt;
		for (StarLinkIterator it = path->begin(); it != path->end(); ++it) {
			StarLink* link = *it;
			if (link->getFlow() < zeroFlow_) {
					link->setFlow(0.0);
			}
			link->updateTime();
		}
	}

};