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: package org.cougaar.logistics.plugin.trans.base;
027:
028: import java.util.Hashtable;
029: import java.util.Enumeration;
030: import java.util.List;
031: import java.util.Iterator;
032: import java.util.Collection;
033: import java.util.Vector;
034: import java.util.Date;
035:
036: import java.io.Serializable;
037:
038: import org.cougaar.glm.util.GLMPrepPhrase;
039:
040: import org.cougaar.planning.ldm.PlanningFactory;
041: import org.cougaar.planning.ldm.plan.Plan;
042: import org.cougaar.planning.ldm.plan.PlanElement;
043: import org.cougaar.planning.ldm.plan.Allocation;
044: import org.cougaar.planning.ldm.plan.AllocationResult;
045: import org.cougaar.planning.ldm.plan.SubTaskResult;
046: import org.cougaar.planning.ldm.plan.Expansion;
047: import org.cougaar.planning.ldm.plan.Workflow;
048: import org.cougaar.planning.ldm.plan.NewWorkflow;
049: import org.cougaar.planning.ldm.plan.Task;
050: import org.cougaar.planning.ldm.plan.NewTask;
051: import org.cougaar.planning.ldm.plan.AspectType;
052: import org.cougaar.planning.ldm.plan.Schedule;
053: import org.cougaar.planning.ldm.plan.NewSchedule;
054: import org.cougaar.planning.ldm.plan.ScheduleImpl;
055: import org.cougaar.planning.ldm.plan.ScheduleElementImpl;
056:
057: import org.cougaar.planning.ldm.asset.Asset;
058: import org.cougaar.core.mts.MessageAddress;
059:
060: import org.cougaar.glm.ldm.asset.Deck;
061: import org.cougaar.glm.ldm.asset.PhysicalAsset;
062: import org.cougaar.lib.callback.UTILAllocationListener;
063: import org.cougaar.lib.callback.UTILAllocationCallback;
064: import org.cougaar.lib.callback.UTILAssetListener;
065: import org.cougaar.lib.callback.UTILAssetCallback;
066: import org.cougaar.lib.callback.UTILExpansionListener;
067: import org.cougaar.lib.callback.UTILExpansionCallback;
068: import org.cougaar.lib.callback.UTILExpandableTaskCallback;
069: import org.cougaar.lib.callback.UTILFilterCallback;
070: import org.cougaar.lib.callback.UTILGenericListener;
071: import org.cougaar.lib.filter.UTILBufferingPlugin;
072: import org.cougaar.lib.filter.UTILBufferingPluginAdapter;
073: import org.cougaar.lib.util.UTILPrepPhrase;
074: import org.cougaar.lib.util.UTILExpand;
075: import org.cougaar.lib.util.UTILPluginException;
076: import org.cougaar.lib.util.UTILAllocationResultAggregator;
077: import org.cougaar.lib.util.UTILAllocate;
078:
079: import org.cougaar.logistics.plugin.trans.GLMTransConst;
080:
081: import org.cougaar.util.log.Logger;
082:
083: /**
084: ** The following is a base class with important utilities to handle the custom schedule
085: ** elements which make up the sequential plan.
086: **/
087: public abstract class SequentialScheduleElement extends
088: ScheduleElementImpl {
089: protected boolean planned = false;
090: protected Task parentTask;
091: protected Vector dependencies = new Vector();
092: protected Task task;
093:
094: public SequentialScheduleElement(Task parent) {
095: parentTask = parent;
096: }
097:
098: public Task getParentTask() {
099: return parentTask;
100: }
101:
102: public Task getTask() {
103: return task;
104: }
105:
106: public void setTask(Task s) {
107: task = s;
108: }
109:
110: /** The dependencies are managed as a Vector of other Schedule Elements */
111: public void setDependencies(Vector vect) {
112: dependencies = vect;
113: }
114:
115: public Vector getDependencies() {
116: return dependencies;
117: }
118:
119: public boolean isPlanned() {
120: return planned;
121: }
122:
123: public void unplan() {
124: planned = false;
125: }
126:
127: public boolean isReady() {
128: Vector dependencies = getDependencies();
129: for (int i = 0; i < dependencies.size(); i++) {
130: if (!((SequentialScheduleElement) dependencies.elementAt(i))
131: .isPlanned()) {
132: return false;
133: }
134: }
135: return true;
136: }
137:
138: /**
139: * planMe does the essential planning on a schedule element. Presumbly it will create
140: * a task and allocate it. If it does not this architecture will fail
141: *
142: * @param plugin to call publish calls on
143: * @return Task that gets created
144: */
145: public abstract Task planMe(SequentialPlannerPlugin plugin);
146:
147: /**
148: * A default finishPlan which simply fills date information into the schedule. Note
149: * that if this is overridden planned must still be set to true.
150: */
151: public void finishPlan(Allocation alloc,
152: SequentialPlannerPlugin plugin) {
153: AllocationResult AR = alloc.getReportedResult() == null ? alloc
154: .getEstimatedResult() : alloc.getReportedResult();
155: Double d_start = new Double(AR.getValue(AspectType.START_TIME));
156: Double d_end = new Double(AR.getValue(AspectType.END_TIME));
157: setStartDate(new Date(d_start.longValue()));
158:
159: double ds = d_start.doubleValue();
160: double de = d_end.doubleValue();
161:
162: if (de > (ds - 0.1) && de < (ds + 0.1)) { // hack so schedule element doesn't complain about a zero length
163: de += 1000; // but this may be an error
164: d_end = new Double(de);
165:
166: reportZeroDuration(alloc, plugin);
167: }
168:
169: setEndDate(new Date(d_end.longValue()));
170: planned = true;
171: }
172:
173: /** default does nothing */
174: protected void reportZeroDuration(Allocation alloc,
175: SequentialPlannerPlugin plugin) {
176: }
177: }
|