예제 #1
0
 public Route clone() {
   Route r = new Route(this.nw, this.id, this.period);
   r.emptyDistance = this.emptyDistance;
   r.loadedDistance = this.loadedDistance;
   r.waitTime = this.waitTime;
   // This clone copies the TA as well not just reference.
   int taskSetSize = taskSet.size();
   for (int i = 0; i < taskSetSize; i++) {
     r.taskSet.add(taskSet.get(i).clone());
   }
   return r;
 }
예제 #2
0
  /**
   * get all the routes that has been assigned from the database save into Vector<Route> to be used
   * by Change.java controller
   *
   * @return
   */
  public Vector<Route> getRoutes() {
    DBManager m = new DBManager();
    ResultSet rs =
        m.getRs(
            "SELECT r.id AS route_id,s.sessionID,session_driverName,"
                + "session_vehicleID,startTime,expireTime,status,shift_normal_start_time "
                + "FROM Route r,Session s WHERE s.sessionID = r.sessionID");
    Vector<Route> routes = new Vector<Route>();
    try {
      while (rs.next()) {
        int route_id = rs.getInt("route_id");
        int sessionID = rs.getInt("sessionID");
        String driverName = rs.getString("session_driverName");
        String vehicleID = rs.getString("session_vehicleID");
        long startTime = Long.parseLong(rs.getString("startTime"));
        long expireTime = Long.parseLong(rs.getString("expireTime"));
        int status =
            rs.getInt(
                "status"); // status, 0:UNASSIGNED, 1:ASSIGNED£¬2£ºSESSION_SUSPENDED£¬
                           // 3£ºSESSION_ENDED

        Calendar shift_normal_start_time =
            StringToCalendar(rs.getString("shift_normal_start_time"));
        // TODO:What is Network and period
        Route route = new Route(null, route_id, 0);

        XMLSession session = new XMLSession(driverName, vehicleID, startTime, expireTime);
        route.setSession(session);
        route.setStatus(intToStatus(status));
        ;
        // TODO:HOW to use the shift_normal_start_time?
        Vector<Task> taskSet = new Vector<Task>();
        ResultSet rss =
            m.getRs(
                "SELECT t.id AS task_id, t.commodity_id,sequence_num,"
                    + "t.small AS task_small,t.large AS task_large,planned_start,planned_finish,"
                    + "actual_start,actual_finish,source,destination,available_t,deadline,"
                    + "c.small AS com_small, c.large AS com_large,finished_small,finished_large "
                    + "FROM Route r, Task t, Commodity c "
                    + "WHERE r.id = t.route_id AND t.commodity_id = c.id AND r.id ="
                    + route_id
                    + " "
                    + "ORDER BY sequence_num ASC");
        while (rss.next()) {
          int task_id = rss.getInt("task_id");
          String commodity_id = rss.getString("commodity_id");
          // int sequenceNo = rss.getInt("sequence_num");
          int task_small = rss.getInt("task_small");
          int task_large = rss.getInt("task_large");
          Calendar planned_start = StringToCalendar(rss.getString("planned_start"));
          Calendar planned_finish = StringToCalendar(rss.getString("planned_finish"));
          Calendar actual_start = StringToCalendar(rss.getString("actual_start"));
          Calendar actual_finish = StringToCalendar(rss.getString("actual_finish"));
          String source = rss.getString("source");
          String destination = rss.getString("destination");
          Calendar available_t = StringToCalendar(rss.getString("available_t"));
          Calendar deadline = StringToCalendar(rss.getString("deadline"));
          int com_small = rss.getInt("com_small");
          int com_large = rss.getInt("com_large");
          int finished_small = rss.getInt("com_small");
          int finished_large = rss.getInt("com_large");

          Task t = new Task();
          // TODO:WHAT IS loadTime and unloadTime
          Node src = new Node(source, 0, 0);
          Node des = new Node(destination, 0, 0);

          Commodity c =
              new Commodity(commodity_id, available_t, deadline, src, des, com_small, com_large);
          t.cmdt = c;
          t.taskID = task_id;
          // TODO:Not sure if its right..
          if (task_small > 0) {
            t.size = 1;
          } else {
            t.size = 2;
          }
          t.startT = planned_start;
          t.finishT = planned_finish;
          t.actualStartT = actual_start;
          t.actualFinishT = actual_finish;
          t.driver = driverName;
          t.vehicleID = vehicleID;
          taskSet.add(t);
        }
        route.taskSet = taskSet;
        routes.add(route);
      }
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return routes;
  }