Commit 2931663a authored by Ulrich Kemloh's avatar Ulrich Kemloh

Refactoring main to separate hybrid from normal simulation

parent 7ff99f1b
......@@ -51,7 +51,6 @@ OutputHandler* Log;
Simulation::Simulation(const ArgumentParser& args)
{
_nPeds = 0;
_tmax = 0;
_seed = 8091983;
_deltaT = 0;
_building = nullptr;
......@@ -202,8 +201,7 @@ bool Simulation::InitArgs(const ArgumentParser& args)
sprintf(tmp, "\tnCPU: %d\n", args.GetMaxOpenMPThreads());
s.append(tmp);
_tmax = args.GetTmax();
sprintf(tmp, "\tt_max: %f\n", _tmax);
sprintf(tmp, "\tt_max: %f\n", args.GetTmax());
s.append(tmp);
_deltaT = args.Getdt();
sprintf(tmp, "\tdt: %f\n", _deltaT);
......@@ -231,7 +229,7 @@ bool Simulation::InitArgs(const ArgumentParser& args)
if(nullptr!=(_hybridSimManager=args.GetHybridSimManager()))
{
_hybridSimManager->Init(_building.get());
};
}
//perform customs initialisation, like computing the phi for the gcfm
//this should be called after the routing engine has been initialised
......@@ -275,7 +273,7 @@ bool Simulation::InitArgs(const ArgumentParser& args)
return true;
}
int Simulation::RunSimulation()
int Simulation::RunSimulation(double maxSimTime)
{
int frameNr = 1; // Frame Number
int writeInterval = (int) ((1. / _fps) / _deltaT + 0.5);
......@@ -297,7 +295,7 @@ int Simulation::RunSimulation()
//time(&starttime);
// main program loop
while ( (_nPeds || !_agentSrcManager.IsCompleted() ) && t < _tmax)
while ( (_nPeds || !_agentSrcManager.IsCompleted() ) && t < maxSimTime)
{
t = 0 + (frameNr - 1) * _deltaT;
......
......@@ -64,7 +64,7 @@ private:
///Number of pedestrians in the simulation
long _nPeds;
///Maximum simulation time
double _tmax;
//double _tmax;
/// time step
double _deltaT;
/// frame rate for the trajectories
......@@ -113,9 +113,10 @@ public:
bool InitArgs(const ArgumentParser& args);
/**
* @param simtime, the maximal simulation time
* @return the total simulated/evacuation time
*/
int RunSimulation();
int RunSimulation(double maxSimTime);
/**
* Updathe route of the pedestrians and reassign rooms, in the case a room change happens
......
......@@ -56,34 +56,31 @@ int main(int argc, char **argv)
if(status&&sim.InitArgs(*args))
{
//Start the threads for managing the sources of agents
std::thread t1(sim.GetAgentSrcManager());
//evacuation time
int evacTime = 0;
//Start the thread for managing incoming messages from MatSim
std::thread t2;
auto hybrid=args->GetHybridSimManager();
if(hybrid){
hybrid->AttachSourceManager(sim.GetAgentSrcManager());
t2 = std::thread(*hybrid);
//process the hybrid simulation
if(hybrid)
{
evacTime=hybrid->Run(sim);
}
//t1.detach();
//t2.detach();
//process the normal simulation
else
{
//Start the threads for managing the sources of agents if any
std::thread t1(sim.GetAgentSrcManager());
//main thread for the simulation
Log->Write("INFO: \tStart runSimulation()");
int evacTime = sim.RunSimulation();
Log->Write("\nINFO: \tEnd runSimulation()");
time(&endtime);
//main thread for the simulation
Log->Write("INFO: \tStart runSimulation()");
evacTime = sim.RunSimulation(args->GetTmax());
Log->Write("\nINFO: \tEnd runSimulation()");
time(&endtime);
//the execution is finished at this time
//so join the other threads
t1.join();
//the execution is finished at this time
//so join the main thread
t1.join();
//only if in hybrid mode
if(hybrid)
{
hybrid->Shutdown();
t2.join();
}
// some statistics output
......
......@@ -55,7 +55,7 @@ HybridSimulationManager::HybridSimulationManager(const std::string& server,
GOOGLE_PROTOBUF_VERIFY_VERSION;
grpc_init();
_rpcClient = std::shared_ptr<JPSclient>(new JPSclient( grpc::CreateChannel("localhost:9999",
_rpcClient = std::unique_ptr<JPSclient>(new JPSclient( grpc::CreateChannel("localhost:9999",
grpc::InsecureCredentials(), ChannelArguments())));
......@@ -84,12 +84,12 @@ bool HybridSimulationManager::Init(Building* building)
return true;
}
bool HybridSimulationManager::Run()
bool HybridSimulationManager::Run(Simulation& sim)
{
//perform some initialisation stuff
GOOGLE_PROTOBUF_VERIFY_VERSION;
grpc_init();
_rpcClient = std::shared_ptr<JPSclient>(new JPSclient( grpc::CreateChannel("localhost:9999",
_rpcClient = std::unique_ptr<JPSclient>(new JPSclient( grpc::CreateChannel("localhost:9999",
grpc::InsecureCredentials(), ChannelArguments())));
//create a socket and use it for the serveur and the client
......@@ -105,7 +105,7 @@ bool HybridSimulationManager::Run()
}
void HybridSimulationManager::operator()()
{
Run();
//Run();
}
bool HybridSimulationManager::RunClient()
{
......
......@@ -18,6 +18,7 @@
class Building;
class AgentsSourcesManager;
class JPSclient;
class Simulation;
class HybridSimulationManager
{
......@@ -26,7 +27,7 @@ public:
virtual ~HybridSimulationManager();
bool Init(Building* building);
bool Run();
bool Run(Simulation& sim);
bool RunClient();
bool RunServer();
void Shutdown();
......@@ -58,7 +59,7 @@ private:
//std::unique_ptr<grpc::Server> _rpcServer;
std::shared_ptr<grpc::Server> _rpcServer;
AgentsSourcesManager _agentSrcMng;
std::shared_ptr<JPSclient> _rpcClient;
std::unique_ptr<JPSclient> _rpcClient;
};
#endif /* HYBRIDSIMULATIONMANAGER_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment