PedDistributor.cpp 25.5 KB
Newer Older
1
/**
Weichen's avatar
Weichen committed
2 3
 * \file        PedDistributor.cpp
 * \date        Oct 12, 2010
4
 * \version     v0.6
Weichen's avatar
Weichen committed
5
 * \copyright   <2009-2014> Forschungszentrum Jülich GmbH. All rights reserved.
Ulrich Kemloh's avatar
Ulrich Kemloh committed
6
 *
Weichen's avatar
Weichen committed
7
 * \section License
8 9 10
 * This file is part of JuPedSim.
 *
 * JuPedSim is free software: you can redistribute it and/or modify
Weichen's avatar
Weichen committed
11
 * it under the terms of the GNU Lesser General Public License as published by
12 13 14 15 16 17 18 19
 * 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.
 *
Weichen's avatar
Weichen committed
20
 * You should have received a copy of the GNU Lesser General Public License
21 22
 * along with JuPedSim. If not, see <http://www.gnu.org/licenses/>.
 *
Weichen's avatar
Weichen committed
23
 * \section Description
24 25
 *
 *
Weichen's avatar
Weichen committed
26
 **/
27 28


Mohcine Chraibi's avatar
Mohcine Chraibi committed
29
#include <cmath>
Ulrich Kemloh's avatar
Ulrich Kemloh committed
30
#include "PedDistributor.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
31
#include "../tinyxml/tinyxml.h"
32
#include "../geometry/Obstacle.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
33 34
#include "../routing/RoutingEngine.h"
#include "../pedestrian/Pedestrian.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
35 36
#include "../geometry/SubRoom.h"
#include "../IO/OutputHandler.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
37

38
using namespace std;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
39 40 41 42 43

/************************************************************
 PedDistributor
 ************************************************************/

44
PedDistributor::PedDistributor(const string& fileName, const std::map<int, std::shared_ptr<AgentsParameters> >& agentPars, unsigned int seed)
45
{
46 47
     _start_dis = vector<std::shared_ptr<StartDistribution> > ();
     _start_dis_sub = vector<std::shared_ptr<StartDistribution> > ();
48
     InitDistributor(fileName, agentPars, seed);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
49 50 51
}


52 53
PedDistributor::~PedDistributor()
{
54 55 56 57 58 59 60 61 62 63 64
//     for (unsigned int i = 0; i < _start_dis.size(); i++)
//     {
//          delete _start_dis[i];
//     }
//     for (unsigned int i = 0; i < _start_dis_sub.size(); i++)
//     {
//          delete _start_dis_sub[i];
//     }

//     _start_dis_sub.clear();
//     _start_dis.clear();
65 66 67 68 69
}

const vector<std::shared_ptr<AgentsSource> >& PedDistributor::GetAgentsSources() const
{
     return _start_dis_sources;
70 71
}

