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 java.util.*;
029:
030: import org.cougaar.glm.ldm.asset.Organization;
031:
032: import org.cougaar.lib.callback.UTILFilterCallback;
033: import org.cougaar.lib.callback.UTILGenericListener;
034: import org.cougaar.lib.callback.UTILWorkflowCallback;
035:
036: import org.cougaar.lib.vishnu.client.XMLizer;
037: import org.cougaar.lib.vishnu.client.custom.CustomVishnuAllocatorPlugin;
038:
039: import org.cougaar.logistics.ldm.Constants;
040:
041: import org.cougaar.planning.ldm.asset.Asset;
042:
043: import org.cougaar.planning.ldm.plan.AspectType;
044: import org.cougaar.planning.ldm.plan.AspectValue;
045: import org.cougaar.planning.ldm.plan.PlanElement;
046: import org.cougaar.planning.ldm.plan.Preference;
047: import org.cougaar.planning.ldm.plan.Relationship;
048: import org.cougaar.planning.ldm.plan.RelationshipType;
049: import org.cougaar.planning.ldm.plan.Role;
050: import org.cougaar.planning.ldm.plan.ScoringFunction;
051: import org.cougaar.planning.ldm.plan.Task;
052:
053: import org.cougaar.util.TimeSpan;
054: import org.cougaar.util.UnaryPredicate;
055:
056: import org.w3c.dom.Document;
057:
058: public class TranscomRouterVishnuPlugin extends TranscomVishnuPlugin {
059: protected void addExpectedProviders() {
060: try {
061: String EURO_TRANSCOM_ID = (getMyParams()
062: .hasParam("EuroTranscomRole")) ? getMyParams()
063: .getStringParam("EuroTranscomRole")
064: : "EuroStrategicTransportationProvider";
065:
066: String CONUS_TRANSCOM_ID = (getMyParams()
067: .hasParam("ConusTranscomRole")) ? getMyParams()
068: .getStringParam("ConusTranscomRole")
069: : "ConusStrategicTransportationProvider";
070:
071: String AMMO_TRANSCOM_ID = (getMyParams()
072: .hasParam("AmmoTranscomRole")) ? getMyParams()
073: .getStringParam("AmmoTranscomRole")
074: : "AmmoStrategicTransportationProvider";
075:
076: expectedIDs.add(EURO_TRANSCOM_ID);
077: expectedIDs.add(CONUS_TRANSCOM_ID);
078: expectedIDs.add(AMMO_TRANSCOM_ID);
079: } catch (Exception e) {
080: error("got really unexpected exception " + e);
081: }
082: }
083:
084: /**
085: * <pre>
086: * Callback for input tasks
087: *
088: * Provide the callback that is paired with the buffering thread, which is a
089: * listener. The buffering thread is the listener to the callback
090: *
091: * Creates an instance of the WorkflowCallback, which means the plugin
092: * is looking for tasks that are part of workflows.
093: *
094: * </pre>
095: * @param bufferingThread -- the thread the callback informs when there are new input tasks
096: * @return a WorkflowCallback with the buffering thread as its listener
097: */
098: protected UTILFilterCallback createThreadCallback(
099: UTILGenericListener bufferingThread) {
100: if (isInfoEnabled())
101: info(getName() + " Filtering for naked tasks...");
102:
103: myWorkflowCallback = new UTILWorkflowCallback(bufferingThread,
104: logger) {
105: protected UnaryPredicate getPredicate() {
106: return new UnaryPredicate() {
107: public boolean execute(Object o) {
108: if (o instanceof Task) {
109: Task subtask = (Task) o;
110:
111: // if (subtask.getWorkflow() == null) {
112: // return false;
113: // }
114:
115: boolean hasBeenAllocated = (subtask
116: .getPlanElement() != null);
117:
118: UTILGenericListener genericListener = (UTILGenericListener) myListener;
119:
120: boolean interesting = (!hasBeenAllocated && genericListener
121: .interestingTask(subtask));
122:
123: if (logger.isDebugEnabled()) {
124: logger.debug("UTILWorkflowCallback : "
125: + myListener
126: + " examined task "
127: + subtask.getUID());
128: }
129:
130: return interesting;
131: }
132: return false;
133: }
134: };
135: }
136: };
137:
138: return myWorkflowCallback;
139: }
140:
141: /**
142: * Creates an allocation or dispostion if the start and end times
143: * violate the preferences.
144: *
145: * Has to slightly decrease the quantity
146: * because sometimes allocating with the requested quantity will
147: * yield a score of 1.0.
148: *
149: * @param task task being assigned to asset
150: * @param asset asset handling the task
151: * @param start start of the task
152: * @param end end of the task
153: * @param confidence of the allocation
154: * @param role of the allocation
155: * @param quantity of stuff for the task
156: * @return Allocation or Disposition
157: */
158: protected PlanElement createAllocation(Task task, Asset asset,
159: Date start, Date end, double confidence, Role role,
160: double quantity) {
161:
162: double prefQuantity = 0;
163: double allocQuantity = 0;
164:
165: Preference pref = prefHelper.getPrefWithAspectType(task,
166: AspectType.QUANTITY);
167: if (pref != null) {
168: ScoringFunction sfunc = pref.getScoringFunction();
169: prefQuantity = sfunc.getBest().getAspectValue().getValue();
170: allocQuantity = prefQuantity - 0.001;
171: if (isInfoEnabled()) {
172: info("called this " + task.getUID()
173: + " alloc quantity " + allocQuantity
174: + " vs pref " + prefQuantity);
175: }
176: }
177:
178: return super.createAllocation(task, asset, start, end,
179: confidence, role, allocQuantity);
180: }
181: }
|