MATSIM
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
org.matsim.vis.snapshotwriters.SnapshotWriterManager Class Reference
Inheritance diagram for org.matsim.vis.snapshotwriters.SnapshotWriterManager:
Inheritance graph
[legend]

Public Member Functions

 SnapshotWriterManager (int snapshotPeriod, QSimConfigGroup.FilterSnapshots filterSnapshots)
 
void notifyMobsimInitialized (MobsimInitializedEvent e)
 
void notifyMobsimBeforeCleanup (MobsimBeforeCleanupEvent e)
 
void notifyMobsimAfterSimStep (MobsimAfterSimStepEvent e)
 
final void addSnapshotWriter (SnapshotWriter snapshotWriter)
 

Private Member Functions

void closeSnapshotWriters ()
 
void doSnapshot (final double time, VisMobsim visMobsim)
 
boolean isGenerateSnapshot (Link link)
 

Private Attributes

final List< SnapshotWritersnapshotWriters = new ArrayList<>()
 
final QSimConfigGroup.FilterSnapshots filterSnapshots
 
final int snapshotPeriod
 
double snapshotTime = 0.0
 

Static Private Attributes

static final Logger log = LogManager.getLogger(SnapshotWriterManager.class)
 

Detailed Description

Definition at line 41 of file SnapshotWriterManager.java.

Constructor & Destructor Documentation

◆ SnapshotWriterManager()

org.matsim.vis.snapshotwriters.SnapshotWriterManager.SnapshotWriterManager ( int  snapshotPeriod,
QSimConfigGroup.FilterSnapshots  filterSnapshots 
)

Member Function Documentation

◆ notifyMobsimInitialized()

void org.matsim.vis.snapshotwriters.SnapshotWriterManager.notifyMobsimInitialized ( MobsimInitializedEvent  e)

Implements org.matsim.core.mobsim.framework.listeners.MobsimInitializedListener.

Definition at line 60 of file SnapshotWriterManager.java.

References org.matsim.core.mobsim.framework.MobsimTimer.getSimStartTime(), org.matsim.core.mobsim.qsim.interfaces.Netsim.getSimTimer(), and org.matsim.vis.snapshotwriters.SnapshotWriterManager.snapshotPeriod.

60  {
61  Netsim mobsim = (Netsim) e.getQueueSimulation();
62  this.snapshotTime = Math.floor(mobsim.getSimTimer().getSimStartTime()
63  / this.snapshotPeriod)
64  * this.snapshotPeriod;
65  if (this.snapshotTime < mobsim.getSimTimer().getSimStartTime()) {
66  this.snapshotTime += this.snapshotPeriod;
67  }
68  }
Here is the call graph for this function:

◆ notifyMobsimBeforeCleanup()

void org.matsim.vis.snapshotwriters.SnapshotWriterManager.notifyMobsimBeforeCleanup ( MobsimBeforeCleanupEvent  e)

◆ closeSnapshotWriters()

void org.matsim.vis.snapshotwriters.SnapshotWriterManager.closeSnapshotWriters ( )
private

Definition at line 75 of file SnapshotWriterManager.java.

Referenced by org.matsim.vis.snapshotwriters.SnapshotWriterManager.notifyMobsimBeforeCleanup().

75  {
76  for (SnapshotWriter writer : this.snapshotWriters) {
77  writer.finish();
78  }
79  }

◆ notifyMobsimAfterSimStep()

void org.matsim.vis.snapshotwriters.SnapshotWriterManager.notifyMobsimAfterSimStep ( MobsimAfterSimStepEvent  e)

◆ doSnapshot()

void org.matsim.vis.snapshotwriters.SnapshotWriterManager.doSnapshot ( final double  time,
VisMobsim  visMobsim 
)
private

Definition at line 90 of file SnapshotWriterManager.java.

References org.matsim.vis.snapshotwriters.VisNetwork.getVisLinks(), org.matsim.vis.snapshotwriters.VisMobsim.getVisNetwork(), and org.matsim.vis.snapshotwriters.SnapshotWriterManager.isGenerateSnapshot().