72
bool PedDistributor::InitDistributor(const string& fileName, const std::map<int, std::shared_ptr<AgentsParameters> >& agentPars, unsigned int seed)
73 74
{
     Log->Write("INFO: \tLoading and parsing the persons attributes");
Mohcine Chraibi's avatar
Mohcine Chraibi committed
75

76
     TiXmlDocument doc(fileName);
Mohcine Chraibi's avatar
Mohcine Chraibi committed
77

78 79 80
     if (!doc.LoadFile()) {
          Log->Write("ERROR: \t%s", doc.ErrorDesc());
          Log->Write("ERROR: \t could not parse the project file");
81
          return false;
82
     }
Mohcine Chraibi's avatar
Mohcine Chraibi committed
83 84


85 86 87
     TiXmlNode* xRootNode = doc.RootElement()->FirstChild("agents");
     if( ! xRootNode ) {
          Log->Write("ERROR:\tcould not load persons attributes");
88
          return false;
89 90 91 92 93 94 95 96
     }


     TiXmlNode* xDist=xRootNode->FirstChild("agents_distribution");
     for(TiXmlElement* e = xDist->FirstChildElement("group"); e;
               e = e->NextSiblingElement("group")) {

          int room_id = xmltoi(e->Attribute("room_id"));
Ulrich Kemloh's avatar
Ulrich Kemloh committed
97
          int group_id = xmltoi(e->Attribute("group_id"));
98 99
          int subroom_id = xmltoi(e->Attribute("subroom_id"),-1);
          int number = xmltoi(e->Attribute("number"),0);
100
          int agent_para_id= xmltoi(e->Attribute("agent_parameter_id"),-1);
101 102 103 104 105 106 107 108

          int goal_id = xmltoi(e->Attribute("goal_id"), FINAL_DEST_OUT);
          int router_id = xmltoi(e->Attribute("router_id"), -1);
          int route_id = xmltoi(e->Attribute("route_id"), -1);
          int age = xmltoi(e->Attribute("age"), -1);
          string gender = xmltoa(e->Attribute("gender"), "male");
          double height = xmltof(e->Attribute("height"), -1);
          double patience=  xmltof(e->Attribute("patience"), 5);
109 110
          double premovement_mean= xmltof(e->Attribute("pre_movement_mean"), 0);
          double premovement_sigma= xmltof(e->Attribute("pre_movement_sigma"), 0);
111 112
          double risk_tolerance_mean= xmltof(e->Attribute("risk_tolerance_mean"), 0);
          double risk_tolerance_sigma= xmltof(e->Attribute("risk_tolerance_sigma"), 0);
113

Ulrich Kemloh's avatar
Ulrich Kemloh committed
114 115 116 117 118 119 120 121 122
          double x_min=xmltof(e->Attribute("x_min"), -FLT_MAX);
          double x_max=xmltof(e->Attribute("x_max"), FLT_MAX);
          double y_min=xmltof(e->Attribute("y_min"), -FLT_MAX);
          double y_max=xmltof(e->Attribute("y_max"), FLT_MAX);
          double bounds [4] = {x_min,x_max,y_min,y_max};

          //sanity check
          if((x_max<x_min) || (y_max<y_min) ){
              Log->Write("ERROR:\tinvalid bounds [%0.2f,%0.2f,%0.2f,%0.2f] of the group [%d]. Max and Min values mismatched?",group_id,x_min,x_max,y_min,y_max);
123
              return false;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
124 125
          }

126
          auto dis=std::shared_ptr<StartDistribution> (new StartDistribution(seed) );
127
          dis->SetRoomID(room_id);
128 129
          dis->SetSubroomID(subroom_id);
          dis->SetGroupId(group_id);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
130
          dis->Setbounds(bounds);
131 132 133 134 135 136 137 138
          dis->SetAgentsNumber(number);
          dis->SetAge(age);
          dis->SetGender(gender);
          dis->SetGoalId(goal_id);
          dis->SetRouteId(route_id);
          dis->SetRouterId(router_id);
          dis->SetHeight(height);
          dis->SetPatience(patience);
139
          dis->InitPremovementTime(premovement_mean,premovement_sigma);
140
          dis->InitRiskTolerance(risk_tolerance_mean,risk_tolerance_sigma);
141

142 143 144 145 146 147
          if(subroom_id==-1) { // no subroom was supplied
               _start_dis.push_back(dis);
          } else {
               _start_dis_sub.push_back(dis);
          }

148
          if(agentPars.count(agent_para_id)==0)
149
          {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
150 151
              Log->Write("ERROR:\t Please specify which set of agents parameters (agent_parameter_id) to use for the group [%d]!",group_id);
              Log->Write("ERROR:\t Default values are not implemented yet");
152
              return false;
153
          }
154
          dis->SetGroupParameters(agentPars.at(agent_para_id).get());
155

156 157 158
          if(e->Attribute("start_x") && e->Attribute("start_y")) {
               double startX = xmltof(e->Attribute("start_x"),NAN);
               double startY = xmltof(e->Attribute("start_y"),NAN);
159
               Log->Write("INFO:\tstart_x = %f, start_y = %f\n", startX, startY);
160 161 162 163
               dis->SetStartPosition(startX,startY,0.0);
          }
     }

164
     //Parse the sources
165 166 167
     TiXmlNode* xSources=xRootNode->FirstChild("agents_sources");
     if(xSources)
          for(TiXmlElement* e = xSources->FirstChildElement("source"); e;
168 169 170 171 172 173 174 175 176 177 178 179
                    e = e->NextSiblingElement("source"))
          {

               int id = xmltoi(e->Attribute("id"),-1);
               int frequency = xmltoi(e->Attribute("frequency"),-1);
               int agents_max = xmltoi(e->Attribute("agents_max"),-1);
               int group_id = xmltoi(e->Attribute("group_id"),-1);
               string caption = xmltoa(e->Attribute("caption"),"no caption");

               //shared_ptr<AgentsSource> my_ptr(new classA);
               auto source= shared_ptr<AgentsSource>(new AgentsSource(id,caption,agents_max,group_id,frequency));
               _start_dis_sources.push_back(source);
180

181 182 183
               //look for the start distribution and populate the source

               Log->Write("INFO:\tSource with id %s will not be parsed !",e->Attribute("id"));
184 185 186
          }

     Log->Write("INFO: \t...Done");
187
     return true;
188 189
}

190
bool PedDistributor::Distribute(Building* building) const
191 192 193 194
{
     Log->Write("INFO: \tInit Distribute");
     int nPeds = 0;

195
     // store the position in a map since we are not computing for all rooms/subrooms.
Oliver Schmidts's avatar
Oliver Schmidts committed
196
     std::map <int, std::map <int, vector <Point> > > allFreePos;
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224

     //collect the available positions for that subroom
     for(const auto& dist: _start_dis_sub)
     {
          int roomID = dist->GetRoomId();
          Room* r = building->GetRoom(roomID);
          if(!r) return false;

          int subroomID = dist->GetSubroomID();
          SubRoom* sr = r->GetSubRoom(subroomID);
          if(!sr) return false;

          auto&  allFreePosRoom=allFreePos[roomID];
          // the positions were already computed
          if(allFreePosRoom.count(subroomID)>0)
               continue;

          allFreePosRoom[subroomID]=PedDistributor::PossiblePositions(*sr);
     }

     //collect the available positions for that room
     for(const auto& dist: _start_dis)
     {
          int roomID = dist->GetRoomId();
          Room* r = building->GetRoom(roomID);
          if(!r) return false;

          //compute all subrooms since no specific one is given
225
          for (const auto& it_sr: r->GetAllSubRooms())
226
          {
227
               int subroomID=it_sr.second->GetSubRoomID();
228 229 230 231 232
               auto&  allFreePosRoom=allFreePos[roomID];
               // the positions were already computed
               if(allFreePosRoom.count(subroomID)>0)
                    continue;

233
               allFreePosRoom[subroomID]=PedDistributor::PossiblePositions(*it_sr.second);
234 235 236
          }
     }

237 238

     // now proceed to the distribution
239 240
     int pid = 1; // the pedID is being increased throughout...

241 242 243
     for(const auto& dist: _start_dis_sub)
     {
          int room_id = dist->GetRoomId();
244 245 246
          Room* r = building->GetRoom(room_id);
          if(!r) continue;
          int roomID = r->GetID();
247 248 249 250
          int subroomID = dist->GetSubroomID();
          int N = dist->GetAgentsNumber();
          SubRoom* sr = r->GetSubRoom(subroomID);
          if(!sr) continue;
Mohcine Chraibi's avatar
Mohcine Chraibi committed
251

252
          if (N < 0) {
Mohcine Chraibi's avatar
Mohcine Chraibi committed
253
               Log->Write("ERROR: \t negative  number of pedestrians!");
254
               return false;
Mohcine Chraibi's avatar
Mohcine Chraibi committed
255
          }
256 257 258

          auto& allpos = allFreePos[roomID][subroomID];

259
          int max_pos = allpos.size();
260 261
          if (max_pos < N)
          {
262 263
               Log->Write("ERROR: \tCannot distribute %d agents in Room %d . Maximum allowed: %d\n",
                          N, roomID, allpos.size());
264
              return false;
265 266 267 268
          }

          // Distributing
          Log->Write("INFO: \tDistributing %d Agents in Room/Subrom [%d/%d]! Maximum allowed: %d", N, roomID, subroomID, max_pos);
269
          DistributeInSubRoom(sr, N, allpos, &pid,dist.get(),building);
270 271 272 273 274
          Log->Write("\t...Done");
          nPeds += N;
     }

     // then continue the distribution according to the rooms
275 276 277
     for(const auto& dist: _start_dis)
     {
          int room_id = dist->GetRoomId();
278 279
          Room* r = building->GetRoom(room_id);
          if(!r) continue;
280
          int N = dist->GetAgentsNumber();
281
          if (N < 0) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
282
               Log->Write("ERROR: \t negative or null number of pedestrians! Ignoring");
283 284 285 286 287 288 289 290 291 292
               continue;
          }

          double sum_area = 0;
          int max_pos = 0;
          double ppm; // pedestrians per square meter
          int ges_anz = 0;
          vector<int> max_anz = vector<int>();
          vector<int> akt_anz = vector<int>();

293
          auto&  allFreePosInRoom=allFreePos[room_id];
294 295 296 297 298 299 300 301 302 303
          for (int is = 0; is < r->GetNumberOfSubRooms(); is++) {
               SubRoom* sr = r->GetSubRoom(is);
               double area = sr->GetArea();
               sum_area += area;
               int anz = allFreePosInRoom[is].size();
               max_anz.push_back(anz);
               max_pos += anz;
          }
          if (max_pos < N) {
               Log->Write("ERROR: \t Distribution of %d pedestrians in Room %d not possible! Maximum allowed: %d\n",
304 305
                         N, r->GetID(), max_pos);
               return false;
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
          }
          ppm = N / sum_area;
          // Anzahl der Personen pro SubRoom bestimmen
          for (int is = 0; is < r->GetNumberOfSubRooms(); is++) {
               SubRoom* sr = r->GetSubRoom(is);
               int anz = sr->GetArea() * ppm + 0.5; // wird absichtlich gerundet
               while (anz > max_anz[is]) {
                    anz--;
               }
               akt_anz.push_back(anz);
               ges_anz += anz;
          }
          // Falls N noch nicht ganz erreicht, von vorne jeweils eine Person dazu
          int j = 0;
          while (ges_anz < N) {
               if (akt_anz[j] < max_anz[j]) {
                    akt_anz[j] = akt_anz[j] + 1;
                    ges_anz++;
               }
               j = (j + 1) % max_anz.size();
          }
          j = 0;
          while (ges_anz > N) {
               if (akt_anz[j] > 0) {
                    akt_anz[j] = akt_anz[j] - 1;
                    ges_anz--;
               }
               j = (j + 1) % max_anz.size();
          }
          // distributing
          for (unsigned int is = 0; is < akt_anz.size(); is++) {
               SubRoom* sr = r->GetSubRoom(is);
338 339 340 341
               //workaround, the subroom will be changing at each run.
               //so the last subroom ID is not necessarily the 'real' one
               // might conflicts with sources
               dist->SetSubroomID(sr->GetSubRoomID());
342
               if (akt_anz[is] > 0)
343
               {
344
                    DistributeInSubRoom(sr, akt_anz[is], allFreePosInRoom[is], &pid, dist.get(),building);
345
               }
346 347 348 349
          }
          nPeds += N;
     }

350 351 352 353 354 355 356 357
     //now populate the sources
     vector<Point> emptyPositions;
     for(const auto& source: _start_dis_sources)
     {
          for(const auto& dist: _start_dis_sub)
          {
               if(source->GetGroupId()==dist->GetGroupId())
               {
358
                    source->SetStartDistribution(dist);
359 360 361
                    for(int i=0;i<source->GetMaxAgents();i++)
                    {
                         source->Add(dist->GenerateAgent(building, &pid,emptyPositions));
362
                         nPeds++;
363 364 365 366 367 368 369 370 371
                    }
               }
               //cout<<"ID sub: "<<dist->GetGroupId()<<endl;
          }

          for(const auto& dist: _start_dis)
          {
               if(source->GetGroupId()==dist->GetGroupId())
               {
372
                    source->SetStartDistribution(dist);
373 374 375
                    for(int i=0;i<source->GetMaxAgents();i++)
                    {
                         source->Add(dist->GenerateAgent(building, &pid,emptyPositions));
376
                         nPeds++;
377 378 379 380 381
                    }
               }
               //cout<<"ID room: "<<dist->GetGroupId()<<endl;
          }
     }
382 383 384
     return nPeds;
}

385

Ulrich Kemloh's avatar
Ulrich Kemloh committed
386
vector<Point> PedDistributor::PositionsOnFixX(double min_x, double max_x, double min_y, double max_y,
387
          const SubRoom& r, double bufx, double bufy, double dy)
