Ejemplo n.º 1
0
PathSet::PathSet(ODSetType setType, StarNetwork *net, ODMatrix *mat, ShortestPath *shPath,
			PathCost *pathCost, 
			FPType zeroFlow, PathBasedFlowMove* flowMove,  
			PathBasedFlowMoveWithStep* flowMoveWithStep, PathBasedFlowMoveGP* flowMoveGP,
			AONAssignment* aon) : 
			odSetList_(mat->getNbODPairs()),
			size_(mat->getNbODPairs()), currPath_(NULL),
			aon_(aon){

	int odIndex = -1;
	for (OriginIterator it = mat->begin(); it != mat->end(); ++it){
		Origin* origin = *it;
		for (PairODIterator jt = origin->begin(); jt != origin->end(); ++jt) {
			PairOD* dest = *jt;
			odIndex = dest->getODIndex();
			if (setType == PEAPP3) {
				odSetList_[odIndex] = new ODSet(odIndex, dest->getIndex(), origin->getIndex(),
												pathCost, net, shPath, 
					zeroFlow, flowMove);
			} else if (setType == WITH_STEP) {
				odSetList_[odIndex] = new ODSetWithStep(odIndex, dest->getIndex(), origin->getIndex(),
														pathCost, net, shPath, zeroFlow,
														flowMoveWithStep);
			} else if (setType == GPAPP3) {
				odSetList_[odIndex] = new ODSetGPApp3(odIndex, dest->getIndex(), origin->getIndex(),
													  pathCost, net, shPath, zeroFlow,
													  flowMoveGP, mat);
			} else {
				throw Error("Unexpected OD set type.");
			}
		}
	}
};
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 ODMatrix::print(){
	std::cout << "nb pairs = " << nbODPairs_ << std::endl;
	for (OriginIterator it = begin(); it != end(); ++it){
		Origin* origin = *it; 
		std::cout << "Origin: " << origin->getIndex() << std::endl;
		for (PairODIterator jt = origin->begin(); jt != origin->end(); ++jt) {
			PairOD* dest = *jt;
			dest->print();
		}
	};
};
Ejemplo n.º 4
0
void TollsManagement::generateRandomTollsOnShortestPath(TollContainerType& tolls, 
		FPType probabylity, TollType maxToll, ODMatrix* mat, ShortestPath *shPath){
	for (OriginIterator it = mat->begin(); it != mat->end(); ++it) {
		Origin* origin = *it;
		shPath->calculate(origin->getIndex());
		for (PairODIterator jt = origin->begin(); jt != origin->end(); ++jt) {
			if (Utils::generateRndNumber(1.0) <= probabylity) {
				PairOD* dest = *jt;
				assignRndTolls(shPath, dest->getIndex(), tolls, probabylity, maxToll);
			}
		}
		
	}
};
Ejemplo n.º 5
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.º 6
0
void ODMatrix::setIndexes(){
	int count = 0;
	int originIndex = -1;
	//
	for (OriginIterator it = begin(); it != end(); ++it){
		Origin* origin = *it; 
		originIndex = origin->getIndex(); 
		for (PairODIterator jt = origin->begin(); jt != origin->end(); ++jt) {
			PairOD* dest = *jt;
			dest->setODIndex(count);
			demandByIndex_.insert(std::make_pair<std::string, FPType>(
					createKey(originIndex, dest->getIndex()), 
							  dest->getDemand()));
			++count;
		}
	}
	nbODPairs_ = count;
	std::cout << "nbODPairs = " << nbODPairs_ << std::endl;	
};