Class Engine<T>

  • Type Parameters:
    T - ignored
    All Implemented Interfaces:
    it.unibo.alchemist.core.interfaces.Simulation<T>, java.lang.Runnable

    public final class Engine<T>
    extends java.lang.Object
    implements it.unibo.alchemist.core.interfaces.Simulation<T>
    This class implements a simulation. It offers a wide number of static factories to ease the creation process.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Engine.StateCommand<T>
      This class provides a flexible Builder to create a new Command whose aim is to change the status of a Engine.
    • Constructor Summary

      Constructors 
      Constructor Description
      Engine​(it.unibo.alchemist.model.interfaces.Environment<T> e, long maxSteps)
      Builds a simulation for a given environment.
      Engine​(it.unibo.alchemist.model.interfaces.Environment<T> e, long maxSteps, it.unibo.alchemist.model.interfaces.Time t)
      Builds a simulation for a given environment.
      Engine​(it.unibo.alchemist.model.interfaces.Environment<T> e, it.unibo.alchemist.model.interfaces.Time t)
      Builds a simulation for a given environment.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addCommand​(it.unibo.alchemist.core.interfaces.Command<T> comm)  
      void addOutputMonitor​(it.unibo.alchemist.boundary.interfaces.OutputMonitor<T> op)  
      static <T> void addOutputMonitor​(it.unibo.alchemist.model.interfaces.Environment<T> env, it.unibo.alchemist.boundary.interfaces.OutputMonitor<T> monitor)
      Statically searches for the simulation running some environment, and adds an OutputMonitor to it.
      static <T> Engine<T> buildSimulation​(it.unibo.alchemist.model.interfaces.Environment<T> env)  
      static <T> Engine<T> buildSimulation​(it.unibo.alchemist.model.interfaces.Environment<T> env, long steps)  
      static <T> Engine<T> buildSimulation​(it.unibo.alchemist.model.interfaces.Environment<T> env, long steps, it.unibo.alchemist.model.interfaces.Time t)  
      static <T> Engine<T> buildSimulation​(it.unibo.alchemist.model.interfaces.Environment<T> env, it.unibo.alchemist.model.interfaces.Time t)  
      static <T> Engine<T> fromEnvironment​(it.unibo.alchemist.model.interfaces.Environment<T> env)
      Given an environment, returns the corresponding simulation.
      it.unibo.alchemist.core.interfaces.DependencyGraph<T> getDependencyGraph()  
      it.unibo.alchemist.model.interfaces.Environment<T> getEnvironment()  
      java.lang.Throwable getError()  
      long getFinalStep()  
      it.unibo.alchemist.model.interfaces.Time getFinalTime()  
      it.unibo.alchemist.core.interfaces.ReactionManager<T> getReactionManager()  
      it.unibo.alchemist.core.interfaces.Status getStatus()  
      long getStep()  
      it.unibo.alchemist.model.interfaces.Time getTime()  
      static <T> void neighborAdded​(it.unibo.alchemist.model.interfaces.Environment<T> env, it.unibo.alchemist.model.interfaces.Node<T> node, it.unibo.alchemist.model.interfaces.Node<T> n)  
      static <T> void neighborRemoved​(it.unibo.alchemist.model.interfaces.Environment<T> env, it.unibo.alchemist.model.interfaces.Node<T> node, it.unibo.alchemist.model.interfaces.Node<T> n)  
      static <T> void nodeAdded​(it.unibo.alchemist.model.interfaces.Environment<T> env, it.unibo.alchemist.model.interfaces.Node<T> node)
      This method provide a facility for adding all the reactions of a node to the current simulation, creating also the dependencies.
      static <T> void nodeMoved​(it.unibo.alchemist.model.interfaces.Environment<T> env, it.unibo.alchemist.model.interfaces.Node<T> node)  
      static <T> void nodeRemoved​(it.unibo.alchemist.model.interfaces.Environment<T> env, it.unibo.alchemist.model.interfaces.Node<T> node, it.unibo.alchemist.model.interfaces.Neighborhood<T> oldNeighborhood)
      This method provide a facility for removing all the reactions of a node from the current simulation, along with their dependencies.
      void removeOutputMonitor​(it.unibo.alchemist.boundary.interfaces.OutputMonitor<T> op)  
      static <T> void removeReaction​(it.unibo.alchemist.model.interfaces.Environment<T> env, it.unibo.alchemist.model.interfaces.Reaction<T> r)  
      void run()  
      java.lang.String toString()  
      it.unibo.alchemist.core.interfaces.Status waitFor​(it.unibo.alchemist.core.interfaces.Status s, long timeout, java.util.concurrent.TimeUnit tu)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Engine

        public Engine​(it.unibo.alchemist.model.interfaces.Environment<T> e,
                      it.unibo.alchemist.model.interfaces.Time t)
        Builds a simulation for a given environment. By default it uses a DependencyGraph and an IndexedPriorityQueue internally. If you want to use your own implementations of DependencyGraph and ReactionManager interfaces, don't use this constructor.
        Parameters:
        e - the environment at the initial time
        t - the maximum time to reach
      • Engine

        public Engine​(it.unibo.alchemist.model.interfaces.Environment<T> e,
                      long maxSteps)
        Builds a simulation for a given environment. By default it uses a DependencyGraph and an IndexedPriorityQueue internally. If you want to use your own implementations of DependencyGraph and ReactionManager interfaces, don't use this constructor.
        Parameters:
        e - the environment at the initial time
        maxSteps - the maximum number of steps to do
      • Engine

        public Engine​(it.unibo.alchemist.model.interfaces.Environment<T> e,
                      long maxSteps,
                      it.unibo.alchemist.model.interfaces.Time t)
        Builds a simulation for a given environment. By default it uses a DependencyGraph and an IndexedPriorityQueue internally. If you want to use your own implementations of DependencyGraph and ReactionManager interfaces, don't use this constructor.
        Parameters:
        e - the environment at the initial time
        maxSteps - the maximum number of steps to do
        t - the maximum time to reach
    • Method Detail

      • addOutputMonitor

        public static <T> void addOutputMonitor​(it.unibo.alchemist.model.interfaces.Environment<T> env,
                                                it.unibo.alchemist.boundary.interfaces.OutputMonitor<T> monitor)
        Statically searches for the simulation running some environment, and adds an OutputMonitor to it.
        Type Parameters:
        T - The format of the concentrations
        Parameters:
        env - The current environment
        monitor - The monitor to add
      • buildSimulation

        public static <T> Engine<T> buildSimulation​(it.unibo.alchemist.model.interfaces.Environment<T> env)
        Type Parameters:
        T - The format of the concentrations
        Parameters:
        env - The environment to be simulated
        Returns:
        A simulation ready to be run, the environment structures get updated coherently
      • buildSimulation

        public static <T> Engine<T> buildSimulation​(it.unibo.alchemist.model.interfaces.Environment<T> env,
                                                    it.unibo.alchemist.model.interfaces.Time t)
        Type Parameters:
        T - The format of the concentrations
        Parameters:
        env - The environment to be simulated
        t - The final simulation time to reach
        Returns:
        A simulation ready to be run, the environment structures get updated coherently
      • buildSimulation

        public static <T> Engine<T> buildSimulation​(it.unibo.alchemist.model.interfaces.Environment<T> env,
                                                    long steps)
        Type Parameters:
        T - The format of the concentrations
        Parameters:
        env - The environment to be simulated
        steps - The number of steps to run
        Returns:
        A simulation ready to be run, the environment structures get updated coherently
      • buildSimulation

        public static <T> Engine<T> buildSimulation​(it.unibo.alchemist.model.interfaces.Environment<T> env,
                                                    long steps,
                                                    it.unibo.alchemist.model.interfaces.Time t)
        Type Parameters:
        T - The format of the concentrations
        Parameters:
        env - The environment to be simulated
        steps - The number of steps to run
        t - The final simulation time to reach
        Returns:
        A simulation ready to be run, the environment structures get updated coherently
      • fromEnvironment

        public static <T> Engine<T> fromEnvironment​(it.unibo.alchemist.model.interfaces.Environment<T> env)
        Given an environment, returns the corresponding simulation.
        Type Parameters:
        T - concentrations
        Parameters:
        env - the environment
        Returns:
        the simulation
      • neighborAdded

        public static <T> void neighborAdded​(it.unibo.alchemist.model.interfaces.Environment<T> env,
                                             it.unibo.alchemist.model.interfaces.Node<T> node,
                                             it.unibo.alchemist.model.interfaces.Node<T> n)
        Type Parameters:
        T - Type for concentrations
        Parameters:
        env - the environment
        node - first node
        n - second node
      • neighborRemoved

        public static <T> void neighborRemoved​(it.unibo.alchemist.model.interfaces.Environment<T> env,
                                               it.unibo.alchemist.model.interfaces.Node<T> node,
                                               it.unibo.alchemist.model.interfaces.Node<T> n)
        Type Parameters:
        T - Type for concentrations
        Parameters:
        env - the environment
        node - first node
        n - second node
      • nodeMoved

        public static <T> void nodeMoved​(it.unibo.alchemist.model.interfaces.Environment<T> env,
                                         it.unibo.alchemist.model.interfaces.Node<T> node)
        Type Parameters:
        T - Type for concentrations
        Parameters:
        env - the environment
        node - the node
      • nodeAdded

        public static <T> void nodeAdded​(it.unibo.alchemist.model.interfaces.Environment<T> env,
                                         it.unibo.alchemist.model.interfaces.Node<T> node)
        This method provide a facility for adding all the reactions of a node to the current simulation, creating also the dependencies. This method must be called only when it is possible for the environment to successfully compute the neighborhood for the new node.
        Type Parameters:
        T - Type for concentrations
        Parameters:
        env - the environment
        node - the freshly added node
      • nodeRemoved

        public static <T> void nodeRemoved​(it.unibo.alchemist.model.interfaces.Environment<T> env,
                                           it.unibo.alchemist.model.interfaces.Node<T> node,
                                           it.unibo.alchemist.model.interfaces.Neighborhood<T> oldNeighborhood)
        This method provide a facility for removing all the reactions of a node from the current simulation, along with their dependencies. This method must be called when it is still possible for the environment to successfully compute the neighborhood for the removed node.
        Type Parameters:
        T - Type for concentrations
        Parameters:
        env - the environment
        node - the freshly removed node
        oldNeighborhood - the neighborhood of the node as it was before it was removed (used to calculate reverse dependencies)
      • removeReaction

        public static <T> void removeReaction​(it.unibo.alchemist.model.interfaces.Environment<T> env,
                                              it.unibo.alchemist.model.interfaces.Reaction<T> r)
        Type Parameters:
        T - Type for concentrations
        Parameters:
        env - the environment
        r - the removed reaction
      • addOutputMonitor

        public void addOutputMonitor​(it.unibo.alchemist.boundary.interfaces.OutputMonitor<T> op)
        Specified by:
        addOutputMonitor in interface it.unibo.alchemist.core.interfaces.Simulation<T>
      • removeOutputMonitor

        public void removeOutputMonitor​(it.unibo.alchemist.boundary.interfaces.OutputMonitor<T> op)
        Specified by:
        removeOutputMonitor in interface it.unibo.alchemist.core.interfaces.Simulation<T>
      • getDependencyGraph

        public it.unibo.alchemist.core.interfaces.DependencyGraph<T> getDependencyGraph()
        Returns:
        the dependency graph
      • getEnvironment

        public it.unibo.alchemist.model.interfaces.Environment<T> getEnvironment()
        Specified by:
        getEnvironment in interface it.unibo.alchemist.core.interfaces.Simulation<T>
      • getFinalStep

        public long getFinalStep()
        Specified by:
        getFinalStep in interface it.unibo.alchemist.core.interfaces.Simulation<T>
      • getFinalTime

        public it.unibo.alchemist.model.interfaces.Time getFinalTime()
        Specified by:
        getFinalTime in interface it.unibo.alchemist.core.interfaces.Simulation<T>
      • getReactionManager

        public it.unibo.alchemist.core.interfaces.ReactionManager<T> getReactionManager()
        Returns:
        The IPQ
      • getStatus

        public it.unibo.alchemist.core.interfaces.Status getStatus()
        Specified by:
        getStatus in interface it.unibo.alchemist.core.interfaces.Simulation<T>
      • getStep

        public long getStep()
        Specified by:
        getStep in interface it.unibo.alchemist.core.interfaces.Simulation<T>
      • getTime

        public it.unibo.alchemist.model.interfaces.Time getTime()
        Specified by:
        getTime in interface it.unibo.alchemist.core.interfaces.Simulation<T>
      • addCommand

        public void addCommand​(it.unibo.alchemist.core.interfaces.Command<T> comm)
        Specified by:
        addCommand in interface it.unibo.alchemist.core.interfaces.Simulation<T>
      • waitFor

        public it.unibo.alchemist.core.interfaces.Status waitFor​(it.unibo.alchemist.core.interfaces.Status s,
                                                                 long timeout,
                                                                 java.util.concurrent.TimeUnit tu)
        Specified by:
        waitFor in interface it.unibo.alchemist.core.interfaces.Simulation<T>
      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getError

        public java.lang.Throwable getError()
        Returns:
        the error, or null if there is none