Maintenance at Wednesday, 30. June 2021, from 7:30 to 9:30
Some of the planned changes may require user action

Commit fe535090 authored by Ulrich Kemloh's avatar Ulrich Kemloh
Browse files

Fixed an issue with sources in non hybrid simulations

parent d4a92fa7
......@@ -275,7 +275,7 @@ bool Simulation::InitArgs(const ArgumentParser& args)
int Simulation::RunStandardSimulation(double maxSimTime)
{
RunHeader(_nPeds);
RunHeader(_nPeds + _agentSrcManager.GetMaxAgentNumber());
double t=RunBody(maxSimTime);
RunFooter();
return (int)t;
......
......@@ -69,13 +69,14 @@ int main(int argc, char **argv)
else
{
//Start the threads for managing the sources of agents if any
//std::thread t1(sim.GetAgentSrcManager());
std::thread t1(sim.GetAgentSrcManager());
std::thread t1(&AgentsSourcesManager::Run, &sim.GetAgentSrcManager());
//std::thread t1(&AgentsSourcesManager::Run, &sim.GetAgentSrcManager());
//main thread for the simulation
Log->Write("INFO: \tStart runSimulation()");
evacTime = sim.RunSimulation(args->GetTmax());
//evacTime = sim.RunSimulation(args->GetTmax());
evacTime = sim.RunStandardSimulation(args->GetTmax());
Log->Write("\nINFO: \tEnd runSimulation()");
time(&endtime);
......
......@@ -35,48 +35,7 @@ AgentsSourcesManager::~AgentsSourcesManager()
void AgentsSourcesManager::operator()()
{
Log->Write("INFO:\tStarting agent manager thread");
//Generate all agents required for the complete simulation
//It might be more efficient to generate at each frequency step
for (const auto& src : _sources)
{
src->GenerateAgentsAndAddToPool(src->GetMaxAgents(), _building);
cout<<"generation: "<<src->GetPoolSize()<<endl;
}
//first call ignoring the return value
ProcessAllSources();
//the loop is updated each x second.
//it might be better to use a timer
_isCompleted = false;
bool finished = false;
long updateFrequency = 5; // 1 second
do
{
int current_time = Pedestrian::GetGlobalTime();
//first step
//if(current_time==0){
//finished=ProcessAllSources();
// ProcessAllSources();
// //cout<<"here:"<<endl; exit(0);
//}
if ((current_time != _lastUpdateTime)
&& ((current_time % updateFrequency) == 0))
{
//cout<<"TIME:"<<current_time<<endl;
finished=ProcessAllSources();
_lastUpdateTime = current_time;
cout << "source size: " << _sources.size() << endl;
}
//wait some time
//cout<<"sleepinp..."<<endl;
//std::this_thread::sleep_for(std::chrono::milliseconds(1));
} while (!finished);
Log->Write("INFO:\tTerminating agent manager thread");
_isCompleted = true;
Run();
}
void AgentsSourcesManager::Run()
......@@ -508,3 +467,13 @@ Building* AgentsSourcesManager::GetBuilding() const
{
return _building;
}
long AgentsSourcesManager::GetMaxAgentNumber() const
{
long pop=0;
for (const auto& src : _sources)
{
pop+=src->GetMaxAgents();
}
return pop;
}
......@@ -29,7 +29,7 @@ public:
/**
* disable copying
*/
AgentsSourcesManager(const AgentsSourcesManager& ) = delete;
//AgentsSourcesManager(const AgentsSourcesManager& ) = delete;
/**
* Destructor
......@@ -85,6 +85,12 @@ public:
*/
void GenerateAgents();
/**
* Return the total number of agents that will be generated.
* used by visualisation to allocate space
*/
long GetMaxAgentNumber() const;
private:
......
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