Skip to content

Commit

Permalink
Set meter fault if node or green detector not found
Browse files Browse the repository at this point in the history
  • Loading branch information
DougLau committed Jan 10, 2025
1 parent 3956f02 commit 9d924b8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/us/mn/state/dot/tms/server/KAdaptiveAlgorithm.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* IRIS -- Intelligent Roadway Information System
* Copyright (C) 2001-2024 Minnesota Department of Transportation
* Copyright (C) 2001-2025 Minnesota Department of Transportation
* Copyright (C) 2011-2012 University of Minnesota Duluth (NATSRL)
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -676,7 +676,7 @@ private boolean isMetering() {
public MeterState(RampMeterImpl mtr, EntranceNode en) {
meter = mtr;
node = en;
SamplerSet ss = meter.getSamplerSet();
SamplerSet ss = meter.getEntranceSet();
queue = ss.filter(LaneCode.QUEUE);
passage = ss.filter(LaneCode.PASSAGE);
merge = ss.filter(LaneCode.MERGE);
Expand Down
69 changes: 48 additions & 21 deletions src/us/mn/state/dot/tms/server/RampMeterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,15 @@ private void setFaultNotify(RampMeterFault flt) {
}
}

/** Update fault with checks */
private void updateFault(RampMeterFault flt) {
RampMeterFault f = fault;
// Don't overwrite POLICE_PANEL / MANUAL_MODE
if (!objectEquals(f, RampMeterFault.POLICE_PANEL) &&
!objectEquals(f, RampMeterFault.MANUAL_MODE))
setFaultNotify(flt);
}

/** Get the ramp meter fault */
@Override
public Integer getFault() {
Expand Down Expand Up @@ -714,27 +723,42 @@ protected long calculateStyles() {
return s;
}

/** Get the detector set associated with the ramp meter */
private SamplerSet getSamplerSet(SamplerSet.Filter f) {
/** Entrance detector set */
private transient SamplerSet entrance_set = new SamplerSet();

/** Get the meter entrance detector set */
public SamplerSet getEntranceSet() {
return entrance_set;
}

/** Lookup the detector set associated with the ramp meter */
private SamplerSet lookupEntranceSet(SamplerSet.Filter f) {
boolean found = false;
DetFinder finder = new DetFinder(f);
Corridor corridor = getCorridor();
if (corridor != null) {
corridor.findActiveNode(finder);
if (corridor.findActiveNode(finder) != null)
found = true;
Iterator<String> it = corridor.getLinkedCDRoads();
while (it.hasNext()) {
String cd = it.next();
Corridor cd_road = corridors.getCorridor(cd);
if (cd_road != null)
cd_road.findActiveNode(finder);
if (cd_road != null) {
if (cd_road.findActiveNode(finder)
!= null)
found = true;
}
}
} else
logError("getSamplerSet: no corridor");
logError("lookupEntranceSet: no corridor");
if (!found)
updateFault(RampMeterFault.NO_ENTRANCE_NODE);
return new SamplerSet(finder.samplers);
}

/** Get the set of non-abandoned detectors */
public SamplerSet getSamplerSet() {
return getSamplerSet(new SamplerSet.Filter() {
/** Get the set of non-abandoned entrance detectors */
private SamplerSet lookupEntranceSet() {
return lookupEntranceSet(new SamplerSet.Filter() {
public boolean check(VehicleSampler vs) {
if (vs instanceof DetectorImpl) {
DetectorImpl d = (DetectorImpl) vs;
Expand All @@ -745,7 +769,7 @@ public boolean check(VehicleSampler vs) {
});
}

/** Detector finder */
/** Entrance detector finder */
private class DetFinder implements Corridor.NodeFinder {
private final ArrayList<VehicleSampler> samplers =
new ArrayList<VehicleSampler>();
Expand All @@ -766,13 +790,11 @@ public boolean check(float m, R_NodeImpl n) {
}
}

/** Merge detector */
private transient SamplerSet merge_set = new SamplerSet();

/** Check if traffic is backed up over merge detector */
private boolean isMergeBackedUp() {
int per_ms = DetectorImpl.BIN_PERIOD_MS;
long stamp = DetectorImpl.calculateEndTime(per_ms);
SamplerSet merge_set = entrance_set.filter(LaneCode.MERGE);
float occ = merge_set.getMaxOccupancy(stamp, per_ms);
return merge_set.isPerfect() && occ >= MERGE_BACKUP_OCC;
}
Expand All @@ -785,22 +807,24 @@ public DetectorImpl getGreenDet() {
return green_det;
}

/** Lookup the merge and green count detectors from R_Nodes */
/** Lookup the entrance detectors from R_Nodes */
public void lookupDetectors() {
SamplerSet ss = getSamplerSet();
merge_set = ss.filter(LaneCode.MERGE);
green_det = lookupGreen(ss);
entrance_set = lookupEntranceSet();
green_det = lookupGreen();
if (green_det != null)
updateFault(null);
}

/** Lookup a single green detector in a sampler set */
private DetectorImpl lookupGreen(SamplerSet ss) {
SamplerSet greens = ss.filter(LaneCode.GREEN);
/** Lookup a single green detector from entrance set */
private DetectorImpl lookupGreen() {
SamplerSet greens = entrance_set.filter(LaneCode.GREEN);
if (1 == greens.size()) {
VehicleSampler vs = greens.getAll().get(0);
if (vs instanceof DetectorImpl)
return (DetectorImpl) vs;
}
logError("lookupGreen: wrong size " + greens.size());
updateFault(RampMeterFault.NO_GREEN_DETECTOR);
return null;
}

Expand Down Expand Up @@ -839,7 +863,10 @@ public R_NodeImpl getR_Node() {
return null;
}

/** Get the entrance r_node on same corridor as ramp meter */
/** Get the entrance r_node on same corridor as ramp meter.
*
* For meters on CD roads, this will search for an entrance from the
* CD road to the main corridor. */
public R_NodeImpl getEntranceNode() {
R_NodeImpl n = getR_Node();
return (n != null) ? findEntrance(n) : null;
Expand Down

0 comments on commit 9d924b8

Please sign in to comment.