Package com.almende.eve.entity

Examples of com.almende.eve.entity.Weight


 
  // TODO: move tests to a unittest
  public static void main (String[] args) {
    List<Weight> intervals = new ArrayList<Weight>();

    intervals.add(new Weight(
        new DateTime(2012, 8, 4, 8, 0, 0),
        new DateTime(2012, 8, 4, 10, 0, 0),
        new Double(1)));
   
    intervals.add(new Weight(
        new DateTime(2012, 8, 4, 12, 0, 0),
        new DateTime(2012, 8, 4, 14, 0, 0),
        new Double(1)));
   
    intervals.add(new Weight(
        new DateTime(2012, 8, 4, 13, 0, 0),
        new DateTime(2012, 8, 4, 16, 0, 0),
        new Double(1)));

    intervals.add(new Weight(
        new DateTime(2012, 8, 4, 3, 0, 0),
        new DateTime(2012, 8, 4, 4, 0, 0),
        new Double(1)));
   
    intervals.add(new Weight(
        new DateTime(2012, 8, 4, 3, 0, 0),
        new DateTime(2012, 8, 4, 4, 0, 0),
        new Double(1)));
   
    intervals.add(new Weight(
        new DateTime(2012, 8, 4, 3, 0, 0),
        new DateTime(2012, 8, 4, 5, 0, 0),
        new Double(1)));
   
    intervals.add(new Weight(
        new DateTime(2012, 8, 4, 17, 30, 0),
        new DateTime(2012, 8, 4, 18, 0, 0),
        new Double(1.5)));
    intervals.add(new Weight(
        new DateTime(2012, 8, 4, 17, 0, 0),
        new DateTime(2012, 8, 4, 17, 30, 0),
        new Double(1.5)));
   
    List<Weight> merged = WeightsUtil.merge(intervals);
View Full Code Here


    // calculate solutions
    List<Weight> solutions = calculateSolutions();
    if (solutions.size() > 0) {
      // there are solutions. yippie!
      Weight solution = solutions.get(0);
      if (activityInterval == null ||
          !solution.getInterval().equals(activityInterval)) {
        // interval is changed, save new interval
        Status status = activity.withStatus();
        status.setStart(solution.getStart().toString());
        status.setEnd(solution.getEnd().toString());
        status.setActivityStatus(Status.ACTIVITY_STATUS.planned);
        status.setUpdated(DateTime.now().toString());
        state.put("activity", activity);
        logger.info("Activity replanned at " + solution.toString()); // TODO: cleanup logging
        try {
          // TODO: cleanup
          logger.info("Replanned activity: " + JOM.getInstance().writeValueAsString(activity));
        } catch (Exception e) {}
        return true;
View Full Code Here

      final List<Weight> preferred, final Interval test,
      List<Weight> solutions) {
    boolean feasible = calculateFeasible(infeasible, test);
    if (feasible) {
      double weight = calculatePreference(preferred, test);
      solutions.add(new Weight(test, weight));
    }
  }
View Full Code Here

          // This attendee is optional.
          // Add its busy intervals to the soft constraints
          List<Interval> attendeeBusy = getAgentBusy(agent);
          if (attendeeBusy != null) {
            for (Interval i : attendeeBusy) {
              Weight wi = new Weight(
                  i.getStart(), i.getEnd(),
                  WEIGHT_BUSY_OPTIONAL_ATTENDEE);

              preferredIntervals.add(wi);
            }
          }         
        }
        else {
          // this attendee is required.
          // Add its busy intervals to the hard constraints
          List<Interval> attendeeBusy = getAgentBusy(agent);
          if (attendeeBusy != null) {
            infeasibleIntervals.addAll(attendeeBusy);
          }
        }       
      }

      // read the time preferences and add them to the soft constraints
      List<Preference> preferences = activity.withConstraints()
        .withTime().withPreferences();
      for (Preference p : preferences) {
        if (p != null) {
          Weight wi = new Weight(
              new DateTime(p.getStart()),
              new DateTime(p.getEnd()),
              p.getWeight());

          preferredIntervals.add(wi);
        }
      }
    }
   
    // add office hours profile to the soft constraints
    // TODO: don't include (hardcoded) office hours here, should be handled
    // by a PersonalAgent
    DateTime timeMin = DateTime.now();
    DateTime timeMax = timeMin.plusDays(LOOK_AHEAD_DAYS);
    List<Interval> officeHours = IntervalsUtil.getOfficeHours(timeMin,
        timeMax);
    for (Interval i : officeHours) {
      Weight wi = new Weight(i, WEIGHT_OFFICE_HOURS);
      preferredIntervals.add(wi);
    }
   
    // add delay penalties to the soft constraints
    DateTime now = DateTime.now();
    MutableDateTime d = new MutableDateTime(now.getYear(),
        now.getMonthOfYear(), now.getDayOfMonth(), 0, 0, 0, 0);
    for (int i = 0; i <= LOOK_AHEAD_DAYS; i++) {
      DateTime start = d.toDateTime();
      DateTime end = start.plusDays(1);
      Weight wi = new Weight(start, end,
          WEIGHT_DELAY_PER_DAY * i);
      preferredIntervals.add(wi);
      d.addDays(1);
    }

 
View Full Code Here

TOP

Related Classes of com.almende.eve.entity.Weight

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.