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.asset.AssetGroup;
031: import org.cougaar.planning.ldm.plan.Task;
032: import org.cougaar.planning.ldm.plan.MPTask;
033:
034: import org.cougaar.logistics.ldm.Constants;
035: import org.cougaar.glm.ldm.asset.GLMAsset;
036: import org.cougaar.glm.ldm.asset.MovabilityPG;
037: import org.cougaar.glm.ldm.plan.GeolocLocation;
038: import org.cougaar.glm.util.GLMMeasure;
039: import org.cougaar.glm.util.GLMPrepPhrase;
040:
041: import org.cougaar.planning.ldm.measure.Distance;
042:
043: public class GroundVishnuPlugin extends GenericVishnuPlugin {
044: public void localSetup() {
045: super .localSetup();
046:
047: glmPrepHelper = new GLMPrepPhrase(logger);
048: measureHelper = new GLMMeasure(logger);
049:
050: try {
051: if (getMyParams().hasParam("MAX_DISTANCE"))
052: MAX_DISTANCE = getMyParams()
053: .getIntParam("MAX_DISTANCE");
054: if (getMyParams().hasParam(
055: "complainAboutMissingMovabilityPG"))
056: complainAboutMissingMovabilityPG = getMyParams()
057: .getBooleanParam(
058: "complainAboutMissingMovabilityPG");
059: } catch (Exception e) {
060: if (isWarnEnabled()) {
061: warn("got unexpected exception " + e);
062: }
063: }
064: }
065:
066: /**
067: * Only tasks with transport verbs are given to Vishnu <p>
068: * If a task has no FROM prep, it is not handled. <p>
069: * If a task has a FROM prep that is in CONUS, it is not handled. <p>
070: * If a task is an MPTask (and possibly an output of the plugin), it is not handled.
071: */
072: public boolean interestingTask(Task t) {
073: boolean super Val = super .interestingTask(t);
074: if (!super Val)
075: return false;
076:
077: boolean hasTransportVerb = t.getVerb().equals(
078: Constants.Verb.TRANSPORT);
079:
080: if (!hasTransportVerb)
081: return false;
082:
083: boolean isSelfPropelled = false;
084:
085: Asset directObject = t.getDirectObject();
086: if (!(directObject instanceof AssetGroup))
087: isSelfPropelled = isSelfPropelled(t, directObject);
088:
089: boolean val = !isSelfPropelled;
090:
091: if (isDebugEnabled() && val) {
092: debug(getName() + ".interestingTask - interested in "
093: + t.getUID());
094: }
095: if (isDebugEnabled() && !val) {
096: debug(getName()
097: + ".interestingTask - IGNORING self-propelled "
098: + t.getUID());
099: }
100:
101: return val;
102: }
103:
104: public boolean interestingAsset(Asset a) {
105: if (a instanceof AggregateAsset)
106: return false;
107: if (!(a instanceof GLMAsset))
108: return false;
109:
110: return ((GLMAsset) a).hasContainPG();
111: }
112:
113: public boolean isTaskWellFormed(Task t) {
114: GeolocLocation from = glmPrepHelper.getFromLocation(t);
115: GeolocLocation to = glmPrepHelper.getToLocation(t);
116:
117: Distance distance = measureHelper.distanceBetween(from, to);
118:
119: return (distance.getMiles() < MAX_DISTANCE);
120: }
121:
122: protected void reportIllFormedTask(Task t) {
123: super .reportIllFormedTask(t);
124:
125: if (!isTaskWellFormed(t)) {
126: GeolocLocation from = glmPrepHelper.getFromLocation(t);
127: GeolocLocation to = glmPrepHelper.getToLocation(t);
128:
129: Distance distance = measureHelper.distanceBetween(from, to);
130:
131: error(getName() + ".reportIllFormedTask - task "
132: + t.getUID() + " distance between FROM " + from
133: + " and to " + to + " is > " + MAX_DISTANCE
134: + " miles = " + distance.getMiles());
135: }
136: }
137:
138: protected boolean isSelfPropelled(Task t, Asset directObject) {
139: GLMAsset baseAsset = (directObject instanceof AggregateAsset) ? (GLMAsset) ((AggregateAsset) directObject)
140: .getAsset()
141: : (GLMAsset) directObject;
142:
143: MovabilityPG move_prop = baseAsset.getMovabilityPG();
144:
145: if (move_prop != null) {
146: String cargocatcode = move_prop.getCargoCategoryCode();
147: if ((cargocatcode != null)
148: && (cargocatcode.charAt(0) == 'R')) {
149: if (isDebugEnabled()) {
150: debug(getName()
151: + ".isSelfPropelled - found self-propelled vehicle on task "
152: + t.getUID());
153: }
154: return true;
155: }
156: } else if (complainAboutMissingMovabilityPG) {
157: error(getName() + ".isSelfPropelled - asset " + baseAsset
158: + " is missing its movability PG.");
159: }
160:
161: return false;
162: }
163:
164: protected boolean complainAboutMissingMovabilityPG = false;
165: protected GLMPrepPhrase glmPrepHelper;
166: protected GLMMeasure measureHelper;
167: public int MAX_DISTANCE = 2000;
168: }
|