@Override
  public void initialize(GlobalTermEvidence termEvidence, GlobalEvidence globalEvidence) {
    super.initialize(termEvidence, globalEvidence);
    avgDocLen = (float) globalEvidence.collectionLength / (float) globalEvidence.numDocs;

    if ("none".equals(idfType)) {
      idf = 1;
    } else if ("classic".equals(idfType)) {
      idf = (float) Math.log((float) globalEvidence.numDocs / (float) termEvidence.getDf());
    } else if ("okapi-positive".equals(idfType)) {
      idf =
          (float)
              Math.log(
                  ((float) globalEvidence.numDocs + 0.5f) / ((float) termEvidence.getDf() + 0.5f));
    } else {
      // Defaults to "Okapi" idf.
      idf =
          (float)
              Math.log(
                  ((float) globalEvidence.numDocs - (float) termEvidence.getDf() + 0.5f)
                      / ((float) termEvidence.getDf() + 0.5f));
    }

    maxScore = (k1 + 1.0f) * idf;
  }
 static double score(
     Job unassignedJob,
     InsertionData best,
     InsertionData secondBest,
     ScoringFunction scoringFunction) {
   if (best == null) {
     throw new IllegalStateException("cannot insert job " + unassignedJob.getId());
   }
   double score;
   if (secondBest
       == null) { // either there is only one vehicle or there are more vehicles, but they cannot
     // load unassignedJob
     // if only one vehicle, I want the job to be inserted with min iCosts
     // if there are more vehicles, I want this job to be prioritized since there are no
     // alternatives
     score =
         Integer.MAX_VALUE - best.getInsertionCost() + scoringFunction.score(best, unassignedJob);
   } else {
     score =
         (secondBest.getInsertionCost() - best.getInsertionCost())
             + scoringFunction.score(best, unassignedJob);
   }
   return score;
 }
Example #3
0
  /** 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;
  }