Line data Source code
1 : #include "Dynamic/Demand/UniformDemandLoader.hpp" 2 : 3 : #include <iostream> 4 : #include <random> 5 : 6 : #include "Alg/ShortestPath/Dijkstra.hpp" 7 : #include "Alg/ShortestPath/DijkstraMany.hpp" 8 : #include "Dynamic/Env/Edge.hpp" 9 : #include "Dynamic/Env/Env.hpp" 10 : #include "Dynamic/Policy/RandomPolicy.hpp" 11 : #include "Dynamic/SUMOAdapter.hpp" 12 : #include "Static/supply/Network.hpp" 13 : 14 : using namespace std; 15 : using namespace Dynamic; 16 : 17 0 : UniformDemandLoader::UniformDemandLoader( 18 : double scale_, 19 : Time beginTime_, 20 : Time endTime_, 21 : Policy::Factory &policyFactory_, 22 : random_device::result_type seed 23 0 : ): 24 : scale(scale_), 25 : beginTime(beginTime_), 26 : endTime(endTime_), 27 : policyFactory(policyFactory_), 28 0 : gen(seed) {} 29 : 30 0 : pair<Demand, Vehicle::ID> UniformDemandLoader::load( 31 : const Static::Demand &staticDemand, 32 : Env::Env &env, 33 : const Dynamic::SUMOAdapter &sumoAdapter, 34 : Vehicle::ID nextID 35 : ) { 36 0 : Demand demand; 37 : 38 0 : uniform_real_distribution<> dist(0, 1); 39 : 40 0 : for(const Static::Network::Node &u: staticDemand.getStartNodes()) { 41 0 : for(const Static::Network::Node &v: staticDemand.getDestinations(u)) { 42 0 : Static::Flow f = staticDemand.getDemand(u, v); 43 0 : Dynamic::Time Dt = 1 / (f * scale); 44 : 45 0 : SUMO::TAZ::ID fromTAZ = sumoAdapter.toSumoTAZ(u); 46 0 : SUMO::TAZ::ID toTAZ = sumoAdapter.toSumoTAZ(v); 47 : 48 0 : Env::TAZ &envFromTAZ = env.getTAZ(sumoAdapter.toTAZ(fromTAZ)); 49 0 : Env::TAZ &envToTAZ = env.getTAZ(sumoAdapter.toTAZ(toTAZ)); 50 : 51 0 : for(Time t = beginTime + Dt * dist(gen); t < endTime; t += Dt) { 52 0 : Vehicle::ID id = nextID++; 53 : 54 0 : shared_ptr<Policy> policy = policyFactory.create( 55 : id, 56 : t, 57 : envFromTAZ, 58 : envToTAZ 59 0 : ); 60 : 61 0 : demand.addVehicle( 62 : id, 63 : t, 64 : envFromTAZ, 65 : envToTAZ, 66 : policy 67 0 : ); 68 : } 69 : } 70 : } 71 : 72 0 : return {demand, nextID}; 73 : }