AgentsSource.cpp 4.11 KB
Newer Older
1 2 3 4 5
/**
 * \file        AgentSource.cpp
 * \date        Apr 04, 2015
 * \version     v0.6
 * \copyright   <2009-2014> Forschungszentrum Jülich GmbH. All rights reserved.
6
 *
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 * \section License
 * This file is part of JuPedSim.
 *
 * JuPedSim is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * JuPedSim is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with JuPedSim. If not, see <http://www.gnu.org/licenses/>.
 *
 * \section Description
 * This class is responsible for materialising agent in a given location at a given frequency up to a maximum number.
 * The optimal position where to put the agents is given by various algorithms, for instance
 * the Voronoi algorithm or the Mitchell Best candidate algorithm.
 *
 **/
29 30 31

#include "AgentsSource.h"
#include "Pedestrian.h"
32
#include "StartDistribution.h"
33 34 35 36
#include "../IO/OutputHandler.h"

#include <iostream>

37
AgentsSource::AgentsSource(int id, const std::string& caption,int max_agents,int group_id,int frequency)
38 39 40 41 42 43
{
    _id=id;
    _caption=caption;
    _maxAgents=max_agents;
    _groupID=group_id;
    _frequency=frequency;
44
    _agentsGenerated=0;
45 46 47 48 49 50 51
    _agents.clear();
}

AgentsSource::~AgentsSource()
{
}

52
void AgentsSource::GenerateAgentsAndAddToPool(int count, Building* building)
53
{
54 55 56 57 58 59 60 61 62
     std::vector<Pedestrian*> peds;
     GenerateAgents(peds, count, building);
     _agents.insert(_agents.begin(),peds.begin(),peds.end());
     _agentsGenerated+=count;
}

void AgentsSource::RemoveAgentsFromPool(std::vector<Pedestrian*>& ped, int count)
{
     if((int)_agents.size()>=count)
63
     {
64 65
          ped.insert(ped.begin(),_agents.begin(),_agents.begin()+count);
          _agents.erase(_agents.begin(),_agents.begin()+count);
66 67 68 69 70 71 72 73 74 75 76 77 78
     }
     else
     {
          ped.insert(ped.begin(),_agents.begin(),_agents.end());
          _agents.clear();
     }
}

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

79
void AgentsSource::AddToPool(Pedestrian* ped)
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
{
     _agents.push_back(ped);
}

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

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

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

99 100 101 102 103 104 105 106
void AgentsSource::Setboundaries(double * bounds)
{
     _boundaries[0]=bounds[0];
     _boundaries[1]=bounds[1];
     _boundaries[2]=bounds[2];
     _boundaries[3]=bounds[3];
}

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
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;
}
131 132 133 134 135 136

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

137 138 139 140 141
int AgentsSource::GetGroupID() const
{
     return _groupID;
}

142 143 144 145 146
const std::shared_ptr<StartDistribution> AgentsSource::GetStartDistribution() const
{
     return _startDistribution;
}

147 148 149
void AgentsSource::GenerateAgents(std::vector<Pedestrian*>& peds, int count, Building* building)
{
     std::vector<Point> emptyPositions;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
150
     int pid=Pedestrian::GetAgentsCreated(); // will be discarded
151 152 153 154 155 156 157
     for(int i=0;i<count;i++)
     {
          peds.push_back(_startDistribution->GenerateAgent(building, &pid,emptyPositions));
     }
}


158 159 160 161 162 163 164 165
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);
166 167 168
     Log->Write("Agents Pool: %d", _agents.size());
     //getc(stdin);

169
}