Beispiel #1
0
  /** Sorts the static LinkedList mainlineLinks in the order they appear on the freeway */
  private LinkedList<Link> recursiveLinkSort(LinkedList<Link> links2) {

    if (links2.size() == 1) {

      return links2;

    } else {

      boolean swapMade = false;
      ListIterator<Link> itr1 = links2.listIterator();
      while (itr1.hasNext()) {
        Link temp = itr1.next();
        int tempindex = itr1.nextIndex();
        // if this loop makes any switches, set the flag to true
        if (links2.getFirst().getUpNode().getNodeID() == temp.getDownNode().getNodeID()) {
          swapMade = true;
          links2.addFirst(temp);
          links2.remove(tempindex);
          return this.recursiveLinkSort(links2);
        }
      }

      if (!swapMade) {
        // assign last n-1 links to links3
        LinkedList<Link> links3 = new LinkedList<Link>();
        Link temp = links2.getFirst();
        links2.removeFirst();
        links3 = this.recursiveLinkSort(links2);
        links3.addFirst(temp);
        return links3;
      } else {
        return links2;
      }
    }
  }
Beispiel #2
0
  /**
   * Translates the link structure into the cell structure depending on healthy detector locations
   */
  public void createCellStructure() {

    int i = 0;

    while (i < mainlineLinks.size() - 1) {

      if (mainlineLinks.get(i).isHasDetector()
          & mainlineLinks.get(i).getDetectorML().getHealthStatus() == 100) {
        Cell c = new Cell((int) totalTimeInHours * 60 / 5);
        c.addLink(mainlineLinks.get(i));
        c.setDetectorML(mainlineLinks.get(i).getDetectorML());
        c.setDetectorHOV(mainlineLinks.get(i).getDetectorHOV());
        while (!mainlineLinks.get(i + 1).isHasDetector() & i < mainlineLinks.size() - 2
            | (mainlineLinks.get(i + 1).isHasDetector()
                & mainlineLinks.get(i + 1).getDetectorML().getHealthStatus() != 100)) {
          c.addLink(mainlineLinks.get(i + 1));
          i++;
        }
        // Onramps and Offramps in the Cell
        for (Link l : c.getLinks()) {

          c.addToOnrampPerLink(l.getUpNode().getInLinks().size() - 1);
          c.addToOfframpPerLink(l.getDownNode().getOutLinks().size() - 1);

          for (int linkID : l.getUpNode().getInLinks()) {
            if (links.get(linkID).getLinkType().equals("onramp")) {
              if (links.get(linkID).getDetectorML().getFlowData().isEmpty()
                  | links.get(linkID).getDetectorML().getHealthStatus() != 100) {
                c.addToImputeOR(true);
                c.appendZeroColumnToMeasuredOnrampFlow();
              } else {
                c.appendColumnToMeasuredOnrampFlow(
                    links.get(linkID).getDetectorML().getFlowDataArray());
                c.addToImputeOR(false);
              }
            }
          }
          for (int linkID : l.getDownNode().getOutLinks()) {
            if (links.get(linkID).getLinkType().equals("offramp")) {
              if (links.get(linkID).getDetectorML().getFlowData().isEmpty()
                  | links.get(linkID).getDetectorML().getHealthStatus() != 100) {
                c.addToImputeFR(true);
                c.appendZeroColumnToMeasuredOfframpFlow();
              } else {
                c.appendColumnToMeasuredOfframpFlow(
                    links.get(linkID).getDetectorML().getFlowDataArray());
                c.addToImputeFR(false);
              }
            }
          }
        }

        cells.add(c);
      }

      i++;
    }
    i = 0;
  }
