Package com.almende.eve.entity

Examples of com.almende.eve.entity.Weight


    // 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

    // 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

    // 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

    // copy the intervals
    ArrayList<Weight> merged = new ArrayList<Weight>();
   
    for (Weight newInterval : intervals) {
      // create a copy of the interval to be merged
      Weight interval = new Weight(newInterval);

      // check if the interval overlaps with any of the others
      int i = 0;
      while (i < merged.size() && interval != null) {
        Weight other = merged.get(i);
        if (interval.getInterval().overlaps(other.getInterval())) {
          // we have an overlap
          // split these two overlapping intervals in three intervals:
          // leftInterval, centerInterval, rightInterval

          // find the start of the left interval
          DateTime start = null;
          Double leftWeight = null;
          if (interval.getStart().isBefore(other.getStart())) {
            start = interval.getStart();
            leftWeight = interval.getWeight();
          }
          else {
            start = other.getStart();
            leftWeight = other.getWeight();
          }
         
          // find the start of the center interval (= end of left interval)
          DateTime centerStart = null;
          if (interval.getStart().isAfter(other.getStart())) {
            centerStart = interval.getStart();
          }
          else {
            centerStart = other.getStart();
          }

          Double centerWeight = interval.getWeight() + other.getWeight();
         
          // find the end of the center interval (= start of right interval)
          DateTime centerEnd = null;
          if (interval.getEnd().isBefore(other.getEnd())) {
            centerEnd = interval.getEnd();
          }
          else {
            centerEnd = other.getEnd();
          }

          // find the end of the right interval
          DateTime end = null;
          Double rightWeight = null;
          if (interval.getEnd().isAfter(other.getEnd())) {
            end = interval.getEnd();
            rightWeight = interval.getWeight();
          }
          else {
            end = other.getEnd();
            rightWeight = other.getWeight();
          }

          // replace old, merged interval with the overlapping part
          if (centerEnd.isAfter(centerStart)) {
            Weight centerInterval = new Weight(
                centerStart, centerEnd, centerWeight);
            merged.set(i, centerInterval);
          }

          // insert a new interval left from the overlapping part
          if (centerStart.isAfter(start)) {
            Weight leftInterval = new Weight(
                start, centerStart, leftWeight);
            merged.add(i, leftInterval);
            i++;
          }
         
          // replace interval with the residual, the non-overlapping
          // right part of the two intervals
          if (end.isAfter(centerEnd)) {
            interval = new Weight(centerEnd, end,
                rightWeight);
          }
          else {
            interval = null;
          }
        }
        else if (interval.getEnd().isBefore(other.getStart()) ||
            interval.getEnd().equals(other.getStart())) {
          // interval is before merged interval. Insert the interval
          // at this position in the list.
          merged.add(i, interval);
          interval = null;
          i++;
        }
        else {
          // interval is after merged interval. check the next merged
          // interval in the list
        }

        i++;
      }
     
      // if interval is not yet merged, add it to the end of the list
      if (interval != null) {
        merged.add(interval);
        interval = null;
      }     
    }
   
    // merge intervals which exactly align
    // (end equals start and weight is the same)
    int i = 1;
    while (i < merged.size()) {
      Weight prev = merged.get(i - 1);
      Weight cur = merged.get(i);
      if (prev.getWeight().equals(cur.getWeight()) &&
          prev.getEnd().equals(cur.getStart())) {
        Weight combi = new Weight(prev.getStart(),
            cur.getEnd(), prev.getWeight());
        merged.set(i - 1, combi);
        merged.remove(i);
        i--;
      }
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.