コード例 #1
0
ファイル: Astar.java プロジェクト: mkote/d505e15-p5-impl
 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;
 }
コード例 #2
0
ファイル: Astar.java プロジェクト: mkote/d505e15-p5-impl
 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;
 }