Beispiel #3
0
  public void writeDemandsAndSplitRatiosToSpreadSheet(String outFilename)
      throws BiffException, IOException, RowsExceededException, WriteException,
          IndexOutOfBoundsException {

    Workbook existingWorkbook = Workbook.getWorkbook(new File(outFilename));
    WritableWorkbook workbookCopy =
        Workbook.createWorkbook(new File("Aimsun\\output.xls"), existingWorkbook);

    // add labels first row
    workbookCopy.getSheet(0).addCell(new Label(15, 0, "Split Ratios"));
    workbookCopy.getSheet(0).addCell(new Label(16, 0, "Offramp Flows"));
    workbookCopy.getSheet(0).addCell(new Label(17, 0, "Demands"));
    workbookCopy.getSheet(0).addCell(new Label(18, 0, "Flows"));
    workbookCopy.getSheet(0).addCell(new Label(19, 0, "Speeds"));
    int rowIndex = 1;
    for (Cell c : splitCells) {

      // find row index
      while (true) {
        NumberCell nc2 = (NumberCell) workbookCopy.getSheet(0).getCell(0, rowIndex);
        if (nc2.getValue() == c.getDetectorML().getSensorID()) {
          break;
        }
        rowIndex++;
      }

      // fill in mainline data columns
      for (int k = rowIndex; k < rowIndex + totalTimeInHours * 60 / 5; k++) {

        workbookCopy.getSheet(0).addCell(new Number(18, k, c.getFlowCompare().get(k - rowIndex)));
        workbookCopy.getSheet(0).addCell(new Number(19, k, c.getVelocity().get(k - rowIndex)));
      }
      rowIndex = 1;

      // if the cell has onramp, find the detector id and fill corresponding columns (assumption:
      // cells have at most one on-ramp or off-ramp)
      int onrampLinkID = 0;
      if (c.getLinks().getFirst().getUpLinks().size() > 1) {
        // By our assumption (above), there are at most 2 upstream links for each mainline link
        onrampLinkID = c.getLinks().getFirst().getUpLinks().get(0);
        for (Link mlLink : mainlineLinks) {
          if (mlLink.getLinkID() == onrampLinkID) {
            onrampLinkID = c.getLinks().getFirst().getUpLinks().get(1);
            break;
          }
        }
        // find associated detector
        int onrampDetId = 0;
        for (int key : detectors.keySet()) {
          if (detectors.get(key).getLinkAssoc() == onrampLinkID) {
            onrampDetId = detectors.get(key).getSensorID();
          }
        }

        if (onrampDetId == 0) continue;

        // find row index
        while (true) {
          NumberCell nc2 = (NumberCell) workbookCopy.getSheet(0).getCell(0, rowIndex);
          if (nc2.getValue() == onrampDetId) {
            break;
          }
          rowIndex++;
        }
        for (int k = rowIndex; k < rowIndex + totalTimeInHours * 60 / 5; k++) {

          workbookCopy.getSheet(0).addCell(new Number(17, k, c.getOnRampInput().get(k - rowIndex)));
          workbookCopy.getSheet(0).addCell(new Number(18, k, c.getOnRampInput().get(k - rowIndex)));
        }
        rowIndex = 1;
      }

      // if the cell has offramp, find the detector id and fill corresponding columns (assumption:
      // cells have at most one on-ramp or off-ramp)
      int offrampLinkID = 0;
      if (c.getLinks().getLast().getDownLinks().size() > 1) {
        // By our assumption (above), there are at most 2 upstream links for each mainline link
        offrampLinkID = c.getLinks().getLast().getDownLinks().get(0);
        for (Link mlLink : mainlineLinks) {
          if (mlLink.getLinkID() == offrampLinkID) {
            offrampLinkID = c.getLinks().getLast().getDownLinks().get(1);
            break;
          }
        }

        // find associated detector
        int offrampDetId = 0;
        for (int key : detectors.keySet()) {
          if (detectors.get(key).getLinkAssoc() == offrampLinkID) {
            offrampDetId = detectors.get(key).getSensorID();
          }
        }

        if (offrampDetId == 0) continue;

        // find row index
        while (true) {
          NumberCell nc2 = (NumberCell) workbookCopy.getSheet(0).getCell(0, rowIndex);
          if (nc2.getValue() == offrampDetId) {
            break;
          }
          rowIndex++;
        }

        for (int k = rowIndex; k < rowIndex + totalTimeInHours * 60 / 5; k++) {

          workbookCopy.getSheet(0).addCell(new Number(15, k, c.getBeta().get(k - rowIndex)));
          workbookCopy.getSheet(0).addCell(new Number(16, k, c.getOffRampFlow().get(k - rowIndex)));
          workbookCopy.getSheet(0).addCell(new Number(18, k, c.getOffRampFlow().get(k - rowIndex)));
        }

        rowIndex = 1;
      }

      // rowIndex += totalTimeInHours*60/5;
      rowIndex = 1;
    }

    workbookCopy.write();
    workbookCopy.close();
    existingWorkbook.close();
  }
