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

📄 activity.java

📁 java code for seifer secds
💻 JAVA
字号:
/* * (C) Copyright 2005 Davide Brugali, Marco Torchiano * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307  USA */package scheduler;public class Activity {  private int id = 0;  private String name;  private double releaseTime;  private double activationTime;  private double terminationTime;  private double dueTime;  private double duration;  private double tempActivationTime = 0.0;  private double tempTerminationTime = 0.0;  // The constructor initialises the temporal parameters and computes the  // activity's duration. During the execution of the scheduling algorithm, only  // the activation time and the termination time will be updated. The reset()  // method initialises the activation time and termination time before any new run  // of the scheduling algorithm. The toString() method returns the string that  // formats the temporal parameters for their textual visualization on the screen.  public Activity(String name, double r, double a, double t, double d) {    this.name = name;    this.releaseTime = r;    this.activationTime = a;    this.terminationTime = t;    this.dueTime = d;    this.duration = t - a;  }  public int getID() { return id; }  public String getName() { return name; }  public double getActivation() { return activationTime; }  public double getRelease() { return releaseTime; }  public double getTermination() { return terminationTime; }  public double getDueTime() { return dueTime; }  public double getDuration() { return duration; }// P2  public Activity getClone() {    Activity clone = new Activity(name, releaseTime, activationTime, terminationTime, dueTime);    clone.id = id;    return clone;  }  public void copy(Activity clone) {    this.name = clone.name;    this.releaseTime = clone.releaseTime;    this.activationTime = clone.activationTime;    this.terminationTime = clone.terminationTime;    this.dueTime = clone.dueTime;    this.duration = terminationTime - activationTime;  }// P2  public void setID(int id) {    this.id = id;  }  public void setReleaseTime(double time) {    if (time < 0.0)      return;    if (time < activationTime || (time + duration) < dueTime)      releaseTime = time;    if (releaseTime > activationTime) {      activationTime = releaseTime;      terminationTime = activationTime + duration;    }  }  // The next two methods set the values of release time and due date. If  // necessary, they change the values of activation time and termination  // time consistently  public void setDueTime(double time) {    if (time < 0.0)      return;    if (time > this.dueTime || (time - this.duration) > this.releaseTime)      this.dueTime = time;    if (dueTime < terminationTime) {      terminationTime = dueTime;      activationTime = terminationTime - duration;    }  }  public void reset() {    activationTime = 0.0;    terminationTime = activationTime + duration;  }  //    The next two methods update the temporal parameters of the activity.  //    Both are invoked by the TemporalSequnce class. The ensureSequence()  //    method enforces the resource and temporal constraints.  //    The update() method takes into account the activity preferences; in  //    particular, it updates the activation time in order to start the  //    activity after the release time and to complete it as closest as  //    possible to the due date. The parameter gain represents the strength  //    of an activity's preferences.  public void serialize(Activity previous) {    if (previous.terminationTime > this.activationTime)      this.activationTime = previous.terminationTime;    this.terminationTime = this.activationTime + this.duration;  }  public void update(double gain) {    activationTime += gain * (dueTime - terminationTime);    if (activationTime < releaseTime)      activationTime += gain * (releaseTime - activationTime);    terminationTime = activationTime + duration;  }  //    The getPerformance() method implements the formula described in  //    Equation 3.1, where the weights on the earliness and tardiness  //    performance parameters are set to 1.0.  public double getPerformance() {    double pe = 0.0;    double pt = 0.0;    if (terminationTime > dueTime)      pt = (terminationTime - dueTime);    if (activationTime < releaseTime)      pe = (releaseTime - activationTime);    return pe + pt;  }  // The store() method is used to store an activity's temporal parameters that  // correspond to the best performance solution found by the scheduling  // algorithm during a given iteration step.  public void store() {    tempActivationTime = activationTime;    tempTerminationTime = terminationTime;  }  //    The restore() method is invoked at the end of the scheduling process  //    to copy in an activity's temporal parameters the values  //    corresponding to the best performance solution.  public void restore() {    activationTime = tempActivationTime;    terminationTime = tempTerminationTime;  }  public String toString() {    return name        + " ("        + releaseTime        + ", "        + activationTime        + ", "        + terminationTime        + ", "        + dueTime        + ")";  }}

⌨️ 快捷键说明

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