Exemplo n.º 1
0
  /**
   * Reads the data from database and writes into detectors hashmap
   *
   * @throws SQLException
   */
  public void readDataIntoDetectorListFromDatabase() throws SQLException {

    // TestConfiguration.dbSetup();

    PeMSStationAggregateReader stationAggregateReader =
        new PeMSStationAggregateReader(oraDatabase.doConnect());
    ArrayList<Long> vdsIDs = new ArrayList<Long>();

    for (int key : detectors.keySet()) {
      vdsIDs.add((long) key);
    }
    List<PeMSStationAggregate> stationsAggregate =
        stationAggregateReader.read(
            this.timeInterval, vdsIDs, PeMSAggregate.AggregationLevel.PEMS_5MIN);

    // Read absolute detector info into the hashmap
    VDSReader stationReader = new VDSReader(oraDatabase.doConnect());
    for (int key : detectors.keySet()) {
      VDS station = stationReader.read((long) key);
      Detector d = detectors.get(key);
      d.setAbsolutePM(station.getAbsolutePostmile());
      d.setDetectorLength(station.getDetectorLength());
      d.setDetectorName(station.getDetectorName());
      d.setFreewayDirection(station.getDirection());
      d.setFreewayNumber(station.getFreewayNum());
      d.setLatitude(station.getPosition().getPoint().get(0).getLat());
      d.setLongitude(station.getPosition().getPoint().get(0).getLng());
      d.setNumberOfLanes(station.getLaneCount());
    }

    // Read 5 minute data into the hashmap
    for (int i = 0; i < stationsAggregate.size(); i++) {
      // find the detector corresponding to the current ID in the data vector and fill the fields
      // accordingly
      Detector d = detectors.get((int) stationsAggregate.get(i).getVdsId());
      d.addDatumToSpeed(stationsAggregate.get(i).getTotal().getAvgSpeed());
      d.addDatumToFlow(
          stationsAggregate.get(i).getTotal().getFlow()
              * 12
              / d
                  .getNumberOfLanes()); // to get the hourly rate at 5 minute granularity, multiply
                                        // by 12
      d.addDatumToDensity(
          stationsAggregate.get(i).getTotal().getFlow()
              * 12
              / stationsAggregate.get(i).getTotal().getAvgSpeed()
              / d.getNumberOfLanes());
      if (i < detectors.size()) {
        d.setHealthStatus(stationsAggregate.get(i).getTotal().getObserved());
      }
    }
  }
Exemplo n.º 2
0
  public void exportMainlineDataToText() throws IOException {

    for (int key : detectors.keySet()) {

      Double[] flow =
          MyUtilities.scaleVector(
              detectors.get(key).getFlowDataArray(),
              (double) detectors.get(key).getNumberOfLanes());
      Double[] speed = detectors.get(key).getSpeedDataArray();
      Double[] density =
          MyUtilities.scaleVector(
              detectors.get(key).getDensityDataArray(),
              (double) detectors.get(key).getNumberOfLanes());

      PrintWriter outFlow = new PrintWriter(new FileWriter(key + "_flw.txt"));
      PrintWriter outSpeed = new PrintWriter(new FileWriter(key + "_spd.txt"));
      PrintWriter outDensity = new PrintWriter(new FileWriter(key + "_dty.txt"));

      for (int i = 0; i < flow.length; i++) {

        outFlow.println(flow[i]);
        outSpeed.println(speed[i]);
        outDensity.println(density[i]);
      }

      outFlow.close();
      outSpeed.close();
      outDensity.close();
    }
  }
Exemplo n.º 3
0
  public void exportDetectors() throws IOException { // doesn't work, remove when done

    for (int key : detectors.keySet()) {

      Detector d = detectors.get(key);
      FileOutputStream fileOut = new FileOutputStream("Detector " + key + ".ser");
      ObjectOutputStream out = new ObjectOutputStream(fileOut);
      out.writeObject(d);
      out.close();
      fileOut.close();
    }
  }
