001: /*
002: * <copyright>
003: *
004: * Copyright 2001-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.planning.plugin.completion;
028:
029: import java.io.Serializable;
030: import java.text.DecimalFormat;
031:
032: import org.cougaar.core.mts.MessageAddress;
033:
034: class Laggard implements Comparable, Serializable {
035: private long timestamp = System.currentTimeMillis();
036: private MessageAddress agent;
037: private double blackboardCompletion;
038: private double cpuConsumption;
039: private boolean isLaggard;
040:
041: // private Map verbCounts = new HashMap();
042: Laggard(MessageAddress me, double blackboardCompletion,
043: double cpuConsumption, boolean isLaggard) {
044: this .agent = me;
045: this .blackboardCompletion = blackboardCompletion;
046: this .cpuConsumption = cpuConsumption;
047: this .isLaggard = isLaggard;
048: }
049:
050: Laggard(MessageAddress me, Laggard oldLaggard) {
051: agent = me;
052: if (oldLaggard != null) {
053: blackboardCompletion = oldLaggard.blackboardCompletion;
054: cpuConsumption = oldLaggard.cpuConsumption;
055: isLaggard = oldLaggard.isLaggard;
056: }
057: }
058:
059: public long getTimestamp() {
060: return timestamp;
061: }
062:
063: public MessageAddress getAgent() {
064: return agent;
065: }
066:
067: public double getBlackboardCompletion() {
068: return blackboardCompletion;
069: }
070:
071: public double getCPUConsumption() {
072: return cpuConsumption;
073: }
074:
075: public boolean isLaggard() {
076: return isLaggard;
077: }
078:
079: // public Map getVerbCounts() {
080: // return verbCounts;
081: // }
082:
083: public int compareTo(Object o) {
084: if (this == o)
085: return 0;
086: Laggard that = (Laggard) o;
087: if (isLaggard()) {
088: if (!that.isLaggard())
089: return -1;
090: } else {
091: if (that.isLaggard())
092: return 1;
093: return 1;
094: }
095: double diff = (this .blackboardCompletion
096: - that.blackboardCompletion + that.cpuConsumption - this .cpuConsumption);
097: if (diff < 0.0)
098: return -1;
099: if (diff > 0.0)
100: return 1;
101: return this .agent.toString().compareTo(that.agent.toString());
102: }
103:
104: private static final DecimalFormat format = new DecimalFormat(
105: "0.00");
106:
107: public String toString() {
108: return "Laggard(" + agent + "," + isLaggard + ","
109: + format.format(blackboardCompletion) + ","
110: + format.format(cpuConsumption) + ")@"
111: + CompletionSourcePlugin.formatDate(timestamp);
112: }
113: }
|