Beispiel #4
0
 /** Reads the network geometry from mainScenario and populates the mainlineLinks list */
 public void createMainlineLinkStructureFromMainScenario(int routeID) {
   for (int i = 0;
       i < this.mainScenario.getNetworkList().getNetwork().get(0).getLinkList().getLink().size();
       i++) {
     if (routeID != 0) {
       int routeIndex = 0;
       // find the route index
       for (routeIndex = 0;
           routeIndex < this.mainScenario.getRoutes().getRoute().size();
           routeIndex++) {
         if (Integer.parseInt(this.mainScenario.getRoutes().getRoute().get(routeIndex).getId())
             == routeID) {
           break;
         }
       }
       // go over the route and see if the link belongs to the given route
       boolean linkInRoute = false;
       for (int k = 0;
           k
               < this.mainScenario
                   .getRoutes()
                   .getRoute()
                   .get(routeIndex)
                   .getLinkReferences()
                   .getLinkReference()
                   .size();
           k++) {
         if (this.mainScenario
             .getRoutes()
             .getRoute()
             .get(routeIndex)
             .getLinkReferences()
             .getLinkReference()
             .get(k)
             .getId()
             .contentEquals(
                 this.mainScenario
                     .getNetworkList()
                     .getNetwork()
                     .get(0)
                     .getLinkList()
                     .getLink()
                     .get(i)
                     .getId())) {
           linkInRoute = true;
           break;
         }
       }
       if (!linkInRoute) {
         continue;
       }
     }
     // collect only mainline links in the links list
     if (this.mainScenario
         .getNetworkList()
         .getNetwork()
         .get(0)
         .getLinkList()
         .getLink()
         .get(i)
         .getType()
         .equals("freeway")) {
       Link l = new Link();
       boolean hasDetector = false;
       Detector detectorML = new Detector();
       l.setLinkID(
           Integer.parseInt(
               this.mainScenario
                   .getNetworkList()
                   .getNetwork()
                   .get(0)
                   .getLinkList()
                   .getLink()
                   .get(i)
                   .getId()));
       l.setUpNode(
           nodes.get(
               Integer.parseInt(
                   this.mainScenario
                       .getNetworkList()
                       .getNetwork()
                       .get(0)
                       .getLinkList()
                       .getLink()
                       .get(i)
                       .getBegin()
                       .getNodeId())));
       l.setDownNode(
           nodes.get(
               Integer.parseInt(
                   this.mainScenario
                       .getNetworkList()
                       .getNetwork()
                       .get(0)
                       .getLinkList()
                       .getLink()
                       .get(i)
                       .getEnd()
                       .getNodeId())));
       l.setUpLinks(l.getUpNode().getInLinks());
       l.setDownLinks(l.getDownNode().getOutLinks());
       l.setLength(
           this.mainScenario
               .getNetworkList()
               .getNetwork()
               .get(0)
               .getLinkList()
               .getLink()
               .get(i)
               .getLength()
               .doubleValue());
       l.setLanesML(
           this.mainScenario
               .getNetworkList()
               .getNetwork()
               .get(0)
               .getLinkList()
               .getLink()
               .get(i)
               .getLanes()
               .intValue());
       for (int key : detectors.keySet()) {
         if (detectors.get(key).getLinkAssoc() == l.getLinkID()) {
           hasDetector = true;
           detectorML = detectors.get(key);
         }
       }
       l.setHasDetector(hasDetector);
       l.setDetectorML(detectorML);
       mainlineLinks.add(l);
     }
   }
   // sort mainline links
   mainlineLinks = this.recursiveLinkSort(mainlineLinks);
 }
Beispiel #5
0
  /** Reads the network geometry from mainScenario and populates the links hashmap */
  public void createLinkStructureFromMainScenario() {
    for (int i = 0;
        i < this.mainScenario.getNetworkList().getNetwork().get(0).getLinkList().getLink().size();
        i++) {
      Link l = new Link();
      boolean hasDetector = false;
      Detector detectorML = new Detector();
      l.setLinkType(
          this.mainScenario
              .getNetworkList()
              .getNetwork()
              .get(0)
              .getLinkList()
              .getLink()
              .get(i)
              .getType());
      l.setLinkID(
          Integer.parseInt(
              this.mainScenario
                  .getNetworkList()
                  .getNetwork()
                  .get(0)
                  .getLinkList()
                  .getLink()
                  .get(i)
                  .getId()));
      l.setUpNode(
          nodes.get(
              Integer.parseInt(
                  this.mainScenario
                      .getNetworkList()
                      .getNetwork()
                      .get(0)
                      .getLinkList()
                      .getLink()
                      .get(i)
                      .getBegin()
                      .getNodeId())));
      l.setDownNode(
          nodes.get(
              Integer.parseInt(
                  this.mainScenario
                      .getNetworkList()
                      .getNetwork()
                      .get(0)
                      .getLinkList()
                      .getLink()
                      .get(i)
                      .getEnd()
                      .getNodeId())));
      l.setUpLinks(l.getUpNode().getInLinks());
      l.setDownLinks(l.getDownNode().getOutLinks());
      l.setLength(
          this.mainScenario
              .getNetworkList()
              .getNetwork()
              .get(0)
              .getLinkList()
              .getLink()
              .get(i)
              .getLength()
              .doubleValue());
      l.setLanesML(
          this.mainScenario
              .getNetworkList()
              .getNetwork()
              .get(0)
              .getLinkList()
              .getLink()
              .get(i)
              .getLanes()
              .intValue());
      for (int key : detectors.keySet()) {
        if (detectors.get(key).getLinkAssoc() == l.getLinkID()) {
          hasDetector = true;
          // Detector dummyDetector = detectors.get(key);
          // if (dummyDetector.getSensorType().toString().equals(arg0) //REVISIT
          detectorML = detectors.get(key);
        }
      }
      l.setHasDetector(hasDetector);
      l.setDetectorML(detectorML);

      links.put(l.getLinkID(), l);
    }
  }