Ejemplo n.º 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;
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
 private ArrayList<FakeNode> getNeighbours(long id) {
   ArrayList<FakeNode> retNodes = new ArrayList<>();
   ArrayList<Segment> neighbours =
       this.segments
           .stream()
           .filter(
               (Segment s) -> {
                 return s.mOrigin == id;
               })
           .collect(Collectors.toCollection(ArrayList<Segment>::new));
   neighbours.addAll(
       this.fakeSegments
           .stream()
           .filter(
               (Segment s) -> {
                 return s.mOrigin == id;
               })
           .collect(Collectors.toCollection(ArrayList<Segment>::new)));
   FakeNode node;
   for (Segment s : neighbours) {
     if (fakeNodes.containsKey(s.mDestination)) {
       node = fakeNodes.get(s.mDestination);
     } else {
       node = new FakeNode(nodes.get(s.mDestination));
       fakeNodes.put(s.mDestination, node);
     }
     ArrayList<CostFunction> functions =
         costs
             .stream()
             .filter(
                 (CostFunction c) -> {
                   return c.getSegmentId() == s.mId;
                 })
             .collect(Collectors.toCollection(ArrayList<CostFunction>::new));
     functions.addAll(
         fakeCosts
             .stream()
             .filter(
                 (CostFunction c) -> {
                   return c.getSegmentId() == s.mId;
                 })
             .collect(Collectors.toCollection(ArrayList<CostFunction>::new)));
     node.node.cost = functions.get(0);
     retNodes.add(fakeNodes.get(s.mDestination));
   }
   return retNodes;
 }