AgentsSource.cpp 2.37 KB
Newer Older
1 2 3 4 5 6 7 8 9
/*
 * AgentSource.cpp
 *
 *  Created on: 14.04.2015
 *      Author: piccolo
 */

#include "AgentsSource.h"
#include "Pedestrian.h"
10
#include "StartDistribution.h"
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
#include "../IO/OutputHandler.h"

#include <iostream>

AgentsSource::AgentsSource(int id,std::string caption,int max_agents,int group_id,int frequency)
{
    _id=id;
    _caption=caption;
    _maxAgents=max_agents;
    _groupID=group_id;
    _frequency=frequency;
    _agents.clear();
}

AgentsSource::~AgentsSource()
{
}

void AgentsSource::GenerateByFrequency(std::vector<Pedestrian*>& ped)
{
     if((int)_agents.size()>=_frequency)
     {
          ped.insert(ped.begin(),_agents.begin(),_agents.begin()+_frequency);
          _agents.erase(_agents.begin(),_agents.begin()+_frequency);
     }
     else
     {
          ped.insert(ped.begin(),_agents.begin(),_agents.end());
          _agents.clear();
     }
}

int AgentsSource::GetPoolSize() const
{
     return _agents.size();
}

void AgentsSource::Add(Pedestrian* ped)
{
     _agents.push_back(ped);
}

int AgentsSource::GetAgentsGenerated() const
{
     return _agentsGenerated;
}

void AgentsSource::SetAgentsGenerated(int agentsGenerated)
{
     _agentsGenerated = agentsGenerated;
}

const double* AgentsSource::GetBoundaries() const
{
     return _boundaries;
}

68 69 70 71 72 73 74 75
void AgentsSource::Setboundaries(double * bounds)
{
     _boundaries[0]=bounds[0];
     _boundaries[1]=bounds[1];
     _boundaries[2]=bounds[2];
     _boundaries[3]=bounds[3];
}

76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
const std::string& AgentsSource::GetCaption() const
{
     return _caption;
}

int AgentsSource::GetFrequency() const
{
     return _frequency;
}

int AgentsSource::GetGroupId() const
{
     return _groupID;
}

int AgentsSource::GetId() const
{
     return _id;
}

int AgentsSource::GetMaxAgents() const
{
     return _maxAgents;
}
100 101 102 103 104 105

void AgentsSource::SetStartDistribution(std::shared_ptr<StartDistribution> startDistribution)
{
     _startDistribution=startDistribution;
}

106 107 108 109 110
const std::shared_ptr<StartDistribution> AgentsSource::GetStartDistribution() const
{
     return _startDistribution;
}

111 112 113 114 115 116 117 118
void AgentsSource::Dump() const
{
     Log->Write("\n--------------------------");
     Log->Write("Dumping Source");
     Log->Write("ID: %d", _id);
     Log->Write("Group ID: %d", _groupID);
     Log->Write("Frequency: %d", _frequency);
     Log->Write("Agents Max: %d", _maxAgents);
119 120 121
     Log->Write("Agents Pool: %d", _agents.size());
     //getc(stdin);

122
}