コード例 #1
0
  private void FetchFromFile(Element eElement) {
    PrintConsole.print("App fetchs gatways from a different file.");
    fileAddress = eElement.getAttribute(ATTFILE);

    try {
      BufferedReader reader = null;
      int Id = 0;
      InputStream in = getClass().getResourceAsStream(fileAddress);
      reader = new BufferedReader(new InputStreamReader(in));
      String var = "";
      String[] Pos;
      gatways = new TreeMap<>();
      Vertex newGateway;
      while ((var = reader.readLine()) != null) {
        Pos = var.split("[ ]");
        newGateway = new Vertex(Id, new Point(Integer.valueOf(Pos[0]), Integer.valueOf(Pos[1])));
        gatways.put(newGateway.getId(), newGateway);
        Id++;
      }
      reader.close();

    } catch (Exception ex) {
      PrintConsole.printErr("GatewayConfig/FetchFromFile message:" + ex.getMessage());
    }
  }
コード例 #2
0
  private void FetchStatic(Element eElement) {
    PrintConsole.print("App fetchs gatways from cofiguration file <config.xml>.");
    gatways = new TreeMap<Integer, Vertex>();
    int Id = 0;
    NodeList childNodes = eElement.getElementsByTagName(CHILD);
    Vertex newGateway;
    for (int counter = 0; counter < childNodes.getLength() && counter < num; counter++) {
      Node childNode = childNodes.item(counter);
      if (childNode.getNodeType() == Node.ELEMENT_NODE) {
        Element childElem = (Element) childNode;
        newGateway =
            new Vertex(
                Id,
                new Point(
                    Integer.valueOf(childElem.getAttribute("x")),
                    Integer.valueOf(childElem.getAttribute("y"))));

        gatways.put(newGateway.getId(), newGateway);
        Id++;
      }
    }
  }
コード例 #3
0
  public List<Arc> chooseArcs(Solution solution, Vertex current) {

    List<Arc> nextArcs;

    List<Arc> currentOutgoing = current.getOutgoingArcs();
    List<Arc> currentOutgoingStillInAreaNotVisited = new LinkedList<Arc>();

    for (Arc arc : currentOutgoing) {
      Vertex endVertex = arc.getEnd();
      if (GeographicDistances.distance(
              endVertex, new Vertex(solution.getLatStart(), solution.getLngStart(), -1))
          < maxDistanceFromStart) {
        if (!arc.isVisited()) {
          currentOutgoingStillInAreaNotVisited.add(arc);
        }
      }
    }

    // The set of outgoing arcs contains arcs that are not visited
    // Choose the best arc among the set
    if (!currentOutgoingStillInAreaNotVisited.isEmpty()) {
      Collections.sort(currentOutgoingStillInAreaNotVisited, comparator);
      nextArcs = Collections.singletonList(currentOutgoingStillInAreaNotVisited.get(0));
    }

    // Else all the arcs are visited
    // Go to the nearest unvisited arc in the area
    // TODO - is there a better choice?
    else {
      nextArcs = pathToNearestUnvisitedArcInArea(current, solution);
    }

    int newTotal = solution.getTotalTime();
    for (Arc arc : nextArcs) newTotal += arc.getDuration();

    if (newTotal > maxTime || nextArcs.isEmpty()) return null;
    else return nextArcs;
  }