Example #1
0
 private ArrayList<Long> findSegmetsEdgeIsPartOf(Node node, boolean isOrigin) {
   ResultSet rs = null;
   PreparedStatement stmt = null;
   ArrayList<Long> ids = new ArrayList<>();
   try {
     stmt =
         db.prepareStatement(
             "SELECT SEGMENTS.ID FROM SEGMENTS, EDGES WHERE EDGES."
                 + (isOrigin ? "ORIGIN" : "DESTINATION")
                 + "= "
                 + node.id
                 + " AND SEGMENTS.ID = EDGES.SEGMENT");
     rs = db.executeQuery(stmt);
     while (rs.next()) {
       long segmentId = rs.getLong("id");
       ids.add(segmentId);
     }
     return ids;
   } catch (SQLException e) {
     System.err.println("Error getting segmentid from method modelNodeToSegment");
     e.printStackTrace();
   } finally {
     try {
       rs.close();
       stmt.close();
     } catch (SQLException e) {
       e.printStackTrace();
     }
   }
   return null;
 }
Example #2
0
 private Segment createSegmentFromEdges(long edgeId, long segmentId, boolean isEdgeOrigin) {
   double length = 0.0;
   Segment seg = null;
   try {
     List<Edge> subset = null;
     seg = db.ReadSegment(segmentId);
     ArrayList<Edge> edges = db.ReadEdges(segmentId);
     Edge edge = null;
     if (!edges.isEmpty()) {
       if (isEdgeOrigin) {
         edge =
             edges
                 .stream()
                 .filter(
                     (Edge e) -> {
                       return e.mOrigin == edgeId;
                     })
                 .findFirst()
                 .get();
       } else {
         edge =
             edges
                 .stream()
                 .filter(
                     (Edge e) -> {
                       return e.mDestination == edgeId;
                     })
                 .findFirst()
                 .get();
       }
       int index = edges.indexOf(edge);
       subset = edges.subList(index, edges.size());
       for (Edge ed : subset) {
         length = +ed.mLength;
       }
     }
     long origin, destination;
     origin = (isEdgeOrigin ? edgeId : seg.mOrigin);
     destination = (isEdgeOrigin ? seg.mDestination : edgeId);
     Segment s = new Segment(nextSegId++, length, seg.mWayId, origin, destination);
     return s;
   } catch (SQLException e) {
     System.err.println("Error getting segmentid from method modelNodeToSegment");
     e.printStackTrace();
   }
   return null;
 }
Example #3
0
 private ArrayList<Segment> createFalseSegments(Node node, boolean isOrigin) {
   ArrayList<Long> segmentIds = null;
   LinkedList<SpeedFunction> speedFunctions = null;
   int speedLimit = -1;
   Segment segment;
   ArrayList<Segment> retSegments = new ArrayList<>();
   if (isOrigin) {
     if (!segments
         .stream()
         .anyMatch(
             (Segment s) -> {
               return s.mOrigin == node.id;
             })) {
       segmentIds = findSegmetsEdgeIsPartOf(node, isOrigin);
     }
   } else {
     if (!segments
         .stream()
         .anyMatch(
             (Segment s) -> {
               return s.mDestination == node.id;
             })) {
       segmentIds = findSegmetsEdgeIsPartOf(node, isOrigin);
     }
   }
   if (segmentIds != null) {
     for (long l : segmentIds) {
       segment = createSegmentFromEdges(node.id, l, isOrigin);
       try {
         speedFunctions = db.ReadSpeedFunctionsForSegment(l);
         speedLimit = db.ReadSpeedLimit(l);
       } catch (SQLException e) {
         e.printStackTrace();
       }
       fakeCosts.add(new CostFunction(segment, speedFunctions, speedLimit));
       retSegments.add(segment);
     }
     return retSegments;
   }
   return null;
 }