001: /*
002: * <copyright>
003: *
004: * Copyright 1999-2004 Honeywell Inc
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:
027: package org.cougaar.glm.packer;
028:
029: //utils
030: import java.util.ArrayList;
031: import java.util.Calendar;
032: import java.util.Iterator;
033:
034: import org.cougaar.planning.ldm.PlanningFactory;
035: import org.cougaar.planning.ldm.plan.AspectType;
036: import org.cougaar.planning.ldm.plan.AspectValue;
037: import org.cougaar.planning.ldm.plan.Preference;
038: import org.cougaar.planning.ldm.plan.ScoringFunction;
039: import org.cougaar.planning.ldm.plan.Task;
040:
041: /**
042: * This is the PreferenceAggregator used by the packer created by
043: * HTC. The set of preferences it creates is set up to meet the
044: * needs of the TOPS MCCGlobalMode cluster that will be receiving
045: * the tasks the packer creates.
046: */
047: public class DefaultPreferenceAggregator implements
048: PreferenceAggregator {
049: // Start time is set to 40 days prior to the specified end time
050: private static long MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
051: private static long START_DECREMENT = 40 * MILLIS_PER_DAY;
052:
053: /* Increments added to specified end time to come up with an earliest,
054: * best, and latest for TOPS. Distribution specified by
055: * tops team
056: */
057: private static long EARLIEST_INCREMENT = -(21 * MILLIS_PER_DAY);
058: private static long BEST_INCREMENT = 0 * MILLIS_PER_DAY;
059: private static long LATEST_INCREMENT = 0 * MILLIS_PER_DAY;
060:
061: private Calendar myCalendar = Calendar.getInstance();
062:
063: /**
064: * Will create a preference as follows:
065: * START_TIME should be at or greater than 0.0
066: * END_TIME should be bracketed around the earliest END_TIME of
067: * the input tasks and
068: * QUANTITY should be set at the sum of the quantities of the
069: * input tasks.
070: */
071: public ArrayList aggregatePreferences(Iterator tasks,
072: PlanningFactory rootFactory) {
073:
074: ArrayList prefs = new ArrayList();
075: double endTime = java.lang.Double.POSITIVE_INFINITY;
076: double startTime = 0.0;
077: double quantity = 0.0;
078:
079: // find values for endTime and quantity
080: while (tasks.hasNext()) {
081: Task t = (Task) tasks.next();
082:
083: // replaced min with this CWG
084: if (t.getPreferredValue(AspectType.END_TIME) < endTime) {
085: endTime = t.getPreferredValue(AspectType.END_TIME);
086: }
087:
088: // replaced min with this CWG
089: if (t.getPreferredValue(AspectType.START_TIME) > startTime) {
090: startTime = t.getPreferredValue(AspectType.START_TIME);
091: }
092: quantity += t.getPreferredValue(AspectType.QUANTITY);
093: }
094:
095: // make the START_TIME preference
096: // this is a placeholder for more faithful logic later...
097: // [1999/11/15:goldman]
098: //
099: // MSB 1-25-2000 : Make Start time 40 days before end_time
100: startTime = endTime - START_DECREMENT;
101:
102: prefs.add(makeStartPreference(startTime, rootFactory));
103:
104: // make the endTime preference...
105: prefs.add(makeEndPreference(endTime, rootFactory));
106:
107: prefs.add(makeQuantityPreference(quantity, rootFactory));
108: return prefs;
109: }
110:
111: // Added the rootFactory argument. Seemed to need it to make the pref. CGW
112: private Preference makeQuantityPreference(double amount,
113: PlanningFactory rootFactory) {
114: AspectValue av = AspectValue.newAspectValue(
115: AspectType.QUANTITY, amount);
116: ScoringFunction sf = ScoringFunction.createNearOrBelow(av, 0.1);
117: Preference pref = rootFactory.newPreference(
118: AspectType.QUANTITY, sf);
119: return pref;
120: }
121:
122: private Preference makeStartPreference(double startDate,
123: PlanningFactory rootFactory) {
124: AspectValue startTime = AspectValue.newAspectValue(
125: AspectType.START_TIME, startDate);
126: ScoringFunction sf = ScoringFunction.createNearOrAbove(
127: startTime, 0.0);
128: Preference pref = rootFactory.newPreference(
129: AspectType.START_TIME, sf);
130: return pref;
131: }
132:
133: /**
134: * makeEndPreference -
135: * separate earliest, best, and latest for TOPS. Picked 1 day out
136: * of the blue (with help from Gordon
137: */
138: private Preference makeEndPreference(double endDate,
139: PlanningFactory rootFactory) {
140:
141: AspectValue earliest = AspectValue.newAspectValue(
142: AspectType.END_TIME, endDate + EARLIEST_INCREMENT);
143:
144: AspectValue best = AspectValue.newAspectValue(
145: AspectType.END_TIME, endDate + BEST_INCREMENT);
146:
147: AspectValue latest = AspectValue.newAspectValue(
148: AspectType.END_TIME, endDate + LATEST_INCREMENT);
149:
150: ScoringFunction sf = ScoringFunction.createVScoringFunction(
151: earliest, best, latest);
152: Preference pref = rootFactory.newPreference(
153: AspectType.END_TIME, sf);
154: return pref;
155: }
156: }
|