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

📄 datapackage.java

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

import java.util.ArrayList;

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

/**
 * Represents the datapackages transferred in the network model. A package contains
 * a list of all routers it has visited.
 *
 * @author Jacob Wahl Winther
 * @author Mikkel Bundgaard
 * @author Troels C. Damgaard
 * @author Federico Decara
 */
public class DataPackage implements NetworkPackage{
  /** Contains the List of Routers this package has visited */
  private ArrayList pathList = new ArrayList();

  /**
   * The source Router from which this package was sent, cannot be modified
   * after initialization
   */
  private Router source;

  /**
   * The destination Router for this package, cannot be modified after
   * initialization
   */
  private Router destination;

  /**
   * Indicates the Time To Live for this package - cannot be externaly modified
   */
  private int ttl;

  /** Current time for the package */
  private double time = 0;

  /** The time when the AntPackage is created */
  private double startTime = 0;

  /**
   * Class constructor specifying the source router, the destination router
   * and the TTL of this object.
   *
   * @param s The source router.
   * @param d The destination router.
   * @param ttl time-to-live value.
   * @param startTime the start time of this package
   */
  public DataPackage( Router s, Router d, int ttl, int startTime ) {
    source = s;
    destination = d;
    this.ttl = ttl;
    this.startTime = startTime;
  }

  /**
   * Appends the router to the pathList. A <code>PackageTTLException</code> is
   * thrown if a package has exceeded its TTL limit.
   *
   * @param w the wire to move by
   * @param r Router to add to pathList
   *
   * @exception PackageTTLException a <code>PackageTTLException</code> is
   * thrown if a package has exceeded its TTL limit.
   *
   * @see dk.itu.nulx30.networkModel.exceptions.PackageTTLException
   */
  public void addRouterToPathList( Wire w, Router r ) throws PackageTTLException {
    if ( ttl-- == 0 ) {
      throw new PackageTTLException( "DataPackage from " + source.getIndex() +
                " to " + destination.getIndex() + " Timed out " );
    }
    pathList.add( r );
  }

  /**
   * Returns the Path list for the package
   *
   * @return the path list for this object
   */
  public ArrayList getPathList() {
    return pathList;
  }

  /**
   * Returns the source Router for this package
   *
   * @return the source Router for this package
   */
  public Router getSource() {
    return source;
  }

  /**
   * Returns the destination Router for this package
   *
   * @return the destination Router for this package
   */
  public Router getDestination() {
    return destination;
  }

  /**
   * Updates the time of this package to <code>newTime</code>.
   *
   * @param newTime the new time of this object
   */
  public void setTime( double newTime ) {
    time = newTime;
  }

  /**
   * Gets the time of this package
   *
   * @return the time of this package
   */
  public double getTime() {
    return time;
  }

  /**
   * Get the difference between creation time and current time for package
   *
   * @return the time this package has spent in the network
   */
  public double getTimeInNetwork() {
    return time - startTime;
  }
}

⌨️ 快捷键说明

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