Ejemplo n.º 1
0
void Simulation::UpdateFlowAtDoors(const Pedestrian& ped) const
{
    if (_config->ShowStatistics()) {
        Transition* trans = _building->GetTransitionByUID(ped.GetExitIndex());
        if (trans) {
            //check if the pedestrian left the door correctly
            if (trans->DistTo(ped.GetPos())>0.5) {
                Log->Write("WARNING:\t pedestrian [%d] left room/subroom [%d/%d] in an unusual way. Please check",
                        ped.GetID(), ped.GetRoomID(), ped.GetSubRoomID());
                Log->Write("       :\t distance to last door (%d | %d) is %f. That should be smaller.",
                        trans->GetUniqueID(), ped.GetExitIndex(),
                        trans->DistTo(ped.GetPos()));
                Log->Write("       :\t correcting the door statistics");
                //ped.Dump(ped.GetID());

                //checking the history and picking the nearest previous destination
                double biggest = 0.3;
                bool success = false;
                for (const auto& dest:ped.GetLastDestinations()) {
                    if (dest!=-1) {
                        Transition* trans_tmp = _building->GetTransitionByUID(dest);
                        if (trans_tmp && trans_tmp->DistTo(ped.GetPos())<biggest) {
                            biggest = trans_tmp->DistTo(ped.GetPos());
                            trans = trans_tmp;
                            Log->Write("       :\t Best match found at door %d", dest);
                            success = true;//at least one door was found
                        }
                    }
                }

                if (!success) {
                    Log->Write("WARNING       :\t correcting the door statistics");
                    return; //todo we need to check if the ped is in a subroom neighboring the target. If so, no problems!
                }
            }
//#pragma omp critical
            trans->IncreaseDoorUsage(1, ped.GetGlobalTime());
        }
    }
}
Ejemplo n.º 2
0
void TrajectoriesJPSV04::WriteGeometry(Building* building)
{
     // just put a link to the geometry file
     string embed_geometry;
     embed_geometry.append("\t<geometry>\n");
     char file_location[CLENGTH] = "";
     sprintf(file_location, "\t<file location= \"%s\"/>\n", building->GetGeometryFilename().c_str());
     embed_geometry.append(file_location);
     embed_geometry.append("\t</geometry>\n");
     //Write(embed_geometry);
     //return;
     //
     string geometry;
     geometry.append("\t<geometry>\n");

     bool plotHlines = true;
     bool plotCrossings = true;
     bool plotTransitions = true;
     bool plotPlayingField=false;
     vector<string> rooms_to_plot;
     unsigned int i;
     // first the rooms
     //to avoid writing navigation line twice
     vector<int> navLineWritten;
     //rooms_to_plot.push_back("U9");

     for (const auto& it:building->GetAllRooms())
     {
          auto&& r = it.second;
          string caption = r->GetCaption(); //if(r->GetID()!=1) continue;
          if (!rooms_to_plot.empty() && !IsElementInVector(rooms_to_plot, caption))
               continue;

          for(auto&& sitr: r->GetAllSubRooms())
          {
               auto&& s = sitr.second; //if(s->GetSubRoomID()!=7) continue;
               geometry.append(s->WriteSubRoom());

               // the hlines
               if (plotHlines) {
                    const vector<Hline*>& hlines = s->GetAllHlines();
                    for (i = 0; i < hlines.size(); i++) {
                         Hline* hline = hlines[i];
                         int uid1 = hline->GetUniqueID();
                         if (!IsElementInVector(navLineWritten, uid1)) {
                              navLineWritten.push_back(uid1);
                              if (rooms_to_plot.empty()
                                        || IsElementInVector(rooms_to_plot, caption)) {
                                   geometry.append(hline->GetDescription());
                              }
                         }
                    }

                    // the crossings
                    if (plotCrossings) {
                         const vector<Crossing*>& crossings = s->GetAllCrossings();
                         for (i = 0; i < crossings.size(); i++) {
                              Crossing* crossing = crossings[i];
                              int uid1 = crossing->GetUniqueID();
                              if (!IsElementInVector(navLineWritten, uid1)) {
                                   navLineWritten.push_back(uid1);
                                   if (rooms_to_plot.empty()
                                             || IsElementInVector(rooms_to_plot,
                                                       caption)) {
                                        geometry.append(crossing->GetDescription());
                                   }
                              }
                         }
                    }

                    // the transitions
                    if (plotTransitions) {
                         const vector<Transition*>& transitions =
                                   s->GetAllTransitions();
                         for (i = 0; i < transitions.size(); i++) {
                              Transition* transition = transitions[i];
                              int uid1 = transition->GetUniqueID();
                              if (!IsElementInVector(navLineWritten, uid1)) {
                                   navLineWritten.push_back(uid1);

                                   if (rooms_to_plot.empty()) {
                                        geometry.append(transition->GetDescription());

                                   } else {

                                        Room* room1 = transition->GetRoom1();
                                        Room* room2 = transition->GetRoom2();
                                        string caption1 = room1->GetCaption();
                                        if (room2) {
                                             string caption2 = room2->GetCaption();
                                             if (IsElementInVector(rooms_to_plot,
                                                       caption1)
                                                       || IsElementInVector(rooms_to_plot,
                                                                 caption2)) {
                                                  geometry.append(transition->GetDescription());
                                             }

                                        } else {
                                             if (IsElementInVector(rooms_to_plot,
                                                       caption1)) {
                                                  geometry.append(transition->GetDescription());
                                             }
                                        }

                                   }
                              }
                         }
                    }
               }
          }
     }

     //eventually write any goal
     for (map<int, Goal*>::const_iterator itr = building->GetAllGoals().begin();
               itr != building->GetAllGoals().end(); ++itr) {
          geometry.append(itr->second->Write());
     }

     if(plotPlayingField) {
          //add the playing area
          double width=3282;
          double length=5668;
          char tmp[100];
          geometry.append("\t\t<wall>\n");
          sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",-length,width);
          geometry.append(tmp);

          sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",-length,-width);
          geometry.append(tmp);
          sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",length,-width);
          geometry.append(tmp);
          sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",length,width);
          geometry.append(tmp);
          sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",-length,width);
          geometry.append(tmp);
          geometry.append("\t\t</wall>\n");

          geometry.append("\t\t<wall>\n");
          sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",0.0,width);
          geometry.append(tmp);
          sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",0.0,-width);
          geometry.append(tmp);
          geometry.append("\t\t</wall>\n");
     }
     geometry.append("\t</geometry>\n");
     Write(geometry);
}