⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eventinputqueue.java

📁 JAVA版的蚂蚁算法(Ant Colony Optimization Algorithms)
💻 JAVA
字号:
package dk.itu.nulx30.eventSimulation;

import dk.itu.nulx30.eventSimulation.exceptions.IllegalTimeException;

import dk.itu.nulx30.networkModel.NetworkPackage;
import dk.itu.nulx30.networkModel.Router;

import dk.itu.nulx30.networkModel.exceptions.RouterQueueFullException;

import dk.itu.nulx30.util.BinaryHeap;

/**
 * This class represents the event, that an input queue of a router has received
 * a package. When this event occurs the package is put into the input queue and
 * an <code>EventRouting</code> event is put into the "global"
 * <code>eventHolder</code>.
 *
 * @author Jacob Wahl Winther
 * @author Mikkel Bundgaard
 * @author Troels C. Damgaard
 * @author Federico Decara
 *
 * @see EventRouting
 */
public class EventInputQueue extends Event {
  /** this router contains the input queue, which receives the package */
  private Router router;
  /** the package to add to the input queue of the router*/
  private NetworkPackage pack;
  /** binary heap, which handles all the events in the whole system*/
  private BinaryHeap eventHolder;
  /** the simulation which in this event has occurred*/
  private EventSimulation simulation;

  /**
   * Class constructor for <code>EventInputQueue</code> which takes a time, a
   * <code>Router</code>, a <code>NetworkPackage</code> and a
   * <code>BinaryHeap</code> as arguments.
   *
   * @param newtime the time when this event is about to occur
   * @param theRouter the router, which contains the input queue, which receives
   * the package given as argument
   * @param aPackage the networkpackage to add to the input queue of the router
   * given as argument
   * @param bh the "global" binary heap, which handles all the events in the
   * system
   * @param sim the simulation in which this event has occurred
   */
  public EventInputQueue( double newtime, Router theRouter,
                 NetworkPackage aPackage, BinaryHeap bh, EventSimulation sim ) {
    super( newtime );
    router = theRouter;
    pack = aPackage;
    eventHolder = bh;
    simulation = sim;
  }

  /**
   * This method is called when this event occurs.
   */
  public void doEvent() {
    pack.setTime( getTime() ); // Update the timecounter in package
    try {
      router.addPackageToInputQueue( pack ); // put package into inputQueue
      // A new event (EventRouting) must be created
      EventRouting newE;
      if ( getTime() >= router.getNextEventTime() ) { // Router is ready
        newE = new EventRouting( getTime() + router.getDelay(), router, pack,
                                      eventHolder, simulation );
        // make the "queue" longer
        router.setNextEventTime( getTime() + router.getDelay() );
      }
      else { // Router is busy and package must wait in queue
        newE = new EventRouting(
           router.getNextEventTime() + router.getDelay(), router, pack,
                                                           eventHolder, simulation );
        // make the "queue" longer
        router.setNextEventTime( router.getNextEventTime() + router.getDelay() );
      }
      eventHolder.add( newE );
    }
    catch ( RouterQueueFullException RQFe ) {
      simulation.incInputQueueDeaths( 1 );
      simulation.incrementLostPackages();
      simulation.incrementAccumulatedPackageTime( pack.getTimeInNetwork(), true );
      simulation.getRoutingAlgorithm().packageLost( pack );
    }
    catch ( IllegalTimeException ITe ) {
      ITe.printStackTrace();
      // Should not happen!
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -