CPD Results
The following document contains the results of PMD's CPD 7.7.0.
Duplications
| File | Line |
|---|---|
| org/opentrafficsim/road/gtu/lane/perception/categories/DirectIntersectionPerception.java | 57 |
| org/opentrafficsim/road/gtu/lane/perception/mental/channel/IntersectionPerceptionChannel.java | 73 |
}
@Override
public final PerceptionCollectable<PerceivedTrafficLight, TrafficLight> getTrafficLights(final RelativeLane lane)
{
return computeIfAbsent("trafficLights", () -> computeTrafficLights(lane), lane);
}
@Override
public final PerceptionCollectable<PerceivedConflict, Conflict> getConflicts(final RelativeLane lane)
{
return computeIfAbsent("conflicts", () -> computeConflicts(lane), lane);
}
@Override
public final boolean isAlongsideConflictLeft()
{
return computeIfAbsent("alongside", () -> computeConflictAlongside(LateralDirectionality.LEFT),
LateralDirectionality.LEFT);
}
@Override
public final boolean isAlongsideConflictRight()
{
return computeIfAbsent("alongside", () -> computeConflictAlongside(LateralDirectionality.RIGHT),
LateralDirectionality.RIGHT);
}
/**
* Compute traffic lights.
* @param lane lane
* @return PerceptionCollectable of traffic lights
*/
private PerceptionCollectable<PerceivedTrafficLight, TrafficLight> computeTrafficLights(final RelativeLane lane)
{
Iterable<Entry<TrafficLight>> iterable = Try.assign(() ->
{
return getPerception().getLaneStructure().getDownstreamObjects(lane, TrafficLight.class, RelativePosition.FRONT,
true);
}, "Unable to get downstream traffic lights from LaneStructure"); | |
| File | Line |
|---|---|
| org/opentrafficsim/road/gtu/lane/perception/categories/neighbors/DirectNeighborsPerception.java | 112 |
| org/opentrafficsim/road/gtu/lane/perception/mental/channel/NeighborsPerceptionChannel.java | 142 |
public final boolean isGtuAlongside(final LateralDirectionality lat)
throws ParameterException, NullPointerException, IllegalArgumentException
{
checkLateralDirectionality(lat);
return computeIfAbsent("gtuAlongside", () -> computeGtuAlongside(lat), lat);
}
/**
* Computes whether there is a GTU alongside.
* @param lat lateral directionality
* @return whether there is a GTU alongside
*/
public boolean computeGtuAlongside(final LateralDirectionality lat)
{
try
{
// check if any GTU is downstream of the rear, within the vehicle length
for (Entry<LaneBasedGtu> entry : getPerception().getLaneStructure().getFirstDownstreamGtus(new RelativeLane(lat, 1),
RelativePosition.REAR, RelativePosition.FRONT, RelativePosition.FRONT, RelativePosition.REAR))
{
if (entry.distance().le0())
{
return true;
}
}
// check if any GTU is upstream of the front, within the vehicle length
for (Entry<LaneBasedGtu> entry : getPerception().getLaneStructure().getFirstUpstreamGtus(new RelativeLane(lat, 1),
RelativePosition.FRONT, RelativePosition.REAR, RelativePosition.REAR, RelativePosition.FRONT))
{
if (entry.distance().le0())
{
return true;
}
}
}
catch (ParameterException | IllegalArgumentException exception) // | GtuException
{
throw new OtsRuntimeException("Unexpected exception while computing gtu alongside.", exception); | |
| File | Line |
|---|---|
| org/opentrafficsim/road/network/lane/conflict/ConflictBuilder.java | 488 |
| org/opentrafficsim/road/network/lane/conflict/ConflictBuilder.java | 595 |
Length longitudinalPosition2 = lane2.getLength().times(f2start);
Length length1 = lane1.getLength().times(Math.abs(f1end - f1start));
Length length2 = lane2.getLength().times(Math.abs(f2end - f2start));
// Get geometries
Polygon2d geometry1 = getGeometry(lane1, f1start, f1end, widthGenerator);
Polygon2d geometry2 = getGeometry(lane2, f2start, f2end, widthGenerator);
// Determine conflict rule
ConflictRule conflictRule;
if (lane1.getLink().getPriority().isBusStop() || lane2.getLink().getPriority().isBusStop())
{
Throw.when(lane1.getLink().getPriority().isBusStop() && lane2.getLink().getPriority().isBusStop(),
IllegalArgumentException.class, "Merge conflict between two links with bus stop priority not supported.");
// TODO: handle bus priority on the model side
conflictRule = new BusStopConflictRule(simulator, DefaultsNl.BUS);
}
else
{
conflictRule = new DefaultConflictRule();
}
// Make conflict
Conflict.generateConflictPair(ConflictType.MERGE, conflictRule, permitted, lane1, longitudinalPosition1, length1, | |
| File | Line |
|---|---|
| org/opentrafficsim/road/gtu/lane/perception/categories/DirectIntersectionPerception.java | 123 |
| org/opentrafficsim/road/gtu/lane/perception/mental/channel/IntersectionPerceptionChannel.java | 144 |
});
}
/**
* Compute whether there is a conflict alongside.
* @param lat lateral directionality
* @return whether there is a conflict alongside
*/
private boolean computeConflictAlongside(final LateralDirectionality lat)
{
try
{
RelativeLane lane = new RelativeLane(lat, 1);
if (getPerception().getLaneStructure().exists(lane))
{
Iterator<Entry<Conflict>> conflicts = getPerception().getLaneStructure()
.getUpstreamObjects(lane, Conflict.class, RelativePosition.FRONT).iterator();
if (conflicts.hasNext())
{
Entry<Conflict> entry = conflicts.next();
return entry.distance().si < entry.object().getLength().si + getGtu().getLength().si;
}
}
return false;
}
catch (ParameterException exception)
{
throw new OtsRuntimeException("Unexpected exception while computing conflict alongside.", exception); | |
| File | Line |
|---|---|
| org/opentrafficsim/road/gtu/lane/tactical/util/lmrs/Cooperation.java | 47 |
| org/opentrafficsim/road/gtu/lane/tactical/util/lmrs/Cooperation.java | 131 |
Acceleration a = new Acceleration(Double.MAX_VALUE, AccelerationUnit.SI);
double dCoop = params.getParameter(DCOOP);
Speed ownSpeed = perception.getPerceptionCategory(EgoPerception.class).getSpeed();
RelativeLane relativeLane = new RelativeLane(lat, 1);
for (PerceivedGtu leader : perception.getPerceptionCategory(NeighborsPerception.class).getLeaders(relativeLane))
{
double desire = leader.getManeuver().isChangingLane(lat.flip()) ? 1.0
: (lat.equals(LateralDirectionality.LEFT) ? leader.getBehavior().rightLaneChangeDesire()
: lat.equals(LateralDirectionality.RIGHT) ? leader.getBehavior().leftLaneChangeDesire() : 0.0);
if (desire >= dCoop && (leader.getSpeed().gt0() || leader.getDistance().gt0())) | |
| File | Line |
|---|---|
| org/opentrafficsim/road/network/lane/conflict/ConflictBuilder.java | 160 |
| org/opentrafficsim/road/network/lane/conflict/ConflictBuilder.java | 1030 |
long combinationsDone = totalCombinations - ((long) (lanes.size() - i)) * ((long) (lanes.size() - i)) / 2;
if (combinationsDone / 100000000 > lastReported)
{
Logger.ots()
.debug(String.format(
"generating conflicts at %.0f%% (generated %d merge conflicts, %d split "
+ "conflicts, %d crossing conflicts)",
100.0 * combinationsDone / totalCombinations, numberMergeConflicts.get(),
numberSplitConflicts.get(), numberCrossConflicts.get()));
lastReported = combinationsDone / 100000000;
}
Lane lane1 = lanes.get(i);
Set<Lane> down1 = lane1.nextLanes(null);
Set<Lane> up1 = lane1.prevLanes(null);
for (int j = i + 1; j < lanes.size(); j++)
{
Lane lane2 = lanes.get(j);
if (ignoreList.contains(lane1, lane2))
{
continue;
} | |
| File | Line |
|---|---|
| org/opentrafficsim/road/network/factory/LaneFactory.java | 180 |
| org/opentrafficsim/road/network/factory/LaneFactory.java | 208 |
this.laneType0 = laneType;
this.speedLimit0 = speedLimit;
Length width = DefaultsRoadNl.SOLID.getWidth();
Length offsetStripeStart = this.offset.plus(this.offsetStart);
Length offsetStripeEnd = this.offset.plus(this.offsetEnd);
ContinuousPiecewiseLinearFunction offsetFunc =
ContinuousPiecewiseLinearFunction.of(0.0, offsetStripeStart.si, 1.0, offsetStripeEnd.si);
ContinuousPiecewiseLinearFunction widthFunc = ContinuousPiecewiseLinearFunction.of(0.0, width.si, 1.0, width.si);
this.firstStripe = Try.assign(
() -> new Stripe("1", DefaultsRoadNl.SOLID, this.link,
CrossSectionGeometry.of(this.line, SEGMENTS, offsetFunc, widthFunc)),
"Unexpected exception while building link.");
return this;
}
/**
* Prepare the factory to add lanes from right to left.
* @param rightLanes number of lanes right from the link design line
* @param laneWidth lane width
* @param laneType lane type
* @param speedLimit speed limit
* @return LaneFactory this lane factory for method chaining
*/
public LaneFactory rightToLeft(final double rightLanes, final Length laneWidth, final LaneType laneType, | |
| File | Line |
|---|---|
| org/opentrafficsim/road/network/lane/conflict/ConflictBuilder.java | 1087 |
| org/opentrafficsim/road/network/lane/conflict/ConflictBuilder.java | 1178 |
}
long time = System.currentTimeMillis();
// wait max 60 sec for last maxqueue jobs
while (numberOfJobs.get() > 0 && System.currentTimeMillis() - time < 60000)
{
try
{
Thread.sleep(10);
}
catch (InterruptedException exception)
{
// ignore
}
}
executor.shutdown();
while (!executor.isTerminated())
{
try
{
Thread.sleep(1);
}
catch (InterruptedException exception)
{
// ignore
}
}
Logger.ots()
.debug(String.format(
"generating conflicts complete (generated %d merge conflicts, %d split "
+ "conflicts, %d crossing conflicts)",
numberMergeConflicts.get(), numberSplitConflicts.get(), numberCrossConflicts.get()));
}
/**
* Build conflicts on list of lanes; parallel implementation. Big jobs.
* @param lanes list of Lanes
* @param simulator the simulator
* @param widthGenerator the width generator
* @param ignoreList lane combinations to ignore
* @param permittedList lane combinations that are permitted by traffic control
*/
public static void buildConflictsParallelBig(final List<Lane> lanes, final OtsSimulatorInterface simulator, | |
| File | Line |
|---|---|
| org/opentrafficsim/road/network/lane/Lane.java | 767 |
| org/opentrafficsim/road/network/lane/Lane.java | 796 |
public final Optional<LaneBasedGtu> getGtuAhead(final Length position, final RelativePosition.Type relativePosition,
final Duration when) throws GtuException
{
List<LaneBasedGtu> list = this.gtuList.get(when);
if (list.isEmpty())
{
return Optional.empty();
}
int[] search = lineSearch((final int index) ->
{
LaneBasedGtu gtu = list.get(index);
return gtu.getPosition(gtu.getRelativePositions().get(relativePosition), when).position().si;
}, list.size(), position.si);
if (search[1] < list.size()) | |
| File | Line |
|---|---|
| org/opentrafficsim/road/network/lane/conflict/ConflictBuilder.java | 1028 |
| org/opentrafficsim/road/network/lane/conflict/ConflictBuilder.java | 1147 |
for (int i = 0; i < lanes.size(); i++)
{
long combinationsDone = totalCombinations - ((long) (lanes.size() - i)) * ((long) (lanes.size() - i - 1)) / 2;
if (combinationsDone / 100000000 > lastReported)
{
Logger.ots()
.debug(String.format(
"generating conflicts at %.0f%% (generated %d merge conflicts, %d split "
+ "conflicts, %d crossing conflicts)",
100.0 * combinationsDone / totalCombinations, numberMergeConflicts.get(),
numberSplitConflicts.get(), numberCrossConflicts.get()));
lastReported = combinationsDone / 100000000;
} | |
| File | Line |
|---|---|
| org/opentrafficsim/road/gtu/lane/perception/structure/LaneStructure.java | 249 |
| org/opentrafficsim/road/gtu/lane/perception/structure/LaneStructure.java | 347 |
public Iterable<Entry<LaneBasedGtu>> getUpstreamGtus(final RelativeLane relativeLane,
final RelativePosition.Type egoPosition, final RelativePosition.Type otherPosition,
final RelativePosition.Type egoDistancePosition, final RelativePosition.Type otherDistancePosition)
{
update();
Length dx = LaneStructure.this.egoGtu.getRelativePositions().get(egoPosition).dx();
Length dxDistance = LaneStructure.this.egoGtu.getRelativePositions().get(egoDistancePosition).dx();
return new NavigatingIterable<>(LaneBasedGtu.class, this.upstream,
start((record) -> startUpstream(record, egoPosition), relativeLane), (record) ->
{ | |
| File | Line |
|---|---|
| org/opentrafficsim/road/network/lane/object/detector/LoopDetector.java | 633 |
| org/opentrafficsim/road/network/lane/object/detector/LoopDetector.java | 749 |
return new Table("periodic", "periodic measurements", columns)
{
@Override
public Iterator<Row> iterator()
{
Iterator<LoopDetector> iterator = detectors.iterator();
Predicate<Entry<GtuType, GtuTypeData>> gtuTypeEntryFilter =
(entry) -> !includeGtuTypeColumn && entry.getKey() == null
|| Arrays.stream(gtuTypes).anyMatch((g) -> Objects.equals(g, entry.getKey()));
return new Iterator<>()
{
/** GTU type data iterator. */
private Iterator<Entry<GtuType, GtuTypeData>> dataIterator = Collections.emptyIterator();
/** Index iterator. */
private Iterator<Integer> indexIterator = Collections.emptyIterator(); | |
| File | Line |
|---|---|
| org/opentrafficsim/road/gtu/lane/control/LinearCacc.java | 33 |
| org/opentrafficsim/road/gtu/lane/control/PloegCacc.java | 31 |
public LinearCacc(final DelayedActuation delayedActuation)
{
super(delayedActuation);
}
@Override
public Acceleration getFollowingAcceleration(final LaneBasedGtu gtu,
final PerceptionCollectable<PerceivedGtu, LaneBasedGtu> leaders, final Parameters settings)
throws ParameterException
{
PerceivedGtu leader = leaders.first();
if (leader.getAcceleration() == null)
{
// ACC mode
return super.getFollowingAcceleration(gtu, leaders, settings);
}
double es =
leader.getDistance().si - gtu.getSpeed().si * settings.getParameter(TDCACC).si - settings.getParameter(X0).si;
double ev = leader.getSpeed().si - gtu.getSpeed().si; | |
| File | Line |
|---|---|
| org/opentrafficsim/road/gtu/lane/perception/categories/neighbors/DirectNeighborsPerception.java | 157 |
| org/opentrafficsim/road/gtu/lane/perception/mental/channel/NeighborsPerceptionChannel.java | 188 |
public final PerceptionCollectable<PerceivedGtu, LaneBasedGtu> getLeaders(final RelativeLane lane)
{
Throw.whenNull(lane, "Lane may not be null.");
return computeIfAbsent("leaders", () -> computeLeaders(lane), lane);
}
/**
* Computes leaders.
* @param lane lane
* @return perception iterable for leaders
*/
private PerceptionCollectable<PerceivedGtu, LaneBasedGtu> computeLeaders(final RelativeLane lane)
{
Iterable<Entry<LaneBasedGtu>> iterable = Try.assign(() ->
{
return getPerception().getLaneStructure().getDownstreamGtus(lane, RelativePosition.FRONT, RelativePosition.FRONT,
RelativePosition.FRONT, RelativePosition.REAR);
}, "Unable to get leaders from LaneStructure"); | |
| File | Line |
|---|---|
| org/opentrafficsim/road/gtu/lane/perception/categories/neighbors/DirectNeighborsPerception.java | 183 |
| org/opentrafficsim/road/gtu/lane/perception/mental/channel/NeighborsPerceptionChannel.java | 217 |
public final PerceptionCollectable<PerceivedGtu, LaneBasedGtu> getFollowers(final RelativeLane lane)
{
Throw.whenNull(lane, "Lane may not be null.");
return computeIfAbsent("followers", () -> computeFollowers(lane), lane);
}
/**
* Computes followers.
* @param lane lane
* @return perception iterable for followers
*/
private PerceptionCollectable<PerceivedGtu, LaneBasedGtu> computeFollowers(final RelativeLane lane)
{
Iterable<Entry<LaneBasedGtu>> iterable = Try.assign(() ->
{
return getPerception().getLaneStructure().getUpstreamGtus(lane, RelativePosition.FRONT, RelativePosition.FRONT,
RelativePosition.REAR, RelativePosition.FRONT);
}, "Unable to get followers from LaneStructure"); | |
