001: /**
002: * <copyright>
003: *
004: * Copyright 1997-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: */package org.cougaar.logistics.plugin.inventory;
026:
027: import org.cougaar.glm.plugins.ClusterOPlan;
028: import org.cougaar.glm.ldm.asset.Organization;
029: import org.cougaar.core.mts.MessageAddress;
030: import org.cougaar.core.util.UID;
031: import org.cougaar.core.util.UniqueObject;
032: import org.cougaar.core.blackboard.IncrementalSubscription;
033: import org.cougaar.glm.ldm.oplan.Oplan;
034: import org.cougaar.glm.ldm.oplan.OrgActivity;
035: import org.cougaar.glm.ldm.plan.ObjectScheduleElement;
036: import org.cougaar.planning.ldm.plan.Schedule;
037: import org.cougaar.logistics.plugin.utils.ScheduleUtils;
038: import org.cougaar.util.TimeSpan;
039:
040: import java.io.Serializable;
041: import java.util.*;
042:
043: public class LogisticsOPlan extends ClusterOPlan implements
044: UniqueObject {
045:
046: long arrivalInTheater;
047: Schedule defensiveSchedule;
048: UID theUID;
049:
050: public LogisticsOPlan(MessageAddress id, Oplan op) {
051: super (id, op);
052: setUID(UID.toUID(id.toString() + ":" + op.getOplanId() + "/1"));
053: arrivalInTheater = Long.MIN_VALUE;
054: defensiveSchedule = ScheduleUtils
055: .newObjectSchedule((new Vector()).elements());
056: }
057:
058: public boolean updateOrgActivities(
059: IncrementalSubscription orgActivitySubscription) {
060: super .updateOrgActivities(orgActivitySubscription.elements());
061: super .updateOPlanTimes();
062: updateArrivalInTheater(orgActivitySubscription);
063: updateDefensiveSchedule(orgActivitySubscription);
064: // System.out.println("DEFENSIVE SCHEDULE : "+defensiveSchedule);
065: return true;
066: }
067:
068: public void updateArrivalInTheater(
069: IncrementalSubscription orgActivitySubscription) {
070: // Arrival in theater is the end date of the Deployment orgActivity
071: long arrival = Long.MIN_VALUE;
072: OrgActivity activity;
073: Enumeration activities = orgActivitySubscription.elements();
074:
075: // search for Deployment orgActivity
076: while (activities.hasMoreElements()) {
077: activity = (OrgActivity) activities.nextElement();
078: if (activity.getActivityType().equals(
079: OrgActivity.DEPLOYMENT)) {
080: if (activity.getEndTime() > arrival) {
081: arrival = activity.getEndTime();
082: }
083: }
084: }
085: arrivalInTheater = arrival;
086: }
087:
088: public long getArrivalTime() {
089: return arrivalInTheater;
090: }
091:
092: public void updateDefensiveSchedule(
093: IncrementalSubscription orgActivitySubscription) {
094: OrgActivity activity;
095: Enumeration activities = orgActivitySubscription.elements();
096: Vector defensiveList = new Vector();
097: ObjectScheduleElement element = null;
098:
099: // search for Deployment orgActivity
100: while (activities.hasMoreElements()) {
101: activity = (OrgActivity) activities.nextElement();
102: if (activity.getActivityType().equals("Defensive")) {
103: element = new ObjectScheduleElement(activity
104: .getStartTime(), activity.getEndTime(),
105: new Boolean(true));
106: } else {
107: element = new ObjectScheduleElement(activity
108: .getStartTime(), activity.getEndTime(),
109: new Boolean(false));
110: }
111: defensiveList.add(element);
112: }
113: Schedule tmpSched = ScheduleUtils
114: .newObjectSchedule(defensiveList.elements());
115: defensiveSchedule = ScheduleUtils
116: .simplifyObjectSchedule(tmpSched);
117: }
118:
119: public Schedule getDefensiveSchedule() {
120: return defensiveSchedule;
121: }
122:
123: public UID getUID() {
124: return theUID;
125: }
126:
127: public void setUID(UID theUID) {
128: this .theUID = theUID;
129: }
130:
131: public long getStartTime() {
132: TimeSpan oplanSpan = getOplanSpan();
133: return oplanSpan.getStartTime();
134: }
135:
136: public long getEndTime() {
137: TimeSpan oplanSpan = getOplanSpan();
138: return oplanSpan.getEndTime();
139: }
140:
141: public String toString() {
142: return new String(super .toString() + " Start: "
143: + TimeUtils.dateString(getStartTime()) + " End: "
144: + TimeUtils.dateString(getEndTime()) + " Arrival: "
145: + TimeUtils.dateString(arrivalInTheater));
146: }
147: }
|