Class MemoryOutputFormatter

  • All Implemented Interfaces:
    OutputFormatter

    public class MemoryOutputFormatter
    extends BaseOutputFormatter
    OutputFormatter which stores data in memory, using specified keys and output properties.
    Author:
    gman6028
    • Field Detail

      • iterator

        public MemoryOutputIterator iterator
        Iterator to loop over results contained in this formatter
    • Constructor Detail

      • MemoryOutputFormatter

        public MemoryOutputFormatter​(IdGroupingToken groupId)
        Constructor
        Parameters:
        groupId - , contiguous id generation within this group for instances of this class
    • Method Detail

      • writeSimulationResultsForCurrentTimePeriod

        protected void writeSimulationResultsForCurrentTimePeriod​(OutputConfiguration outputConfiguration,
                                                                  OutputTypeConfiguration outputTypeConfiguration,
                                                                  OutputTypeEnum currentOutputType,
                                                                  OutputAdapter outputAdapter,
                                                                  Set<Mode> modes,
                                                                  TimePeriod timePeriod,
                                                                  int iterationIndex)
                                                           throws PlanItException
        Write Simulation results for the current time period to the CSV file
        Specified by:
        writeSimulationResultsForCurrentTimePeriod in class BaseOutputFormatter
        Parameters:
        outputConfiguration - output configuration
        outputTypeConfiguration - OutputTypeConfiguration for current persistence
        currentOutputType - , the active output type of the configuration we are persisting for (can be a suboutputtype)
        outputAdapter - OutputAdapter for current persistence
        modes - Set of modes of travel
        timePeriod - current time period
        iterationIndex - the iterationIndex we are persisting for
        Throws:
        PlanItException - thrown if there is an error
      • writeGeneralResultsForCurrentTimePeriod

        protected void writeGeneralResultsForCurrentTimePeriod​(OutputConfiguration outputConfiguration,
                                                               OutputTypeConfiguration outputTypeConfiguration,
                                                               OutputTypeEnum currentOutputType,
                                                               OutputAdapter outputAdapter,
                                                               Set<Mode> modes,
                                                               TimePeriod timePeriod,
                                                               int iterationIndex)
                                                        throws PlanItException
        Write General results for the current time period to the CSV file
        Specified by:
        writeGeneralResultsForCurrentTimePeriod in class BaseOutputFormatter
        Parameters:
        outputConfiguration - output configuration
        outputTypeConfiguration - OutputTypeConfiguration for current persistence
        currentOutputType - , the active output type of the configuration we are persisting for (can be a suboutputtype)
        outputAdapter - OutputAdapter for current persistence
        modes - Set of modes of travel
        timePeriod - current time period
        iterationIndex - the iteration index we are persisting for
        Throws:
        PlanItException - thrown if there is an error
      • writeLinkResultsForCurrentTimePeriod

        protected void writeLinkResultsForCurrentTimePeriod​(OutputConfiguration outputConfiguration,
                                                            OutputTypeConfiguration outputTypeConfiguration,
                                                            OutputTypeEnum currentOutputType,
                                                            OutputAdapter outputAdapter,
                                                            Set<Mode> modes,
                                                            TimePeriod timePeriod,
                                                            int iterationIndex)
                                                     throws PlanItException
        Write link results for the current time period to Map in memory
        Specified by:
        writeLinkResultsForCurrentTimePeriod in class BaseOutputFormatter
        Parameters:
        outputConfiguration - outputConfiguration
        outputTypeConfiguration - OutputTypeConfiguration for current persistence
        currentOutputType - , the active output type of the configuration we are persisting for (can be a suboutputtype)
        outputAdapter - OutputAdapter for current persistence
        modes - Set of modes of travel
        timePeriod - current time period
        iterationIndex - the iteration index we are persisting for
        Throws:
        PlanItException - thrown if there is an error
      • writeOdResultsForCurrentTimePeriod

        protected void writeOdResultsForCurrentTimePeriod​(OutputConfiguration outputConfiguration,
                                                          OutputTypeConfiguration outputTypeConfiguration,
                                                          OutputTypeEnum currentOutputType,
                                                          OutputAdapter outputAdapter,
                                                          Set<Mode> modes,
                                                          TimePeriod timePeriod,
                                                          int iterationIndex)
                                                   throws PlanItException
        Write Origin-Destination results for the time period to the Map in memory
        Specified by:
        writeOdResultsForCurrentTimePeriod in class BaseOutputFormatter
        Parameters:
        outputConfiguration - outputConfiguration
        outputTypeConfiguration - OutputTypeConfiguration for current persistence
        currentOutputType - , the active output type of the configuration we are persisting for (can be a suboutputtype)
        outputAdapter - OutputAdapter for current persistence
        modes - Set of modes of travel
        timePeriod - current time period
        iterationIndex - the iteration index we are persisting for
        Throws:
        PlanItException - thrown if there is an error
      • writePathResultsForCurrentTimePeriod

        protected void writePathResultsForCurrentTimePeriod​(OutputConfiguration outputConfiguration,
                                                            OutputTypeConfiguration outputTypeConfiguration,
                                                            OutputTypeEnum currentOutputType,
                                                            OutputAdapter outputAdapter,
                                                            Set<Mode> modes,
                                                            TimePeriod timePeriod,
                                                            int iterationIndex)
                                                     throws PlanItException
        Write Path results for the time period to the CSV file
        Specified by:
        writePathResultsForCurrentTimePeriod in class BaseOutputFormatter
        Parameters:
        outputConfiguration - outputConfiguration
        outputTypeConfiguration - OutputTypeConfiguration for current persistence
        currentOutputType - the output type we are persisting for
        outputAdapter - OutputAdapter for the current persistence
        modes - Set of modes of travel
        timePeriod - current time period
        iterationIndex - current iteration index
        Throws:
        PlanItException - thrown if there is an error
      • getOutputDataValue

        public Object getOutputDataValue​(Mode mode,
                                         TimePeriod timePeriod,
                                         Integer iterationIndex,
                                         OutputType outputType,
                                         OutputPropertyType outputProperty,
                                         Object[] keyValues)
                                  throws PlanItException
        Get a specified data value
        Parameters:
        mode - value of mode key
        timePeriod - value of time period key
        iterationIndex - value of iteration index key
        outputType - value of output type key
        outputProperty - output property to identify the column
        keyValues - values of keys to identify the row
        Returns:
        data map for the specified keys
        Throws:
        PlanItException - thrown if there is an error
      • initialiseBeforeSimulation

        public void initialiseBeforeSimulation​(OutputConfiguration outputConfiguration,
                                               long runId)
                                        throws PlanItException
        Opens all resources used in the formatter
        Parameters:
        outputConfiguration - OutputTypeConfiguration for the assignment
        runId - the traffic assignments runId
        Throws:
        PlanItException - thrown if there is an error
      • finaliseAfterSimulation

        public void finaliseAfterSimulation​(OutputConfiguration outputConfiguration,
                                            OutputAdapter outputAdapter)
                                     throws PlanItException
        Close all resources used in this formatter
        Parameters:
        outputConfiguration - OutputConfiguration of the assignment
        outputAdapter - the outputAdapter
        Throws:
        PlanItException - thrown if there is an error
      • getOutputKeyProperties

        public OutputProperty[] getOutputKeyProperties​(OutputType outputType)
        Returns the array of output properties representing the output types of the keys for the current output type
        Parameters:
        outputType - the current output type
        Returns:
        array of output properties of the keys
      • getOutputValueProperties

        public OutputProperty[] getOutputValueProperties​(OutputType outputType)
        Returns the array of output properties representing the output types of the data values for the current output type
        Parameters:
        outputType - the current output type
        Returns:
        array of output properties of the data values for the current output type
      • getLastIteration

        public int getLastIteration()
        Returns the value of the last iteration of recorded data
        Returns:
        the last iteration of recorded data
      • canHandleMultipleIterations

        public boolean canHandleMultipleIterations()
        Flag to indicate whether an implementation can handle multiple iterations If this returns false, acts as though OutputConfiguration.setPersistOnlyFinalIteration() is set to true
        Returns:
        flag to indicate whether the OutputFormatter can handle multiple iterations
      • getIterator

        public MemoryOutputIterator getIterator​(Mode mode,
                                                TimePeriod timePeriod,
                                                Integer iterationIndex,
                                                OutputType outputType)
        Returns a MemoryOutputIterator for the contents of the specified MultiKeyPlanItData map
        Parameters:
        mode - value of mode key
        timePeriod - value of time period key
        iterationIndex - value of iteration index key
        outputType - value of output type key
        Returns:
        map iterator storing the keys and values of this map, null when one or more inputs are invalid
      • getPositionOfOutputValueProperty

        public int getPositionOfOutputValueProperty​(OutputType outputType,
                                                    OutputPropertyType outputValueProperty)
                                             throws PlanItException
        Returns the position of a property type in the output values property array
        Parameters:
        outputType - value of output type key
        outputValueProperty - the output value property whose position is required
        Returns:
        the position of the output value property
        Throws:
        PlanItException - thrown if the output property type is not in the output value property array
      • getPositionOfOutputKeyProperty

        public int getPositionOfOutputKeyProperty​(OutputType outputType,
                                                  OutputPropertyType outputKeyProperty)
                                           throws PlanItException
        Returns the position of a property type in the output key property array
        Parameters:
        outputType - value of output type key
        outputKeyProperty - the output key property whose position is required
        Returns:
        the position of the output key property
        Throws:
        PlanItException - thrown if the output property type is not in the output key property array