コード例 #1
0
  public static AllocationResult createEstimatedAllocationResult(Task t, PlanningFactory ldmf) {
    Enumeration preferences = t.getPreferences();
    if (preferences != null && preferences.hasMoreElements()) {
      // do something really simple for now.
      Vector aspects = new Vector();
      Vector results = new Vector();
      while (preferences.hasMoreElements()) {
        Preference pref = (Preference) preferences.nextElement();
        int at = pref.getAspectType();
        aspects.addElement(new Integer(at));
        ScoringFunction sf = pref.getScoringFunction();
        // allocate as if you can do it at the "Best" point
        double myresult = ((AspectScorePoint) sf.getBest()).getValue();
        results.addElement(new Double(myresult));
      }
      int[] aspectarray = new int[aspects.size()];
      double[] resultsarray = new double[results.size()];
      for (int i = 0; i < aspectarray.length; i++)
        aspectarray[i] = (int) ((Integer) aspects.elementAt(i)).intValue();
      for (int j = 0; j < resultsarray.length; j++)
        resultsarray[j] = (double) ((Double) results.elementAt(j)).doubleValue();

      AllocationResult myestimate = ldmf.newAllocationResult(0.0, true, aspectarray, resultsarray);
      return myestimate;
    }
    // if there were no preferences...return a null estimate for the allocation result (for now)
    return null;
  }
コード例 #2
0
ファイル: Filler.java プロジェクト: djw1149/cougaar-logistics
  /** This is the driving function in the whole packing process. */
  public double execute() {
    // boolean finished = false;
    double tonsPacked = 0;

    if (_gp.getLoggingService().isInfoEnabled())
      _gp.getLoggingService().info("Filler.execute - entered.");
    int numTasks = 0;
    int numParents = 0;

    // while there's still ammo to put in milvans
    while (_sz.moreTasksInQueue()) {
      // initialize the aggregation
      ArrayList agglist = new ArrayList();
      double amount = 0.0;
      double earliest = 0.0;
      double latest = java.lang.Double.POSITIVE_INFINITY;

      // while our milvan is not yet full and there is more ammo left to pack
      while (_ac.getQuantity() - amount > MIN_DELTA && _sz.moreTasksInQueue()) {
        // ask the sizer for what an amount that would fill the milvan
        Task t = _sz.provide(_ac.getQuantity() - amount, earliest, latest);
        if (t == null) { // the next task is outside the earliest->latest window
          //	    finished = true;
          break;
        }
        numTasks++;

        // if we reach here, t is a Task that provides
        // some amount towards our overall amount
        double provided = t.getPreferredValue(AspectType.QUANTITY);

        if (_gp.getLoggingService().isInfoEnabled()) {
          _gp.getLoggingService()
              .info(
                  "Filler.execute - adding "
                      + provided
                      + " to agg list vs "
                      + (_ac.getQuantity() - amount)
                      + " amount "
                      + amount);
        }

        Preference endDatePref = t.getPreference(AspectType.END_TIME);
        ScoringFunction sf = endDatePref.getScoringFunction();

        AspectScorePoint aspStart = sf.getDefinedRange().getRangeStartPoint();
        AspectScorePoint aspBest = sf.getBest();
        AspectScorePoint aspEnd = sf.getDefinedRange().getRangeEndPoint();

        Date taskEarlyDate = new Date((long) aspStart.getValue());
        Date taskBestDateMinusFiveDays =
            new Date((long) aspBest.getValue() - MAX_GROUP_DAYS * ONE_DAY_MILLIS);

        // no earlier than earliest arrival, but no more than 5 days before best
        if (taskBestDateMinusFiveDays.getTime() < taskEarlyDate.getTime())
          taskBestDateMinusFiveDays = taskEarlyDate;
        if (taskBestDateMinusFiveDays.getTime() > earliest) {
          earliest = taskBestDateMinusFiveDays.getTime();
        }

        // restrict the window of time within which we'll aggregate tasks together
        // to be
        //
        //   earliest arrival->best date + one day
        //
        // instead of
        //
        //   earliest arrival->latest arrival
        //
        // because that can have problems when we replan
        // tasks without plan elements (happens when all aggregations of an mptask get
        // removed when any parent is removed). Resulting task has too narrow a time
        // window, since the replanned transport task will have an arrival window of
        // now->best date, and now could potentially be too close to the best date.

        Date taskLateDate = new Date((long) aspEnd.getValue());
        Date taskBestDatePlusOneDay = new Date((long) aspBest.getValue() + ONE_DAY_MILLIS);

        // no later than late date, but no more than one day after best
        if (taskBestDatePlusOneDay.getTime() > taskLateDate.getTime())
          taskBestDatePlusOneDay = taskLateDate;
        if (taskBestDatePlusOneDay.getTime() < latest) {
          latest = taskBestDatePlusOneDay.getTime();
        }

        amount += provided;
        agglist.add(t);
      }

      if (!agglist.isEmpty()) {
        double loadedQuantity = createMPTask(agglist);
        numParents += agglist.size();
        TRANSPORT_TONS += loadedQuantity;
        tonsPacked += loadedQuantity;
      }

      if (_gp.getLoggingService().isInfoEnabled()) {
        _gp.getLoggingService()
            .info("Filler.execute - aggregating together " + agglist.size() + " parents:");
        for (Iterator iter = agglist.iterator(); iter.hasNext(); ) {
          Task task = (Task) iter.next();
          _gp.getLoggingService()
              .info(
                  "Filler.execute - "
                      + task.getUID()
                      + " end date "
                      + new Date((long) task.getPreferredValue(AspectType.END_TIME)));
        }
      }
    }

    if (numTasks != numParents)
      _gp.getLoggingService()
          .error(
              "Filler.execute - num tasks created "
                  + numTasks
                  + " != parents of MPTask "
                  + numParents);

    if (numParents != _sz.sizedMade)
      _gp.getLoggingService()
          .error(
              "Filler.execute - sizer num tasks made "
                  + _sz.sizedMade
                  + " != total parents of MPTask "
                  + numParents);

    if (_gp.getLoggingService().isInfoEnabled())
      _gp.getLoggingService()
          .info("Packer  - current aggregated requested transport: " + TRANSPORT_TONS + " tons.");

    if (_gp.getLoggingService().isInfoEnabled())
      _gp.getLoggingService().info("Filler.execute - exited.");

    return tonsPacked;
  }