Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
JPScore
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
92
Issues
92
List
Boards
Labels
Service Desk
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
JuPedSim
JPScore
Commits
2d1fb525
Commit
2d1fb525
authored
May 03, 2018
by
Mohcine Chraibi
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Main thread waits until source thread starts
parent
e34ec347
Pipeline
#9288
failed with stages
in 4 minutes and 34 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
10 deletions
+29
-10
main.cpp
main.cpp
+5
-3
pedestrian/AgentsSourcesManager.cpp
pedestrian/AgentsSourcesManager.cpp
+20
-6
pedestrian/AgentsSourcesManager.h
pedestrian/AgentsSourcesManager.h
+4
-1
No files found.
main.cpp
View file @
2d1fb525
...
@@ -87,8 +87,11 @@ int main(int argc, char** argv)
...
@@ -87,8 +87,11 @@ int main(int argc, char** argv)
//std::thread t1(sim.GetAgentSrcManager());
//std::thread t1(sim.GetAgentSrcManager());
double
simMaxTime
=
configuration
->
GetTmax
();
double
simMaxTime
=
configuration
->
GetTmax
();
std
::
thread
t1
(
&
AgentsSourcesManager
::
Run
,
&
sim
.
GetAgentSrcManager
());
std
::
thread
t1
(
&
AgentsSourcesManager
::
Run
,
&
sim
.
GetAgentSrcManager
());
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
100
));
while
(
!
sim
.
GetAgentSrcManager
().
IsRunning
())
//main thread for the simulation
{
// std::cout << "waiting...\n";
}
//main thread for the simulation
evacTime
=
sim
.
RunStandardSimulation
(
simMaxTime
);
evacTime
=
sim
.
RunStandardSimulation
(
simMaxTime
);
//Join the main thread
//Join the main thread
t1
.
join
();
t1
.
join
();
...
@@ -112,7 +115,6 @@ int main(int argc, char** argv)
...
@@ -112,7 +115,6 @@ int main(int argc, char** argv)
}
}
double
execTime
=
difftime
(
endtime
,
starttime
);
double
execTime
=
difftime
(
endtime
,
starttime
);
std
::
stringstream
summary
;
std
::
stringstream
summary
;
summary
<<
std
::
setprecision
(
2
)
<<
std
::
fixed
;
summary
<<
std
::
setprecision
(
2
)
<<
std
::
fixed
;
summary
<<
"
\n
Exec Time [s] : "
<<
execTime
<<
std
::
endl
;
summary
<<
"
\n
Exec Time [s] : "
<<
execTime
<<
std
::
endl
;
...
...
pedestrian/AgentsSourcesManager.cpp
View file @
2d1fb525
...
@@ -55,13 +55,15 @@ void AgentsSourcesManager::operator()()
...
@@ -55,13 +55,15 @@ void AgentsSourcesManager::operator()()
void
AgentsSourcesManager
::
Run
()
void
AgentsSourcesManager
::
Run
()
{
{
SetRunning
(
true
);
Log
->
Write
(
"INFO:
\t
Starting agent manager thread"
);
Log
->
Write
(
"INFO:
\t
Starting agent manager thread"
);
/* std::cout<< KGRN << "\n Starting agent manager thread\n" << "\n>> time: " << Pedestrian::GetGlobalTime() << RESET << "\n"; */
//Generate all agents required for the complete simulation
//Generate all agents required for the complete simulation
//It might be more efficient to generate at each frequency step
//It might be more efficient to generate at each frequency step
//TODO this loop is exactly GenerateAgents( --> REFACTOR)
//TODO this loop is exactly GenerateAgents( --> REFACTOR)
for
(
const
auto
&
src
:
_sources
)
for
(
const
auto
&
src
:
_sources
)
{
{
/* std::cout << "Generate AgentsAndAddToPool src: " << src->GetId() << "\n" ; */
src
->
GenerateAgentsAndAddToPool
(
src
->
GetMaxAgents
(),
_building
);
src
->
GenerateAgentsAndAddToPool
(
src
->
GetMaxAgents
(),
_building
);
}
}
...
@@ -78,13 +80,16 @@ void AgentsSourcesManager::Run()
...
@@ -78,13 +80,16 @@ void AgentsSourcesManager::Run()
do
do
{
{
int
current_time
=
(
int
)
Pedestrian
::
GetGlobalTime
();
int
current_time
=
(
int
)
Pedestrian
::
GetGlobalTime
();
/* std::cout << KBLU << ">> RUN: current_time " << current_time << " last update " << _lastUpdateTime << "\n" << RESET; */
if
((
current_time
!=
_lastUpdateTime
)
if
((
current_time
!=
_lastUpdateTime
)
&&
((
current_time
%
updateFrequency
)
==
0
))
&&
((
current_time
%
updateFrequency
)
==
0
))
{
{
/* std::cout << "
>> RUN: current_time " << current_time << " last update " << _lastUpdateTime << std::endl
; */
/* std::cout << "
--- Enter IF --- \n" << KRED << "QUEUE isempty: " << AgentsQueueIn::IsEmpty() << "\n" << RESET
; */
if
(
AgentsQueueIn
::
IsEmpty
())
if
(
AgentsQueueIn
::
IsEmpty
())
//if queue is empty. Otherwise, wait for main thread to empty it and update _building
//if queue is empty. Otherwise, wait for main thread to empty it and update _building
{
{
/* std::cout << " --- Enter QUEUE EMPTY --- \n"; */
finished
=
ProcessAllSources
();
finished
=
ProcessAllSources
();
_lastUpdateTime
=
current_time
;
_lastUpdateTime
=
current_time
;
//SetBuildingUpdated(false);
//SetBuildingUpdated(false);
...
@@ -95,22 +100,20 @@ void AgentsSourcesManager::Run()
...
@@ -95,22 +100,20 @@ void AgentsSourcesManager::Run()
break
;
// break if max simulation time is reached.
break
;
// break if max simulation time is reached.
}
while
(
!
finished
);
}
while
(
!
finished
);
std
::
cout
<<
">> Terminating agent manager thread"
<<
RESET
<<
std
::
endl
;
Log
->
Write
(
"INFO:
\t
Terminating agent manager thread"
);
Log
->
Write
(
"INFO:
\t
Terminating agent manager thread"
);
_isCompleted
=
true
;
_isCompleted
=
true
;
}
}
bool
AgentsSourcesManager
::
ProcessAllSources
()
const
bool
AgentsSourcesManager
::
ProcessAllSources
()
const
{
{
std
::
cout
<<
"
\n
START AgentsSourcesManager::ProcessAllSources()
\n
"
;
/* std::cout << "\nSTART AgentsSourcesManager::ProcessAllSources()\n"; */
bool
empty
=
true
;
bool
empty
=
true
;
double
current_time
=
Pedestrian
::
GetGlobalTime
();
double
current_time
=
Pedestrian
::
GetGlobalTime
();
vector
<
Pedestrian
*>
source_peds
;
// we have to collect peds from all sources, so that we can consider them while computing new positions
vector
<
Pedestrian
*>
source_peds
;
// we have to collect peds from all sources, so that we can consider them while computing new positions
for
(
const
auto
&
src
:
_sources
)
for
(
const
auto
&
src
:
_sources
)
{
{
/* std::cout << KRED << "\nprocessing src: " << src->GetId() << " -- current time: " << current_time << " schedule: " << src->GetPlanTime() <<". number of peds in building " << _building->GetAllPedestrians().size() << "\n" << RESET; */
/* std::cout << KRED << "\nprocessing src: " << src->GetId() << " -- current time: " << current_time << " schedule
time
: " << src->GetPlanTime() <<". number of peds in building " << _building->GetAllPedestrians().size() << "\n" << RESET; */
if
(
src
->
GetPoolSize
()
&&
(
src
->
GetPlanTime
()
<=
current_time
)
)
// maybe diff<eps
if
(
src
->
GetPoolSize
()
&&
(
src
->
GetPlanTime
()
<=
current_time
)
)
// maybe diff<eps
{
{
...
@@ -602,6 +605,11 @@ bool AgentsSourcesManager::IsCompleted() const
...
@@ -602,6 +605,11 @@ bool AgentsSourcesManager::IsCompleted() const
return
_isCompleted
;
return
_isCompleted
;
}
}
bool
AgentsSourcesManager
::
IsRunning
()
const
{
return
_isRunning
;
}
bool
AgentsSourcesManager
::
IsBuildingUpdated
()
const
bool
AgentsSourcesManager
::
IsBuildingUpdated
()
const
{
{
...
@@ -613,6 +621,12 @@ void AgentsSourcesManager::SetBuildingUpdated(bool update)
...
@@ -613,6 +621,12 @@ void AgentsSourcesManager::SetBuildingUpdated(bool update)
_buildingUpdated
=
update
;
_buildingUpdated
=
update
;
}
}
void
AgentsSourcesManager
::
SetRunning
(
bool
running
)
{
_isRunning
=
running
;
}
Building
*
AgentsSourcesManager
::
GetBuilding
()
const
Building
*
AgentsSourcesManager
::
GetBuilding
()
const
{
{
return
_building
;
return
_building
;
...
...
pedestrian/AgentsSourcesManager.h
View file @
2d1fb525
...
@@ -84,6 +84,7 @@ public:
...
@@ -84,6 +84,7 @@ public:
* Set the building object
* Set the building object
*/
*/
void
SetBuilding
(
Building
*
building
);
void
SetBuilding
(
Building
*
building
);
void
SetRunning
(
bool
running
);
/**
/**
* @return true if all agents have been generated
* @return true if all agents have been generated
...
@@ -125,7 +126,7 @@ public:
...
@@ -125,7 +126,7 @@ public:
int
GetMaxSimTime
()
const
;
int
GetMaxSimTime
()
const
;
void
SetMaxSimTime
(
int
t
);
void
SetMaxSimTime
(
int
t
);
bool
IsRunning
()
const
;
private:
private:
/**
/**
...
@@ -184,6 +185,8 @@ private:
...
@@ -184,6 +185,8 @@ private:
//std::atomic<bool>_isCompleted=false;
//std::atomic<bool>_isCompleted=false;
// std::atomic<bool>_buildingUpdated=false;
// std::atomic<bool>_buildingUpdated=false;
bool
_buildingUpdated
;
bool
_buildingUpdated
;
bool
_isRunning
=
false
;
};
};
#endif
/* AGENTSSOURCESMANAGER_H_ */
#endif
/* AGENTSSOURCESMANAGER_H_ */
Mohcine Chraibi
@chraibi1
mentioned in issue
#158 (closed)
·
May 03, 2018
mentioned in issue
#158 (closed)
mentioned in issue #158
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment