01: /*
02: * <copyright>
03: *
04: * Copyright 1997-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26:
27: package org.cougaar.mlm.plugin.sample;
28:
29: import java.util.Date;
30: import java.util.Enumeration;
31:
32: import org.cougaar.planning.ldm.plan.AllocationResult;
33: import org.cougaar.planning.ldm.plan.AspectType;
34: import org.cougaar.planning.ldm.plan.Predictor;
35: import org.cougaar.planning.ldm.plan.Preference;
36: import org.cougaar.planning.ldm.plan.Task;
37: import org.cougaar.planning.plugin.legacy.PluginDelegate;
38:
39: public class MCCPredictor implements Predictor {
40: long SHIP_DAYS = 86400000L;
41:
42: public AllocationResult Predict(Task for_task, PluginDelegate plugin) {
43: // Get Task Preferences, paying attention only to START_TIME
44: // and END_TIME for this simple example;
45: Date start = null;
46: Date end = null;
47: boolean is_success = true;
48: Enumeration preferences = for_task.getPreferences();
49: while (preferences.hasMoreElements()) {
50: Preference pref = (Preference) preferences.nextElement();
51: int at = pref.getAspectType();
52: if (at == AspectType.START_TIME)
53: start = new Date(pref.getScoringFunction().getBest()
54: .getAspectValue().longValue());
55: if (at == AspectType.END_TIME)
56: end = new Date(pref.getScoringFunction().getBest()
57: .getAspectValue().longValue());
58: }
59: int[] aspect_array = null;
60: double[] results_array = null;
61: if ((end.getTime() - start.getTime()) < SHIP_DAYS) {
62: is_success = false;
63: aspect_array = new int[1];
64: results_array = new double[1];
65: } else {
66: aspect_array = new int[2];
67: results_array = new double[2];
68: aspect_array[0] = AspectType.START_TIME;
69: aspect_array[1] = AspectType.END_TIME;
70: results_array[0] = (double) start.getTime();
71: results_array[0] = (double) (start.getTime() + SHIP_DAYS);
72: ;
73: }
74: AllocationResult myestimate = plugin.getFactory()
75: .newAllocationResult(0.1, is_success, aspect_array,
76: results_array);
77: return myestimate;
78: }
79: }
|