388 389 390 391 392 393 394 395 396
{
     vector<Point> positions;
     double x = (max_x + min_x)*0.5;
     double y = min_y;

     while (y < max_y) {
          Point pos = Point(x, y);
          // Abstand zu allen Wänden prüfen
          int k;
397 398
          for (k = 0; k < r.GetNumberOfWalls(); k++) {
               if (r.GetWall(k).DistTo(pos) < max(bufx, bufy) || !r.IsInSubRoom(pos)) {
399 400 401
                    break; // Punkt ist zu nah an einer Wand oder nicht im Raum => ungültig
               }
          }
402
          if (k == r.GetNumberOfWalls()) {
403 404
               //check all transitions
               bool tooNear=false;
405 406
               for(unsigned int t=0; t<r.GetAllTransitions().size(); t++) {
                    if(r.GetTransition(t)->DistTo(pos)<J_EPS_GOAL) {
407 408 409 410 411 412
                         //too close
                         tooNear=true;
                         break;
                    }
               }

413 414
               for(unsigned int c=0; c<r.GetAllCrossings().size(); c++) {
                    if(r.GetCrossing(c)->DistTo(pos)<J_EPS_GOAL) {
415 416 417 418 419 420 421 422 423 424
                         //too close
                         tooNear=true;
                         break;
                    }
               }
               if(tooNear==false) positions.push_back(pos);
          }
          y += dy;
     }
     return positions;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
425 426 427 428

}

vector<Point>PedDistributor::PositionsOnFixY(double min_x, double max_x, double min_y, double max_y,
429
          const SubRoom& r, double bufx, double bufy, double dx)
430 431 432 433 434 435 436 437 438
{
     vector<Point> positions;
     double y = (max_y + min_y)*0.5;
     double x = min_x;

     while (x < max_x) {
          Point pos = Point(x, y);
          // check distance to wall
          int k;
439 440
          for (k = 0; k < r.GetNumberOfWalls(); k++) {
               if (r.GetWall(k).DistTo(pos) < max(bufx, bufy) || !r.IsInSubRoom(pos)) {
441 442 443
                    break; // Punkt ist zu nah an einer Wand oder nicht im Raum => ungültig
               }
          }
444
          if (k == r.GetNumberOfWalls()) {
445 446
               //check all transitions
               bool tooNear=false;
447 448
               for(unsigned int t=0; t<r.GetAllTransitions().size(); t++) {
                    if(r.GetTransition(t)->DistTo(pos)<J_EPS_GOAL) {
449 450 451 452 453 454
                         //too close
                         tooNear=true;
                         break;
                    }
               }

455 456
               for(unsigned int c=0; c<r.GetAllCrossings().size(); c++) {
                    if(r.GetCrossing(c)->DistTo(pos)<J_EPS_GOAL) {
457 458 459 460 461 462 463 464 465 466
                         //too close
                         tooNear=true;
                         break;
                    }
               }
               if(tooNear==false) positions.push_back(pos);
          }
          x += dx;
     }
     return positions;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
467 468
}

