Package coconad

Class TrainSet

java.lang.Object
coconad.TrainSet
All Implemented Interfaces:
Serializable

public class TrainSet extends Object implements Serializable
Class for a set of trains.
Since:
2013.11.27
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
    the current number of trains
    protected util.IdMap
    the underlying item base
    static final int
    read/write mode: pair of item and time
    static final int
    read/write mode: train with preceding item
    protected double
    the maximum event/spike time
    protected int
    the maximal length of a train
    protected double
    the minimum event/spike time
    static final int
    read/write mode: pure train, that is, no item
    static final int
    read/write mode: pair of time and item
    protected Train[]
    the set of trains
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create an empty set of trains.
    TrainSet(util.IdMap ibase)
    Create an empty set of trains.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    addTrain(Train train)
    Add a train.
    void
    filter(double start, double end)
    Filter a train set.
    double[][]
    Get all trains as arrays of floating point values.
    int
    getItem(int i)
    Get the item identifier of a (spike/event) train.
    util.IdMap
    Get the underlying item base.
    int
    getItemId(int i)
    Get the item identifier of a (spike/event) train.
    getItemName(int i)
    Get the item name of a (spike/event) train.
    int
    Get the maximal length of a train.
    double
    Get the maximum time.
    double
    Get the minimum time.
    int
    Get the number of (spike/event) trains.
    getTrain(int i)
    Get a train.
    static void
    main(String[] args)
    Main function for testing some basic functionality.
    void
    Pack the trains of a set, i.e., optimize memory usage.
    static TrainSet
    parse(util.IdMap ibase, InputStream inp, int mode)
    Parse a set of (spike/event) trains.
    static TrainSet
    parse(util.IdMap ibase, Reader reader, int mode)
    Parse a set of (spike/event) trains.
    static TrainSet
    parse(util.IdMap ibase, String desc, int mode)
    Parse a set of (spike/event) trains.
    static TrainSet
    parse(util.IdMap ibase, util.TableReader reader, int mode)
    Parse a set of (spike/event) trains.
    void
    Sort trains by their item names.
    void
    Sort a train set (that is, sort all contained trains).
    void
    write(util.TableWriter writer, int mode)
    Write a set of trains.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ITEM_TRAIN

      public static final int ITEM_TRAIN
      read/write mode: train with preceding item
      See Also:
    • PURE_TRAIN

      public static final int PURE_TRAIN
      read/write mode: pure train, that is, no item
      See Also:
    • ITEM_TIME

      public static final int ITEM_TIME
      read/write mode: pair of item and time
      See Also:
    • TIME_ITEM

      public static final int TIME_ITEM
      read/write mode: pair of time and item
      See Also:
    • ibase

      protected util.IdMap ibase
      the underlying item base
    • trains

      protected Train[] trains
      the set of trains
    • cnt

      protected int cnt
      the current number of trains
    • maxlen

      protected int maxlen
      the maximal length of a train
    • min

      protected double min
      the minimum event/spike time
    • max

      protected double max
      the maximum event/spike time
  • Constructor Details

    • TrainSet

      public TrainSet()
      Create an empty set of trains.
      Since:
      2013.11.27 (Christian Borgelt)
    • TrainSet

      public TrainSet(util.IdMap ibase)
      Create an empty set of trains.
      Parameters:
      ibase - the underlying item base
      Since:
      2013.11.27 (Christian Borgelt)
  • Method Details

    • getItemBase

      public util.IdMap getItemBase()
      Get the underlying item base.
      Returns:
      the underlying item base
      Since:
      2013.11.27 (Christian Borgelt)
    • getItem

      public int getItem(int i)
      Get the item identifier of a (spike/event) train.
      Parameters:
      i - the index of the train of which to get the item
      Returns:
      the item of the train with index i
      Since:
      2016.08.26 (Christian Borgelt)
    • getItemId

      public int getItemId(int i)
      Get the item identifier of a (spike/event) train.
      Parameters:
      i - the index of the train of which to get the item
      Returns:
      the item of the train with index i
      Since:
      2016.08.26 (Christian Borgelt)
    • getItemName

      public String getItemName(int i)
      Get the item name of a (spike/event) train.
      Parameters:
      i - the index of the train of which to get the item name
      Returns:
      the item name of the train with index i
      Since:
      2013.11.28 (Christian Borgelt)
    • getSize

      public int getSize()
      Get the number of (spike/event) trains.
      Returns:
      the number of trains
      Since:
      2013.11.28 (Christian Borgelt)
    • getTrain

      public Train getTrain(int i)
      Get a train.
      Parameters:
      i - the index of the train
      Returns:
      the train with index i
      Since:
      2013.11.28 (Christian Borgelt)
    • getAllTrains

      public double[][] getAllTrains()
      Get all trains as arrays of floating point values.
      Returns:
      all trains as arrays of floating point values
      Since:
      2013.11.28 (Christian Borgelt)
    • addTrain

      public int addTrain(Train train)
      Add a train.
      Parameters:
      train - the train to add
      Returns:
      the index of the train in the set
      Since:
      2013.11.28 (Christian Borgelt)
    • getMaxLength

      public int getMaxLength()
      Get the maximal length of a train.
      Returns:
      the maximal size of a train
      Since:
      2013.11.28 (Christian Borgelt)
    • sort

      public void sort()
      Sort trains by their item names.
      Since:
      2013.11.28 (Christian Borgelt)
    • sortTimes

      public void sortTimes()
      Sort a train set (that is, sort all contained trains).
      Since:
      2013.12.03 (Christian Borgelt)
    • filter

      public void filter(double start, double end)
      Filter a train set.
      Parameters:
      start - the start of the filter interval
      end - the end of the filter interval
      Since:
      2013.11.28 (Christian Borgelt)
    • pack

      public void pack()
      Pack the trains of a set, i.e., optimize memory usage.
      Since:
      2013.11.29 (Christian Borgelt)
    • getMinTime

      public double getMinTime()
      Get the minimum time.
      Returns:
      the minimum time
      Since:
      2013.11.29 (Christian Borgelt)
    • getMaxTime

      public double getMaxTime()
      Get the maximum time.
      Returns:
      the maximum time
      Since:
      2013.11.29 (Christian Borgelt)
    • write

      public void write(util.TableWriter writer, int mode) throws IOException
      Write a set of trains.
      Parameters:
      writer - the table writer to write to
      mode - the read mode of the writer
      Throws:
      IOException - if a write error occurs
      Since:
      2013.11.28 (Christian Borgelt)
    • parse

      public static TrainSet parse(util.IdMap ibase, util.TableReader reader, int mode) throws IOException
      Parse a set of (spike/event) trains.
      Parameters:
      ibase - the underlying item base
      reader - the table reader to read from
      mode - the read mode of the writer
      Returns:
      the parsed set of (spike/event) trains
      Throws:
      IOException - if a read error occurs
      Since:
      2013.11.28 (Christian Borgelt)
    • parse

      public static TrainSet parse(util.IdMap ibase, Reader reader, int mode) throws IOException
      Parse a set of (spike/event) trains.
      Parameters:
      ibase - the underlying item base
      reader - the reader to read from
      mode - the read mode of the writer
      Returns:
      the parsed set of (spike/event) trains
      Throws:
      IOException - if a read error occurs
      Since:
      2013.11.28 (Christian Borgelt)
    • parse

      public static TrainSet parse(util.IdMap ibase, String desc, int mode) throws IOException
      Parse a set of (spike/event) trains.
      Parameters:
      ibase - the underlying item base
      desc - the string description to parse
      mode - the read mode of the writer
      Returns:
      the parsed set of (spike/event) trains
      Throws:
      IOException - if a read error occurs
      Since:
      2013.11.28 (Christian Borgelt)
    • parse

      public static TrainSet parse(util.IdMap ibase, InputStream inp, int mode) throws IOException
      Parse a set of (spike/event) trains.
      Parameters:
      ibase - the underlying item base
      inp - the input stream to read from
      mode - the read mode of the writer
      Returns:
      the parsed set of (spike/event) trains
      Throws:
      IOException - if a read error occurs
      Since:
      2013.11.28 (Christian Borgelt)
    • main

      public static void main(String[] args)
      Main function for testing some basic functionality.

      It is tried to parse the file that is given as the first command line argument as a set of trains.

      Parameters:
      args - the command line arguments
      Since:
      2013.11.28 (Christian Borgelt)