The following document contains the results of PMD's CPD 6.21.0.
File | Line |
---|---|
org\opentrafficsim\demo\web\OTSDemoServer.java | 428 |
org\opentrafficsim\demo\web\OTSFederatedDemoServer.java | 309 |
this.webServer.sessionWebModelMap.get(sessionId).handle(target, baseRequest, request, response); } else if (this.webServer.sessionModelMap.containsKey(sessionId)) { OTSModelInterface model = this.webServer.sessionModelMap.get(sessionId); String answer = "<message>ok</message>"; if (request.getParameter("message") != null) { String message = request.getParameter("message"); String[] parts = message.split("\\|"); String command = parts[0]; switch (command) { case "getTitle": { answer = "<title>" + model.getShortName() + "</title>"; break; } case "getParameterMap": { answer = makeParameterMap(model); break; } case "setParameters": { answer = setParameters(model, message); break; } default: { System.err.println("Got unknown message from client: " + command); answer = "<message>" + request.getParameter("message") + "</message>"; break; } } } response.setContentType("text/xml"); response.setHeader("Cache-Control", "no-cache"); response.setContentLength(answer.length()); response.setStatus(HttpServletResponse.SC_OK); response.getWriter().write(answer); response.flushBuffer(); baseRequest.setHandled(true); } } } /** * Make the parameter set that can be interpreted by the parameters.html page. * @param model the model with parameters * @return an XML string with the parameters */ private String makeParameterMap(final OTSModelInterface model) { StringBuffer answer = new StringBuffer(); answer.append("<parameters>\n"); InputParameterMap inputParameterMap = model.getInputParameterMap(); for (InputParameter<?, ?> tab : inputParameterMap.getSortedSet()) { if (!(tab instanceof InputParameterMap)) { System.err.println("Input parameter " + tab.getShortName() + " cannot be displayed in a tab"); } else { answer.append("<tab>" + tab.getDescription() + "</tab>\n"); InputParameterMap tabbedMap = (InputParameterMap) tab; for (InputParameter<?, ?> parameter : tabbedMap.getSortedSet()) { addParameterField(answer, parameter); } } } answer.append("</parameters>\n"); return answer.toString(); } /** * Add the right type of field for this parameter to the string buffer. * @param answer StringBuffer; the buffer to add the XML-info for the parameter * @param parameter InputParameter<?,?>; the input parameter to display */ public void addParameterField(final StringBuffer answer, final InputParameter<?, ?> parameter) { if (parameter instanceof InputParameterDouble) { InputParameterDouble pd = (InputParameterDouble) parameter; answer.append("<double key='" + pd.getExtendedKey() + "' name='" + pd.getShortName() + "' description='" + pd.getDescription() + "'>" + pd.getValue() + "</double>\n"); } else if (parameter instanceof InputParameterFloat) { InputParameterFloat pf = (InputParameterFloat) parameter; answer.append("<float key='" + pf.getExtendedKey() + "' name='" + pf.getShortName() + "' description='" + pf.getDescription() + "'>" + pf.getValue() + "</float>\n"); } else if (parameter instanceof InputParameterBoolean) { InputParameterBoolean pb = (InputParameterBoolean) parameter; answer.append("<boolean key='" + pb.getExtendedKey() + "' name='" + pb.getShortName() + "' description='" + pb.getDescription() + "'>" + pb.getValue() + "</boolean>\n"); } else if (parameter instanceof InputParameterLong) { InputParameterLong pl = (InputParameterLong) parameter; answer.append("<long key='" + pl.getExtendedKey() + "' name='" + pl.getShortName() + "' description='" + pl.getDescription() + "'>" + pl.getValue() + "</long>\n"); } else if (parameter instanceof InputParameterInteger) { InputParameterInteger pi = (InputParameterInteger) parameter; answer.append("<integer key='" + pi.getExtendedKey() + "' name='" + pi.getShortName() + "' description='" + pi.getDescription() + "'>" + pi.getValue() + "</integer>\n"); } else if (parameter instanceof InputParameterString) { InputParameterString ps = (InputParameterString) parameter; answer.append("<string key='" + ps.getExtendedKey() + "' name='" + ps.getShortName() + "' description='" + ps.getDescription() + "'>" + ps.getValue() + "</string>\n"); } else if (parameter instanceof InputParameterDoubleScalar) { InputParameterDoubleScalar<?, ?> pds = (InputParameterDoubleScalar<?, ?>) parameter; String val = getValueInUnit(pds); List<String> units = getUnits(pds); answer.append("<doubleScalar key='" + pds.getExtendedKey() + "' name='" + pds.getShortName() + "' description='" + pds.getDescription() + "'><value>" + val + "</value>\n"); for (String unit : units) { Unit<?> unitValue = pds.getUnitParameter().getOptions().get(unit); if (unitValue.equals(pds.getUnitParameter().getValue())) answer.append("<unit chosen='true'>" + unit + "</unit>\n"); else answer.append("<unit chosen='false'>" + unit + "</unit>\n"); } answer.append("</doubleScalar>\n"); } else if (parameter instanceof InputParameterFloatScalar) { InputParameterFloatScalar<?, ?> pds = (InputParameterFloatScalar<?, ?>) parameter; String val = getValueInUnit(pds); List<String> units = getUnits(pds); answer.append("<floatScalar key='" + pds.getExtendedKey() + "' name='" + pds.getShortName() + "' description='" + pds.getDescription() + "'><value>" + val + "</value>\n"); for (String unit : units) { Unit<?> unitValue = pds.getUnitParameter().getOptions().get(unit); if (unitValue.equals(pds.getUnitParameter().getValue())) answer.append("<unit chosen='true'>" + unit + "</unit>\n"); else answer.append("<unit chosen='false'>" + unit + "</unit>\n"); } answer.append("</floatScalar>\n"); } else if (parameter instanceof InputParameterSelectionList<?>) { // TODO InputParameterSelectionList } else if (parameter instanceof InputParameterDistDiscreteSelection) { // TODO InputParameterSelectionList } else if (parameter instanceof InputParameterDistContinuousSelection) { // TODO InputParameterDistContinuousSelection } else if (parameter instanceof InputParameterSelectionMap<?, ?>) { // TODO InputParameterSelectionMap } } /** * @param <U> the unit * @param <T> the scalar type * @param parameter double scalar input parameter * @return default value in the unit */ private <U extends Unit<U>, T extends AbstractDoubleScalar<U, T>> String getValueInUnit(final InputParameterDoubleScalar<U, T> parameter) { return "" + parameter.getDefaultTypedValue().getInUnit(parameter.getDefaultTypedValue().getDisplayUnit()); } /** * @param <U> the unit * @param <T> the scalar type * @param parameter double scalar input parameter * @return abbreviations for the units */ private <U extends Unit<U>, T extends AbstractDoubleScalar<U, T>> List<String> getUnits(final InputParameterDoubleScalar<U, T> parameter) { List<String> unitList = new ArrayList<>(); for (String option : parameter.getUnitParameter().getOptions().keySet()) { unitList.add(option.toString()); } return unitList; } /** * @param <U> the unit * @param <T> the scalar type * @param parameter double scalar input parameter * @return default value in the unit */ private <U extends Unit<U>, T extends AbstractFloatScalar<U, T>> String getValueInUnit(final InputParameterFloatScalar<U, T> parameter) { return "" + parameter.getDefaultTypedValue().getInUnit(parameter.getDefaultTypedValue().getDisplayUnit()); } /** * @param <U> the unit * @param <T> the scalar type * @param parameter double scalar input parameter * @return abbreviations for the units */ private <U extends Unit<U>, T extends AbstractFloatScalar<U, T>> List<String> getUnits(final InputParameterFloatScalar<U, T> parameter) { List<String> unitList = new ArrayList<>(); for (String option : parameter.getUnitParameter().getOptions().keySet()) { unitList.add(option.toString()); } return unitList; } /** * Make the parameter set that can be interpreted by the parameters.html page. * @param model the model with parameters * @param message the key-value pairs of the set parameters * @return the errors if they are detected. If none, errors is set to "OK" */ private String setParameters(final OTSModelInterface model, final String message) { String errors = "OK"; InputParameterMap inputParameters = model.getInputParameterMap(); String[] parts = message.split("\\|"); Map<String, String> unitMap = new LinkedHashMap<>(); for (int i = 1; i < parts.length - 3; i += 3) { String id = parts[i].trim().replaceFirst("model.", ""); String type = parts[i + 1].trim(); String val = parts[i + 2].trim(); if (type.equals("UNIT")) { unitMap.put(id, val); } } for (int i = 1; i < parts.length - 3; i += 3) { String id = parts[i].trim().replaceFirst("model.", ""); String type = parts[i + 1].trim(); String val = parts[i + 2].trim(); try { if (type.equals("DOUBLE")) { InputParameterDouble param = (InputParameterDouble) inputParameters.get(id); param.setDoubleValue(Double.valueOf(val)); } else if (type.equals("FLOAT")) { InputParameterFloat param = (InputParameterFloat) inputParameters.get(id); param.setFloatValue(Float.valueOf(val)); } else if (type.equals("BOOLEAN")) { InputParameterBoolean param = (InputParameterBoolean) inputParameters.get(id); param.setBooleanValue(val.toUpperCase().startsWith("T")); } else if (type.equals("LONG")) { InputParameterLong param = (InputParameterLong) inputParameters.get(id); param.setLongValue(Long.valueOf(val)); } else if (type.equals("INTEGER")) { InputParameterInteger param = (InputParameterInteger) inputParameters.get(id); param.setIntValue(Integer.valueOf(val)); } else if (type.equals("STRING")) { InputParameterString param = (InputParameterString) inputParameters.get(id); param.setStringValue(val); } if (type.equals("DOUBLESCALAR")) { InputParameterDoubleScalar<?, ?> param = (InputParameterDoubleScalar<?, ?>) inputParameters.get(id); param.getDoubleParameter().setDoubleValue(Double.valueOf(val)); String unitString = unitMap.get(id); if (unitString == null) System.err.println("Could not find unit for DoubleScalar parameter with id=" + id); else { Unit<?> unit = param.getUnitParameter().getOptions().get(unitString); if (unit == null) System.err.println( "Could not find unit " + unitString + " for DoubleScalar parameter with id=" + id); else { param.getUnitParameter().setObjectValue(unit); param.setCalculatedValue(); // it will retrieve the set double value and unit } } } } catch (Exception exception) { if (errors.equals("OK")) errors = "ERRORS IN INPUT VALUES:\n"; errors += "Field " + id + ": " + exception.getMessage() + "\n"; } } return errors; } } } |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 293 |
org\opentrafficsim\demo\cacc\CaccSimulation.java | 543 |
if (this.networkName.equals("onramp")) { // points OTSPoint3D pointA = new OTSPoint3D(0, 0); OTSPoint3D pointB = new OTSPoint3D(2000, 0); // 700 meters toerit OTSPoint3D pointC = new OTSPoint3D(2330, 0); // 330 meters onramp OTSPoint3D pointD = new OTSPoint3D(3330, 0); OTSPoint3D pointE = new OTSPoint3D(1300, -40); // nodes OTSRoadNode nodeA = new OTSRoadNode(network, "A", pointA, Direction.ZERO); OTSRoadNode nodeB = new OTSRoadNode(network, "B", pointB, Direction.ZERO); OTSRoadNode nodeC = new OTSRoadNode(network, "C", pointC, Direction.ZERO); OTSRoadNode nodeD = new OTSRoadNode(network, "D", pointD, Direction.ZERO); OTSRoadNode nodeE = new OTSRoadNode(network, "E", pointE, Direction.ZERO); // links CrossSectionLink linkAB = new CrossSectionLink(network, "AB", nodeA, nodeB, freewayLinkType, new OTSLine3D(pointA, pointB), LaneKeepingPolicy.KEEPRIGHT); CrossSectionLink linkBC = new CrossSectionLink(network, "BC", nodeB, nodeC, freewayLinkType, new OTSLine3D(pointB, pointC), LaneKeepingPolicy.KEEPRIGHT); CrossSectionLink linkCD = new CrossSectionLink(network, "CD", nodeC, nodeD, freewayLinkType, new OTSLine3D(pointC, pointD), LaneKeepingPolicy.KEEPRIGHT); CrossSectionLink linkEB = new CrossSectionLink(network, "EB", nodeE, nodeB, freewayLinkType, Bezier.cubic(nodeE.getLocation(), nodeB.getLocation()), LaneKeepingPolicy.KEEPRIGHT); // lanes and stripes int n = this.numberOfLanes; // List<Lane> originLanes = new ArrayList<>(); for (int i = 0; i < n; i++) { for (CrossSectionLink link : new CrossSectionLink[] { linkAB, linkBC, linkCD }) { Lane lane = new Lane(link, "Lane " + (i + 1), laneWidth.times((0.5 + i)), laneWidth, freewayLaneType, new Speed(100, SpeedUnit.KM_PER_HOUR)); Length offset = laneWidth.times(i + 1.0); Stripe stripe = new Stripe(link, offset, offset, stripeWidth); if (i < n - 1) { if (lane.getParentLink().getId().equals("BC")) { // stripe.addPermeability(GTUType.VEHICLE, Permeable.LEFT); stripe.addPermeability(vehicle, Permeable.BOTH); } else { stripe.addPermeability(vehicle, Permeable.BOTH); } } if (lane.getParentLink().getId().equals("BC")) { // new Detector(lane.getFullId(), lane, Length.createSI(150.0), sim); new Detector(lane.getFullId(), lane, Length.instantiateSI(330.0), sim); } // sink sensors if (lane.getParentLink().getId().equals("CD")) { new SinkSensor(lane, lane.getLength().minus(Length.instantiateSI(100.0)), GTUDirectionality.DIR_PLUS, sim); // detectors 100m after on ramp // new Detector(lane.getFullId(), lane, Length.createSI(0.0), sim); // id equal to lane, may be // different } if (lane.getParentLink().getId().equals("AB")) { // originLanes.add(lane); this.graphLanes.add(lane); } } } new Stripe(linkAB, Length.ZERO, Length.ZERO, stripeWidth); Stripe stripe = new Stripe(linkBC, Length.ZERO, Length.ZERO, stripeWidth); stripe.addPermeability(vehicle, Permeable.LEFT); new Stripe(linkCD, Length.ZERO, Length.ZERO, stripeWidth); new Lane(linkBC, "Acceleration lane", laneWidth.times(-0.5), laneWidth, freewayLaneType, new Speed(100, SpeedUnit.KM_PER_HOUR)); Lane onramp = new Lane(linkEB, "Onramp", laneWidth.times(-0.5), laneWidth, freewayLaneType, new Speed(100, SpeedUnit.KM_PER_HOUR)); new Stripe(linkEB, Length.ZERO, Length.ZERO, stripeWidth); new Stripe(linkEB, laneWidth.neg(), laneWidth.neg(), stripeWidth); new Stripe(linkBC, laneWidth.neg(), laneWidth.neg(), stripeWidth); // Detector on onramp // new Detector("Acceleration lane", accel, Length.createSI(200.0), sim); // OD without demand List<OTSNode> origins = new ArrayList<>(); origins.add(nodeA); origins.add(nodeE); List<OTSNode> destinations = new ArrayList<>(); destinations.add(nodeD); TimeVector timeVector = DoubleVector.instantiate(new double[] { 0.0, 0.25, 0.50, 0.75, 1.0, 1.25, 1.50, 1.75, 2.0 }, TimeUnit.BASE_HOUR, StorageType.DENSE); Interpolation interpolation = Interpolation.LINEAR; // or STEPWISE Categorization categorization = new Categorization("CACC", GTUType.class, Lane.class); // Category carCategory1 = new Category(categorization, carGTUType, originLanes.get(1)); // Category carCategory0 = new Category(categorization, carGTUType, originLanes.get(0)); Category carCategory1 = new Category(categorization, carGTUType, this.graphLanes.get(1)); Category carCategory0 = new Category(categorization, carGTUType, this.graphLanes.get(0)); Category carCategoryR = new Category(categorization, carGTUType, onramp); Category truCategory0 = new Category(categorization, truckGTUType, this.graphLanes.get(0)); Category truCategoryR = new Category(categorization, truckGTUType, onramp); Category caccCategory = new Category(categorization, caccGTUType, this.graphLanes.get(0)); |
File | Line |
---|---|
org\opentrafficsim\ahfe\AHFEAnimation.java | 102 |
org\opentrafficsim\ahfe\AHFESimulation.java | 90 |
int replication = 1; String anticipationStrategy = "none"; Duration reactionTime = Duration.instantiateSI(0.0); Duration anticipationTime = Duration.ZERO; double truckFraction = 0.05; double distanceError = 0.0; // 0.05; double speedError = 0.0; // 0.01; double accelerationError = 0.0; // 0.10; Frequency leftDemand = new Frequency(3500.0, FrequencyUnit.PER_HOUR); Frequency rightDemand = new Frequency(3200.0, FrequencyUnit.PER_HOUR); double leftFraction = 0.55; String scenario = "test"; for (String arg : args) { int equalsPos = arg.indexOf("="); if (equalsPos >= 0) { // set something String key = arg.substring(0, equalsPos); String value = arg.substring(equalsPos + 1); if ("autorun".equalsIgnoreCase(key)) { if ("true".equalsIgnoreCase(value)) { autorun = true; } else if ("false".equalsIgnoreCase(value)) { autorun = false; } else { System.err.println("bad autorun value " + value + " (ignored)"); } } else if ("replication".equalsIgnoreCase(key)) { try { replication = Integer.parseInt(value); } catch (NumberFormatException nfe) { System.err.println("Ignoring unparsable replication number \"" + value + "\""); } } else if ("anticipation".equalsIgnoreCase(key)) { if (value.equalsIgnoreCase("none") || value.equalsIgnoreCase("constant_speed") || value.equalsIgnoreCase("constant_acceleration")) { anticipationStrategy = value; } else { System.err.println("Ignoring unparsable anticipation \"" + value + "\""); } } else if ("reactiontime".equalsIgnoreCase(key)) { try { reactionTime = Duration.instantiateSI(java.lang.Double.parseDouble(value)); } catch (NumberFormatException nfe) { System.err.println("Ignoring unparsable reaction time \"" + value + "\""); } } else if ("anticipationtime".equalsIgnoreCase(key)) { try { anticipationTime = Duration.instantiateSI(java.lang.Double.parseDouble(value)); } catch (NumberFormatException nfe) { System.err.println("Ignoring unparsable anticipation time \"" + value + "\""); } } else if ("truckfraction".equalsIgnoreCase(key)) { try { truckFraction = java.lang.Double.parseDouble(value); Throw.when(truckFraction < 0.0 || truckFraction > 1.0, IllegalArgumentException.class, "Truck fraction must be between 0 and 1."); } catch (NumberFormatException nfe) { System.err.println("Ignoring unparsable truck fraction \"" + value + "\""); } } else if ("distanceerror".equalsIgnoreCase(key)) { try { distanceError = java.lang.Double.parseDouble(value); } catch (NumberFormatException nfe) { System.err.println("Ignoring unparsable distance error \"" + value + "\""); } } else if ("speederror".equalsIgnoreCase(key)) { try { speedError = java.lang.Double.parseDouble(value); } catch (NumberFormatException nfe) { System.err.println("Ignoring unparsable speed error \"" + value + "\""); } } else if ("accelerationerror".equalsIgnoreCase(key)) { try { accelerationError = java.lang.Double.parseDouble(value); } catch (NumberFormatException nfe) { System.err.println("Ignoring unparsable acceleration error \"" + value + "\""); } } else if ("leftdemand".equalsIgnoreCase(key)) { try { leftDemand = new Frequency(java.lang.Double.parseDouble(value), FrequencyUnit.PER_HOUR); } catch (NumberFormatException nfe) { System.err.println("Ignoring unparsable left demand \"" + value + "\""); } } else if ("rightdemand".equalsIgnoreCase(key)) { try { rightDemand = new Frequency(java.lang.Double.parseDouble(value), FrequencyUnit.PER_HOUR); } catch (NumberFormatException nfe) { System.err.println("Ignoring unparsable right demand \"" + value + "\""); } } else if ("leftfraction".equalsIgnoreCase(key)) { try { leftFraction = java.lang.Double.parseDouble(value); } catch (NumberFormatException nfe) { System.err.println("Ignoring unparsable left fraction \"" + value + "\""); } } else if ("scenario".equalsIgnoreCase(key)) { scenario = value; } else { System.out.println("Ignoring unknown setting " + arg); } } else { // not a flag System.err.println("Ignoring argument " + arg); } } final boolean finalAutoRun = autorun; final int finalReplication = replication; final String finalAnticipationStrategy = anticipationStrategy; final Duration finalReactionTime = reactionTime; final Duration finalAnticipationTime = anticipationTime; final double finalTruckFraction = truckFraction; final double finalDistanceError = distanceError; final double finalSpeedError = speedError; final double finalAccelerationError = accelerationError; final Frequency finalLeftDemand = leftDemand; final Frequency finalRightDemand = rightDemand; final double finalLeftFraction = leftFraction; final String finalScenario = scenario; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 543 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 645 |
else if (this.networkName.equals("onrampMERGE")) { // points OTSPoint3D pointA = new OTSPoint3D(0, 0); OTSPoint3D pointB = new OTSPoint3D(2000, 0); // 700 meters toerit (1300 - 2000) OTSPoint3D pointC = new OTSPoint3D(2330, 0); // 330 meters onramp OTSPoint3D pointD = new OTSPoint3D(3330, 0); OTSPoint3D pointE = new OTSPoint3D(1300, -40); // nodes OTSRoadNode nodeA = new OTSRoadNode(network, "A", pointA, Direction.ZERO); OTSRoadNode nodeB = new OTSRoadNode(network, "B", pointB, Direction.ZERO); OTSRoadNode nodeC = new OTSRoadNode(network, "C", pointC, Direction.ZERO); OTSRoadNode nodeD = new OTSRoadNode(network, "D", pointD, Direction.ZERO); OTSRoadNode nodeE = new OTSRoadNode(network, "E", pointE, Direction.ZERO); // links CrossSectionLink linkAB = new CrossSectionLink(network, "AB", nodeA, nodeB, freewayLinkType, new OTSLine3D(pointA, pointB), LaneKeepingPolicy.KEEPRIGHT); CrossSectionLink linkBC = new CrossSectionLink(network, "BC", nodeB, nodeC, freewayLinkType, new OTSLine3D(pointB, pointC), LaneKeepingPolicy.KEEPRIGHT); CrossSectionLink linkCD = new CrossSectionLink(network, "CD", nodeC, nodeD, freewayLinkType, new OTSLine3D(pointC, pointD), LaneKeepingPolicy.KEEPRIGHT); CrossSectionLink linkEB = new CrossSectionLink(network, "EB", nodeE, nodeB, freewayLinkType, Bezier.cubic(nodeE.getLocation(), nodeB.getLocation()), LaneKeepingPolicy.KEEPRIGHT); // lanes and stripes int n = this.numberOfLanes; // List<Lane> originLanes = new ArrayList<>(); for (int i = 0; i < n; i++) { for (CrossSectionLink link : new CrossSectionLink[] { linkAB, linkBC, linkCD }) { Lane lane = new Lane(link, "Lane " + (i + 1), laneWidth.times((0.5 + i)), laneWidth, freewayLaneType, new Speed(100, SpeedUnit.KM_PER_HOUR)); Length offset = laneWidth.times(i + 1.0); Stripe stripe = new Stripe(link, offset, offset, stripeWidth); if (i < n - 1) { if (lane.getParentLink().getId().equals("BC")) { // stripe.addPermeability(GTUType.VEHICLE, Permeable.LEFT); stripe.addPermeability(vehicle, Permeable.BOTH); } else { stripe.addPermeability(vehicle, Permeable.BOTH); } } if (lane.getParentLink().getId().equals("BC")) { new Detector(lane.getFullId(), lane, Length.instantiateSI(330.0), sim); } // sink sensors if (lane.getParentLink().getId().equals("CD")) { new SinkSensor(lane, lane.getLength().minus(Length.instantiateSI(100.0)), GTUDirectionality.DIR_PLUS, sim); // detectors 0m after on ramp // new Detector(lane.getFullId(), lane, Length.createSI(0.0), sim); // id equal to lane, may be // different } if (lane.getParentLink().getId().equals("AB")) { // originLanes.add(lane); this.graphLanes.add(lane); } } } new Stripe(linkAB, Length.ZERO, Length.ZERO, stripeWidth); Stripe stripe = new Stripe(linkBC, Length.ZERO, Length.ZERO, stripeWidth); stripe.addPermeability(vehicle, Permeable.LEFT); new Stripe(linkCD, Length.ZERO, Length.ZERO, stripeWidth); new Lane(linkBC, "Acceleration lane", laneWidth.times(-0.5), laneWidth, freewayLaneType, new Speed(100, SpeedUnit.KM_PER_HOUR)); Lane onramp = new Lane(linkEB, "Onramp", laneWidth.times(-0.5), laneWidth, freewayLaneType, new Speed(100, SpeedUnit.KM_PER_HOUR)); new Stripe(linkEB, Length.ZERO, Length.ZERO, stripeWidth); new Stripe(linkEB, laneWidth.neg(), laneWidth.neg(), stripeWidth); new Stripe(linkBC, laneWidth.neg(), laneWidth.neg(), stripeWidth); // OD without demand List<OTSNode> origins = new ArrayList<>(); |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 293 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 645 |
if (this.networkName.equals("onramp")) { // points OTSPoint3D pointA = new OTSPoint3D(0, 0); OTSPoint3D pointB = new OTSPoint3D(2000, 0); // 700 meters toerit OTSPoint3D pointC = new OTSPoint3D(2330, 0); // 330 meters onramp OTSPoint3D pointD = new OTSPoint3D(3330, 0); OTSPoint3D pointE = new OTSPoint3D(1300, -40); // nodes OTSRoadNode nodeA = new OTSRoadNode(network, "A", pointA, Direction.ZERO); OTSRoadNode nodeB = new OTSRoadNode(network, "B", pointB, Direction.ZERO); OTSRoadNode nodeC = new OTSRoadNode(network, "C", pointC, Direction.ZERO); OTSRoadNode nodeD = new OTSRoadNode(network, "D", pointD, Direction.ZERO); OTSRoadNode nodeE = new OTSRoadNode(network, "E", pointE, Direction.ZERO); // links CrossSectionLink linkAB = new CrossSectionLink(network, "AB", nodeA, nodeB, freewayLinkType, new OTSLine3D(pointA, pointB), LaneKeepingPolicy.KEEPRIGHT); CrossSectionLink linkBC = new CrossSectionLink(network, "BC", nodeB, nodeC, freewayLinkType, new OTSLine3D(pointB, pointC), LaneKeepingPolicy.KEEPRIGHT); CrossSectionLink linkCD = new CrossSectionLink(network, "CD", nodeC, nodeD, freewayLinkType, new OTSLine3D(pointC, pointD), LaneKeepingPolicy.KEEPRIGHT); CrossSectionLink linkEB = new CrossSectionLink(network, "EB", nodeE, nodeB, freewayLinkType, Bezier.cubic(nodeE.getLocation(), nodeB.getLocation()), LaneKeepingPolicy.KEEPRIGHT); // lanes and stripes int n = this.numberOfLanes; // List<Lane> originLanes = new ArrayList<>(); for (int i = 0; i < n; i++) { for (CrossSectionLink link : new CrossSectionLink[] { linkAB, linkBC, linkCD }) { Lane lane = new Lane(link, "Lane " + (i + 1), laneWidth.times((0.5 + i)), laneWidth, freewayLaneType, new Speed(100, SpeedUnit.KM_PER_HOUR)); Length offset = laneWidth.times(i + 1.0); Stripe stripe = new Stripe(link, offset, offset, stripeWidth); if (i < n - 1) { if (lane.getParentLink().getId().equals("BC")) { // stripe.addPermeability(GTUType.VEHICLE, Permeable.LEFT); stripe.addPermeability(vehicle, Permeable.BOTH); } else { stripe.addPermeability(vehicle, Permeable.BOTH); } } if (lane.getParentLink().getId().equals("BC")) { // new Detector(lane.getFullId(), lane, Length.createSI(150.0), sim); new Detector(lane.getFullId(), lane, Length.instantiateSI(330.0), sim); } // sink sensors if (lane.getParentLink().getId().equals("CD")) { new SinkSensor(lane, lane.getLength().minus(Length.instantiateSI(100.0)), GTUDirectionality.DIR_PLUS, sim); // detectors 100m after on ramp // new Detector(lane.getFullId(), lane, Length.createSI(0.0), sim); // id equal to lane, may be // different } if (lane.getParentLink().getId().equals("AB")) { // originLanes.add(lane); this.graphLanes.add(lane); } } } new Stripe(linkAB, Length.ZERO, Length.ZERO, stripeWidth); Stripe stripe = new Stripe(linkBC, Length.ZERO, Length.ZERO, stripeWidth); stripe.addPermeability(vehicle, Permeable.LEFT); new Stripe(linkCD, Length.ZERO, Length.ZERO, stripeWidth); new Lane(linkBC, "Acceleration lane", laneWidth.times(-0.5), laneWidth, freewayLaneType, new Speed(100, SpeedUnit.KM_PER_HOUR)); Lane onramp = new Lane(linkEB, "Onramp", laneWidth.times(-0.5), laneWidth, freewayLaneType, new Speed(100, SpeedUnit.KM_PER_HOUR)); new Stripe(linkEB, Length.ZERO, Length.ZERO, stripeWidth); new Stripe(linkEB, laneWidth.neg(), laneWidth.neg(), stripeWidth); new Stripe(linkBC, laneWidth.neg(), laneWidth.neg(), stripeWidth); // Detector on onramp // new Detector("Acceleration lane", accel, Length.createSI(200.0), sim); // OD without demand List<OTSNode> origins = new ArrayList<>(); |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 725 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 827 |
double endTime = generationTimes.get(i) + (generationDuration * this.platoonSize); platoons.addPlatoon(Time.instantiateSI(generationTimes.get(i)), Time.instantiateSI(endTime)); for (double t = generationTimes.get(i); t < endTime; t += dt) { platoons.addGtu(Time.instantiateSI(t)); } } // OD demand // cars (without compensation we use fraction 0.5 in putDemandVector, otherwise we multiply by laneshare) odMatrix.putDemandVector(nodeA, nodeD, carCategory1, freq(new double[] { 0, 0, 1000 * (1 + intensityIncrease), 1000 * (1 + intensityIncrease), 1000 * (1 + intensityIncrease), 1000 * (1 + intensityIncrease), 1000 * (1 + intensityIncrease), 0, 0 }), timeVector, interpolation, 0.5); odMatrix.putDemandVector(nodeA, nodeD, carCategory0, freq(new double[] { 0, 0, 1000 * (1 + intensityIncrease), 1000 * (1 + intensityIncrease), 1000 * (1 + intensityIncrease), 1000 * (1 + intensityIncrease), 1000 * (1 + intensityIncrease), 0, 0 }), timeVector, interpolation, 0.5); odMatrix.putDemandVector(nodeE, nodeD, carCategoryR, platoons.compensate(carCategoryR, freq(new double[] { 0, 0, 250 * (1 + intensityIncrease), 250 * (1 + intensityIncrease), 250 * (1 + intensityIncrease), 250 * (1 + intensityIncrease), 250 * (1 + intensityIncrease), 0, 0 }), timeVector, interpolation)); // trucks odMatrix.putDemandVector(nodeA, nodeD, truCategory0, platoons.compensate(truCategory0, freq(new double[] { 0, 0, 180 * (1 + intensityIncrease), 180 * (1 + intensityIncrease), 180 * (1 + intensityIncrease), 180 * (1 + intensityIncrease), 180 * (1 + intensityIncrease), 0, 0 }), timeVector, interpolation)); // cacc trucks & compensated normal trucks - if there are no, or only, cacc vehicles -> remove demand if (this.penetration != 1.0) { odMatrix.putDemandVector(nodeE, nodeD, truCategoryR, freq(new double[] { demandList.get(0), demandList.get(1), demandList.get(2), demandList.get(3), demandList.get(4), demandList.get(5), demandList.get(6), demandList.get(7), demandList.get(8) }), timeVector, interpolation); } if (this.penetration != 0.0) { odMatrix.putDemandVector(nodeE, nodeD, caccCategory, platoons.compensate(caccCategory, freq(new double[] { demandPlatoonVehicles.get(0), demandPlatoonVehicles.get(1), demandPlatoonVehicles.get(2), demandPlatoonVehicles.get(3), demandPlatoonVehicles.get(4), demandPlatoonVehicles.get(5), demandPlatoonVehicles.get(6), demandPlatoonVehicles.get(7), demandPlatoonVehicles.get(8) }), timeVector, interpolation)); } // options ODOptions odOptions = new ODOptions().set(ODOptions.NO_LC_DIST, Length.instantiateSI(300.0)).set(ODOptions.GTU_TYPE, characteristicsGenerator); odApplierOutput = ODApplier.applyOD(network, odMatrix, odOptions); // start platoons platoonDetector1 = "E1"; platoons.start(odApplierOutput.get(platoonDetector1).getGenerator()); // Write platoon generation times to file BufferedWriter bw; bw = new BufferedWriter( new OutputStreamWriter(Writer.createOutputStream(this.outputFileGen, CompressionType.NONE))); bw.write(String.format("Platoon generation times [s]: %s", generationTimes)); bw.close(); } else { throw new RuntimeException("Network " + this.networkName + " not supported."); |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 293 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 369 |
if (this.networkName.equals("onramp")) { // points OTSPoint3D pointA = new OTSPoint3D(0, 0); OTSPoint3D pointB = new OTSPoint3D(2000, 0); // 700 meters toerit OTSPoint3D pointC = new OTSPoint3D(2330, 0); // 330 meters onramp OTSPoint3D pointD = new OTSPoint3D(3330, 0); OTSPoint3D pointE = new OTSPoint3D(1300, -40); // nodes OTSRoadNode nodeA = new OTSRoadNode(network, "A", pointA, Direction.ZERO); OTSRoadNode nodeB = new OTSRoadNode(network, "B", pointB, Direction.ZERO); OTSRoadNode nodeC = new OTSRoadNode(network, "C", pointC, Direction.ZERO); OTSRoadNode nodeD = new OTSRoadNode(network, "D", pointD, Direction.ZERO); OTSRoadNode nodeE = new OTSRoadNode(network, "E", pointE, Direction.ZERO); // links CrossSectionLink linkAB = new CrossSectionLink(network, "AB", nodeA, nodeB, freewayLinkType, new OTSLine3D(pointA, pointB), LaneKeepingPolicy.KEEPRIGHT); CrossSectionLink linkBC = new CrossSectionLink(network, "BC", nodeB, nodeC, freewayLinkType, new OTSLine3D(pointB, pointC), LaneKeepingPolicy.KEEPRIGHT); CrossSectionLink linkCD = new CrossSectionLink(network, "CD", nodeC, nodeD, freewayLinkType, new OTSLine3D(pointC, pointD), LaneKeepingPolicy.KEEPRIGHT); CrossSectionLink linkEB = new CrossSectionLink(network, "EB", nodeE, nodeB, freewayLinkType, Bezier.cubic(nodeE.getLocation(), nodeB.getLocation()), LaneKeepingPolicy.KEEPRIGHT); // lanes and stripes int n = this.numberOfLanes; // List<Lane> originLanes = new ArrayList<>(); for (int i = 0; i < n; i++) { for (CrossSectionLink link : new CrossSectionLink[] { linkAB, linkBC, linkCD }) { Lane lane = new Lane(link, "Lane " + (i + 1), laneWidth.times((0.5 + i)), laneWidth, freewayLaneType, new Speed(100, SpeedUnit.KM_PER_HOUR)); Length offset = laneWidth.times(i + 1.0); Stripe stripe = new Stripe(link, offset, offset, stripeWidth); if (i < n - 1) { if (lane.getParentLink().getId().equals("BC")) { // stripe.addPermeability(GTUType.VEHICLE, Permeable.LEFT); stripe.addPermeability(vehicle, Permeable.BOTH); } else { stripe.addPermeability(vehicle, Permeable.BOTH); } } if (lane.getParentLink().getId().equals("BC")) { // new Detector(lane.getFullId(), lane, Length.createSI(150.0), sim); new Detector(lane.getFullId(), lane, Length.instantiateSI(330.0), sim); } // sink sensors if (lane.getParentLink().getId().equals("CD")) { new SinkSensor(lane, lane.getLength().minus(Length.instantiateSI(100.0)), GTUDirectionality.DIR_PLUS, sim); |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 543 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 369 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 645 |
else if (this.networkName.equals("onrampMERGE")) { // points OTSPoint3D pointA = new OTSPoint3D(0, 0); OTSPoint3D pointB = new OTSPoint3D(2000, 0); // 700 meters toerit (1300 - 2000) OTSPoint3D pointC = new OTSPoint3D(2330, 0); // 330 meters onramp OTSPoint3D pointD = new OTSPoint3D(3330, 0); OTSPoint3D pointE = new OTSPoint3D(1300, -40); // nodes OTSRoadNode nodeA = new OTSRoadNode(network, "A", pointA, Direction.ZERO); OTSRoadNode nodeB = new OTSRoadNode(network, "B", pointB, Direction.ZERO); OTSRoadNode nodeC = new OTSRoadNode(network, "C", pointC, Direction.ZERO); OTSRoadNode nodeD = new OTSRoadNode(network, "D", pointD, Direction.ZERO); OTSRoadNode nodeE = new OTSRoadNode(network, "E", pointE, Direction.ZERO); // links CrossSectionLink linkAB = new CrossSectionLink(network, "AB", nodeA, nodeB, freewayLinkType, new OTSLine3D(pointA, pointB), LaneKeepingPolicy.KEEPRIGHT); CrossSectionLink linkBC = new CrossSectionLink(network, "BC", nodeB, nodeC, freewayLinkType, new OTSLine3D(pointB, pointC), LaneKeepingPolicy.KEEPRIGHT); CrossSectionLink linkCD = new CrossSectionLink(network, "CD", nodeC, nodeD, freewayLinkType, new OTSLine3D(pointC, pointD), LaneKeepingPolicy.KEEPRIGHT); CrossSectionLink linkEB = new CrossSectionLink(network, "EB", nodeE, nodeB, freewayLinkType, Bezier.cubic(nodeE.getLocation(), nodeB.getLocation()), LaneKeepingPolicy.KEEPRIGHT); // lanes and stripes int n = this.numberOfLanes; // List<Lane> originLanes = new ArrayList<>(); for (int i = 0; i < n; i++) { for (CrossSectionLink link : new CrossSectionLink[] { linkAB, linkBC, linkCD }) { Lane lane = new Lane(link, "Lane " + (i + 1), laneWidth.times((0.5 + i)), laneWidth, freewayLaneType, new Speed(100, SpeedUnit.KM_PER_HOUR)); Length offset = laneWidth.times(i + 1.0); Stripe stripe = new Stripe(link, offset, offset, stripeWidth); if (i < n - 1) { if (lane.getParentLink().getId().equals("BC")) { // stripe.addPermeability(GTUType.VEHICLE, Permeable.LEFT); stripe.addPermeability(vehicle, Permeable.BOTH); } else { stripe.addPermeability(vehicle, Permeable.BOTH); } } if (lane.getParentLink().getId().equals("BC")) { new Detector(lane.getFullId(), lane, Length.instantiateSI(330.0), sim); } // sink sensors if (lane.getParentLink().getId().equals("CD")) { new SinkSensor(lane, lane.getLength().minus(Length.instantiateSI(100.0)), GTUDirectionality.DIR_PLUS, sim); |
File | Line |
---|---|
org\opentrafficsim\ahfe\AHFEAnimation.java | 405 |
org\opentrafficsim\ahfe\AHFESimulation.java | 385 |
return new Rectangle2D.Double(-50, -100, 8050, 150); } /** * The AHFE simulation model. */ static class AHFEModel extends AbstractOTSModel { /** */ private static final long serialVersionUID = 20170228L; /** The network. */ private OTSRoadNetwork network; /** Replication. */ private final Integer replication; /** Anticipation strategy. */ private final String anticipationStrategy; /** Reaction time. */ private final Duration reactionTime; /** Future anticipation time. */ private final Duration anticipationTime; /** Truck fraction. */ private final double truckFraction; /** Distance error. */ private final double distanceError; /** Speed error. */ private final double speedError; /** Acceleration error. */ private final double accelerationError; /** Left demand. */ private final Frequency leftDemand; /** Right demand. */ private final Frequency rightDemand; /** Left fraction, per road. */ private final double leftFraction; /** Sampler. */ private Sampler<GtuData> sampler; /** * @param simulator OTSSimulatorInterface; the simulator * @param replication Integer; replication * @param anticipationStrategy String; anticipation strategy * @param reactionTime Duration; reaction time * @param anticipationTime Duration; anticipation time * @param truckFraction double; truck fraction * @param distanceError double; distance error * @param speedError double; speed error * @param accelerationError double; acceleration error * @param leftFraction double; left demand * @param rightDemand Frequency; right demand * @param leftDemand Frequency; left fraction, per road */ @SuppressWarnings("checkstyle:parameternumber") AHFEModel(final OTSSimulatorInterface simulator, final Integer replication, final String anticipationStrategy, final Duration reactionTime, final Duration anticipationTime, final double truckFraction, final double distanceError, final double speedError, final double accelerationError, final Frequency leftDemand, final Frequency rightDemand, final double leftFraction) { super(simulator); this.replication = replication; this.anticipationStrategy = anticipationStrategy; this.reactionTime = reactionTime; this.anticipationTime = anticipationTime; this.truckFraction = truckFraction; this.distanceError = distanceError; this.speedError = speedError; this.accelerationError = accelerationError; this.leftDemand = leftDemand; this.rightDemand = rightDemand; this.leftFraction = leftFraction; } /** {@inheritDoc} */ @SuppressWarnings("synthetic-access") @Override public void constructModel() throws SimRuntimeException { this.sampler = RoadSampler.build(this.network).registerExtendedDataType(new TimeToCollision()).create(); try { URL xmlURL = URLResource.getResource("/AHFE/Network.xml"); this.network = new OTSRoadNetwork("AHFE", true, getSimulator()); XmlNetworkLaneParser.build(xmlURL, this.network, false); // Space-time regions for sampler LinkData linkData = new LinkData((CrossSectionLink) this.network.getLink("LEFTIN")); registerLinkToSampler(linkData, ignoreStart, linkData.getLength()); linkData = new LinkData((CrossSectionLink) this.network.getLink("RIGHTIN")); registerLinkToSampler(linkData, ignoreStart, linkData.getLength()); linkData = new LinkData((CrossSectionLink) this.network.getLink("CONVERGE")); registerLinkToSampler(linkData, Length.ZERO, linkData.getLength()); linkData = new LinkData((CrossSectionLink) this.network.getLink("WEAVING")); registerLinkToSampler(linkData, Length.ZERO, linkData.getLength()); linkData = new LinkData((CrossSectionLink) this.network.getLink("END")); registerLinkToSampler(linkData, Length.ZERO, linkData.getLength().minus(ignoreEnd)); // Generator AHFEUtil.createDemand(this.network, new DefaultSwitchableGTUColorer(), this.simulator, getReplication(), |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 629 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 731 |
List<OTSNode> destinations = new ArrayList<>(); destinations.add(nodeD); TimeVector timeVector = DoubleVector.instantiate(new double[] { 0.0, 0.25, 0.50, 0.75, 1.0, 1.25, 1.50, 1.75, 2.0 }, TimeUnit.BASE_HOUR, StorageType.DENSE); Interpolation interpolation = Interpolation.LINEAR; // or STEPWISE Categorization categorization = new Categorization("CACC", GTUType.class, Lane.class); Category carCategory1 = new Category(categorization, carGTUType, this.graphLanes.get(1)); Category carCategory0 = new Category(categorization, carGTUType, this.graphLanes.get(0)); Category carCategoryR = new Category(categorization, carGTUType, onramp); Category truCategory0 = new Category(categorization, truckGTUType, this.graphLanes.get(0)); Category truCategoryR = new Category(categorization, truckGTUType, onramp); Category caccCategory = new Category(categorization, caccGTUType, onramp); ODMatrix odMatrix = new ODMatrix("CACC OD", origins, destinations, categorization, timeVector, interpolation); double intensityIncrease = this.intensity; double platoonPenetration = this.penetration; // Demand of trucks departing from onramp List<Double> demandList = new ArrayList<Double>(); demandList.add((double) 0); demandList.add((double) 0); demandList.add(45 * (1 + intensityIncrease)); demandList.add(45 * (1 + intensityIncrease)); demandList.add(45 * (1 + intensityIncrease)); demandList.add(45 * (1 + intensityIncrease)); demandList.add(45 * (1 + intensityIncrease)); demandList.add((double) 0); demandList.add((double) 0); List<Double> demandPlatoon = new ArrayList<Double>(); // List for number of platoons (not number of platoon // vehicles!) List<Double> demandPlatoonVehicles = new ArrayList<Double>(); // Demand for platoon vehicles for (int k = 0; k < demandList.size(); k++) { double platoonVehicles = (demandList.get(k) * platoonPenetration); // double platoonPlatoons = Math.round(platoonVehicles/this.platoonSize)/4; // Actual generated platoons -> divide by 4 to account for 15 minutes double platoonPlatoons = Math.ceil(Math.abs(platoonVehicles / this.platoonSize)) / 4; // Rounding up |
File | Line |
---|---|
org\opentrafficsim\ahfe\AHFEAnimation.java | 309 |
org\opentrafficsim\ahfe\AHFESimulation.java | 296 |
int reportTimeClick = 60; while (true) { int currentTime = (int) simulator.getSimulatorTime().si; if (currentTime >= lastReportedTime + reportTimeClick) { lastReportedTime = currentTime / reportTimeClick * reportTimeClick; System.out.println("time is " + simulator.getSimulatorTime()); } try { simulator.step(); } catch (SimRuntimeException sre) { if (sre.getCause() != null && sre.getCause().getCause() != null && sre.getCause().getCause().getMessage().equals( "Model has calcalated a negative infinite or negative max value acceleration.")) { System.err.println("Collision detected."); String file = finalScenario + ".csv.zip"; FileOutputStream fos = null; ZipOutputStream zos = null; OutputStreamWriter osw = null; BufferedWriter bw = null; try { fos = new FileOutputStream(file); zos = new ZipOutputStream(fos); zos.putNextEntry(new ZipEntry(finalScenario + ".csv")); osw = new OutputStreamWriter(zos); bw = new BufferedWriter(osw); bw.write("Collision"); bw.write(simulator.getSimulatorTime().toString()); } catch (IOException exception2) { throw new RuntimeException("Could not write to file.", exception2); } // close file on fail finally { try { if (bw != null) { bw.close(); } if (osw != null) { osw.close(); } if (zos != null) { zos.close(); } if (fos != null) { fos.close(); } } catch (IOException ex) { ex.printStackTrace(); } } } else { System.out.println("Simulation ends; time is " + simulator.getSimulatorTime()); if (ahfeModel.getSampler() != null) { ahfeModel.getSampler().getSamplerData().writeToFile(finalScenario + ".csv"); } } long t2 = System.currentTimeMillis(); System.out.println("Run took " + (t2 - t1) / 1000 + "s."); System.exit(0); break; } } } } catch (SimRuntimeException | NamingException | RemoteException | OTSDrawingException | DSOLException exception) |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 438 |
org\opentrafficsim\demo\cacc\CaccSimulation.java | 684 |
platoons.fixInfo(nodeA, nodeD, caccCategory); double dt = this.startSpacing; // Determine platoon generation times (of leading vehicle only) using pseudorandom generation (exponential // distribution) // Then check if interval times do not overlap with whole platoon generation, adjust accordingly List<Double> generationTimes = new ArrayList<Double>(); double previous = 0; for (int k = 0; k < demandList.size(); k++) { for (int i = 0; i < demandPlatoon.get(k); i++) { double lambda = (demandPlatoon.get(k) * 4); // Number of platoons to be generated (per hour -> times 4) StreamInterface rand = sim.getReplication().getStream("generation"); // Random rand = new Random(); double arrival = (Math.log(1 - rand.nextDouble()) / (-lambda) * 3600); // Inter arrival time is in the unit of lambda (here per 15 minutes) double startTime = (arrival + previous); // (k * 900) + (arrival + previous); // Interarrival plus 15 // minutes (900 seconds) generationTimes.add(startTime); previous = previous + arrival; } } // Sorting the generation time to check for overlap in generation Collections.sort(generationTimes); for (int i = 0; i < generationTimes.size() - 1; i++) { double diff = generationTimes.get(i + 1) - generationTimes.get(i); double generationDuration = 0.5; double maxDuration = (generationDuration * this.platoonSize) + 1.0; if (diff <= maxDuration) { generationTimes.set(i + 1, generationTimes.get(i) + maxDuration); } // ((platoonSize-1)*((12.0 + 3.0)/22.22) + 0.3) + ( (12.0 + 3.0)/22.22 + 1.0); double endTime = generationTimes.get(i) + (generationDuration * this.platoonSize); platoons.addPlatoon(Time.instantiateSI(generationTimes.get(i)), Time.instantiateSI(endTime)); for (double t = generationTimes.get(i); t < endTime; t += dt) { platoons.addGtu(Time.instantiateSI(t)); } } // OD demand // cars (without compensation we use fraction 0.5 in putDemandVector, otherwise we multiply by laneshare) odMatrix.putDemandVector(nodeA, nodeD, carCategory1, freq(new double[] { 0, 0, 1000 * (1 + intensityIncrease), 1000 * (1 + intensityIncrease), 1000 * (1 + intensityIncrease), 1000 * (1 + intensityIncrease), 1000 * (1 + intensityIncrease), 0, 0 }), timeVector, interpolation, 0.5); odMatrix.putDemandVector(nodeA, nodeD, carCategory0, platoons.compensate(carCategory0, |
File | Line |
---|---|
org\opentrafficsim\demo\conflictAndControl\DemoTrafcodAndTurbo.java | 253 |
org\opentrafficsim\demo\trafficcontrol\TrafCODDemo2_Generators.java | 176 |
this.simulator, this.controllerDisplayPanel, null, null); this.trafCOD.addListener(this, TrafficController.TRAFFICCONTROL_CONTROLLER_EVALUATING); this.trafCOD.addListener(this, TrafficController.TRAFFICCONTROL_CONTROLLER_WARNING); this.trafCOD.addListener(this, TrafficController.TRAFFICCONTROL_CONFLICT_GROUP_CHANGED); this.trafCOD.addListener(this, TrafficController.TRAFFICCONTROL_STATE_CHANGED); this.trafCOD.addListener(this, TrafficController.TRAFFICCONTROL_VARIABLE_CREATED); this.trafCOD.addListener(this, TrafficController.TRAFFICCONTROL_TRACED_VARIABLE_UPDATED); // Subscribe the TrafCOD machine to trace command events that we // emit addListener(this.trafCOD, TrafficController.TRAFFICCONTROL_SET_TRACING); // fireEvent(TrafficController.TRAFFICCONTROL_SET_TRACING, new // Object[] {controllerName, "TGX", 8, true}); // fireEvent(TrafficController.TRAFFICCONTROL_SET_TRACING, new // Object[] {controllerName, "XR1", 11, true}); // fireEvent(TrafficController.TRAFFICCONTROL_SET_TRACING, new // Object[] {controllerName, "TD1", 11, true}); // fireEvent(TrafficController.TRAFFICCONTROL_SET_TRACING, new // Object[] {controllerName, "TGX", 11, true}); // fireEvent(TrafficController.TRAFFICCONTROL_SET_TRACING, new // Object[] {controllerName, "TL", 11, true}); // System.out.println("demo: emitting a SET TRACING event for // all variables related to stream 11"); // fireEvent(TrafficController.TRAFFICCONTROL_SET_TRACING, new // Object[] { controllerName, "", 11, true }); // TrafCODDemo2.this.trafCOD.traceVariablesOfStream(TrafficController.NO_STREAM, // true); // TrafCODDemo2.this.trafCOD.traceVariablesOfStream(11, true); // TrafCODDemo2.this.trafCOD.traceVariable("MRV", 11, true); } catch (Exception exception) { exception.printStackTrace(); } } /** {@inheritDoc} */ @Override public final OTSRoadNetwork getNetwork() { return this.network; } /** * @return trafCOD */ public final TrafCOD getTrafCOD() { return this.trafCOD; } /** * @return controllerDisplayPanel */ public final JPanel getControllerDisplayPanel() { return this.controllerDisplayPanel; } /** {@inheritDoc} */ @Override public void notify(final EventInterface event) throws RemoteException { EventTypeInterface type = event.getType(); Object[] payload = (Object[]) event.getContent(); if (TrafficController.TRAFFICCONTROL_CONTROLLER_EVALUATING.equals(type)) { // System.out.println("Evaluation starts at " + // getSimulator().getSimulatorTime()); return; } else if (TrafficController.TRAFFICCONTROL_CONFLICT_GROUP_CHANGED.equals(type)) { System.out.println("Conflict group changed from " + ((String) payload[1]) + " to " + ((String) payload[2])); } else if (TrafficController.TRAFFICCONTROL_TRACED_VARIABLE_UPDATED.equals(type)) { System.out.println(String.format("Variable changed %s <- %d %s", payload[1], payload[4], payload[5])); } else if (TrafficController.TRAFFICCONTROL_CONTROLLER_WARNING.equals(type)) { System.out.println("Warning " + payload[1]); } else { System.out.print("TrafCODDemo received event of type " + event.getType() + ", payload ["); String separator = ""; for (Object o : payload) { System.out.print(separator + o); separator = ","; } System.out.println("]"); } } /** {@inheritDoc} */ @Override public Serializable getSourceId() { return "TrafCODModel"; } } } |
File | Line |
---|---|
org\opentrafficsim\demo\CircularLaneSwing.java | 100 |
org\opentrafficsim\demo\StraightSwing.java | 97 |
CircularLaneSwing app = new CircularLaneSwing("Circular Lane", animationPanel, otsModel); app.setExitOnClose(exitOnClose); animationPanel.enableSimulationControlButtons(); } else { if (exitOnClose) { System.exit(0); } } } catch (SimRuntimeException | NamingException | RemoteException | OTSDrawingException | DSOLException exception) { exception.printStackTrace(); } } /** * Add the statistics tabs. * @param simulator OTSSimulatorInterface; the simulator on which sampling can be scheduled */ protected final void addStatisticsTabs(final OTSSimulatorInterface simulator) { GraphPath<KpiLaneDirection> path; try { path = GraphLaneUtil.createPath("Lane", new LaneDirection(getModel().getPath().get(0), GTUDirectionality.DIR_PLUS)); } catch (NetworkException exception) { throw new RuntimeException("Could not create a path as a lane has no set speed limit.", exception); } RoadSampler sampler = new RoadSampler(getModel().getNetwork()); GraphPath.initRecording(sampler, path); ContourDataSource<?> dataPool = new ContourDataSource<>(sampler.getSamplerData(), path); TablePanel charts = new TablePanel(3, 2); SwingPlot plot = null; plot = new SwingTrajectoryPlot( new TrajectoryPlot("TrajectoryPlot", Duration.instantiateSI(10.0), simulator, sampler.getSamplerData(), path)); charts.setCell(plot.getContentPane(), 0, 0); plot = new SwingContourPlot(new ContourPlotDensity("DensityPlot", simulator, dataPool)); charts.setCell(plot.getContentPane(), 1, 0); plot = new SwingContourPlot(new ContourPlotSpeed("SpeedPlot", simulator, dataPool)); charts.setCell(plot.getContentPane(), 2, 0); plot = new SwingContourPlot(new ContourPlotFlow("FlowPlot", simulator, dataPool)); charts.setCell(plot.getContentPane(), 1, 1); plot = new SwingContourPlot(new ContourPlotAcceleration("AccelerationPlot", simulator, dataPool)); charts.setCell(plot.getContentPane(), 2, 1); getAnimationPanel().getTabbedPane().addTab(getAnimationPanel().getTabbedPane().getTabCount(), "statistics ", charts); } } |
File | Line |
---|---|
org\opentrafficsim\demo\CircularLaneSwing.java | 100 |
org\opentrafficsim\demo\SequentialLanes.java | 139 |
org\opentrafficsim\demo\StraightSwing.java | 97 |
CircularLaneSwing app = new CircularLaneSwing("Circular Lane", animationPanel, otsModel); app.setExitOnClose(exitOnClose); animationPanel.enableSimulationControlButtons(); } else { if (exitOnClose) { System.exit(0); } } } catch (SimRuntimeException | NamingException | RemoteException | OTSDrawingException | DSOLException exception) { exception.printStackTrace(); } } /** * Add the statistics tabs. * @param simulator OTSSimulatorInterface; the simulator on which sampling can be scheduled */ protected final void addStatisticsTabs(final OTSSimulatorInterface simulator) { GraphPath<KpiLaneDirection> path; try { path = GraphLaneUtil.createPath("Lane", new LaneDirection(getModel().getPath().get(0), GTUDirectionality.DIR_PLUS)); } catch (NetworkException exception) { throw new RuntimeException("Could not create a path as a lane has no set speed limit.", exception); } RoadSampler sampler = new RoadSampler(getModel().getNetwork()); GraphPath.initRecording(sampler, path); ContourDataSource<?> dataPool = new ContourDataSource<>(sampler.getSamplerData(), path); TablePanel charts = new TablePanel(3, 2); SwingPlot plot = null; plot = new SwingTrajectoryPlot( new TrajectoryPlot("TrajectoryPlot", Duration.instantiateSI(10.0), simulator, sampler.getSamplerData(), path)); charts.setCell(plot.getContentPane(), 0, 0); plot = new SwingContourPlot(new ContourPlotDensity("DensityPlot", simulator, dataPool)); charts.setCell(plot.getContentPane(), 1, 0); plot = new SwingContourPlot(new ContourPlotSpeed("SpeedPlot", simulator, dataPool)); charts.setCell(plot.getContentPane(), 2, 0); plot = new SwingContourPlot(new ContourPlotFlow("FlowPlot", simulator, dataPool)); charts.setCell(plot.getContentPane(), 1, 1); plot = new SwingContourPlot(new ContourPlotAcceleration("AccelerationPlot", simulator, dataPool)); charts.setCell(plot.getContentPane(), 2, 1); getAnimationPanel().getTabbedPane().addTab(getAnimationPanel().getTabbedPane().getTabCount(), "statistics ", charts); } |
File | Line |
---|---|
org\opentrafficsim\ahfe\AHFEAnimation.java | 514 |
org\opentrafficsim\ahfe\AHFESimulation.java | 494 |
AHFEUtil.createDemand(this.network, new DefaultSwitchableGTUColorer(), this.simulator, getReplication(), getAnticipationStrategy(), getReactionTime(), getAnticipationTime(), getTruckFraction(), SIMEND, getLeftDemand(), getRightDemand(), getLeftFraction(), getDistanceError(), getSpeedError(), getAccelerationError()); } catch (Exception exception) { exception.printStackTrace(); } } /** * Register a link to the sampler, so data is sampled there. * @param linkData LinkData; link data * @param startDistance Length; start distance on link * @param endDistance Length; end distance on link */ private void registerLinkToSampler(final LinkData linkData, final Length startDistance, final Length endDistance) { for (LaneDataInterface laneData : linkData.getLaneDatas()) { Length start = laneData.getLength().times(startDistance.si / linkData.getLength().si); Length end = laneData.getLength().times(endDistance.si / linkData.getLength().si); this.sampler.registerSpaceTimeRegion(new SpaceTimeRegion( new KpiLaneDirection(laneData, KpiGtuDirectionality.DIR_PLUS), start, end, WARMUP, SIMEND)); } } /** {@inheritDoc} */ @Override public OTSRoadNetwork getNetwork() { return this.network; } /** * @return replication. */ public Integer getReplication() { return this.replication; } /** * @return anticipationStrategy. */ public String getAnticipationStrategy() { return this.anticipationStrategy; } /** * @return reactionTime. */ public Duration getReactionTime() { return this.reactionTime; } /** * @return anticipationTime. */ public Duration getAnticipationTime() { return this.anticipationTime; } /** * @return truckFraction. */ public double getTruckFraction() { return this.truckFraction; } /** * @return distanceError. */ public double getDistanceError() { return this.distanceError; } /** * @return speedError. */ public double getSpeedError() { return this.speedError; } /** * @return accelerationError. */ public double getAccelerationError() { return this.accelerationError; } /** * @return leftDemand. */ public Frequency getLeftDemand() { return this.leftDemand; } /** * @return rightDemand. */ public Frequency getRightDemand() { return this.rightDemand; } /** * @return leftFraction. */ public double getLeftFraction() { return this.leftFraction; } /** * @return sampler */ public final Sampler<GtuData> getSampler() { return this.sampler; } /** {@inheritDoc} */ @Override public Serializable getSourceId() { return "AHFEAnimation.Model"; |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 508 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 612 |
45 * (1 + intensityIncrease), 45 * (1 + intensityIncrease), 45 * (1 + intensityIncrease), 0, 0 })); // cacc trucks & compensated normal trucks - if there are no, or only, cacc vehicles -> remove demand if (this.penetration != 1.0) { odMatrix.putDemandVector(nodeA, nodeD, truCategory0, platoons.compensate(truCategory0, freq(new double[] { demandList.get(0), demandList.get(1), demandList.get(2), demandList.get(3), demandList.get(4), demandList.get(5), demandList.get(6), demandList.get(7), demandList.get(8) }), timeVector, interpolation)); } if (this.penetration != 0.0) { odMatrix.putDemandVector(nodeA, nodeD, caccCategory, platoons.compensate(caccCategory, freq(new double[] { demandPlatoonVehicles.get(0), demandPlatoonVehicles.get(1), demandPlatoonVehicles.get(2), demandPlatoonVehicles.get(3), demandPlatoonVehicles.get(4), demandPlatoonVehicles.get(5), demandPlatoonVehicles.get(6), demandPlatoonVehicles.get(7), demandPlatoonVehicles.get(8) }), timeVector, interpolation)); } // options ODOptions odOptions = new ODOptions().set(ODOptions.NO_LC_DIST, Length.instantiateSI(300.0)).set(ODOptions.GTU_TYPE, characteristicsGenerator); odApplierOutput = ODApplier.applyOD(network, odMatrix, odOptions); // start platoons platoonDetector1 = "A1"; platoons.start(odApplierOutput.get(platoonDetector1).getGenerator()); // Write platoon generation times to file BufferedWriter bw; bw = new BufferedWriter( new OutputStreamWriter(Writer.createOutputStream(this.outputFileGen, CompressionType.NONE))); bw.write(String.format("Platoon generation times [s]: %s", generationTimes)); bw.close(); } else if (this.networkName.equals("onrampMERGE")) |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 430 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 702 |
new SinkSensor(lane, lane.getLength().minus(Length.instantiateSI(80.0)), GTUDirectionality.DIR_PLUS, sim); // detectors 100m after on ramp // new Detector(lane.getFullId(), lane, Length.instantiateSI(0.0), sim); // id equal to lane, may be // different } if (lane.getParentLink().getId().equals("AB")) { // originLanes.add(lane); this.graphLanes.add(lane); } } } new Stripe(linkAB, Length.ZERO, Length.ZERO, stripeWidth); Stripe stripe = new Stripe(linkBC, Length.ZERO, Length.ZERO, stripeWidth); stripe.addPermeability(vehicle, Permeable.LEFT); new Stripe(linkCD, Length.ZERO, Length.ZERO, stripeWidth); new Lane(linkBC, "Acceleration lane", laneWidth.times(-0.5), laneWidth, freewayLaneType, new Speed(100, SpeedUnit.KM_PER_HOUR)); Lane onramp = new Lane(linkEB, "Onramp", laneWidth.times(-0.5), laneWidth, freewayLaneType, new Speed(100, SpeedUnit.KM_PER_HOUR)); new Stripe(linkEB, Length.ZERO, Length.ZERO, stripeWidth); new Stripe(linkEB, laneWidth.neg(), laneWidth.neg(), stripeWidth); new Stripe(linkBC, laneWidth.neg(), laneWidth.neg(), stripeWidth); // Detector on onramp // new Detector("Acceleration lane", accel, Length.createSI(200.0), sim); // OD without demand List<OTSRoadNode> origins = new ArrayList<>(); origins.add(nodeA); origins.add(nodeE); List<OTSRoadNode> destinations = new ArrayList<>(); destinations.add(nodeD); TimeVector timeVector = DoubleVector.instantiate(new double[] {0.0, 0.25, 0.50, 0.75, 1.0, 1.25, 1.50, 1.75, 2.0}, TimeUnit.BASE_HOUR, StorageType.DENSE); Interpolation interpolation = Interpolation.LINEAR; // or STEPWISE Categorization categorization = new Categorization("CACC", GTUType.class, Lane.class); // Category carCategory1 = new Category(categorization, GTUType.CAR, originLanes.get(1)); Category carCategory2 = new Category(categorization, carGTUType, this.graphLanes.get(2)); |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 1029 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 1056 |
timerampList.add(tPos); } } if (region.getLaneDirection().getLaneData().getLinkData().getId().equals("CD") && trajectory.size() > 1 && trajectory.getX(0) < detectorPosition.si && trajectory.getX(trajectory.size() - 1) > detectorPosition.si) { double t = trajectory.getTimeAtPosition(detectorPosition).si - region.getStartTime().si; counts[(int) (t / 60.0)]++; } } catch (SamplingException exception) { throw new RuntimeException("Unexpected exception: TimeToCollission not available or index out of bounds.", exception); } } } int qMax = 0; for (int i = 0; i < counts.length - 4; i++) { int q = 0; for (int j = i; j < i + 5; j++) { q += counts[j]; } qMax = qMax > q ? qMax : q; } BufferedWriter bw; try { bw = new BufferedWriter( new OutputStreamWriter(Writer.createOutputStream(this.outputFileTraj, CompressionType.NONE))); bw.write(String.format("total time spent [s]: %.0f", tts)); bw.newLine(); bw.write(String.format("maximum flow [veh/5min]: %d", qMax)); bw.newLine(); bw.write(String.format("time to collision [s]: %s", ttcList)); bw.newLine(); bw.write(String.format("time to collision GTU type: %s", ttcListGtuType)); bw.newLine(); bw.write(String.format("strong decelerations [m/s^2]: %s", decList)); bw.newLine(); bw.write(String.format("strong decelerations GTU type: %s", decListGtuType)); bw.newLine(); |
File | Line |
---|---|
org\opentrafficsim\remotecontrol\Sim0MQRemoteController.java | 133 |
org\opentrafficsim\remotecontrol\Sim0MQRemoteControllerNew.java | 134 |
gui = new Sim0MQRemoteController(); gui.setVisible(true); } catch (Exception e) { e.printStackTrace(); System.exit(ERROR); } } }); } catch (Exception e) { e.printStackTrace(); System.exit(ERROR); } // We don't get here until the GUI is fully running. Options options = new Options(); CliUtil.execute(options, args); // register Unit converters, parse the command line, etc.. gui.processArguments(options.getHost(), options.getPort()); } /** ... */ private ZContext zContext = new ZContext(1); /** Message relayer. */ private Thread pollerThread; /** * Poller thread for relaying messages between the remote OTS and local AWT. */ class PollerThread extends Thread { /** The ZContext. */ private final ZContext context; /** The host that runs the OTS simulation. */ private final String slaveHost; /** The port on which to connect to the OTS simulation. */ private final int slavePort; /** * Construct a new PollerThread for relaying messages. * @param context ZContext; the ZMQ context * @param slaveHost String; host name of the OTS server machine * @param slavePort int; port number on which to connect to the OTS server machine */ PollerThread(final ZContext context, final String slaveHost, final int slavePort) { this.context = context; this.slaveHost = slaveHost; this.slavePort = slavePort; } @Override public final void run() { int nextExpectedPacket = 0; ZMQ.Socket slaveSocket = this.context.createSocket(SocketType.PAIR); // changed to PAIR slaveSocket.setHWM(100000); ZMQ.Socket awtSocketIn = this.context.createSocket(SocketType.PULL); awtSocketIn.setHWM(100000); ZMQ.Socket awtSocketOut = this.context.createSocket(SocketType.PUSH); awtSocketOut.setHWM(100000); slaveSocket.connect("tcp://" + this.slaveHost + ":" + this.slavePort); awtSocketIn.bind("inproc://fromAWT"); awtSocketOut.bind("inproc://toAWT"); ZMQ.Poller items = this.context.createPoller(2); items.register(slaveSocket, ZMQ.Poller.POLLIN); items.register(awtSocketIn, ZMQ.Poller.POLLIN); while (!Thread.currentThread().isInterrupted()) { |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 523 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 786 |
platoons.fixInfo(nodeA, nodeD, caccCategory); double dt = this.startSpacing; // Determine platoon generation times (of leading vehicle only) using pseudorandom generation (exponential // distribution) // Then check if interval times do not overlap with whole platoon generation, adjust accordingly List<Double> generationTimes = new ArrayList<Double>(); double previous = 0; for (int k = 0; k < demandList.size(); k++) { for (int i = 0; i < demandPlatoon.get(k); i++) { double lambda = (demandPlatoon.get(k) * 4); // Number of platoons to be generated (per hour -> times 4) StreamInterface rand = sim.getReplication().getStream("generation"); // Random rand = new Random(); double arrival = (Math.log(1 - rand.nextDouble()) / (-lambda) * 3600); // Inter arrival time is in the unit // of lambda (here per 15 minutes) double startTime = (arrival + previous); // (k * 900) + (arrival + previous); // Interarrival plus 15 // minutes (900 seconds) generationTimes.add(startTime); previous = previous + arrival; } } // Sorting the generation time to check for overlap in generation Collections.sort(generationTimes); for (int i = 0; i < generationTimes.size() - 1; i++) { double diff = generationTimes.get(i + 1) - generationTimes.get(i); double generationDuration = 0.5; double maxDuration = (generationDuration * platoonSize) + 1.0; if (diff <= maxDuration) { generationTimes.set(i + 1, generationTimes.get(i) + maxDuration); } // ((platoonSize-1)*((12.0 + 3.0)/22.22) + 0.3) + ( (12.0 + 3.0)/22.22 + 1.0); double endTime = generationTimes.get(i) + (generationDuration * platoonSize); platoons.addPlatoon(Time.instantiateSI(generationTimes.get(i)), Time.instantiateSI(endTime)); for (double t = generationTimes.get(i); t < endTime; t += dt) { platoons.addGtu(Time.instantiateSI(t)); } } // OD demand // cars (without compensation we use fraction 0.5 in putDemandVector, otherwise we multiply by laneshare) odMatrix.putDemandVector(nodeA, nodeD, carCategory2, |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 425 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 510 |
platoonVehicles = platoonPlatoons * this.platoonSize * 4; // Based on actual generated platoons, but used to // compensate per hour demandPlatoonVehicles.add(platoonVehicles); } // Platoon definition (platoons = ... divide into multiple for multiple origins) Set<LaneDirection> position = new LinkedHashSet<>(); position.add(new LaneDirection(this.graphLanes.get(0), GTUDirectionality.DIR_PLUS)); DefaultGTUCharacteristicsGeneratorOD characteristicsGenerator = getCharacteristicsGenerator(longitudinalControllerFactory, sim, parameters); Platoons<Category> platoons = Platoons.ofCategory(characteristicsGenerator, sim, sim.getReplication().getStream("generation"), position); platoons.fixInfo(nodeA, nodeD, caccCategory); double dt = this.startSpacing; // Determine platoon generation times (of leading vehicle only) using pseudorandom generation (exponential // distribution) // Then check if interval times do not overlap with whole platoon generation, adjust accordingly List<Double> generationTimes = new ArrayList<Double>(); double previous = 0; for (int k = 0; k < demandList.size(); k++) { for (int i = 0; i < demandPlatoon.get(k); i++) { double lambda = (demandPlatoon.get(k) * 4); // Number of platoons to be generated (per hour -> times 4) StreamInterface rand = sim.getReplication().getStream("generation"); // Random rand = new Random(); double arrival = (Math.log(1 - rand.nextDouble()) / (-lambda) * 3600); // Inter arrival time is in the unit of lambda (here per 15 minutes) double startTime = (arrival + previous); // (k * 900) + (arrival + previous); // Interarrival plus 15 // minutes (900 seconds) generationTimes.add(startTime); previous = previous + arrival; } } // Sorting the generation time to check for overlap in generation Collections.sort(generationTimes); for (int i = 0; i < generationTimes.size() - 1; i++) { double diff = generationTimes.get(i + 1) - generationTimes.get(i); double generationDuration = 0.5; double maxDuration = (generationDuration * this.platoonSize) + 1.0; |
File | Line |
---|---|
org\opentrafficsim\remotecontrol\Sim0MQRemoteController.java | 293 |
org\opentrafficsim\remotecontrol\Sim0MQRemoteControllerNew.java | 292 |
Sim0MQRemoteController() { // Construct the GUI setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setBounds(100, 100, 1000, 800); JPanel panelAll = new JPanel(); panelAll.setBorder(new EmptyBorder(5, 5, 5, 5)); panelAll.setLayout(new BorderLayout(0, 0)); setContentPane(panelAll); JPanel panelControls = new JPanel(); panelAll.add(panelControls, BorderLayout.PAGE_START); JTextArea textArea = new JTextArea(); textArea.setFont(new Font("monospaced", Font.PLAIN, 12)); JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setPreferredSize(new Dimension(800, 400)); panelAll.add(scrollPane, BorderLayout.PAGE_END); this.output = new PrintStream(new TextAreaOutputStream(textArea), true); JPanel controls = new JPanel(); controls.setLayout(new FlowLayout()); JButton sendNetwork = new JButton("Send network"); sendNetwork.setActionCommand("SendNetwork"); sendNetwork.addActionListener(this); controls.add(sendNetwork); this.stepTo = new JButton("Step to 10 s"); this.stepTo.setActionCommand("StepTo"); this.stepTo.addActionListener(this); controls.add(this.stepTo); JButton step100TimesTo = new JButton("Step 100 times 10 s"); step100TimesTo.setActionCommand("Step100To"); step100TimesTo.addActionListener(this); controls.add(step100TimesTo); JButton getGTUPositions = new JButton("Get all GTU positions"); getGTUPositions.setActionCommand("GetAllGTUPositions"); getGTUPositions.addActionListener(this); controls.add(getGTUPositions); |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 671 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 773 |
platoonVehicles = platoonPlatoons * this.platoonSize * 4; // Based on actual generated platoons, but used to // compensate per hour demandPlatoonVehicles.add(platoonVehicles); } // Platoon definition (platoons = ... divide into multiple for multiple origins) Set<LaneDirection> position = new LinkedHashSet<>(); position.add(new LaneDirection(onramp, GTUDirectionality.DIR_PLUS)); DefaultGTUCharacteristicsGeneratorOD characteristicsGenerator = getCharacteristicsGenerator(longitudinalControllerFactory, sim, parameters); Platoons<Category> platoons = Platoons.ofCategory(characteristicsGenerator, sim, sim.getReplication().getStream("generation"), position); platoons.fixInfo(nodeE, nodeD, caccCategory); double dt = this.startSpacing; // Determine platoon generation times (of leading vehicle only) using pseudorandom generation (exponential // distribution) // Then check if interval times do not overlap with whole platoon generation, adjust accordingly List<Double> generationTimes = new ArrayList<Double>(); double previous = 0; for (int k = 0; k < demandList.size(); k++) { for (int i = 0; i < demandPlatoon.get(k); i++) { double lambda = (demandPlatoon.get(k) * 4); // Number of platoons to be generated (per hour -> times 4) StreamInterface rand = sim.getReplication().getStream("generation"); // Random rand = new Random(); double arrival = (Math.log(1 - rand.nextDouble()) / (-lambda) * 3600); // Inter arrival time is in the unit // of lambda (here per 15 minutes) double startTime = (arrival + previous); // (k * 900) + (arrival + previous); // Interarrival plus 15 // minutes (900 seconds) generationTimes.add(startTime); previous = previous + arrival; } } // Sorting the generation time to check for overlap in generation Collections.sort(generationTimes); for (int i = 0; i < generationTimes.size() - 1; i++) { double diff = generationTimes.get(i + 1) - generationTimes.get(i); double generationDuration = 0.5; double maxDuration = (generationDuration * this.platoonSize) + 1.0; |
File | Line |
---|---|
org\opentrafficsim\demo\conflictAndControl\DemoTrafcodAndTurbo.java | 310 |
org\opentrafficsim\demo\trafficcontrol\TrafCODDemo1.java | 234 |
org\opentrafficsim\demo\trafficcontrol\TrafCODDemo2_Generators.java | 224 |
} /** {@inheritDoc} */ @Override public void notify(final EventInterface event) throws RemoteException { EventTypeInterface type = event.getType(); Object[] payload = (Object[]) event.getContent(); if (TrafficController.TRAFFICCONTROL_CONTROLLER_EVALUATING.equals(type)) { // System.out.println("Evaluation starts at " + // getSimulator().getSimulatorTime()); return; } else if (TrafficController.TRAFFICCONTROL_CONFLICT_GROUP_CHANGED.equals(type)) { System.out.println("Conflict group changed from " + ((String) payload[1]) + " to " + ((String) payload[2])); } else if (TrafficController.TRAFFICCONTROL_TRACED_VARIABLE_UPDATED.equals(type)) { System.out.println(String.format("Variable changed %s <- %d %s", payload[1], payload[4], payload[5])); } else if (TrafficController.TRAFFICCONTROL_CONTROLLER_WARNING.equals(type)) { System.out.println("Warning " + payload[1]); } else { System.out.print("TrafCODDemo received event of type " + event.getType() + ", payload ["); String separator = ""; for (Object o : payload) { System.out.print(separator + o); separator = ","; } System.out.println("]"); } } /** {@inheritDoc} */ @Override public Serializable getSourceId() { return "TrafCODModel"; } } } |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 1104 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 1099 |
bw.write(String.format("X pos down GTU type: %s", postimedownstreamList)); bw.close(); } catch (IOException exception) { throw new RuntimeException(exception); } } /** * Creates a frequency vector. * @param array double[]; array in veh/h * @return FrequencyVector; frequency vector * @throws ValueRuntimeException on problem */ private FrequencyVector freq(final double[] array) throws ValueRuntimeException { return DoubleVector.instantiate(array, FrequencyUnit.PER_HOUR, StorageType.DENSE); } /** * Returns an OD compatible characteristics generator that uses the GTUType to select either regular models or CACC specific * models. * @param longitudinalControllerFactory LongitudinalControllerFactory<? extends CACC>; longitudinal controller factory * @param simulator OTSSimulatorInterface; simulator * @param parameters ParameterFactory parameters * @return OD compatible characteristics generator */ private DefaultGTUCharacteristicsGeneratorOD getCharacteristicsGenerator( final LongitudinalControllerFactory<? extends CaccController> longitudinalControllerFactory, final OTSSimulatorInterface simulator, final ParameterFactory parameters) { // create template for CACC truck properties (this is then used instead of GTUType.defaultCharacteristics(...)) Set<TemplateGTUType> templates = new LinkedHashSet<>(); templates.add(new TemplateGTUType(caccGTUType, new ConstantGenerator<>(Length.instantiateSI(12.0)), new ConstantGenerator<>(Length.instantiateSI(2.55)), new ConstantGenerator<>(Speed.instantiateSI(this.setspeed.si + 2.78)))); // anonymous class for factory supplier that overwrites the getFactory() method to return one based on the GTU type return new DefaultGTUCharacteristicsGeneratorOD(templates, new StrategicalPlannerFactorySupplierOD() { /** Strategical planner for regular traffic. */ private LaneBasedStrategicalPlannerFactory<?> lmrsFactory = null; /** Strategical planner for CACC trucks. */ private LaneBasedStrategicalPlannerFactory<?> caccFactory = null; /** {@inheritDoc} */ @Override public LaneBasedStrategicalPlannerFactory<?> getFactory(final Node origin, final Node destination, final Category category, final StreamInterface randomStream) throws GTUException { GTUType gtuType = category.get(GTUType.class); if (!gtuType.equals(caccGTUType)) { if (this.lmrsFactory == null) { |
File | Line |
---|---|
org\opentrafficsim\ahfe\AnticipationRelianceScript.java | 693 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 1243 |
params.setParameter(BETA, AnticipationRelianceScript.this.beta); params.setParameter(Fuller.TC, 1.0); params.setParameter(Fuller.TS_CRIT, 1.0); // Was not changed! params.setParameter(Fuller.TS_MAX, 2.0); params.setParameter(AdaptationSituationalAwareness.SA, 1.0); params.setParameter(AdaptationSituationalAwareness.SA_MAX, 1.0); params.setParameter(AdaptationSituationalAwareness.SA_MIN, 0.5); params.setParameter(AdaptationSituationalAwareness.TR_MAX, Duration.instantiateSI(2.0)); params.setParameter(ParameterTypes.TR, Duration.ZERO); params.setParameter(AdaptationHeadway.BETA_T, 1.0); // Increase? return params; } } /** Task manager for AR. */ private class TaskManagerAR implements TaskManager { /** {@inheritDoc} */ @Override public void manage(final Set<Task> tasksMan, final LanePerception perception, final LaneBasedGTU gtu, final Parameters parameters) throws ParameterException, GTUException { Task primary = null; Set<Task> auxiliaryTasks = new LinkedHashSet<>(); for (Task task : tasksMan) { if (task.getId().equals("lane-changing")) { primary = task; } else { auxiliaryTasks.add(task); } } Throw.whenNull(primary, "There is no task with id 'lane-changing'."); double primaryTaskDemand = primary.calculateTaskDemand(perception, gtu, parameters); primary.setTaskDemand(primaryTaskDemand); // max AR is alpha of TD, actual AR approaches 0 for increasing TD double a = parameters.getParameter(ALPHA); |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 350 |
org\opentrafficsim\demo\cacc\CaccSimulation.java | 600 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 430 |
new SinkSensor(lane, lane.getLength().minus(Length.instantiateSI(100.0)), GTUDirectionality.DIR_PLUS, sim); // detectors 100m after on ramp // new Detector(lane.getFullId(), lane, Length.createSI(0.0), sim); // id equal to lane, may be // different } if (lane.getParentLink().getId().equals("AB")) { // originLanes.add(lane); this.graphLanes.add(lane); } } } new Stripe(linkAB, Length.ZERO, Length.ZERO, stripeWidth); Stripe stripe = new Stripe(linkBC, Length.ZERO, Length.ZERO, stripeWidth); stripe.addPermeability(vehicle, Permeable.LEFT); new Stripe(linkCD, Length.ZERO, Length.ZERO, stripeWidth); new Lane(linkBC, "Acceleration lane", laneWidth.times(-0.5), laneWidth, freewayLaneType, new Speed(100, SpeedUnit.KM_PER_HOUR)); Lane onramp = new Lane(linkEB, "Onramp", laneWidth.times(-0.5), laneWidth, freewayLaneType, new Speed(100, SpeedUnit.KM_PER_HOUR)); new Stripe(linkEB, Length.ZERO, Length.ZERO, stripeWidth); new Stripe(linkEB, laneWidth.neg(), laneWidth.neg(), stripeWidth); new Stripe(linkBC, laneWidth.neg(), laneWidth.neg(), stripeWidth); // Detector on onramp // new Detector("Acceleration lane", accel, Length.createSI(200.0), sim); // OD without demand List<OTSNode> origins = new ArrayList<>(); |
File | Line |
---|---|
org\opentrafficsim\demo\FundamentalDiagrams.java | 320 |
org\opentrafficsim\demo\SequentialLanes.java | 376 |
} /** * Generate cars at a fixed rate (implemented by re-scheduling this method). */ protected final void generateCar() { try { boolean generateTruck = this.stream.nextDouble() > this.carProbability; Length vehicleLength = new Length(generateTruck ? 15 : 4, METER); LaneBasedIndividualGTU gtu = new LaneBasedIndividualGTU("" + (++this.carsCreated), this.network.getGtuType( GTUType.DEFAULTS.CAR), vehicleLength, new Length(1.8, METER), new Speed(200, KM_PER_HOUR), vehicleLength .times(0.5), this.simulator, this.network); gtu.setParameters(generateTruck ? this.parametersTruck : this.parametersCar); gtu.setNoLaneChangeDistance(Length.ZERO); gtu.setMaximumAcceleration(Acceleration.instantiateSI(3.0)); gtu.setMaximumDeceleration(Acceleration.instantiateSI(-8.0)); // strategical planner LaneBasedStrategicalPlanner strategicalPlanner = generateTruck ? this.strategicalPlannerGeneratorTrucks.create( gtu, null, null, null) : this.strategicalPlannerGeneratorCars.create(gtu, null, null, null); Set<DirectedLanePosition> initialPositions = new LinkedHashSet<>(1); Length initialPosition = new Length(20, METER); initialPositions.add(new DirectedLanePosition(this.lane, initialPosition, GTUDirectionality.DIR_PLUS)); |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 848 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 961 |
for (Link link : network.getLinkMap().values()) { for (Lane lane : ((CrossSectionLink) link).getLanes()) { KpiLaneDirection kpiLane = new KpiLaneDirection(new LaneData(lane), KpiGtuDirectionality.DIR_PLUS); SpaceTimeRegion region = new SpaceTimeRegion(kpiLane, Length.ZERO, lane.getLength(), start, end); this.regions.add(region); this.sampler.registerSpaceTimeRegion(region); } } return network; } /** {@inheritDoc} */ @Override protected void addTabs(final OTSSimulatorInterface sim, final OTSSimulationApplication<?> animation) { if (this.graphs) { // create tab int h = (int) Math.sqrt(this.graphLanes.size()); int w = (int) Math.ceil(((double) this.graphLanes.size()) / h); TablePanel charts = new TablePanel(w, h); animation.getAnimationPanel().getTabbedPane().addTab(animation.getAnimationPanel().getTabbedPane().getTabCount(), "statistics", charts); |
File | Line |
---|---|
org\opentrafficsim\demo\conflictAndControl\DemoTrafcodAndTurbo.java | 197 |
org\opentrafficsim\demo\conflictAndControl\DemoTrafcodAndTurbo.java | 223 |
TrafficLight tl = new SimpleTrafficLight(String.format("%02d", stream), lane, lane.getLength().minus(stopLineMargin), this.simulator); trafficLights.add(tl); try { new TrafficLightAnimation(tl, this.simulator); } catch (RemoteException | NamingException exception) { throw new NetworkException(exception); } sensors.add(new TrafficLightSensor(String.format("D%02d1", stream), lane, lane.getLength().minus(headDetectorMargin), lane, lane.getLength().minus(headDetectorMargin).plus(headDetectorLength), null, RelativePosition.FRONT, RelativePosition.REAR, this.simulator, Compatible.EVERYTHING)); sensors.add(new TrafficLightSensor(String.format("D%02d2", stream), lane, lane.getLength().minus(longDetectorMargin), lane, lane.getLength().minus(longDetectorMargin).plus(longDetectorLength), null, RelativePosition.FRONT, RelativePosition.REAR, this.simulator, Compatible.EVERYTHING)); } |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 438 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 786 |
platoons.fixInfo(nodeA, nodeD, caccCategory); double dt = this.startSpacing; // Determine platoon generation times (of leading vehicle only) using pseudorandom generation (exponential // distribution) // Then check if interval times do not overlap with whole platoon generation, adjust accordingly List<Double> generationTimes = new ArrayList<Double>(); double previous = 0; for (int k = 0; k < demandList.size(); k++) { for (int i = 0; i < demandPlatoon.get(k); i++) { double lambda = (demandPlatoon.get(k) * 4); // Number of platoons to be generated (per hour -> times 4) StreamInterface rand = sim.getReplication().getStream("generation"); // Random rand = new Random(); double arrival = (Math.log(1 - rand.nextDouble()) / (-lambda) * 3600); // Inter arrival time is in the unit of lambda (here per 15 minutes) double startTime = (arrival + previous); // (k * 900) + (arrival + previous); // Interarrival plus 15 // minutes (900 seconds) generationTimes.add(startTime); previous = previous + arrival; } } // Sorting the generation time to check for overlap in generation Collections.sort(generationTimes); for (int i = 0; i < generationTimes.size() - 1; i++) { double diff = generationTimes.get(i + 1) - generationTimes.get(i); double generationDuration = 0.5; double maxDuration = (generationDuration * this.platoonSize) + 1.0; |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 684 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 523 |
platoons.fixInfo(nodeE, nodeD, caccCategory); double dt = this.startSpacing; // Determine platoon generation times (of leading vehicle only) using pseudorandom generation (exponential // distribution) // Then check if interval times do not overlap with whole platoon generation, adjust accordingly List<Double> generationTimes = new ArrayList<Double>(); double previous = 0; for (int k = 0; k < demandList.size(); k++) { for (int i = 0; i < demandPlatoon.get(k); i++) { double lambda = (demandPlatoon.get(k) * 4); // Number of platoons to be generated (per hour -> times 4) StreamInterface rand = sim.getReplication().getStream("generation"); // Random rand = new Random(); double arrival = (Math.log(1 - rand.nextDouble()) / (-lambda) * 3600); // Inter arrival time is in the unit // of lambda (here per 15 minutes) double startTime = (arrival + previous); // (k * 900) + (arrival + previous); // Interarrival plus 15 // minutes (900 seconds) generationTimes.add(startTime); previous = previous + arrival; } } // Sorting the generation time to check for overlap in generation Collections.sort(generationTimes); for (int i = 0; i < generationTimes.size() - 1; i++) { double diff = generationTimes.get(i + 1) - generationTimes.get(i); double generationDuration = 0.5; double maxDuration = (generationDuration * this.platoonSize) + 1.0; |
File | Line |
---|---|
org\opentrafficsim\demo\network\xml\TestXMLParserA58.java | 146 |
org\opentrafficsim\demo\network\xml\TestXMLParserEindhoven.java | 147 |
URL xmlURL = URLResource.getResource("/xml/A58.xml"); this.network = new OTSRoadNetwork("Example network", true, getSimulator()); try { XmlNetworkLaneParser.build(xmlURL, this.network, false); } catch (NetworkException | ParserConfigurationException | SAXException | OTSGeometryException | JAXBException | URISyntaxException | XmlParserException | GTUException | IOException | TrafficControlException exception) { exception.printStackTrace(); } for (TrafficLight tl : this.network.getObjectMap(TrafficLight.class).values()) { tl.setTrafficLightColor(TrafficLightColor.GREEN); } URL gisURL = URLResource.getResource("/xml/A58/map.xml"); System.err.println("GIS-map file: " + gisURL.toString()); CoordinateTransform rdto0 = new CoordinateTransformWGS84toRDNew(0, 0); this.gisMap = new GisRenderable2D(this.simulator, gisURL, rdto0); } /** * @return gisMap */ public final GisRenderable2D getGisMap() { return this.gisMap; } /** {@inheritDoc} */ @Override public OTSRoadNetwork getNetwork() { return this.network; } /** {@inheritDoc} */ @Override public final String toString() { return "TestXMLModelA58 [simulator=" + this.simulator + "]"; |
File | Line |
---|---|
org\opentrafficsim\remotecontrol\Sim0MQControlledOTS.java | 198 |
org\opentrafficsim\remotecontrol\Sim0MQControlledOTSNew.java | 43 |
} /** * The command line options. */ @Command(description = "Sim0MQ Remotely Controlled OTS", name = "Sim0MQOTS", mixinStandardHelpOptions = true, version = "1.0") public static class Options implements Checkable { /** The IP port. */ @Option(names = { "-p", "--port" }, description = "Internet port to use", defaultValue = "8888") private int port; /** * Retrieve the port. * @return int; the port */ public final int getPort() { return this.port; } @Override public final void check() throws Exception { if (this.port <= 0 || this.port > 65535) { throw new Exception("Port should be between 1 and 65535"); } } } /** * Program entry point. * @param args String[]; the command line arguments * @throws OTSGeometryException on error * @throws NetworkException on error * @throws NamingException on error * @throws ValueRuntimeException on error * @throws SimRuntimeException on error * @throws ParameterException on error * @throws SerializationException on error * @throws Sim0MQException on error * @throws IOException on error */ public static void main(final String[] args) throws NetworkException, OTSGeometryException, NamingException, ValueRuntimeException, ParameterException, SimRuntimeException, Sim0MQException, SerializationException, IOException { CategoryLogger.setAllLogLevel(Level.WARNING); CategoryLogger.setLogCategories(LogCategory.ALL); Options options = new Options(); CliUtil.execute(options, args); // register Unit converters, parse the command line, etc.. int port = options.getPort(); System.out.println("Creating OTS server listening on port " + port); |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 245 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 319 |
new CaccSimulation(args).start(); } /** {@inheritDoc} */ @Override protected OTSRoadNetwork setupSimulation(final OTSSimulatorInterface sim) throws Exception { OTSRoadNetwork network = new OTSRoadNetwork(this.networkName, true, sim); GTUType carGTUType = network.getGtuType(GTUType.DEFAULTS.CAR); GTUType truckGTUType = network.getGtuType(GTUType.DEFAULTS.TRUCK); this.caccGTUType = new GTUType("CACC", truckGTUType); LinkType freewayLinkType = network.getLinkType(LinkType.DEFAULTS.FREEWAY); LaneType freewayLaneType = network.getLaneType(LaneType.DEFAULTS.FREEWAY); GTUType vehicle = network.getGtuType(GTUType.DEFAULTS.VEHICLE); this.caccController = new CaccController(); this.caccController.setCACCGTUType(this.caccGTUType); setGtuColorer(new SwitchableGTUColorer(0, new FixedColor(Color.BLUE, "Blue"), new GTUTypeColorer().add(carGTUType, Color.BLUE).add(truckGTUType, Color.RED) .add(truckGTUType, Color.GREEN), |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 809 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 907 |
private Platoon platoon = null; /** Last generated CACC GTU. */ private LaneBasedGTU lastGtu; /** {@inheritDoc} */ @Override public void notify(final EventInterface event) throws RemoteException { if (event.getType().equals(LaneBasedGTUGenerator.GTU_GENERATED_EVENT)) { LaneBasedGTU gtu = (LaneBasedGTU) event.getContent(); if (gtu.getGTUType().equals(caccGTUType)) { // If platoon is not within 2 seconds, or platoon is equal or larger than set platoon size -> new // platoon // || this.lastGtu.getLocation().distance(gtu.getLocation()) > 2.0 * gtu.getSpeed().si if (this.lastGtu == null || this.lastGtu.isDestroyed() || this.lastGtu.getLocation().distance(gtu.getLocation()) > 3.0 * gtu.getSpeed().si || this.platoon.size() >= platoonSize) { this.platoon = new Platoon(); } this.platoon.addGtu(gtu.getId()); ((CaccTacticalPlanner) gtu.getTacticalPlanner()).setPlatoon(this.platoon); this.lastGtu = gtu; } } } }, LaneBasedGTUGenerator.GTU_GENERATED_EVENT); |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 382 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 731 |
List<OTSNode> destinations = new ArrayList<>(); destinations.add(nodeD); TimeVector timeVector = DoubleVector.instantiate(new double[] { 0.0, 0.25, 0.50, 0.75, 1.0, 1.25, 1.50, 1.75, 2.0 }, TimeUnit.BASE_HOUR, StorageType.DENSE); Interpolation interpolation = Interpolation.LINEAR; // or STEPWISE Categorization categorization = new Categorization("CACC", GTUType.class, Lane.class); // Category carCategory1 = new Category(categorization, carGTUType, originLanes.get(1)); // Category carCategory0 = new Category(categorization, carGTUType, originLanes.get(0)); Category carCategory1 = new Category(categorization, carGTUType, this.graphLanes.get(1)); Category carCategory0 = new Category(categorization, carGTUType, this.graphLanes.get(0)); Category carCategoryR = new Category(categorization, carGTUType, onramp); Category truCategory0 = new Category(categorization, truckGTUType, this.graphLanes.get(0)); Category truCategoryR = new Category(categorization, truckGTUType, onramp); Category caccCategory = new Category(categorization, caccGTUType, this.graphLanes.get(0)); |
File | Line |
---|---|
org\opentrafficsim\remotecontrol\Sim0MQRemoteController.java | 232 |
org\opentrafficsim\remotecontrol\Sim0MQRemoteControllerNew.java | 231 |
message = awtSocketIn.recv(0); // System.out.println("poller has received a message on the fromAWT PULL socket; transmitting to OTS"); slaveSocket.send(message); } } } } /** * Open connections as specified on the command line, then start the message transfer threads. * @param host String; host to connect to (listening OTS server should already be running) * @param port int; port to connect to (listening OTS server should be listening on that port) */ public void processArguments(final String host, final int port) { this.output.println("host is " + host + ", port is " + port); this.pollerThread = new PollerThread(this.zContext, host, port); this.pollerThread.start(); this.toOTS = this.zContext.createSocket(SocketType.PUSH); this.toOTS.setHWM(100000); new OTS2AWT(this.zContext).start(); this.toOTS.connect("inproc://fromAWT"); } /** * Write something to the remote OTS. * @param command String; the command to write * @throws IOException when communication fails */ public void write(final String command) throws IOException { this.toOTS.send(command); // output.println("Wrote " + command.getBytes().length + " bytes"); this.output.println("Sent string \"" + command + "\""); } /** * Write something to the remote OTS. * @param bytes byte[]; the bytes to write * @throws IOException when communication fails */ public void write(final byte[] bytes) throws IOException { this.toOTS.send(bytes); // output.println("Wrote " + command.getBytes().length + " bytes"); // output.println(HexDumper.hexDumper(bytes)); } /** Step to button. */ private JButton stepTo; |
File | Line |
---|---|
org\opentrafficsim\remotecontrol\Sim0MQRemoteController.java | 477 |
org\opentrafficsim\remotecontrol\Sim0MQRemoteControllerNew.java | 531 |
Sim0MQRemoteController.this.output.println(HexDumper.hexDumper(bytes)); } } catch (ZMQException | Sim0MQException | SerializationException e) { e.printStackTrace(); return; } } while (true); } } /** * Open an URL, read it and store the contents in a string. Adapted from * https://stackoverflow.com/questions/4328711/read-url-to-string-in-few-lines-of-java-code * @param url URL; the URL * @return String * @throws IOException when reading the file fails */ public static String readStringFromURL(final URL url) throws IOException { try (Scanner scanner = new Scanner(url.openStream(), StandardCharsets.UTF_8.toString())) { scanner.useDelimiter("\\A"); return scanner.hasNext() ? scanner.next() : ""; } } /** {@inheritDoc} */ @Override public void actionPerformed(final ActionEvent e) { switch (e.getActionCommand()) { case "SendNetwork": { String networkFile = "/TrafCODDemo2/TrafCODDemo2.xml"; Duration warmupDuration = Duration.ZERO; Duration runDuration = new Duration(3600, DurationUnit.SECOND); Long seed = 123456L; URL url = URLResource.getResource(networkFile); // System.out.println("url is " + url); try { String xml = readStringFromURL(url); |
File | Line |
---|---|
org\opentrafficsim\remotecontrol\Sim0MQRemoteController.java | 327 |
org\opentrafficsim\remotecontrol\Sim0MQRemoteControllerNew.java | 330 |
controls.add(getGTUPositions); panelAll.add(controls, BorderLayout.CENTER); } /** Debugging and other output goes here. */ @SuppressWarnings("checkstyle:visibilitymodifier") PrintStream output = null; /** * Shut down this application. */ public void shutDown() { // Do we have to kill anything for a clean exit? } /** {@inheritDoc} */ @Override public void windowOpened(final WindowEvent e) { // Do nothing } /** {@inheritDoc} */ @Override public final void windowClosing(final WindowEvent e) { shutDown(); } /** {@inheritDoc} */ @Override public void windowClosed(final WindowEvent e) { // Do nothing } /** {@inheritDoc} */ @Override public void windowIconified(final WindowEvent e) { // Do nothing } /** {@inheritDoc} */ @Override public void windowDeiconified(final WindowEvent e) { // Do nothing } /** {@inheritDoc} */ @Override public void windowActivated(final WindowEvent e) { // Do nothing } /** {@inheritDoc} */ @Override public void windowDeactivated(final WindowEvent e) { // Do nothing } /** * Thread that reads results from OTS and (for now) writes those to the textArea. */ class OTS2AWT extends Thread { /** Socket where the message from OTS will appear. */ private final ZMQ.Socket fromOTS; /** * Construct a new OTS2AWT thread. * @param zContext ZContext; the ZContext that is needed to construct the PULL socket to read the messages */ OTS2AWT(final ZContext zContext) { this.fromOTS = zContext.createSocket(SocketType.PULL); this.fromOTS.setHWM(100000); this.fromOTS.connect("inproc://toAWT"); } |
File | Line |
---|---|
org\opentrafficsim\demo\CircularLaneModel.java | 156 |
org\opentrafficsim\demo\CircularRoadModel.java | 215 |
new LMRSFactory(new IDMPlusFactory(this.stream), new DefaultLMRSPerceptionFactory())); LaneType laneType = this.network.getLaneType(LaneType.DEFAULTS.TWO_WAY_LANE); OTSRoadNode start = new OTSRoadNode(this.network, "Start", new OTSPoint3D(radius, 0, 0), new Direction(90, DirectionUnit.EAST_DEGREE)); OTSRoadNode halfway = new OTSRoadNode(this.network, "Halfway", new OTSPoint3D(-radius, 0, 0), new Direction(270, DirectionUnit.EAST_DEGREE)); OTSPoint3D[] coordsHalf1 = new OTSPoint3D[127]; for (int i = 0; i < coordsHalf1.length; i++) { double angle = Math.PI * (1 + i) / (1 + coordsHalf1.length); coordsHalf1[i] = new OTSPoint3D(radius * Math.cos(angle), radius * Math.sin(angle), 0); } |
File | Line |
---|---|
org\opentrafficsim\remotecontrol\Sim0MQRemoteController.java | 59 |
org\opentrafficsim\remotecontrol\Sim0MQRemoteControllerNew.java | 60 |
public class Sim0MQRemoteController extends JFrame implements WindowListener, ActionListener { /** ... */ private static final long serialVersionUID = 20200304L; /** * The command line options. */ @Command(description = "Test program for Remote Control OTS", name = "Remote Control OTS", mixinStandardHelpOptions = true, version = "1.0") public static class Options implements Checkable { /** The IP port. */ @Option(names = {"-p", "--port"}, description = "Internet port to use", defaultValue = "8888") private int port; /** * Retrieve the port. * @return int; the port */ public final int getPort() { return this.port; } /** The host name. */ @Option(names = {"-H", "--host"}, description = "Internet host to use", defaultValue = "localhost") private String host; /** * Retrieve the host name. * @return String; the host name */ public final String getHost() { return this.host; } @Override public final void check() throws Exception { if (this.port <= 0 || this.port > 65535) { throw new Exception("Port should be between 1 and 65535"); } } } /** The instance of the RemoteControl. */ @SuppressWarnings("checkstyle:visibilitymodifier") static Sim0MQRemoteController gui = null; |
File | Line |
---|---|
org\opentrafficsim\demo\CrossingTrafficLightsModel.java | 279 |
org\opentrafficsim\demo\NetworksModel.java | 377 |
{ Distribution<LaneBasedTemplateGTUType> distribution = new Distribution<>(this.stream); Length initialPosition = new Length(16, METER); Set<DirectedLanePosition> initialPositions = new LinkedHashSet<>(1); initialPositions.add(new DirectedLanePosition(lane, initialPosition, GTUDirectionality.DIR_PLUS)); LaneBasedTemplateGTUType template = makeTemplate(this.stream, lane, new ContinuousDistDoubleScalar.Rel<Length, LengthUnit>(new DistUniform(this.stream, 3, 6), METER), new ContinuousDistDoubleScalar.Rel<Length, LengthUnit>(new DistUniform(this.stream, 1.6, 2.0), METER), new ContinuousDistDoubleScalar.Rel<Speed, SpeedUnit>(new DistUniform(this.stream, 140, 180), KM_PER_HOUR), initialPositions, this.strategicalPlannerFactoryCar, routeGenerator); |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 479 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 827 |
double endTime = generationTimes.get(i) + (generationDuration * this.platoonSize); platoons.addPlatoon(Time.instantiateSI(generationTimes.get(i)), Time.instantiateSI(endTime)); for (double t = generationTimes.get(i); t < endTime; t += dt) { platoons.addGtu(Time.instantiateSI(t)); } } // OD demand // cars (without compensation we use fraction 0.5 in putDemandVector, otherwise we multiply by laneshare) odMatrix.putDemandVector(nodeA, nodeD, carCategory1, freq(new double[] { 0, 0, 1000 * (1 + intensityIncrease), 1000 * (1 + intensityIncrease), 1000 * (1 + intensityIncrease), 1000 * (1 + intensityIncrease), 1000 * (1 + intensityIncrease), 0, 0 }), timeVector, interpolation, 0.5); odMatrix.putDemandVector(nodeA, nodeD, carCategory0, platoons.compensate(carCategory0, |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 162 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 218 |
@Option(names = "--nn", description = "Network name", defaultValue = "onramp") private String networkName; /** Intensity factor. */ @Option(names = "--intensity", description = "Intensity factor", defaultValue = "1.00") private double intensity; /** Penetration. */ @Option(names = "--penetration", description = "Fraction of vehicles equipped with CACC", defaultValue = "1.00") private double penetration; /** Platoon size. */ @Option(names = "--platoon", description = "Platoon size", defaultValue = "3") private int platoonSize; /** Headway. */ @Option(names = "--headway", description = "Platoon headway", defaultValue = "0.9") private double headway; /** Synchronization. */ @Option(names = "--synchronization", description = "Synchronization", defaultValue = "0.0") private double synchronization; /** Free flow speed of platoon vehicles. */ @Option(names = "--setspeed", description = "Free flow speed of platoon vehicles", defaultValue = "80 km/h") private Speed setspeed; /** Time step. */ @Option(names = "--sd", description = "Simulation time", defaultValue = "5400s") |
File | Line |
---|---|
org\opentrafficsim\demo\conflict\TJunctionDemo.java | 167 |
org\opentrafficsim\demo\conflict\TurboRoundaboutDemo.java | 182 |
this.simulator.scheduleEventRel(new Duration(30.0, DurationUnit.SECOND), this, this, "changePhase", new Object[] {trafficLight}); break; } case YELLOW: { trafficLight.setTrafficLightColor(TrafficLightColor.RED); this.simulator.scheduleEventRel(new Duration(56.0, DurationUnit.SECOND), this, this, "changePhase", new Object[] {trafficLight}); break; } case GREEN: { trafficLight.setTrafficLightColor(TrafficLightColor.YELLOW); this.simulator.scheduleEventRel(new Duration(4.0, DurationUnit.SECOND), this, this, "changePhase", new Object[] {trafficLight}); break; } default: { // } } } /** {@inheritDoc} */ @Override public OTSRoadNetwork getNetwork() { return this.network; } /** {@inheritDoc} */ @Override public Serializable getSourceId() { return "TJunctionModel"; |
File | Line |
---|---|
org\opentrafficsim\demo\CircularLaneModel.java | 223 |
org\opentrafficsim\demo\FundamentalDiagrams.java | 328 |
org\opentrafficsim\demo\SequentialLanes.java | 384 |
{ // GTU itself boolean generateTruck = this.stream.nextDouble() > this.carProbability; Length vehicleLength = new Length(generateTruck ? 15 : 4, METER); LaneBasedIndividualGTU gtu = new LaneBasedIndividualGTU("" + (++this.carsCreated), this.network.getGtuType(GTUType.DEFAULTS.CAR), vehicleLength, new Length(1.8, METER), new Speed(200, KM_PER_HOUR), vehicleLength.times(0.5), this.simulator, this.network); gtu.setParameters(generateTruck ? this.parametersTruck : this.parametersCar); gtu.setNoLaneChangeDistance(Length.ZERO); gtu.setMaximumAcceleration(Acceleration.instantiateSI(3.0)); gtu.setMaximumDeceleration(Acceleration.instantiateSI(-8.0)); // strategical planner LaneBasedStrategicalPlanner strategicalPlanner; |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 896 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 1004 |
ContourDataSource<?> dataPool = new ContourDataSource<>(graphSampler.getSamplerData(), graphPath); SwingContourPlot plot = new SwingContourPlot(new ContourPlotSpeed("Speed lane " + (i + 1), sim, dataPool)); charts.setCell(plot.getContentPane(), w2, h2); w2++; if (w2 > w) { w = 0; h2++; } } } } /** {@inheritDoc} */ @Override protected void onSimulationEnd() { // periodic = true; periodic data is stored, if false other mesoscopic data would be stored, but that has not been setup Detector.writeToFile(getNetwork(), this.outputFileDets, true); // this.sampler.writeToFile(getProperty("outputFile")); double tts = 0.0; List<Float> ttcList = new ArrayList<>(); List<String> ttcListGtuType = new ArrayList<>(); List<Float> decList = new ArrayList<>(); List<String> decListGtuType = new ArrayList<>(); |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 521 |
org\opentrafficsim\demo\cacc\CaccSimulation.java | 773 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 623 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 874 |
odMatrix.putDemandVector(nodeA, nodeD, caccCategory, platoons.compensate(caccCategory, freq(new double[] { demandPlatoonVehicles.get(0), demandPlatoonVehicles.get(1), demandPlatoonVehicles.get(2), demandPlatoonVehicles.get(3), demandPlatoonVehicles.get(4), demandPlatoonVehicles.get(5), demandPlatoonVehicles.get(6), demandPlatoonVehicles.get(7), demandPlatoonVehicles.get(8) }), timeVector, interpolation)); } // options ODOptions odOptions = new ODOptions().set(ODOptions.NO_LC_DIST, Length.instantiateSI(300.0)).set(ODOptions.GTU_TYPE, characteristicsGenerator); odApplierOutput = ODApplier.applyOD(network, odMatrix, odOptions); // start platoons platoonDetector1 = "A1"; |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 387 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 469 |
Categorization categorization = new Categorization("CACC", GTUType.class, Lane.class); // Category carCategory1 = new Category(categorization, carGTUType, originLanes.get(1)); // Category carCategory0 = new Category(categorization, carGTUType, originLanes.get(0)); Category carCategory1 = new Category(categorization, carGTUType, this.graphLanes.get(1)); Category carCategory0 = new Category(categorization, carGTUType, this.graphLanes.get(0)); Category carCategoryR = new Category(categorization, carGTUType, onramp); Category truCategory0 = new Category(categorization, truckGTUType, this.graphLanes.get(0)); Category truCategoryR = new Category(categorization, truckGTUType, onramp); Category caccCategory = new Category(categorization, caccGTUType, this.graphLanes.get(0)); ODMatrix odMatrix = new ODMatrix("CACC OD", origins, destinations, categorization, timeVector, interpolation); double intensityIncrease = this.intensity; double platoonPenetration = this.penetration; |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 267 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 343 |
new SynchronizationColorer())); // Factory for settable parameters ParameterFactoryByType parameters = new ParameterFactoryByType(); // Parameters parameters.addParameter(CaccParameters.T_SYSTEM_CACC, new Duration(this.headway, DurationUnit.SI)); parameters.addParameter(CaccParameters.A_REDUCED, Acceleration.instantiateSI(this.synchronization)); parameters.addParameter(CaccParameters.SET_SPEED, this.setspeed); CaccControllerFactory longitudinalControllerFactory; String controllerName = this.controller; if (controllerName.equals("CACC")) { longitudinalControllerFactory = new CaccControllerFactory(); } else { throw new RuntimeException("Controller " + controllerName + " not supported."); } Length laneWidth = Length.instantiateSI(3.5); Length stripeWidth = Length.instantiateSI(0.2); Map<String, GeneratorObjects> odApplierOutput; String platoonDetector1; if (this.networkName.equals("onramp")) |
File | Line |
---|---|
org\opentrafficsim\demo\CircularLaneModel.java | 145 |
org\opentrafficsim\demo\CircularRoadModel.java | 202 |
this.carProbability = (double) getInputParameter("generic.carProbability"); double radius = ((Length) getInputParameter("generic.trackLength")).si / 2 / Math.PI; double headway = 1000.0 / (double) getInputParameter("generic.densityMean"); double headwayVariability = (double) getInputParameter("generic.densityVariability"); this.parametersCar = InputParameterHelper.getParametersCar(getInputParameterMap()); this.parametersTruck = InputParameterHelper.getParametersTruck(getInputParameterMap()); this.strategicalPlannerGeneratorCars = new LaneBasedStrategicalRoutePlannerFactory( new LMRSFactory(new IDMPlusFactory(this.stream), new DefaultLMRSPerceptionFactory())); this.strategicalPlannerGeneratorTrucks = new LaneBasedStrategicalRoutePlannerFactory( new LMRSFactory(new IDMPlusFactory(this.stream), new DefaultLMRSPerceptionFactory())); |
File | Line |
---|---|
org\opentrafficsim\demo\conflictAndControl\DemoTrafcodAndTurbo.java | 254 |
org\opentrafficsim\demo\trafficcontrol\TrafCODDemo1.java | 195 |
org\opentrafficsim\demo\trafficcontrol\TrafCODDemo2_Generators.java | 177 |
this.trafCOD.addListener(this, TrafficController.TRAFFICCONTROL_CONTROLLER_EVALUATING); this.trafCOD.addListener(this, TrafficController.TRAFFICCONTROL_CONTROLLER_WARNING); this.trafCOD.addListener(this, TrafficController.TRAFFICCONTROL_CONFLICT_GROUP_CHANGED); this.trafCOD.addListener(this, TrafficController.TRAFFICCONTROL_STATE_CHANGED); this.trafCOD.addListener(this, TrafficController.TRAFFICCONTROL_VARIABLE_CREATED); this.trafCOD.addListener(this, TrafficController.TRAFFICCONTROL_TRACED_VARIABLE_UPDATED); // Subscribe the TrafCOD machine to trace command events that we // emit addListener(this.trafCOD, TrafficController.TRAFFICCONTROL_SET_TRACING); // fireEvent(TrafficController.TRAFFICCONTROL_SET_TRACING, new // Object[] {controllerName, "TGX", 8, true}); // fireEvent(TrafficController.TRAFFICCONTROL_SET_TRACING, new // Object[] {controllerName, "XR1", 11, true}); // fireEvent(TrafficController.TRAFFICCONTROL_SET_TRACING, new // Object[] {controllerName, "TD1", 11, true}); // fireEvent(TrafficController.TRAFFICCONTROL_SET_TRACING, new // Object[] {controllerName, "TGX", 11, true}); // fireEvent(TrafficController.TRAFFICCONTROL_SET_TRACING, new // Object[] {controllerName, "TL", 11, true}); // System.out.println("demo: emitting a SET TRACING event for // all variables related to stream 11"); // fireEvent(TrafficController.TRAFFICCONTROL_SET_TRACING, new // Object[] { controllerName, "", 11, true }); // TrafCODDemo2.this.trafCOD.traceVariablesOfStream(TrafficController.NO_STREAM, // true); // TrafCODDemo2.this.trafCOD.traceVariablesOfStream(11, true); // TrafCODDemo2.this.trafCOD.traceVariable("MRV", 11, true); } catch (Exception exception) { exception.printStackTrace(); } } /** {@inheritDoc} */ @Override public final OTSRoadNetwork getNetwork() { return this.network; } /** * @return trafCOD */ public final TrafCOD getTrafCOD() { return this.trafCOD; } |
File | Line |
---|---|
strategies\LmrsStrategies.java | 600 |
strategies\StrategiesDemo.java | 695 |
origin, destination, VehicleModel.NONE); } } /** Perception factory. */ class LmrsStrategiesPerceptionFactory implements PerceptionFactory { /** {@inheritDoc} */ @Override public LanePerception generatePerception(final LaneBasedGTU gtu) { LanePerception perception = new CategoricalLanePerception(gtu); perception.addPerceptionCategory(new DirectEgoPerception<>(perception)); perception.addPerceptionCategory(new DirectInfrastructurePerception(perception)); perception.addPerceptionCategory(new DirectNeighborsPerception(perception, HeadwayGtuType.WRAP)); perception.addPerceptionCategory(new AnticipationTrafficPerception(perception)); return perception; } /** {@inheritDoc} */ @Override public Parameters getParameters() throws ParameterException { return new ParameterSet().setDefaultParameter(ParameterTypes.LOOKAHEAD).setDefaultParameter( ParameterTypes.LOOKBACKOLD).setDefaultParameter(ParameterTypes.PERCEPTION).setDefaultParameter( ParameterTypes.LOOKBACK); } } |
File | Line |
---|---|
org\opentrafficsim\demo\trafficcontrol\TrafCODDemo1.java | 66 |
org\opentrafficsim\demo\trafficcontrol\TrafCODDemo2.java | 66 |
org\opentrafficsim\demo\trafficcontrol\TrafCODDemo2_Generators.java | 59 |
public TrafCODDemo1(final String title, final OTSAnimationPanel panel, final TrafCODModel model) throws OTSDrawingException { super(model, panel); } /** * Main program. * @param args String[]; the command line arguments (not used) * @throws IOException ... */ public static void main(final String[] args) throws IOException { demo(true); } /** * Open an URL, read it and store the contents in a string. Adapted from * https://stackoverflow.com/questions/4328711/read-url-to-string-in-few-lines-of-java-code * @param url URL; the URL * @return String * @throws IOException when reading the file fails */ public static String readStringFromURL(final URL url) throws IOException { try (Scanner scanner = new Scanner(url.openStream(), StandardCharsets.UTF_8.toString())) { scanner.useDelimiter("\\A"); return scanner.hasNext() ? scanner.next() : ""; } } /** * Start the demo. * @param exitOnClose boolean; when running stand-alone: true; when running as part of a demo: false * @throws IOException when reading the file fails */ public static void demo(final boolean exitOnClose) throws IOException { try { OTSAnimator simulator = new OTSAnimator("TrafCODDemo1"); |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 843 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 944 |
RoadSampler.build(network).registerExtendedDataType(this.ttc).registerFilterDataType(this.metaGtu).create(); // Construct sample time and space window Time start = new Time(0.25, TimeUnit.BASE_HOUR); // TODO set times Time end = new Time(2.00, TimeUnit.BASE_HOUR); for (Link link : network.getLinkMap().values()) { for (Lane lane : ((CrossSectionLink) link).getLanes()) { KpiLaneDirection kpiLane = new KpiLaneDirection(new LaneData(lane), KpiGtuDirectionality.DIR_PLUS); SpaceTimeRegion region = new SpaceTimeRegion(kpiLane, Length.ZERO, lane.getLength(), start, end); this.regions.add(region); this.sampler.registerSpaceTimeRegion(region); } } |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 370 |
org\opentrafficsim\demo\cacc\CaccSimulation.java | 620 |
org\opentrafficsim\demo\steering\SteeringSimulation.java | 206 |
new Speed(100, SpeedUnit.KM_PER_HOUR)); new Stripe(linkEB, Length.ZERO, Length.ZERO, stripeWidth); new Stripe(linkEB, laneWidth.neg(), laneWidth.neg(), stripeWidth); new Stripe(linkBC, laneWidth.neg(), laneWidth.neg(), stripeWidth); // Detector on onramp // new Detector("Acceleration lane", accel, Length.createSI(200.0), sim); // OD without demand List<OTSNode> origins = new ArrayList<>(); origins.add(nodeA); origins.add(nodeE); List<OTSNode> destinations = new ArrayList<>(); destinations.add(nodeD); TimeVector timeVector = DoubleVector.instantiate(new double[] { 0.0, 0.25, 0.50, 0.75, 1.0, 1.25, 1.50, 1.75, 2.0 }, |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 937 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 1029 |
List<String> posrampListGtuType = new ArrayList<>(); int[] counts = new int[120]; Length detectorPosition = Length.instantiateSI(100.0); for (SpaceTimeRegion region : this.regions) { TrajectoryGroup<?> trajectoryGroup = this.sampler.getSamplerData().getTrajectoryGroup(region.getLaneDirection()).getTrajectoryGroup( region.getStartPosition(), region.getEndPosition(), region.getStartTime(), region.getEndTime()); for (Trajectory<?> trajectory : trajectoryGroup) { try { tts += trajectory.getTotalDuration().si; String gtuTypeId = trajectory.getMetaData(this.metaGtu /*new FilterDataGtuType()*/).getId(); |
File | Line |
---|---|
org\opentrafficsim\demo\FundamentalDiagrams.java | 275 |
org\opentrafficsim\demo\SequentialLanes.java | 333 |
this.carProbability = (double) getInputParameter("generic.carProbability"); this.parametersCar = InputParameterHelper.getParametersCar(getInputParameterMap()); this.parametersTruck = InputParameterHelper.getParametersTruck(getInputParameterMap()); this.strategicalPlannerGeneratorCars = new LaneBasedStrategicalRoutePlannerFactory(new LMRSFactory( new IDMPlusFactory(this.stream), new DefaultLMRSPerceptionFactory())); this.strategicalPlannerGeneratorTrucks = new LaneBasedStrategicalRoutePlannerFactory(new LMRSFactory( new IDMPlusFactory(this.stream), new DefaultLMRSPerceptionFactory())); // 1500 [veh / hour] == 2.4s headway this.headway = new Duration(3600.0 / 1500.0, SECOND); // Schedule creation of the first car (this will re-schedule itself one headway later, etc.). this.simulator.scheduleEventAbs(Time.ZERO, this, this, "generateCar", null); |
File | Line |
---|---|
org\opentrafficsim\demo\cacc\CaccSimulation.java | 950 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 1042 |
String gtuTypeId = trajectory.getMetaData(this.metaGtu /*new FilterDataGtuType()*/).getId(); for (FloatDuration ttcVal : trajectory.getExtendedData(this.ttc)) { if (!Float.isNaN(ttcVal.si) && ttcVal.si < 20) { ttcList.add(ttcVal.si); ttcListGtuType.add(gtuTypeId); } } for (float decVal : trajectory.getA()) { if (decVal < -2.0) { decList.add(decVal); decListGtuType.add(gtuTypeId); } } // collect data for merging lane and acceleration lane if (region.getLaneDirection().getLaneData().getLinkData().getId().equals("BC") |
File | Line |
---|---|
org\opentrafficsim\demo\web\OTSDemoServer.java | 323 |
org\opentrafficsim\demo\web\OTSFederatedDemoServer.java | 221 |
else if (modelId.toLowerCase().contains("trafcoddemosimple")) { URL url = URLResource.getResource("/TrafCODDemo1/TrafCODDemo1.xml"); String xml = TrafCODDemo2.readStringFromURL(url); model = new TrafCODDemo1.TrafCODModel(simulator, "TrafCODDemo1", "TrafCODDemo1", xml); } else if (modelId.toLowerCase().contains("trafcoddemocomplex")) { URL url = URLResource.getResource("/TrafCODDemo2/TrafCODDemo2.xml"); String xml = TrafCODDemo2.readStringFromURL(url); model = new TrafCODDemo2.TrafCODModel(simulator, "TrafCODDemo2", "TrafCODDemo2", xml); } else if (modelId.toLowerCase().contains("tjunction")) |
File | Line |
---|---|
org\opentrafficsim\remotecontrol\Sim0MQRemoteController.java | 210 |
org\opentrafficsim\remotecontrol\Sim0MQRemoteControllerNew.java | 210 |
message = slaveSocket.recv(0); String expectedSenderField = String.format("slave_%05d", ++nextExpectedPacket); try { Object[] messageFields = Sim0MQMessage.decode(message).createObjectArray(); String senderTag = (String) messageFields[3]; if (!senderTag.equals(expectedSenderField)) { System.err.println("Got message " + senderTag + " , expected " + expectedSenderField + ", message is " + messageFields[5]); } } catch (Sim0MQException | SerializationException e) { e.printStackTrace(); } // System.out.println("poller has received a message on the fromOTS DEALER socket; transmitting to AWT"); awtSocketOut.send(message); } if (items.pollin(1)) { |
File | Line |
---|---|
org\opentrafficsim\demo\CircularLaneModel.java | 231 |
org\opentrafficsim\demo\CircularRoadModel.java | 290 |
gtu.setNoLaneChangeDistance(Length.ZERO); gtu.setMaximumAcceleration(Acceleration.instantiateSI(3.0)); gtu.setMaximumDeceleration(Acceleration.instantiateSI(-8.0)); // strategical planner LaneBasedStrategicalPlanner strategicalPlanner; Route route = null; if (!generateTruck) { strategicalPlanner = this.strategicalPlannerGeneratorCars.create(gtu, route, null, null); } else { strategicalPlanner = this.strategicalPlannerGeneratorTrucks.create(gtu, route, null, null); } // init Set<DirectedLanePosition> initialPositions = new LinkedHashSet<>(1); initialPositions.add(new DirectedLanePosition(lane, initialPosition, GTUDirectionality.DIR_PLUS)); Speed initialSpeed = new Speed(0, KM_PER_HOUR); |
File | Line |
---|---|
org\opentrafficsim\ahfe\AnticipationRelianceScript.java | 667 |
org\opentrafficsim\demo\cacc\CaccSimulationAdv.java | 1220 |
if (AnticipationRelianceScript.this.tasks) { Fuller fuller = new Fuller(tasksSet, behavioralAdapatations, new TaskManagerAR()); perception = new CategoricalLanePerception(gtu, fuller); } else { perception = new CategoricalLanePerception(gtu); } perception.addPerceptionCategory(new DirectEgoPerception<>(perception)); perception.addPerceptionCategory(new DirectInfrastructurePerception(perception)); Estimation est = Try.assign(() -> this.estimation.draw(), "Probability exception while drawing estimation."); perception.addPerceptionCategory( new DirectNeighborsPerception(perception, new PerceivedHeadwayGtuType(est, Anticipation.CONSTANT_SPEED))); perception.addPerceptionCategory(new AnticipationTrafficPerception(perception)); |
File | Line |
---|---|
org\opentrafficsim\demo\CrossingTrafficLightsModel.java | 289 |
org\opentrafficsim\demo\NetworksModel.java | 387 |
initialPositions, this.strategicalPlannerFactoryCar, routeGenerator); // System.out.println("Constructed template " + template); distribution.add(new FrequencyAndObject<>(this.carProbability, template)); template = makeTemplate(this.stream, lane, new ContinuousDistDoubleScalar.Rel<Length, LengthUnit>(new DistUniform(this.stream, 8, 14), METER), new ContinuousDistDoubleScalar.Rel<Length, LengthUnit>(new DistUniform(this.stream, 2.0, 2.5), METER), new ContinuousDistDoubleScalar.Rel<Speed, SpeedUnit>(new DistUniform(this.stream, 100, 140), KM_PER_HOUR), initialPositions, this.strategicalPlannerFactoryTruck, routeGenerator); |
File | Line |
---|---|
org\opentrafficsim\demo\FundamentalDiagrams.java | 288 |
org\opentrafficsim\demo\StraightModel.java | 188 |
this.simulator.scheduleEventAbs(Time.ZERO, this, this, "generateCar", null); this.block = new SimpleTrafficLight(this.lane.getId() + "_TL", this.lane, new Length(new Length(4000.0, LengthUnit.METER)), this.simulator); this.block.setTrafficLightColor(TrafficLightColor.GREEN); // Create a block at t = 5 minutes this.simulator.scheduleEventAbs(new Time(300, TimeUnit.BASE_SECOND), this, this, "createBlock", null); // Remove the block at t = 7 minutes this.simulator.scheduleEventAbs(new Time(420, TimeUnit.BASE_SECOND), this, this, "removeBlock", null); } catch (SimRuntimeException | NetworkException | GTUException | OTSGeometryException | ParameterException |
File | Line |
---|---|
org\opentrafficsim\remotecontrol\Sim0MQRemoteController.java | 569 |
org\opentrafficsim\remotecontrol\Sim0MQRemoteControllerNew.java | 634 |
button.setText(caption.substring(0, position) + String.format("%.0f %s", toTime.getInUnit(), toTime.getDisplayUnit())); } catch (IOException | Sim0MQException | SerializationException e1) { e1.printStackTrace(); } break; } case "Step100To": { for (int i = 0; i < 100; i++) { actionPerformed(new ActionEvent(this.stepTo, 0, "StepTo")); } break; } case "GetAllGTUPositions": { try { write(Sim0MQMessage.encodeUTF8(true, 0, "RemoteControl", "OTS", "SENDALLGTUPOSITIONS", 0)); |
File | Line |
---|---|
org\opentrafficsim\demo\web\SuperDemoWebApplication.java | 334 |
org\opentrafficsim\demo\web\SuperDemoWebApplication.java | 389 |
org\opentrafficsim\demo\web\SuperDemoWebApplication.java | 426 |
} catch (Exception e) { status = false; error = e.getMessage(); } byte[] mc2Message = new MC2AckNakMessage(this.federationRunId, this.modelId, message.getSenderId(), ++this.messageCount, message.getMessageId(), status, error).createByteArray(); this.fsSocket.sendMore(identity); this.fsSocket.sendMore(""); this.fsSocket.send(mc2Message, 0); System.out.println("Sent MC.2"); System.out.flush(); } /** * Process FM.3 message and send MC.2 message back. * @param identity reply id for REQ-ROUTER pattern * @param message the FM3 message * @throws Sim0MQException on error * @throws SerializationException on serialization problem */ private void processSetParameter(final String identity, final FM3SetParameterMessage message) |
File | Line |
---|---|
org\opentrafficsim\demo\web\OTSDemoServer.java | 559 |
org\opentrafficsim\demo\web\OTSDemoServer.java | 576 |
org\opentrafficsim\demo\web\OTSFederatedDemoServer.java | 440 |
org\opentrafficsim\demo\web\OTSFederatedDemoServer.java | 457 |
answer.append("<doubleScalar key='" + pds.getExtendedKey() + "' name='" + pds.getShortName() + "' description='" + pds.getDescription() + "'><value>" + val + "</value>\n"); for (String unit : units) { Unit<?> unitValue = pds.getUnitParameter().getOptions().get(unit); if (unitValue.equals(pds.getUnitParameter().getValue())) answer.append("<unit chosen='true'>" + unit + "</unit>\n"); else answer.append("<unit chosen='false'>" + unit + "</unit>\n"); } answer.append("</doubleScalar>\n"); |