469
vector<Point >  PedDistributor::PossiblePositions(const SubRoom& r)
470 471 472 473 474
{
     double uni = 0.7; // wenn ein Raum in x oder y -Richtung schmaler ist als 0.7 wird in der Mitte verteilt
     double bufx = 0.12;
     double bufy = 0.12;

475 476 477 478 479
     double amin=0.18; // = GetAmin()->GetMean();
     double bmax=0.25; // = GetBmax()->GetMean();

     double dx = amin + bufx;
     double dy = bmax + bufy;
480

481 482
     double max_buf=max(bufx, bufy);

483
     vector<double>::iterator min_x, max_x, min_y, max_y;
484 485
     const vector<Point>& poly = r.GetPolygon();
     vector<Point > all_positions;
486 487 488 489 490 491 492 493 494 495 496 497 498 499
     vector<double> xs;
     vector<double> ys;

     for (int p = 0; p < (int) poly.size(); ++p) {
          xs.push_back(poly[p].GetX());
          ys.push_back(poly[p].GetY());
     }

     min_x = min_element(xs.begin(), xs.end());
     max_x = max_element(xs.begin(), xs.end());
     min_y = min_element(ys.begin(), ys.end());
     max_y = max_element(ys.begin(), ys.end());

     if (*max_y - *min_y < uni) {
500
          all_positions = PositionsOnFixY(*min_x, *max_x, *min_y, *max_y, r, bufx, bufy, dx);
501
     } else if (*max_x - *min_x < uni) {
502
          all_positions = PositionsOnFixX(*min_x, *max_x, *min_y, *max_y, r, bufx, bufy, dy);
503 504 505
     } else {
          // create the grid
          double x = (*min_x);
506 507
          while (x < *max_x)
          {
508
               double y = (*min_y);
509 510
               while (y < *max_y)
               {
511 512 513 514
                    y += dy;
                    Point pos = Point(x, y);
                    bool tooNear=false;

515 516 517 518 519 520 521
                    //skip if the position is not in the polygon
                    if(!r.IsInSubRoom(pos)) continue;

                    // check the distance to all Walls
                    for (const auto & w : r.GetAllWalls())
                    {
                         if (w.DistTo(pos) < max_buf) {
522 523 524 525 526
                              tooNear=true;
                              break; // too close
                         }
                    }

527
                    //check the distance to all transitions
528
                    if(tooNear==true) continue;
529 530 531
                    for (const auto & t : r.GetAllTransitions())
                    {
                         if(t->DistTo(pos)<max_buf) {
532 533 534 535 536 537
                              //too close
                              tooNear=true;
                              break;
                         }
                    }

538
                    //  and check the distance to all crossings
539
                    if(tooNear==true) continue;
540 541 542
                    for (const auto & c : r.GetAllCrossings())
                    {
                         if(c->DistTo(pos)<max_buf) {
543 544 545 546 547 548
                              //too close
                              tooNear=true;
                              break;
                         }
                    }

549
                    // and finally the distance to all opened obstacles
550 551
                    if(tooNear==true) continue;

552 553 554 555 556
                    for (const auto & obst : r.GetAllObstacles())
                    {
                         for (const auto & wall : obst->GetAllWalls())
                         {
                              if (wall.DistTo(pos) < max_buf) {
557 558 559 560 561 562 563 564
                                   tooNear=true;
                                   break; // too close
                              }
                         }

                         //only continue if...
                         if(tooNear==true) continue;

565 566
                         if((obst->GetClosed()==1) && (obst->Contains(pos)==true))
                         {
567 568 569 570 571
                              tooNear=true;
                              break; // too close
                         }
                    }

572
                    if(tooNear==false) all_positions.push_back(pos);
573 574 575 576
               }
               x += dx;
          }
     }
577 578 579

     std::random_shuffle(all_positions.begin(), all_positions.end());
     return all_positions;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
}
/* Verteilt N Fußgänger in SubRoom r
 * Algorithms:
 *   - Lege Gitter von min_x bis max_x mit Abstand dx und entsprechend min_y bis max_y mit
 *     Abstand dy
 *   - Prüfe alle so enstandenen Gitterpunkte, ob ihr Abstand zu Wänden und Übergängen aus
 *     reicht
 *   - Wenn nicht verwerfe Punkt, wenn ja merke Punkt in Vector positions
 *   - Wähle zufällig einen Punkt aus dem Vektor aus Position der einzelnen Fußgänger
 * Parameter:
 *   - r:       SubRoom in den verteilt wird
 *   - N:       Anzahl der Fußgänger für SubRoom r
 *   - pid:     fortlaufender Index der Fußgänger (wird auch wieder zurückgegeben, für den
 *              nächsten Aufruf)
 *   - routing: wird benötigt um die Zielline der Fußgänger zu initialisieren
 * */
596
void PedDistributor::DistributeInSubRoom(SubRoom* r,int nAgents , vector<Point>& positions, int* pid,
597
          StartDistribution* para, Building* building) const
