From c446815c6f1d718a70ee0990244d951162e3e314 Mon Sep 17 00:00:00 2001 From: rakow Date: Mon, 6 Jan 2025 11:26:07 +0100 Subject: [PATCH 1/4] don't add daily costs of unused modes --- .../matsim/modechoice/search/TopKChoicesGenerator.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/contribs/informed-mode-choice/src/main/java/org/matsim/modechoice/search/TopKChoicesGenerator.java b/contribs/informed-mode-choice/src/main/java/org/matsim/modechoice/search/TopKChoicesGenerator.java index e3791702020..b1497664d11 100644 --- a/contribs/informed-mode-choice/src/main/java/org/matsim/modechoice/search/TopKChoicesGenerator.java +++ b/contribs/informed-mode-choice/src/main/java/org/matsim/modechoice/search/TopKChoicesGenerator.java @@ -306,7 +306,7 @@ public List generatePredefined(PlanModel planModel, List> e : planModel.getEstimates().entrySet()) { for (ModeEstimate o : e.getValue()) { - // check if a mode can be use at all + // check if a mode can be used at all if (!o.isUsable() || o.isMin()) continue; @@ -320,6 +320,8 @@ public List generatePredefined(PlanModel planModel, List consolidateModes = planModel.filterModes(ModeEstimate::isMin); Set usableModes = planModel.filterModes(ModeEstimate::isUsable); + ReferenceSet usedModes = new ReferenceOpenHashSet<>(); + // Same Logic as the top k estimator for (String[] result : modes) { @@ -351,10 +353,11 @@ public List generatePredefined(PlanModel planModel, List usedModes = new ReferenceOpenHashSet<>(result); - estimate += computePlanEstimate(context, planModel, result, usedModes, consolidateModes, singleOptions.values()); for (ConstraintHolder c : constraints) { From 9bed1805458c3b2a2a5478812e150cbd5af4977c Mon Sep 17 00:00:00 2001 From: rakow Date: Mon, 6 Jan 2025 14:03:33 +0100 Subject: [PATCH 2/4] increase tolerances for some new rng based test --- .../matsim/modechoice/replanning/SelectVsRandomSubtourTest.java | 2 +- .../choosers/BalancedInnovationStrategyChooserTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contribs/informed-mode-choice/src/test/java/org/matsim/modechoice/replanning/SelectVsRandomSubtourTest.java b/contribs/informed-mode-choice/src/test/java/org/matsim/modechoice/replanning/SelectVsRandomSubtourTest.java index 249dc433365..f1abe228a22 100644 --- a/contribs/informed-mode-choice/src/test/java/org/matsim/modechoice/replanning/SelectVsRandomSubtourTest.java +++ b/contribs/informed-mode-choice/src/test/java/org/matsim/modechoice/replanning/SelectVsRandomSubtourTest.java @@ -60,7 +60,7 @@ void replanning() { double[] selectModes = sampleModes(plans, select); assertThat(selectModes) - .containsExactly(randomModes, Offset.offset(1200d)); + .containsExactly(randomModes, Offset.offset(1400d)); } diff --git a/matsim/src/test/java/org/matsim/core/replanning/choosers/BalancedInnovationStrategyChooserTest.java b/matsim/src/test/java/org/matsim/core/replanning/choosers/BalancedInnovationStrategyChooserTest.java index 6eefa355b4d..7e285468f2c 100644 --- a/matsim/src/test/java/org/matsim/core/replanning/choosers/BalancedInnovationStrategyChooserTest.java +++ b/matsim/src/test/java/org/matsim/core/replanning/choosers/BalancedInnovationStrategyChooserTest.java @@ -103,7 +103,7 @@ void innovationRates() { } - assertThat(count.getSum()).isCloseTo(3000 * 600, Offset.offset(300)); + assertThat(count.getSum()).isCloseTo(3000 * 600, Offset.offset(2000)); assertThat(count.getDifference()).isLessThanOrEqualTo(2); } From 012a614e83f40ec15af6328d7e3052d64f7affd5 Mon Sep 17 00:00:00 2001 From: rakow Date: Mon, 6 Jan 2025 14:05:00 +0100 Subject: [PATCH 3/4] increase tolerances for some new rng based test --- .../matsim/modechoice/replanning/SelectVsRandomSubtourTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contribs/informed-mode-choice/src/test/java/org/matsim/modechoice/replanning/SelectVsRandomSubtourTest.java b/contribs/informed-mode-choice/src/test/java/org/matsim/modechoice/replanning/SelectVsRandomSubtourTest.java index f1abe228a22..1c03792a3e7 100644 --- a/contribs/informed-mode-choice/src/test/java/org/matsim/modechoice/replanning/SelectVsRandomSubtourTest.java +++ b/contribs/informed-mode-choice/src/test/java/org/matsim/modechoice/replanning/SelectVsRandomSubtourTest.java @@ -60,7 +60,7 @@ void replanning() { double[] selectModes = sampleModes(plans, select); assertThat(selectModes) - .containsExactly(randomModes, Offset.offset(1400d)); + .containsExactly(randomModes, Offset.offset(1700d)); } From ea881ab7808dcda38c2bded32989d122078b3e08 Mon Sep 17 00:00:00 2001 From: rakow Date: Mon, 6 Jan 2025 15:02:44 +0100 Subject: [PATCH 4/4] fix previous comment --- .../replanning/SelectSubtourModeStrategy.java | 10 ++-------- .../matsim/modechoice/search/TopKChoicesGenerator.java | 4 ++-- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/contribs/informed-mode-choice/src/main/java/org/matsim/modechoice/replanning/SelectSubtourModeStrategy.java b/contribs/informed-mode-choice/src/main/java/org/matsim/modechoice/replanning/SelectSubtourModeStrategy.java index 3c6b74665a5..5e64ab5a241 100644 --- a/contribs/informed-mode-choice/src/main/java/org/matsim/modechoice/replanning/SelectSubtourModeStrategy.java +++ b/contribs/informed-mode-choice/src/main/java/org/matsim/modechoice/replanning/SelectSubtourModeStrategy.java @@ -137,20 +137,14 @@ public void run(Plan plan) { for (int i = 0; i < mask.length; i++) { if (mask[i]) option[i] = m; - - options.add(option); } + + options.add(option); } List singleModeCandidates = ctx.generator.generatePredefined(model, options); singleModeCandidates.removeIf(p -> p.getUtility() == Double.NEGATIVE_INFINITY); - // if none of the single mode options are valid, no further search is needed - // this works in conjunction with subtour constraints, with other constraints it might be too strict - if (singleModeCandidates.size() <= 1) { - continue; - } - // Single modes are also added Set candidateSet = new LinkedHashSet<>(singleModeCandidates); diff --git a/contribs/informed-mode-choice/src/main/java/org/matsim/modechoice/search/TopKChoicesGenerator.java b/contribs/informed-mode-choice/src/main/java/org/matsim/modechoice/search/TopKChoicesGenerator.java index b1497664d11..7641c3f16f7 100644 --- a/contribs/informed-mode-choice/src/main/java/org/matsim/modechoice/search/TopKChoicesGenerator.java +++ b/contribs/informed-mode-choice/src/main/java/org/matsim/modechoice/search/TopKChoicesGenerator.java @@ -320,8 +320,6 @@ public List generatePredefined(PlanModel planModel, List consolidateModes = planModel.filterModes(ModeEstimate::isMin); Set usableModes = planModel.filterModes(ModeEstimate::isUsable); - ReferenceSet usedModes = new ReferenceOpenHashSet<>(); - // Same Logic as the top k estimator for (String[] result : modes) { @@ -330,6 +328,8 @@ public List generatePredefined(PlanModel planModel, List usedModes = new ReferenceOpenHashSet<>(); + // Collect estimates for all entries for (int i = 0; i < result.length; i++) {