Skip to content

Commit

Permalink
#100, #101, #99 working on path based implementation. Removed empiric…
Browse files Browse the repository at this point in the history
… approach, improved testing for stochastic results, added option to use only non-overlapping links for derivative calculation
  • Loading branch information
markr committed Feb 2, 2024
1 parent 28693d0 commit 585d5c0
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,9 @@
*/
public interface StaticLtmDirectedPath extends ManagedDirectedPath {

public abstract void updatePathChoiceProbability(double probability);
public abstract void setPathChoiceProbability(double probability);

/** update previous value to current one, without changing it */
public abstract void setPrevPathChoiceProbabilityToCurr();

public abstract double getCurrentPathChoiceProbability();

public abstract double getPreviousPathChoiceProbability();

public abstract void setPathCost(double pathCost);

public abstract double getPathCost();
public abstract double getPathChoiceProbability();

/**
* Hashcode based solely on the directed link segments of this path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ public class StaticLtmDirectedPathImpl implements StaticLtmDirectedPath {
*/
private double currentPathChoiceProbability;

/**
* Previous path choice probability
*/
private double previousPathChoiceProbability;

/**
* Current path cost
*/
private double pathCost;

/** the path we're decorating */
private ManagedDirectedPath wrappedPath;

Expand All @@ -45,8 +35,6 @@ public class StaticLtmDirectedPathImpl implements StaticLtmDirectedPath {
*/
public StaticLtmDirectedPathImpl(ManagedDirectedPath pathToWrap) {
this.currentPathChoiceProbability = 0;
this.previousPathChoiceProbability = 0;
this.pathCost = 0;
this.linkSegmentsOnlyHashCode = java.util.Arrays.hashCode(
IterableUtils.asStream(IterableUtils.toIterable(pathToWrap.iterator())).mapToLong( e -> e.getId()).toArray());
this.wrappedPath = pathToWrap;
Expand All @@ -60,51 +48,25 @@ public StaticLtmDirectedPathImpl(ManagedDirectedPath pathToWrap) {
*/
public StaticLtmDirectedPathImpl(StaticLtmDirectedPathImpl other, boolean deepCopy) {
this.currentPathChoiceProbability = other.currentPathChoiceProbability;
this.previousPathChoiceProbability = other.previousPathChoiceProbability;
this.pathCost = other.pathCost;
this.linkSegmentsOnlyHashCode = other.linkSegmentsOnlyHashCode;
this.wrappedPath = deepCopy ? other.wrappedPath.deepClone() : other.wrappedPath.shallowClone();
}

@Override
public void updatePathChoiceProbability(double probability){
setPrevPathChoiceProbabilityToCurr();
public void setPathChoiceProbability(double probability){
this.currentPathChoiceProbability = probability;
}

/**
* {@inheritDoc}
*/
@Override
public void setPrevPathChoiceProbabilityToCurr() {
this.previousPathChoiceProbability = currentPathChoiceProbability;
}

@Override
public double getCurrentPathChoiceProbability(){
public double getPathChoiceProbability(){
return this.currentPathChoiceProbability;
}

@Override
public double getPreviousPathChoiceProbability(){
return this.previousPathChoiceProbability;
}

@Override
public void setPathCost(double pathCost) {
this.pathCost = pathCost;
}
@Override
public double getPathCost() {
return pathCost;
}

@Override
public int getLinkSegmentsOnlyHashCode(){
return this.linkSegmentsOnlyHashCode;
}


@Override
public long getId() {
return wrappedPath.getId();
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void accept(OdZone origin, OdZone destination, Double odDemand) {
/* path */
var odPaths = odMultiPaths.getValue(origin, destination);
for (StaticLtmDirectedPath odPath : odPaths) {
double acceptedPathFlowRate = odDemand * odPath.getCurrentPathChoiceProbability();
double acceptedPathFlowRate = odDemand * odPath.getPathChoiceProbability();
if (odPath == null || odPath.isEmpty()) {
LOGGER.warning(String.format("IGNORE: encountered empty path %s", odPath == null ? "" : odPath.getXmlId()));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class PathLinkFlowUpdateConsumer extends PathFlowUpdateConsumer<NetworkFl
private static final Logger LOGGER = Logger.getLogger(PathLinkFlowUpdateConsumer.class.getCanonicalName());

/**
* For each entry segment update the in(sending)flow
* For each entry segment update the in(sending)flow (and outflow if so specified)
*
* @param prevSegment to use
* @param currentSegment to use
Expand All @@ -32,7 +32,15 @@ protected double applySingleFlowUpdate(final EdgeSegment prevSegment, final Edge
/* u_a: update inflow for link segment */
int prevSegmentId = (int) prevSegment.getId();
dataConfig.sendingFlows[prevSegmentId] += turnSendingFlowPcuH;
return turnSendingFlowPcuH * dataConfig.flowAcceptanceFactors[prevSegmentId];

/* v_ap = u_bp = alpha_a*...*f_p */
double acceptedTurnFlowPcuH = turnSendingFlowPcuH * dataConfig.flowAcceptanceFactors[prevSegmentId];

/* v_a = SUM(v_ap) (only when enabled) */
if (dataConfig.isOutflowsUpdate()) {
dataConfig.outFlows[prevSegmentId] += acceptedTurnFlowPcuH;
}
return acceptedTurnFlowPcuH;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ public boolean stepFiveCheckNetworkLoadingConvergence(int networkLoadingIteratio
/**
* When loading has converged, outputs might be persisted for (intermediate) iterations. Since the loading does not always
* track the entire network for performance reasons. This method can be invoked before persisting results to populate the gaps
* (if any) regarding for example link in and outflows that might otherwise not be available, e.g. in the POINT_QUEUE_BASIC laoding scheme
* (if any) regarding for example link in and outflows that might otherwise not be available, e.g. in the POINT_QUEUE_BASIC loading scheme
* only potentially blocking nodes and their immediate links might be tracked on the network level. Whereas if we want to see the results of this
* iteration, we would want the full inflows/outflows on all links in the network. This is what this methods ensure with minimal overhead.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private Demands createDemands() {
return demands;
}

private void testOutputs(StaticLtm sLTM) {
private void testDeterministicOutputs(StaticLtm sLTM) {
double outflow0 = sLTM.getLinkSegmentOutflowPcuHour(networkLayer.getLinks().getByXmlId("0").getLinkSegmentAb());
double outflow1 = sLTM.getLinkSegmentOutflowPcuHour(networkLayer.getLinks().getByXmlId("1").getLinkSegmentAb());
double outflow2 = sLTM.getLinkSegmentOutflowPcuHour(networkLayer.getLinks().getByXmlId("2").getLinkSegmentAb());
Expand All @@ -96,7 +96,7 @@ private void testOutputs(StaticLtm sLTM) {
assertTrue(Precision.smallerEqual(outflow8, 4000));

assertEquals(outflow0, 8000, Precision.EPSILON_3);
assertEquals(outflow1, 4523, 1);
assertEquals(outflow1, 4522.6, 1);
assertEquals(outflow2, 1500.0, Precision.EPSILON_3);
assertEquals(outflow3, outflow2, Precision.EPSILON_3);
//assertEquals(outflow4, 3750, 1); do not test due to non-uniqueness being allowed under no congestion an triangular FD
Expand Down Expand Up @@ -140,6 +140,71 @@ private void testOutputs(StaticLtm sLTM) {
assertEquals(outflow12, inflow13 + inflow14, Precision.EPSILON_6);
}

private void testStochasticOutputs(StaticLtm sLTM) {
double outflow0 = sLTM.getLinkSegmentOutflowPcuHour(networkLayer.getLinks().getByXmlId("0").getLinkSegmentAb());
double outflow1 = sLTM.getLinkSegmentOutflowPcuHour(networkLayer.getLinks().getByXmlId("1").getLinkSegmentAb());
double outflow2 = sLTM.getLinkSegmentOutflowPcuHour(networkLayer.getLinks().getByXmlId("2").getLinkSegmentAb());
double outflow3 = sLTM.getLinkSegmentOutflowPcuHour(networkLayer.getLinks().getByXmlId("3").getLinkSegmentAb());
double outflow4 = sLTM.getLinkSegmentOutflowPcuHour(networkLayer.getLinks().getByXmlId("4").getLinkSegmentAb());
double outflow5 = sLTM.getLinkSegmentOutflowPcuHour(networkLayer.getLinks().getByXmlId("5").getLinkSegmentAb());
double outflow6 = sLTM.getLinkSegmentOutflowPcuHour(networkLayer.getLinks().getByXmlId("6").getLinkSegmentAb());
double outflow7 = sLTM.getLinkSegmentOutflowPcuHour(networkLayer.getLinks().getByXmlId("7").getLinkSegmentAb());
double outflow8 = sLTM.getLinkSegmentOutflowPcuHour(networkLayer.getLinks().getByXmlId("8").getLinkSegmentAb());
double outflow9 = sLTM.getLinkSegmentOutflowPcuHour(networkLayer.getLinks().getByXmlId("9").getLinkSegmentAb());
double outflow10 = sLTM.getLinkSegmentOutflowPcuHour(networkLayer.getLinks().getByXmlId("10").getLinkSegmentAb());
double outflow11 = sLTM.getLinkSegmentOutflowPcuHour(networkLayer.getLinks().getByXmlId("11").getLinkSegmentAb());
double outflow12 = sLTM.getLinkSegmentOutflowPcuHour(networkLayer.getLinks().getByXmlId("12").getLinkSegmentAb());
double outflow13 = sLTM.getLinkSegmentOutflowPcuHour(networkLayer.getLinks().getByXmlId("13").getLinkSegmentAb());
double outflow14 = sLTM.getLinkSegmentOutflowPcuHour(networkLayer.getLinks().getByXmlId("14").getLinkSegmentAb());

assertTrue(Precision.smallerEqual(outflow4, 4000));
assertTrue(Precision.smallerEqual(outflow8, 4000));

assertEquals(outflow0, 8000, Precision.EPSILON_3);
assertEquals(outflow1, 4520.3, 1);
assertEquals(outflow2, 1500.0, Precision.EPSILON_3);
assertEquals(outflow3, outflow2, Precision.EPSILON_3);
assertEquals(outflow4, 3749.7, 1);
assertEquals(outflow5, 3290.3, 1);
assertEquals(outflow6, 1500.0, Precision.EPSILON_3);
assertEquals(outflow7, outflow6, Precision.EPSILON_3);
assertEquals(outflow8, 3750.3, 1);
assertEquals(outflow9, 3000.0, Precision.EPSILON_3);
assertEquals(outflow10, 1500.0, Precision.EPSILON_3);
assertEquals(outflow11, outflow10, Precision.EPSILON_3);
assertEquals(outflow12, 4500.0, Precision.EPSILON_3);
assertEquals(outflow13, 2249.7, 1);
assertEquals(outflow14, 2249.7, 1);

double inflow1 = sLTM.getLinkSegmentInflowPcuHour(networkLayer.getLinks().getByXmlId("1").getLinkSegmentAb());
double inflow2 = sLTM.getLinkSegmentInflowPcuHour(networkLayer.getLinks().getByXmlId("2").getLinkSegmentAb());
double inflow3 = sLTM.getLinkSegmentInflowPcuHour(networkLayer.getLinks().getByXmlId("3").getLinkSegmentAb());
double inflow4 = sLTM.getLinkSegmentInflowPcuHour(networkLayer.getLinks().getByXmlId("4").getLinkSegmentAb());
double inflow5 = sLTM.getLinkSegmentInflowPcuHour(networkLayer.getLinks().getByXmlId("5").getLinkSegmentAb());
double inflow6 = sLTM.getLinkSegmentInflowPcuHour(networkLayer.getLinks().getByXmlId("6").getLinkSegmentAb());
double inflow7 = sLTM.getLinkSegmentInflowPcuHour(networkLayer.getLinks().getByXmlId("7").getLinkSegmentAb());
double inflow8 = sLTM.getLinkSegmentInflowPcuHour(networkLayer.getLinks().getByXmlId("8").getLinkSegmentAb());
double inflow9 = sLTM.getLinkSegmentInflowPcuHour(networkLayer.getLinks().getByXmlId("9").getLinkSegmentAb());
double inflow10 = sLTM.getLinkSegmentInflowPcuHour(networkLayer.getLinks().getByXmlId("10").getLinkSegmentAb());
double inflow11 = sLTM.getLinkSegmentInflowPcuHour(networkLayer.getLinks().getByXmlId("11").getLinkSegmentAb());
double inflow12 = sLTM.getLinkSegmentInflowPcuHour(networkLayer.getLinks().getByXmlId("12").getLinkSegmentAb());
double inflow13 = sLTM.getLinkSegmentInflowPcuHour(networkLayer.getLinks().getByXmlId("13").getLinkSegmentAb());
double inflow14 = sLTM.getLinkSegmentInflowPcuHour(networkLayer.getLinks().getByXmlId("14").getLinkSegmentAb());

assertEquals(outflow0, inflow1 + inflow5, Precision.EPSILON_6);
assertEquals(outflow1, inflow2 + inflow9, Precision.EPSILON_6);
assertEquals(outflow2, inflow3, Precision.EPSILON_6);
assertEquals(outflow3 + outflow13, inflow4, Precision.EPSILON_6);
assertEquals(outflow4, inflow4, Precision.EPSILON_6);
assertEquals(outflow5, inflow10 + inflow6, Precision.EPSILON_6);
assertEquals(outflow6, inflow7, Precision.EPSILON_6);
assertEquals(outflow7 + outflow14, inflow8, Precision.EPSILON_6);
assertEquals(outflow8, inflow8, Precision.EPSILON_6);
assertEquals(outflow9 + outflow11, inflow12, Precision.EPSILON_6);
assertEquals(outflow10, inflow11, Precision.EPSILON_6);
assertEquals(outflow12, inflow13 + inflow14, Precision.EPSILON_6);
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -342,7 +407,7 @@ public void sLtmPointQueuePathBasedAssignmentTest() {
{
/* Weibit for path choice */
var choiceModel = suePathChoice.createAndRegisterChoiceModel(ChoiceModel.WEIBIT);
choiceModel.setScalingFactor(7);
choiceModel.setScalingFactor(1); // we go for rather muddled perceived cost to differentiate from deterministic result
// by not setting a fixed od path set (suePathChoice.setFixedOdPathMatrix(...)), it is assumed we want a dynamic path set
}

Expand All @@ -360,7 +425,7 @@ public void sLtmPointQueuePathBasedAssignmentTest() {
sLTM.setActivateDetailedLogging(true);
sLTM.execute();

testOutputs(sLTM);
testStochasticOutputs(sLTM);

} catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -394,7 +459,7 @@ public void sLtmPointQueueBushOriginBasedAssignmentTest() {
sLTM.setActivateDetailedLogging(true);
sLTM.execute();

testOutputs(sLTM);
testDeterministicOutputs(sLTM);

} catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -428,7 +493,7 @@ public void sLtmPointQueueBushDestinationBasedAssignmentTest() {
sLTM.setActivateDetailedLogging(true);
sLTM.execute();

testOutputs(sLTM);
testDeterministicOutputs(sLTM);

} catch (Exception e) {
e.printStackTrace();
Expand Down

0 comments on commit 585d5c0

Please sign in to comment.