598 599
{

Ulrich Kemloh's avatar
Ulrich Kemloh committed
600
    // set the pedestrians
601 602
    for (int i = 0; i < nAgents; ++i) {

603 604
        Pedestrian* ped = para->GenerateAgent(building,pid,positions);

605
        building->AddPedestrian(ped);
606
    }
607
}
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
//void PedDistributor::DistributeInSubRoom(SubRoom* r,int nAgents , vector<Point>& positions, int* pid,
//          StartDistributionRoom* para, Building* building) const
//{
//
//    //in the case a range was specified
//    double distArea[4];
//    para->Getbounds(distArea);
//    AgentsParameters* agents_para=para->GetGroupParameters();
//
//    // set the pedestrians
//    for (int i = 0; i < nAgents; ++i) {
//
//        Pedestrian* ped = new Pedestrian();
//        // PedIndex
//        ped->SetID(*pid);
//        ped->SetAge(para->GetAge());
//        ped->SetGender(para->GetGender());
//        ped->SetHeight(para->GetHeight());
//        ped->SetFinalDestination(para->GetGoalId());
//        ped->SetGroup(para->GetGroupId());
//        ped->SetRouter(building->GetRoutingEngine()->GetRouter(para->GetRouterId()));
//        //ped->SetTrip(); // not implemented
//
//        // a und b setzen muss vor v0 gesetzt werden,
//        // da sonst v0 mit Null überschrieben wird
//        JEllipse E = JEllipse();
//        E.SetAv(agents_para->GetAtau());
//        E.SetAmin(agents_para->GetAmin());
//        E.SetBmax(agents_para->GetBmax());
//        E.SetBmin(agents_para->GetBmin());
//        ped->SetEllipse(E);
//        ped->SetTau(agents_para->GetTau());
//        ped->SetV0Norm(agents_para->GetV0(),
//                  agents_para->GetV0DownStairs(),
//                  agents_para->GetV0UpStairs());
//        //ped->SetV(Point(0.0,0.0));
//
//        // first default Position
//        int index = -1;
//        //int index = rand() % positions.size();
//
//        //in the case a range was specified
//        for (unsigned int a=0;a<positions.size();a++)
//        {
//            Point pos=positions[a];
//            if((distArea[0]<=pos._x) &&
//                    (pos._x <= distArea[1])&&
//                    (distArea[2]<=pos._y) &&
//                    (pos._y < distArea[3]))
//            {
//                index=a;
//                break;
//            }
//        }
//        if(index==-1)
//        {
//            Log->Write("ERROR:\t Cannot distribute pedestrians in the mentioned area [%0.2f,%0.2f,%0.2f,%0.2f]",
//                    distArea[0],distArea[1],distArea[2],distArea[3]);
//            Log->Write("ERROR:\t Specifying a subroom_id might help");
//        }
//
//        Point pos = positions[index];
//        ped->SetPos(pos,true); //true for the initial position
//        ped->SetBuilding(building);
//        positions.erase(positions.begin() + index);
//        ped->SetRoomID(para->GetRoomId(),"");
//        ped->SetSubRoomID(r->GetSubRoomID());
//        ped->SetPatienceTime(para->GetPatience());
//        ped->SetPremovementTime(para->GetPremovementTime());
//        ped->SetRiskTolerance(para->GetRiskTolerance());
//        const Point& start_pos = para->GetStartPosition();
//
//
//        if((std::isnan(start_pos._x)==0 ) && (std::isnan(start_pos._y)==0 ) ) {
//            if(r->IsInSubRoom(start_pos)==false){
//                Log->Write("ERROR: \t cannot distribute pedestrian %d in Room %d at fixed position %s",
//                                    *pid, para->GetRoomId(), start_pos.toString().c_str());
//                Log->Write("ERROR: \t Make sure that the position is inside the geometry and belongs to the specified room / subroom");
//                exit(EXIT_FAILURE);
//            }
//
//            ped->SetPos(start_pos,true); //true for the initial position
//            Log->Write("INFO: \t fixed position for ped %d in Room %d %s",
//                    *pid, para->GetRoomId(), start_pos.toString().c_str());
//        }
//
//        //r->AddPedestrian(ped);
//        building->AddPedestrian(ped);
//        (*pid)++;
//    }
//}
//SubRoom* r,int nAgents , vector<Point>& positions, int* pid,
//          StartDistributionRoom* para, Building* building
701