AgentsSourcesManager.cpp 1.58 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
/*
 * AgentsSourcesManager.cpp
 *
 *  Created on: 14.04.2015
 *      Author: piccolo
 */

#include "AgentsSourcesManager.h"
#include "Pedestrian.h"
#include "AgentsQueue.h"
#include "AgentsSource.h"
#include <iostream>
#include <thread>
#include <chrono>

using namespace std;

AgentsSourcesManager::AgentsSourcesManager()
{

}

AgentsSourcesManager::~AgentsSourcesManager()
{
}

void AgentsSourcesManager::operator()(int value)
{
     //the loop is updated each second.
     //it might be better to use a timer
     bool finished=false;

     do
     {
          finished=true;
          for (const auto& src: _sources)
          {
               if(src->GetPoolSize())
               {
                    vector<Pedestrian*> peds;
                    src->GenerateByFrequency(peds);
                    AgentsQueue::Add(peds);

                    // compute the optimal position for insertion
                    for (auto&& ped: peds)
                    {
                         ped->SetPos(Point(15,15),true);
                    }
                    finished=false;
                    cout<<"Agents generated: "<<peds.size()<<endl;
               }
               //src->Dump();
          }
          //cout<<"Number of sources: "<<_sources.size()<<endl;

          //wait one second
          std::this_thread::sleep_for(std::chrono::milliseconds(1000));
     }while (!finished);
}

void AgentsSourcesManager::AddSource(std::shared_ptr<AgentsSource> src)
{
     _sources.push_back(src);
}

const std::vector<std::shared_ptr<AgentsSource> >& AgentsSourcesManager::GetSources() const
{
     return _sources;
}