/** * 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; }
/** 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; } } }