Ejemplo n.º 1
0
 public Astar(
     long startId,
     long endId,
     DBHelper db,
     Map<Long, Node> nodes,
     LinkedList<Segment> segments,
     LinkedList<CostFunction> costs) {
   this.db = db;
   this.nodes = nodes;
   this.segments = segments;
   this.costs = costs;
   this.db.Connect();
   this.fakeNodes.put(startId, new FakeNode(this.nodes.get(startId)));
   this.fakeNodes.put(endId, new FakeNode(this.nodes.get(endId)));
   this.startNode = this.fakeNodes.get(startId);
   this.endNode = this.fakeNodes.get(endId);
   this.startNode.g_scores = 0;
   ArrayList<Segment> fakeStart = createFalseSegments(startNode.node, true);
   ArrayList<Segment> fakeEnd = createFalseSegments(endNode.node, false);
   if (fakeStart != null) {
     fakeSegments.addAll(fakeStart);
   }
   if (fakeEnd != null) {
     fakeSegments.addAll(fakeEnd);
   }
   /*if(!fakeSegments.isEmpty()) {
       segments.addAll(fakeSegments);
       if(!fakeCosts.isEmpty()){
           costs.addAll(fakeCosts);
       }
   }*/
 }
Ejemplo n.º 2
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;
 }