View Javadoc

    1   package nl.tudelft.simulation.dsol.formalisms.flow;
    2
    3   import java.util.Collections;
    4   import java.util.SortedMap;
    5   import java.util.TreeMap;
    6
    7   import nl.tudelft.simulation.dsol.SimRuntimeException;
    8   import nl.tudelft.simulation.dsol.formalisms.devs.SimEvent;
    9   import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
    10  import nl.tudelft.simulation.jstats.distributions.DistContinuous;
    11  import nl.tudelft.simulation.logger.Logger;
    12
    13  /***
    14   * The schedule is an extension to the generate which accepts a schedule of
    15   * interarrival times. Instead of generating with a continuous interarrival
    16   * distribution we submit a map consiting of keys (execution times). Each key
    17   * indicates the <i>starting time </i> of a new interval, while the value in the
    18   * map is the continuous distribution function to use to draw the interarrival
    19   * times. If no values have to be generated in a certain interval, use a large
    20   * interarrival time value in the distribution function, or use
    21   * DistConstant(stream, 1E20) to indicate that the next drawing will take place
    22   * <i>after </i> the end of the interval. <br>
    23   * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
    24   * University of Technology </a>, the Netherlands. <br>
    25   * See for project information <a
    26   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
    27   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
    28   * License (GPL) </a>, no warranty <br>
    29   *
    30   * @version 2.0 21.09.2003 <br>
    31   * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
    32   *         Jacobs </a>, <a
    33   *         href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
    34   *         Verbraeck </a>
    35   */
    36  public class Schedule extends Generator
    37  {
    38  	/*** schedule is a time sorted map of distributions */
    39  	private SortedMap schedule = Collections
    40  			.synchronizedSortedMap(new TreeMap());
    41
    42  	/***
    43  	 * constructs a new Schedule
    44  	 *
    45  	 * @param simulator is the on which the construction of the objects must be
    46  	 *        scheduled.
    47  	 * @param myClass is the class of which entities are created
    48  	 * @param constructorArguments are the parameters for the constructor of
    49  	 *        myClass. of arguments.
    50  	 *        <code>constructorArgument[n]=new Integer(12)</code> may have
    51  	 *        constructorArgumentClasses[n]=int.class;
    52  	 * @throws SimRuntimeException on constructor invokation.
    53  	 */
    54  	public Schedule(final DEVSSimulatorInterface simulator,
    55  			final Class myClass, final Object[] constructorArguments)
    56  			throws SimRuntimeException
    57  	{
    58  		super(simulator, myClass, constructorArguments);
    59  	}
    60
    61  	/***
    62  	 * returns the schedule
    63  	 *
    64  	 * @return SortedMap the schedule
    65  	 */
    66  	public SortedMap getSchedule()
    67  	{
    68  		return this.schedule;
    69  	}
    70
    71  	/***
    72  	 * sets the schedule
    73  	 *
    74  	 * @param map is the new map
    75  	 */
    76  	public synchronized void setSchedule(final SortedMap map)
    77  	{
    78  		this.schedule = map;
    79  		this.schedule.putAll(map);
    80  		this.changeIntervalTime();
    81  	}
    82
    83  	/***
    84  	 * changes the intervalTime of the schedule
    85  	 */
    86  	public synchronized void changeIntervalTime()
    87  	{
    88  		try
    89  		{
    90  			if (!this.schedule.isEmpty())
    91  			{
    92  				this.simulator.cancelEvent(super.nextEvent);
    93  				this.interval = (DistContinuous) this.schedule.values()
    94  						.iterator().next();
    95  				this.schedule.remove(this.schedule.firstKey());
    96  				this.simulator.scheduleEvent(new SimEvent(
    97  						((Double) this.schedule.firstKey()).doubleValue(),
    98  						this, this, "changeIntervalTime", null));
    99  				this.generate(this.constructorArguments);
    100 				Logger.finest(this, "changeIntervalTime",
    101 						"set the intervalTime to " + this.interval);
    102 			}
    103 		} catch (Exception exception)
    104 		{
    105 			Logger.warning(this, "changeIntervalTime", exception);
    106 		}
    107 	}
    108 }