Referenced by org.matsim.vis.snapshotwriters.SnapshotWriterManager.notifyMobsimAfterSimStep().

90  {
91  if (!this.snapshotWriters.isEmpty()) {
92 
93  // This could be parallel since mihal has fixed some concurrency issues in the SnapshotInfoBuilder
94  // I think mainly by using separate builders for each generated AgentPositionInfo.
95  // I don't have time to test this right now, but if this ever appears to be a bottle neck, this probably
96  // can be replaced by a parallel stream. janek: oct' 2021
97  var positions = visMobsim.getVisNetwork().getVisLinks().values().stream()
98  .filter(visLink -> isGenerateSnapshot(visLink.getLink()))
99  .flatMap(visLink -> visLink.getVisData().addAgentSnapshotInfo(new HashSet<>()).stream())
100  .collect(Collectors.toSet());
101 
102  // We do not put non-network agents in movies.
103  // Otherwise, we would add snapshots from visMobsim.getNonNetworkAgentSnapshots() here.
104 
105  for (SnapshotWriter writer : this.snapshotWriters) {
106  writer.beginSnapshot(time);
107  for (AgentSnapshotInfo position : positions) {
108  writer.addAgent(position);
109  }
110  writer.endSnapshot();
111  }
112  }
113  }
Here is the call graph for this function:

◆ addSnapshotWriter()

final void org.matsim.vis.snapshotwriters.SnapshotWriterManager.addSnapshotWriter ( SnapshotWriter  snapshotWriter)

◆ isGenerateSnapshot()

boolean org.matsim.vis.snapshotwriters.SnapshotWriterManager.isGenerateSnapshot ( Link  link)
private

Definition at line 119 of file SnapshotWriterManager.java.

References org.matsim.vis.snapshotwriters.SnapshotWriterManager.filterSnapshots, org.matsim.vis.snapshotwriters.SnapshotWritersModule.GENERATE_SNAPSHOT_FOR_LINK_KEY, org.matsim.utils.objectattributes.attributable.Attributes.getAttribute(), and org.matsim.utils.objectattributes.attributable.Attributable.getAttributes().

Referenced by org.matsim.vis.snapshotwriters.SnapshotWriterManager.doSnapshot().

119  {
120  switch (filterSnapshots) {
121  case no:
122  return true;
123  case withLinkAttributes:
124  return Objects.equals(link.getAttributes().getAttribute(SnapshotWritersModule.GENERATE_SNAPSHOT_FOR_LINK_KEY), true);
125  default:
126  throw new RuntimeException("Unexpected filter snapshot setting: " + filterSnapshots + " Possible are: [no, withLinkAttributes]. This can be changed in config.qsim.filterSnapshots");
127  }
128  }
final QSimConfigGroup.FilterSnapshots filterSnapshots
Here is the call graph for this function:

Member Data Documentation

◆ log

final Logger org.matsim.vis.snapshotwriters.SnapshotWriterManager.log = LogManager.getLogger(SnapshotWriterManager.class)
staticprivate

Definition at line 43 of file SnapshotWriterManager.java.

◆ snapshotWriters

final List<SnapshotWriter> org.matsim.vis.snapshotwriters.SnapshotWriterManager.snapshotWriters = new ArrayList<>()
private

Definition at line 45 of file SnapshotWriterManager.java.

◆ filterSnapshots

final QSimConfigGroup.FilterSnapshots org.matsim.vis.snapshotwriters.SnapshotWriterManager.filterSnapshots
private

◆ snapshotPeriod

final int org.matsim.vis.snapshotwriters.SnapshotWriterManager.snapshotPeriod
private

◆ snapshotTime

double org.matsim.vis.snapshotwriters.SnapshotWriterManager.snapshotTime = 0.0
private

time since last snapshot

Definition at line 52 of file SnapshotWriterManager.java.


The documentation for this class was generated from the following file: