The following document contains the results of PMD's CPD 5.3.5.
File | Line |
---|---|
org\opentrafficsim\imb\demo\CircularRoadIMB.java | 496 |
org\opentrafficsim\imb\demo\ModelControlDemo.java | 553 |
} final int laneCount = 2; for (int laneIndex = 0; laneIndex < laneCount; laneIndex++) { this.paths.add(new ArrayList<Lane>()); } this.simulator = (OTSDEVSSimulatorInterface) theSimulator; double radius = 6000 / 2 / Math.PI; double headway = 40; double headwayVariability = 0; try { // Get car-following model name String carFollowingModelName = null; CompoundProperty propertyContainer = new CompoundProperty("", "", "", this.properties, false, 0); Property<?> cfmp = propertyContainer.findByKey("CarFollowingModel"); if (null == cfmp) { throw new Error("Cannot find \"Car following model\" property"); } if (cfmp instanceof SelectionProperty) { carFollowingModelName = ((SelectionProperty) cfmp).getValue(); } else { throw new Error("\"Car following model\" property has wrong type"); } // Get car-following model parameter for (Property<?> ap : new CompoundProperty("", "", "", this.properties, false, 0)) { if (ap instanceof CompoundProperty) { CompoundProperty cp = (CompoundProperty) ap; // System.out.println("Checking compound property " + cp); if (ap.getKey().contains("IDM")) { System.out.println("Car following model name appears to be " + ap.getKey()); Acceleration a = IDMPropertySet.getA(cp); Acceleration b = IDMPropertySet.getB(cp); Length s0 = IDMPropertySet.getS0(cp); Duration tSafe = IDMPropertySet.getTSafe(cp); GTUFollowingModelOld gtuFollowingModel = null; if (carFollowingModelName.equals("IDM")) { gtuFollowingModel = new IDMOld(a, b, s0, tSafe, 1.0); } else if (carFollowingModelName.equals("IDM+")) { gtuFollowingModel = new IDMPlusOld(a, b, s0, tSafe, 1.0); } else { throw new Error("Unknown gtu following model: " + carFollowingModelName); } if (ap.getKey().contains("Car")) { this.carFollowingModelCars = gtuFollowingModel; } else if (ap.getKey().contains("Truck")) { this.carFollowingModelTrucks = gtuFollowingModel; } else { throw new Error("Cannot determine gtu type for " + ap.getKey()); } } } } // Get lane change model cfmp = propertyContainer.findByKey("LaneChanging"); if (null == cfmp) { throw new Error("Cannot find \"Lane changing\" property"); } if (cfmp instanceof SelectionProperty) { String laneChangeModelName = ((SelectionProperty) cfmp).getValue(); if ("Egoistic".equals(laneChangeModelName)) { this.laneChangeModel = new Egoistic(); } else if ("Altruistic".equals(laneChangeModelName)) { this.laneChangeModel = new Altruistic(); } else { throw new Error("Lane changing " + laneChangeModelName + " not implemented"); } } else { throw new Error("\"Lane changing\" property has wrong type"); } // Get remaining properties for (Property<?> ap : new CompoundProperty("", "", "", this.properties, false, 0)) { if (ap instanceof SelectionProperty) { SelectionProperty sp = (SelectionProperty) ap; if ("TacticalPlanner".equals(sp.getKey())) { String tacticalPlannerName = sp.getValue(); if ("MOBIL".equals(tacticalPlannerName)) { this.strategicalPlannerGeneratorCars = new LaneBasedStrategicalRoutePlannerFactory( new LaneBasedCFLCTacticalPlannerFactory(this.carFollowingModelCars, this.laneChangeModel)); this.strategicalPlannerGeneratorTrucks = new LaneBasedStrategicalRoutePlannerFactory(new LaneBasedCFLCTacticalPlannerFactory( this.carFollowingModelTrucks, this.laneChangeModel)); } else if ("LMRS".equals(tacticalPlannerName)) { // provide default parameters with the car-following model BehavioralCharacteristics defaultBehavioralCFCharacteristics = new BehavioralCharacteristics(); defaultBehavioralCFCharacteristics.setDefaultParameters(AbstractIDM.class); this.strategicalPlannerGeneratorCars = new LaneBasedStrategicalRoutePlannerFactory( new LMRSFactory(new IDMPlusFactory(), defaultBehavioralCFCharacteristics)); this.strategicalPlannerGeneratorTrucks = new LaneBasedStrategicalRoutePlannerFactory( new LMRSFactory(new IDMPlusFactory(), defaultBehavioralCFCharacteristics)); } else if ("Toledo".equals(tacticalPlannerName)) { this.strategicalPlannerGeneratorCars = new LaneBasedStrategicalRoutePlannerFactory(new ToledoFactory()); this.strategicalPlannerGeneratorTrucks = new LaneBasedStrategicalRoutePlannerFactory(new ToledoFactory()); } else { throw new Error("Don't know how to create a " + tacticalPlannerName + " tactical planner"); } } } else if (ap instanceof ProbabilityDistributionProperty) { ProbabilityDistributionProperty pdp = (ProbabilityDistributionProperty) ap; if (ap.getKey().equals("TrafficComposition")) { this.carProbability = pdp.getValue()[0]; } } else if (ap instanceof IntegerProperty) { IntegerProperty ip = (IntegerProperty) ap; if ("TrackLength".equals(ip.getKey())) { radius = ip.getValue() / 2 / Math.PI; } } else if (ap instanceof ContinuousProperty) { ContinuousProperty cp = (ContinuousProperty) ap; if (cp.getKey().equals("MeanDensity")) { headway = 1000 / cp.getValue(); } if (cp.getKey().equals("DensityVariability")) { headwayVariability = cp.getValue(); } } else if (ap instanceof CompoundProperty) { if (ap.getKey().equals("OutputGraphs")) { continue; // Output settings are handled elsewhere } } } GTUType gtuType = new GTUType("car"); Set<GTUType> compatibility = new HashSet<GTUType>(); compatibility.add(gtuType); LaneType laneType = new LaneType("CarLane", compatibility); OTSNode start = new OTSNode(this.network, "Start", new OTSPoint3D(radius, 0, 0)); OTSNode halfway = new OTSNode(this.network, "Halfway", new OTSPoint3D(-radius, 0, 0)); 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); } Lane[] lanes1 = LaneFactory.makeMultiLane(this.network, "FirstHalf", start, halfway, coordsHalf1, laneCount, laneType, this.speedLimit, this.simulator, LongitudinalDirectionality.DIR_PLUS); OTSPoint3D[] coordsHalf2 = new OTSPoint3D[127]; for (int i = 0; i < coordsHalf2.length; i++) { double angle = Math.PI + Math.PI * (1 + i) / (1 + coordsHalf2.length); coordsHalf2[i] = new OTSPoint3D(radius * Math.cos(angle), radius * Math.sin(angle), 0); } Lane[] lanes2 = LaneFactory.makeMultiLane(this.network, "SecondHalf", halfway, start, coordsHalf2, laneCount, laneType, this.speedLimit, this.simulator, LongitudinalDirectionality.DIR_PLUS); for (int laneIndex = 0; laneIndex < laneCount; laneIndex++) { this.paths.get(laneIndex).add(lanes1[laneIndex]); this.paths.get(laneIndex).add(lanes2[laneIndex]); } // create a sensor on every lane int sensorNr = 0; for (Lane lane : lanes1) { SimpleSilentSensor sensor = new SimpleSilentSensor("sensor " + ++sensorNr, lane, new Length(10.0, LengthUnit.METER), RelativePosition.FRONT, imbAnimator); lane.addSensor(sensor, gtuType); } for (Lane lane : lanes2) { SimpleSilentSensor sensor = new SimpleSilentSensor("sensor" + ++sensorNr, lane, new Length(20.0, LengthUnit.METER), RelativePosition.REAR, imbAnimator); lane.addSensor(sensor, gtuType); } // Put the (not very evenly spaced) cars on the track double variability = (headway - 20) * headwayVariability; System.out.println("headway is " + headway + " variability limit is " + variability); Random random = new Random(12345); for (int laneIndex = 0; laneIndex < laneCount; laneIndex++) { double lane1Length = lanes1[laneIndex].getLength().getSI(); double trackLength = lane1Length + lanes2[laneIndex].getLength().getSI(); for (double pos = 0; pos <= trackLength - headway - variability;) { Lane lane = pos >= lane1Length ? lanes2[laneIndex] : lanes1[laneIndex]; // Actual headway is uniformly distributed around headway double laneRelativePos = pos > lane1Length ? pos - lane1Length : pos; double actualHeadway = headway + (random.nextDouble() * 2 - 1) * variability; // System.out.println(lane + ", len=" + lane.getLength() + ", pos=" + laneRelativePos); generateCar(new Length(laneRelativePos, METER), lane, gtuType); pos += actualHeadway; } } // Schedule regular updates of the graph this.simulator.scheduleEventAbs(new Time(9.999, SECOND), this, this, "drawGraphs", null); } catch (SimRuntimeException | NamingException | NetworkException | GTUException | OTSGeometryException | PropertyException exception) { exception.printStackTrace(); } |
File | Line |
---|---|
org\opentrafficsim\imb\demo\CircularRoadIMB.java | 741 |
org\opentrafficsim\imb\demo\ModelControlDemo.java | 820 |
} /** * Notify the contour plots that the underlying data has changed. */ protected final void drawGraphs() { for (LaneBasedGTUSampler plot : this.plots) { plot.reGraph(); } // Re schedule this method try { this.simulator.scheduleEventAbs(new Time(this.simulator.getSimulatorTime().get().getSI() + 10, SECOND), this, this, "drawGraphs", null); } catch (SimRuntimeException exception) { exception.printStackTrace(); } } /** * Generate cars at a fixed rate (implemented by re-scheduling this method). * @param initialPosition Length; the initial position of the new cars * @param lane Lane; the lane on which the new cars are placed * @param gtuType GTUType<String>; the type of the new cars * @throws NamingException on ??? * @throws SimRuntimeException cannot happen * @throws NetworkException on network inconsistency * @throws GTUException when something goes wrong during construction of the car * @throws OTSGeometryException when the initial position is outside the center line of the lane */ protected final void generateCar(final Length initialPosition, final Lane lane, final GTUType gtuType) throws NamingException, NetworkException, SimRuntimeException, GTUException, OTSGeometryException { // GTU itself boolean generateTruck = this.randomGenerator.nextDouble() > this.carProbability; Length vehicleLength = new Length(generateTruck ? 15 : 4, METER); LaneBasedIndividualGTU gtu = new LaneBasedIndividualGTU("" + (++this.carsCreated), gtuType, vehicleLength, new Length(1.8, METER), new Speed(200, KM_PER_HOUR), this.simulator, this.network); // strategical planner LaneBasedStrategicalPlanner strategicalPlanner; if (!generateTruck) { strategicalPlanner = this.strategicalPlannerGeneratorCars.create(gtu); } else { strategicalPlanner = this.strategicalPlannerGeneratorTrucks.create(gtu); } // init Set<DirectedLanePosition> initialPositions = new LinkedHashSet<>(1); initialPositions.add(new DirectedLanePosition(lane, initialPosition, GTUDirectionality.DIR_PLUS)); Speed initialSpeed = new Speed(0, KM_PER_HOUR); gtu.initWithAnimation(strategicalPlanner, initialPositions, initialSpeed, DefaultCarAnimation.class, this.gtuColorer); } /** {@inheritDoc} */ @Override public SimulatorInterface<Time, Duration, OTSSimTimeDouble> getSimulator() throws RemoteException { return this.simulator; } /** * @return plots */ public final List<LaneBasedGTUSampler> getPlots() { return this.plots; } /** * @return minimumDistance */ public final Length getMinimumDistance() { return this.minimumDistance; } /** * Stop simulation and throw an Error. * @param theSimulator OTSDEVSSimulatorInterface; the simulator * @param errorMessage String; the error message */ public void stopSimulator(final OTSDEVSSimulatorInterface theSimulator, final String errorMessage) { System.out.println("Error: " + errorMessage); try { if (theSimulator.isRunning()) { theSimulator.stop(); } } catch (SimRuntimeException exception) { exception.printStackTrace(); } throw new Error(errorMessage); } /** * Simple sensor that does not provide output, but is drawn on the Lanes. * <p> * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. * <br> * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>. * </p> * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $, * initial version Sep 18, 2016 <br> * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a> * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a> * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a> */ public static class SimpleSilentSensor extends AbstractSensor { /** */ private static final long serialVersionUID = 20150130L; /** * @param lane the lane of the sensor. * @param position the position of the sensor * @param triggerPosition RelativePosition.TYPE; the relative position type (e.g., FRONT, REAR) of the vehicle that * triggers the sensor. * @param id the id of the sensor. * @param simulator the simulator to enable animation. * @throws NetworkException when the position on the lane is out of bounds w.r.t. the center line of the lane * @throws OTSGeometryException when the geometry of the sensor cannot be calculated, e.g. when the lane width is zero, * or the position is beyond or before the lane length */ public SimpleSilentSensor(final String id, final Lane lane, final Length position, final RelativePosition.TYPE triggerPosition, final OTSDEVSSimulatorInterface simulator) throws NetworkException, OTSGeometryException { super(id, lane, position, triggerPosition, simulator, LaneBasedObject.makeGeometry(lane, position)); try { new SensorAnimation(this, position, simulator, Color.RED); } catch (RemoteException | NamingException exception) { exception.printStackTrace(); } } /** {@inheritDoc} */ @Override public final void triggerResponse(final LaneBasedGTU gtu) { // do nothing. } /** {@inheritDoc} */ @Override public final String toString() { return "SimpleSilentSensor [Lane=" + this.getLane() + "]"; } /** {@inheritDoc} */ @Override |
File | Line |
---|---|
org\opentrafficsim\imb\transceiver\urbanstrategy\GTUTransceiver.java | 477 |
org\opentrafficsim\imb\transceiver\urbanstrategy\GTUTransceiver.java | 515 |
private Object[] transformChange(final EventInterface event) { // moveInfo contains: {String gtuId, DirectedPoint position, Speed speed, Acceleration acceleration, // TurnIndicatorStatus turnIndicatorStatus, Length odometer, Lane referenceLane, Length positionOnReferenceLane} Object[] moveInfo = (Object[]) event.getContent(); String gtuId = moveInfo[0].toString(); DirectedPoint location = (DirectedPoint) moveInfo[1]; LaneBasedGTU gtu = (LaneBasedGTU) event.getSource(); Lane lane = (Lane) moveInfo[6]; double longitudinalPosition = ((Length) moveInfo[7]).si; double speed = ((Speed) moveInfo[2]).si; double acceleration = ((Acceleration) moveInfo[3]).si; double timestamp = gtu.getSimulator().getSimulatorTime().getTime().si; String turnIndicatorStatus = ((TurnIndicatorStatus) moveInfo[4]).toString(); double odometer = ((Length) moveInfo[5]).si; boolean brakingLights = acceleration < 0.0; // TODO proper function for isBraking() return new Object[] { timestamp, gtuId, location.x, location.y, location.z, location.getRotZ(), lane.getParentLink().getNetwork().getId(), lane.getParentLink().getId(), lane.getId(), longitudinalPosition, speed, acceleration, turnIndicatorStatus, brakingLights, odometer }; } |
File | Line |
---|---|
org\opentrafficsim\imb\demo\A58IMB.java | 279 |
org\opentrafficsim\imb\demo\N201IMB.java | 279 |
return "A58Model [simulator=" + this.simulator + "]"; } } /** * Convert coordinates to/from the Dutch RD system. */ class CoordinateTransformRD implements CoordinateTransform, Serializable { /** */ private static final long serialVersionUID = 20141017L; /** */ final double dx; /** */ final double dy; /** * @param dx x transform * @param dy y transform */ public CoordinateTransformRD(final double dx, final double dy) { this.dx = dx; this.dy = dy; } /** {@inheritDoc} */ @Override public float[] floatTransform(double x, double y) { double[] d = doubleTransform(x, y); return new float[] { (float) d[0], (float) d[1] }; } /** {@inheritDoc} */ @Override public double[] doubleTransform(double x, double y) { try { Point2D c = TransformWGS84DutchRDNew.fromWGS84(x, y); return new double[] { c.getX() - this.dx, c.getY() - this.dy }; } catch (Exception exception) { System.err.println(exception.getMessage()); return new double[] { 0, 0 }; } } /** {@inheritDoc} */ @Override public final String toString() { return "CoordinateTransformRD [dx=" + this.dx + ", dy=" + this.dy + "]"; } } } |
File | Line |
---|---|
org\opentrafficsim\imb\demo\A58IMB.java | 205 |
org\opentrafficsim\imb\demo\N201IMB.java | 207 |
System.out.println("A58IMB: constructModel called; Connecting to IMB"); this.simulator = (OTSDEVSSimulatorInterface) pSimulator; SimpleAnimator imbAnimator = (SimpleAnimator) pSimulator; try { CompoundProperty imbSettings = null; for (Property<?> property : this.modelProperties) { if (property.getKey().equals(OTSIMBConnector.PROPERTY_KEY)) { imbSettings = (CompoundProperty) property; } } System.out.println("link count " + this.network.getLinkMap().size()); Throw.whenNull(imbSettings, "IMB Settings not found in properties"); this.imbConnector = OTSIMBConnector.create(imbSettings, "OTS"); new NetworkTransceiver(this.imbConnector, imbAnimator, this.network); new NodeTransceiver(this.imbConnector, imbAnimator, this.network); new LinkGTUTransceiver(this.imbConnector, imbAnimator, this.network); new LaneGTUTransceiver(this.imbConnector, imbAnimator, this.network); new GTUTransceiver(this.imbConnector, imbAnimator, this.network); new SensorGTUTransceiver(this.imbConnector, imbAnimator, this.network); new SimulatorTransceiver(this.imbConnector, imbAnimator); } catch (IMBException exception) { throw new SimRuntimeException(exception); } // Stream to allow the xml-file to be retrievable from a JAR file InputStream stream = URLResource.getResourceAsStream("/A58v1.xml"); |
File | Line |
---|---|
org\opentrafficsim\imb\transceiver\urbanstrategy\LaneGTUTransceiver.java | 221 |
org\opentrafficsim\imb\transceiver\urbanstrategy\LinkGTUTransceiver.java | 209 |
org\opentrafficsim\imb\transceiver\urbanstrategy\SensorGTUTransceiver.java | 221 |
super("Lane_GTU", connector, simulator); this.network = network; // listen on network changes and register the listener to all the Links addListeners(); } /** * Ensure that we get notified about newly created and destroyed Links instrument all currently existing Links. * @throws IMBException in case notification of existing Lanes fails */ private void addListeners() throws IMBException { // Subscribe to all future link creation and removal events. this.network.addListener(this, Network.LINK_ADD_EVENT); this.network.addListener(this, Network.LINK_REMOVE_EVENT); // For already existing links, post ourselves a LINK_ADD_EVENT for (Link link : this.network.getLinkMap().values()) { try { this.notify(new TimedEvent<OTSSimTimeDouble>(Network.LINK_ADD_EVENT, this.network, link.getId(), getSimulator().getSimulatorTime())); } catch (RemoteException exception) { throw new IMBException(exception); } } } /** {@inheritDoc} */ @Override public void notify(final EventInterface event) throws RemoteException { EventType type = event.getType(); if (type.equals(Network.LINK_ADD_EVENT)) { Link link = this.network.getLink((String) event.getContent()); if (!(link instanceof CrossSectionLink)) { System.err.println("LaneGTUTransceiver.notify(LINK_ADD) - Don't know how to handle a non-CrossSectionLink"); |
File | Line |
---|---|
org\opentrafficsim\imb\demo\CircularRoadIMB.java | 146 |
org\opentrafficsim\imb\demo\ModelControlDemo.java | 462 |
for (int lane = 1; lane <= 2; lane++) { String laneId = String.format("Lane %d ", lane); outputProperties.add(new BooleanProperty(laneId + "Density", laneId + " Density", laneId + "Density contour plot", true, false, 0)); outputProperties .add(new BooleanProperty(laneId + "Flow", laneId + " Flow", laneId + "Flow contour plot", true, false, 1)); outputProperties.add( new BooleanProperty(laneId + "Speed", laneId + " Speed", laneId + "Speed contour plot", true, false, 2)); outputProperties.add(new BooleanProperty(laneId + "Acceleration", laneId + " Acceleration", laneId + "Acceleration contour plot", true, false, 3)); outputProperties.add(new BooleanProperty(laneId + "Trajectories", laneId + " Trajectories", laneId + "Trajectory (time/distance) diagram", true, false, 4)); } |
File | Line |
---|---|
org\opentrafficsim\imb\demo\A58IMB.java | 219 |
org\opentrafficsim\imb\demo\CircularRoadIMB.java | 483 |
org\opentrafficsim\imb\demo\N201IMB.java | 221 |
Throw.whenNull(imbSettings, "IMB Settings not found in properties"); this.imbConnector = OTSIMBConnector.create(imbSettings, "OTS"); new NetworkTransceiver(this.imbConnector, imbAnimator, this.network); new NodeTransceiver(this.imbConnector, imbAnimator, this.network); new LinkGTUTransceiver(this.imbConnector, imbAnimator, this.network); new LaneGTUTransceiver(this.imbConnector, imbAnimator, this.network); new GTUTransceiver(this.imbConnector, imbAnimator, this.network); new SensorGTUTransceiver(this.imbConnector, imbAnimator, this.network); new SimulatorTransceiver(this.imbConnector, imbAnimator); } catch (IMBException exception) { throw new SimRuntimeException(exception); } |
File | Line |
---|---|
org\opentrafficsim\imb\transceiver\urbanstrategy\LaneGTUTransceiver.java | 263 |
org\opentrafficsim\imb\transceiver\urbanstrategy\SensorGTUTransceiver.java | 263 |
System.err.println("LaneGTUTransceiver.notify(LINK_ADD) - Don't know how to handle a non-CrossSectionLink"); return; } CrossSectionLink csl = (CrossSectionLink) link; csl.addListener(this, CrossSectionLink.LANE_ADD_EVENT); csl.addListener(this, CrossSectionLink.LANE_REMOVE_EVENT); // For already existing lanes, post ourselves a LANE_ADD_EVENT for (Lane lane : csl.getLanes()) { try { this.notify(new Event(CrossSectionLink.LANE_ADD_EVENT, csl, new Object[] { link.getNetwork().getId(), link.getId(), lane.getId(), lane, csl.getLanes().indexOf(lane) })); } catch (RemoteException exception) { System.err.println("LaneGTUTransceiver.notify(LINK_ADD) - RemoteException: " + exception.getMessage()); |
File | Line |
---|---|
org\opentrafficsim\imb\demo\A58IMB.java | 220 |
org\opentrafficsim\imb\demo\CircularRoadIMB.java | 484 |
org\opentrafficsim\imb\demo\ModelControlDemo.java | 540 |
org\opentrafficsim\imb\demo\N201IMB.java | 222 |
this.imbConnector = OTSIMBConnector.create(imbSettings, "OTS"); new NetworkTransceiver(this.imbConnector, imbAnimator, this.network); new NodeTransceiver(this.imbConnector, imbAnimator, this.network); new LinkGTUTransceiver(this.imbConnector, imbAnimator, this.network); new LaneGTUTransceiver(this.imbConnector, imbAnimator, this.network); new GTUTransceiver(this.imbConnector, imbAnimator, this.network); new SensorGTUTransceiver(this.imbConnector, imbAnimator, this.network); new SimulatorTransceiver(this.imbConnector, imbAnimator); } catch (IMBException exception) { throw new SimRuntimeException(exception); } |