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;
027:
028: import org.cougaar.planning.ldm.asset.AggregateAsset;
029: import org.cougaar.planning.ldm.asset.Asset;
030: import org.cougaar.planning.ldm.plan.Task;
031: import org.cougaar.planning.ldm.plan.MPTask;
032:
033: import org.cougaar.lib.vishnu.client.VishnuAggregatorPlugin;
034:
035: import org.cougaar.logistics.ldm.Constants;
036: import org.cougaar.glm.ldm.asset.GLMAsset;
037: import org.cougaar.glm.ldm.asset.MovabilityPG;
038: import org.cougaar.glm.ldm.plan.GeolocLocation;
039: import org.cougaar.util.log.Logger;
040:
041: import java.util.Calendar;
042: import java.util.Date;
043: import java.util.Enumeration;
044: import java.util.HashMap;
045: import java.util.Map;
046:
047: import org.cougaar.planning.ldm.plan.AspectScorePoint;
048: import org.cougaar.planning.ldm.plan.AspectScoreRange;
049: import org.cougaar.planning.ldm.plan.AspectType;
050: import org.cougaar.planning.ldm.plan.AspectValue;
051: import org.cougaar.planning.ldm.plan.Preference;
052: import org.cougaar.planning.ldm.plan.ScoringFunction;
053:
054: import org.cougaar.lib.callback.UTILExpandableTaskCallback;
055: import org.cougaar.lib.callback.UTILFilterCallback;
056: import org.cougaar.lib.callback.UTILGenericListener;
057:
058: /**
059: * Note that although this is an aggregator, an expansion is made and subtasks created. <p>
060: *
061: * This is because after the aggregation, the setup and wrapup times must be represented. <br>
062: * They are represented as separate tasks with verb "Transit". They represent the time <br>
063: * taken to travel from the supply point and to return. They should not be figured into <br>
064: * the time that the task takes to perform, since they are only indirectly related to it. <p>
065: *
066: * If the specs were altered, and no setup and wrapup duration were included, only aggregations <br>
067: * would be made, and therefore only MPTask would be produced. The allocator downstream <br>
068: * would have to be sensitive to this change.
069: */
070: public class TransportAggregatorPlugin extends VishnuAggregatorPlugin {
071: boolean debugPrefs = false;
072:
073: /**
074: * Only tasks with transport verbs are given to Vishnu <p>
075: * If a task has no FROM prep, it is not handled. <p>
076: * If a task has a FROM prep that is in CONUS, it is not handled. <p>
077: * If a task is an MPTask (and possibly an output of the plugin), it is not handled.
078: */
079: public boolean interestingTask(Task t) {
080: if (debugPrefs) {
081: for (Enumeration prefs = t.getPreferences(); prefs
082: .hasMoreElements();) {
083: Preference pref = (Preference) prefs.nextElement();
084: int aspectType = pref.getAspectType();
085:
086: AspectValue lower = AspectValue.newAspectValue(
087: aspectType, 0.0d);
088:
089: Calendar cal = java.util.Calendar.getInstance();
090: cal.set(2200, 0, 0, 0, 0, 0);
091: cal.set(Calendar.MILLISECOND, 0);
092: double endOfRange = (double) ((Date) cal.getTime())
093: .getTime();
094: AspectValue upper = AspectValue.newAspectValue(
095: aspectType, endOfRange);
096:
097: print(pref,
098: pref.getScoringFunction().getDefinedRange(),
099: pref.getScoringFunction().getValidRanges(lower,
100: upper), logger);
101: }
102: }
103:
104: boolean hasTransport = t.getVerb().equals(
105: Constants.Verb.TRANSPORT)
106: || t.getVerb().equals(Constants.Verb.TRANSIT);
107:
108: if (!hasTransport)
109: return false;
110: if (!prepHelper.hasPrepNamed(t, Constants.Preposition.FROM)) {
111: if (isInfoEnabled())
112: info(getName()
113: + ".interestingTask - ignoring TRANSPORT task "
114: + t.getUID()
115: + " that doesn't have a FROM prep.");
116: return false;
117: }
118: /*
119: GeolocLocation geoloc =
120: (GeolocLocation) UTILPrepPhrase.getIndirectObject (t, Constants.Preposition.FROM);
121: if (geoloc.getLongitude().getDegrees () < 0) {
122: if (isInfoEnabled())
123: info (getName () + ".interestingTask - ignoring task " + t.getUID() + " with FROM of " + geoloc + " - it's not in theater.");
124: return false;
125: }
126: geoloc =
127: (GeolocLocation) UTILPrepPhrase.getIndirectObject (t, Constants.Preposition.TO);
128: if (geoloc.getLongitude().getDegrees () < 0) {
129: if (isInfoEnabled())
130: info (getName () + ".interestingTask - ignoring task " + t.getUID() + " with TO of " + geoloc + " - it's not in theater.");
131: return false;
132: }
133: */
134:
135: /*
136: boolean hasPrepo = UTILPrepPhrase.hasPrepNamed (t, "PREPO");
137: boolean hasStratTrans = false;
138:
139: if (UTILPrepPhrase.hasPrepNamed (t, "OFTYPE")) {
140: Asset oftype = (Asset) UTILPrepPhrase.getIndirectObject (t, "OFTYPE");
141: String typeid = oftype.getTypeIdentificationPG().getTypeIdentification ();
142: hasStratTrans = typeid.equals ("StrategicTransportation");
143: }
144: */
145:
146: boolean val = !(t instanceof MPTask)
147: && super .interestingTask(t);
148: // !hasPrepo && !hasStratTrans;
149:
150: if (isDebugEnabled() && val)
151: debug(getName() + ".interestingTask - interested in "
152: + t.getUID());
153:
154: return val;
155: }
156:
157: protected void print(Preference pref,
158: AspectScoreRange definedRange, Enumeration validRanges,
159: Logger logger) {
160: double prefval = pref.getScoringFunction().getBest().getValue();
161: String prefstr = "" + prefval;
162: String type = "" + pref.getAspectType();
163: boolean isDate = false;
164: switch (pref.getAspectType()) {
165: case AspectType.START_TIME:
166: type = "START_TIME";
167: prefstr = "" + new Date((long) prefval);
168: isDate = true;
169: break;
170: case AspectType.END_TIME:
171: type = "END_TIME";
172: prefstr = "" + new Date((long) prefval);
173: isDate = true;
174: break;
175: case AspectType.COST:
176: type = "COST";
177: prefstr = "$" + (long) prefval;
178: break;
179: }
180:
181: logger.info("pref type " + type + " value " + prefstr + " sf "
182: + pref.getScoringFunction());
183:
184: for (; validRanges.hasMoreElements();) {
185: AspectScoreRange range = (AspectScoreRange) validRanges
186: .nextElement();
187: AspectScorePoint start = range.getRangeStartPoint();
188: AspectScorePoint end = range.getRangeEndPoint();
189: double startValue = start.getValue();
190: double endValue = end.getValue();
191:
192: if (isDate) {
193: logger.info("<" + new Date((long) (startValue)) + "-"
194: + new Date((long) (endValue)) + "> ");
195: } else {
196: logger.info("<" + startValue + "-" + endValue + "> ");
197: }
198: }
199: logger.info("");
200: }
201:
202: /** only trucks, which have contain pgs, are given to Vishnu */
203: public boolean interestingAsset(Asset a) {
204: if (!(a instanceof GLMAsset)) {
205: if (isInfoEnabled())
206: info(getName() + ".interestingAsset - ignoring asset "
207: + a + " because it's not an GLMAsset.");
208: return false;
209: }
210:
211: boolean val = ((GLMAsset) a).hasContainPG();
212: if (isInfoEnabled() && !val)
213: info(getName() + ".interestingAsset - ignoring GLMAsset "
214: + a + " because it's missing a Contain PG.");
215: return val;
216: }
217: }
|