RoutingEngine.cpp 3.79 KB
Newer Older
Weichen's avatar
Weichen committed
1 2 3
/**
 * \file        RoutingEngine.cpp
 * \date        Jan 10, 2013
4 5
 * \version     v0.7
 * \copyright   <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved.
6
 *
Weichen's avatar
Weichen committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 * \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
 *
 *
 **/

28 29

#include "RoutingEngine.h"
30
#include "../pedestrian/Pedestrian.h"
31
#include "../geometry/Trips.h"
32 33 34

using namespace std;

35

36 37
RoutingEngine::RoutingEngine()
{
38 39 40

}

41 42 43 44 45 46
RoutingEngine::~RoutingEngine()
{
     for(unsigned int r=0; r<_routersCollection.size(); r++) {
          delete _routersCollection[r];
     }
     _routersCollection.clear();
47 48
}

49 50 51 52 53
void RoutingEngine::AddFinalDestinationID(int id)
{
     for(unsigned int r=0; r<_routersCollection.size(); r++) {
          _routersCollection[r]->AddFinalDestinationID(id);
     }
54 55
}

56 57 58
void RoutingEngine::FindRoute(Pedestrian* ped)
{
     ped->FindRoute();
59 60
}

61 62 63 64 65 66 67 68 69 70
void RoutingEngine::AddRouter(Router* router)
{
     for(unsigned int r=0; r<_routersCollection.size(); r++) {
          if(_routersCollection[r]->GetStrategy()==router->GetStrategy()) {
               Log->Write("ERROR: \tDuplicate router found with 'id' [%d].",router->GetID());
               Log->Write("ERROR: \tDouble check your configuration files");
               exit(EXIT_FAILURE);
          }
     }
     _routersCollection.push_back(router);
71
}
72 73 74 75 76 77 78 79 80 81 82 83 84
//
//const vector<string>& RoutingEngine::GetTrip(int index) const
//{
//     if ((index >= 0) && (index < (int) _tripsCollection.size()))
//          return _tripsCollection[index];
//     else {
//          char tmp[CLENGTH];
//          sprintf(tmp, "ERROR: \tWrong 'index' [%d] > [%d] in Routing::GetTrip()",
//                  index, int(_tripsCollection.size()));
//          Log->Write(tmp);
//          exit(EXIT_FAILURE);
//     }
//}
85

86 87 88 89 90 91
const std::vector<Router*> RoutingEngine::GetAvailableRouters() const
{
     return _routersCollection;
}


92 93
Router* RoutingEngine::GetRouter(RoutingStrategy strategy) const
{
94 95 96 97
     for(Router* router:_routersCollection)
     {
          if(router->GetStrategy()==strategy)
               return router;
98
     }
99
     //Log->Write("ERROR: \t Could not Find any router with Strategy:  [%d].",strategy);
100
     return /*(Router*)*/ nullptr;
101 102
}

103 104
Router* RoutingEngine::GetRouter(int id) const
{
105 106 107 108
     for(Router* router:_routersCollection)
     {
          if(router->GetID()==id)
               return router;
109
     }
110
     Log->Write("ERROR: \t Could not Find any router with ID:  [%d].",id);
111
     return /*(Router*)*/ nullptr;
112 113
}

114
void RoutingEngine::AddTrip(Trips trip)
115
{
116 117 118 119 120 121
//     _tripsCollection.push_back(trip);
//     _tripsCollection = trip;
     for(Router* router:_routersCollection)
     {
          router->SetTrips(trip);
     }
122 123
}

124
bool RoutingEngine::Init(Building* building)
125
{
126
     bool status=true;
127
     for(unsigned int r=0; r<_routersCollection.size(); r++) {
128 129
          if(_routersCollection[r]->Init(building)==false)
               status=false;
130
     }
131
     return status;
132
}
133

tobias schroedter's avatar
tobias schroedter committed
134
bool RoutingEngine::NeedsUpdate() const
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
{
     return _needUpdate;
}

void RoutingEngine::setNeedUpdate(bool needUpdate)
{
     _needUpdate = needUpdate;
}

void RoutingEngine::UpdateRouter()
{
     for (auto* router : _routersCollection){
          router->Update();
     }
     _needUpdate = false;
}