Exemplo n.º 4
0
 /** Reads fundamental diagram parameters from AIMSUN generated xml */
 public void readFundamentalDiagramsFromXML_AIMSUN() {
   for (int key : detectors.keySet()) {
     Detector d = detectors.get(key);
     // find the corresponding FD profile
     int i;
     for (i = 0;
         i
             < this.mainScenario
                 .getFundamentalDiagramProfileSet()
                 .getFundamentalDiagramProfile()
                 .size();
         i++) {
       if (Integer.parseInt(
               this.mainScenario
                   .getFundamentalDiagramProfileSet()
                   .getFundamentalDiagramProfile()
                   .get(i)
                   .getLinkId())
           == d.getLinkAssoc()) {
         break;
       }
     }
     BigDecimal vf =
         this.mainScenario
             .getFundamentalDiagramProfileSet()
             .getFundamentalDiagramProfile()
             .get(i)
             .getFundamentalDiagram()
             .get(0)
             .getFreeFlowSpeed();
     BigDecimal q_max =
         this.mainScenario
             .getFundamentalDiagramProfileSet()
             .getFundamentalDiagramProfile()
             .get(i)
             .getFundamentalDiagram()
             .get(0)
             .getCapacity();
     BigDecimal rhojam =
         this.mainScenario
             .getFundamentalDiagramProfileSet()
             .getFundamentalDiagramProfile()
             .get(i)
             .getFundamentalDiagram()
             .get(0)
             .getJamDensity();
     double w =
         q_max.doubleValue() / (rhojam.doubleValue() - q_max.doubleValue() / vf.doubleValue());
     d.getFdParams().setFD(vf.doubleValue(), w, q_max.doubleValue() / d.getNumberOfLanes());
     detectors.put(key, d);
   }
 }
Exemplo n.º 5
0
  /**
   * Reads the detector data from spreadsheet and writes into detectors hashmap The files should be
   * in the following format and placed in the root directory of the imputer project folder (for
   * example, see detOutMainlines_431.csv) 1) 5 minute data granularity is assumed 2) The data
   * should be sorted by alphabetical order of detector IDs and the data column should be
   * chronologically sorted for each detector
   *
   * @throws IOException
   * @throws BiffException
   */
  public void readDataIntoDetectorListFromSpreadSheet(String filename)
      throws BiffException, IOException {

    Workbook workbook = Workbook.getWorkbook(new File(filename));

    int rowIndex =
        1; // start the index at 1 and increase by number of data points after each iteration
    // Read absolute detector info and 5 minute data into the hashmap (some fields not important for
    // fake detectors, left blank or 0 for the time being)
    for (int key : detectors.keySet()) {
      Detector d = detectors.get(key);
      // find row index
      while (true) {
        NumberCell nc2 = (NumberCell) workbook.getSheet(0).getCell(0, rowIndex);
        if (nc2.getValue() == key) {
          break;
        }
        rowIndex++;
      }
      NumberCell nc = (NumberCell) workbook.getSheet(0).getCell(4, rowIndex); // Postmile
      d.setAbsolutePM(nc.getValue());
      d.setDetectorLength(0.0);
      d.setDetectorName(workbook.getSheet(0).getCell(1, rowIndex).getContents()); // Name
      d.setFreewayDirection("");
      d.setFreewayNumber(0);
      d.setLatitude(0.0);
      d.setLongitude(0.0);
      NumberCell nc1 = (NumberCell) workbook.getSheet(0).getCell(13, rowIndex); // Number of Lanes
      Double temp = nc1.getValue();
      d.setNumberOfLanes(temp.intValue());
      for (int k = rowIndex; k < rowIndex + totalTimeInHours * 60 / 5; k++) {
        NumberCell ncSpeed = (NumberCell) workbook.getSheet(0).getCell(6, k); // Speed
        NumberCell ncFlow = (NumberCell) workbook.getSheet(0).getCell(5, k); // Flow
        d.addDatumToSpeed(ncSpeed.getValue());
        d.addDatumToFlow(ncFlow.getValue() / d.getNumberOfLanes());
        d.addDatumToDensity(ncFlow.getValue() / ncSpeed.getValue() / d.getNumberOfLanes());
      }
      nc = (NumberCell) workbook.getSheet(0).getCell(14, rowIndex); // Health
      if (nc.getValue() == 0) {
        d.setHealthStatus(100.0);
      } else {
        d.setHealthStatus(0.0);
      }
      rowIndex = 1;
      // rowIndex += totalTimeInHours*60/5;
    }
  }
Exemplo n.º 6
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();
  }
Exemplo n.º 7
0
 /** Calibrates fundamental diagram parameters for detectors */
 public void calibrateFundamentalDiagrams() {
   for (int key : detectors.keySet()) {
     FDCalibrator fdCalib = new FDCalibrator();
     detectors.put(key, fdCalib.calibrateParameters(detectors.get(key)));
   }
 }
Exemplo n.º 8
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);
 }
Exemplo n.º 9
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);
    }
  }