Commit 1839e607 authored by Mohcine Chraibi's avatar Mohcine Chraibi

Solve #258

- Sources can define id and time to appear for one single agent
- Sources do not conflict with other distributed agents
- However, they could conflict with other sources with unspecified
- agent's id
parent 2975195d
Pipeline #5800 passed with stages
in 5 minutes and 16 seconds
...@@ -162,7 +162,23 @@ const std::shared_ptr<StartDistribution> AgentsSource::GetStartDistribution() co ...@@ -162,7 +162,23 @@ const std::shared_ptr<StartDistribution> AgentsSource::GetStartDistribution() co
void AgentsSource::GenerateAgents(std::vector<Pedestrian*>& peds, int count, Building* building) void AgentsSource::GenerateAgents(std::vector<Pedestrian*>& peds, int count, Building* building)
{ {
std::vector<Point> emptyPositions; std::vector<Point> emptyPositions;
int pid=Pedestrian::GetAgentsCreated(); // will be discarded int pid;
// if(this->GetAgentId() < 0)
// {
// // TODO: get the reserved ids by other sources
// std::vector<int> reserved_ids;
// for (const auto &source: _start_dis_sources)
// if(source->GetAgentId() >= 0)
// reserved_ids.push_back(source->GetAgentId());
// while( std::find(reserved_ids.begin(), reserved_ids.end(), pid) != reserved_ids.end() ){
// std::cout << "\n\nSOURCE SORRY " << pid << " is reserved!\n";
// pid += 1;
// }
// }
pid = (this->GetAgentId() >=0 )?this->GetAgentId() : Pedestrian::GetAgentsCreated() + building->GetAllPedestrians().size();
for(int i=0;i<count;i++) for(int i=0;i<count;i++)
{ {
peds.push_back(_startDistribution->GenerateAgent(building, &pid,emptyPositions)); peds.push_back(_startDistribution->GenerateAgent(building, &pid,emptyPositions));
......
...@@ -100,7 +100,7 @@ bool AgentsSourcesManager::ProcessAllSources() const ...@@ -100,7 +100,7 @@ bool AgentsSourcesManager::ProcessAllSources() const
{ {
bool empty=true; bool empty=true;
double current_time = Pedestrian::GetGlobalTime(); double current_time = Pedestrian::GetGlobalTime();
std::cout << "\n -- current time: " << current_time << std::endl; // std::cout << "\n -- current time: " << current_time << " number " << _building->GetAllPedestrians().size() << std::endl;
for (const auto& src : _sources) for (const auto& src : _sources)
{ {
if (src->GetPoolSize() && (src->GetPlanTime() <= current_time) )// maybe diff<eps if (src->GetPoolSize() && (src->GetPlanTime() <= current_time) )// maybe diff<eps
...@@ -116,7 +116,7 @@ bool AgentsSourcesManager::ProcessAllSources() const ...@@ -116,7 +116,7 @@ bool AgentsSourcesManager::ProcessAllSources() const
AgentsQueueIn::Add(peds); AgentsQueueIn::Add(peds);
empty = false; empty = false;
src->Dump(); //src->Dump();
} }
if (src->GetPlanTime() > current_time) // for the case we still expect if (src->GetPlanTime() > current_time) // for the case we still expect
// agents coming // agents coming
......
...@@ -598,8 +598,21 @@ vector<Point> PedDistributor::PossiblePositions(const SubRoom &r) { ...@@ -598,8 +598,21 @@ vector<Point> PedDistributor::PossiblePositions(const SubRoom &r) {
* */ * */
void PedDistributor::DistributeInSubRoom(int nAgents, vector<Point> &positions, int *pid, void PedDistributor::DistributeInSubRoom(int nAgents, vector<Point> &positions, int *pid,
StartDistribution *para, Building *building) const { StartDistribution *para, Building *building) const {
std::vector<int> reserved_ids;
for (const auto &source: _start_dis_sources) {
if(source->GetAgentId() >=0)
reserved_ids.push_back(source->GetAgentId());
}
// set the pedestrians // set the pedestrians
for (int i = 0; i < nAgents; ++i) { for (int i = 0; i < nAgents; ++i) {
// look for a not reserved id.
while( std::find(reserved_ids.begin(), reserved_ids.end(), *pid) != reserved_ids.end() ){
*pid += 1;
}
Pedestrian *ped = para->GenerateAgent(building, pid, positions); Pedestrian *ped = para->GenerateAgent(building, pid, positions);
building->AddPedestrian(ped); building->AddPedestrian(ped);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment