diff --git a/matsim/src/main/java/org/matsim/core/population/algorithms/PlanMutateTimeAllocationSimplified.java b/matsim/src/main/java/org/matsim/core/population/algorithms/MutateActivityTimeAllocation.java similarity index 84% rename from matsim/src/main/java/org/matsim/core/population/algorithms/PlanMutateTimeAllocationSimplified.java rename to matsim/src/main/java/org/matsim/core/population/algorithms/MutateActivityTimeAllocation.java index 405aba45d2c..09dce347ef4 100644 --- a/matsim/src/main/java/org/matsim/core/population/algorithms/PlanMutateTimeAllocationSimplified.java +++ b/matsim/src/main/java/org/matsim/core/population/algorithms/MutateActivityTimeAllocation.java @@ -20,27 +20,21 @@ package org.matsim.core.population.algorithms; -import java.util.Map; import java.util.Random; import org.matsim.api.core.v01.population.Activity; import org.matsim.api.core.v01.population.Leg; import org.matsim.api.core.v01.population.Plan; import org.matsim.api.core.v01.population.PlanElement; -import org.matsim.core.population.PopulationUtils; import org.matsim.core.router.TripStructureUtils; import org.matsim.core.router.TripStructureUtils.StageActivityHandling; /** * Mutates the duration of activities randomly within a specified range. - *
- * Other than the "full" version, this version just mutates activity end time and activity duration if they are defined, - * without thinking any further. If this produces invalid plans, they will eventually be removed through the selection - * process. kai, jun'12 * - * @author knagel + * @author knagel, jbischoff */ -public final class PlanMutateTimeAllocationSimplified implements PlanAlgorithm { +public final class MutateActivityTimeAllocation implements PlanAlgorithm { public static final String INITIAL_END_TIME_ATTRIBUTE = "initialEndTime"; @@ -52,7 +46,7 @@ public final class PlanMutateTimeAllocationSimplified implements PlanAlgorithm { private final double mutationRangeStep; - public PlanMutateTimeAllocationSimplified(final double mutationRange, boolean affectingDuration, final Random random, double latestActivityEndTime, boolean mutateAroundInitialEndTimeOnly, double mutationRangeStep) { + public MutateActivityTimeAllocation(final double mutationRange, boolean affectingDuration, final Random random, double latestActivityEndTime, boolean mutateAroundInitialEndTimeOnly, double mutationRangeStep) { this.mutationRange = mutationRange; this.affectingDuration = affectingDuration; this.random = random; @@ -76,11 +70,8 @@ public void run(final Plan plan) { } } double newEndTime = Math.min(mutateTime(endTime, mutationRange),this.latestActivityEndTime); - double shift = endTime -newEndTime; act.setEndTime(newEndTime); - if (act.getStartTime().isDefined()){ - act.setStartTime(act.getStartTime().seconds()-shift); - } + act.setStartTimeUndefined(); } else if ( affectingDuration ) { if ( act.getMaximumDuration().isDefined()) { diff --git a/matsim/src/main/java/org/matsim/core/replanning/strategies/TimeAllocationMutatorModule.java b/matsim/src/main/java/org/matsim/core/replanning/strategies/TimeAllocationMutatorModule.java index 70cae3d1e8e..485089a53ee 100644 --- a/matsim/src/main/java/org/matsim/core/replanning/strategies/TimeAllocationMutatorModule.java +++ b/matsim/src/main/java/org/matsim/core/replanning/strategies/TimeAllocationMutatorModule.java @@ -22,26 +22,13 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.matsim.api.core.v01.population.Population; import org.matsim.api.core.v01.replanning.PlanStrategyModule; -import org.matsim.core.config.Config; -import org.matsim.core.config.ConfigGroup; import org.matsim.core.config.groups.GlobalConfigGroup; -import org.matsim.core.config.groups.PlansConfigGroup; import org.matsim.core.config.groups.TimeAllocationMutatorConfigGroup; import org.matsim.core.gbl.MatsimRandom; import org.matsim.core.population.algorithms.PlanAlgorithm; -import org.matsim.core.population.algorithms.PlanMutateTimeAllocationSimplified; -import org.matsim.core.population.algorithms.TripPlanMutateTimeAllocation; +import org.matsim.core.population.algorithms.MutateActivityTimeAllocation; import org.matsim.core.replanning.modules.AbstractMultithreadedModule; -import org.matsim.core.router.TripRouter; -import org.matsim.core.router.TripStructureUtils.StageActivityHandling; - -import jakarta.inject.Provider; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; /** * Wraps the {@link org.matsim.core.population.algorithms.TripPlanMutateTimeAllocation}- @@ -70,7 +57,7 @@ class TimeAllocationMutatorModule extends AbstractMultithreadedModule{ @Override public PlanAlgorithm getPlanAlgoInstance() { - PlanAlgorithm pmta = new PlanMutateTimeAllocationSimplified + PlanAlgorithm pmta = new MutateActivityTimeAllocation (this.mutationRange, this.affectingDuration, MatsimRandom.getLocalInstance(), timeAllocationMutatorConfigGroup.getLatestActivityEndTime(), timeAllocationMutatorConfigGroup.isMutateAroundInitialEndTimeOnly(), timeAllocationMutatorConfigGroup.getMutationRangeStep()); diff --git a/matsim/src/test/java/org/matsim/core/replanning/strategies/TimeAllocationMutatorModuleTest.java b/matsim/src/test/java/org/matsim/core/replanning/strategies/TimeAllocationMutatorModuleTest.java index a447d5b2a90..0f908843e27 100644 --- a/matsim/src/test/java/org/matsim/core/replanning/strategies/TimeAllocationMutatorModuleTest.java +++ b/matsim/src/test/java/org/matsim/core/replanning/strategies/TimeAllocationMutatorModuleTest.java @@ -22,13 +22,10 @@ import static org.junit.Assert.assertTrue; -import jakarta.inject.Provider; - import org.junit.Rule; import org.junit.Test; import org.matsim.api.core.v01.Coord; import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.TransportMode; import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; @@ -36,22 +33,18 @@ import org.matsim.api.core.v01.population.Activity; import org.matsim.api.core.v01.population.Person; import org.matsim.api.core.v01.population.Plan; -import org.matsim.core.config.Config; -import org.matsim.core.config.ConfigUtils; import org.matsim.core.gbl.MatsimRandom; import org.matsim.core.network.NetworkUtils; import org.matsim.core.population.PersonUtils; import org.matsim.core.population.PopulationUtils; import org.matsim.core.population.algorithms.PlanAlgorithm; -import org.matsim.core.population.algorithms.PlanMutateTimeAllocationSimplified; -import org.matsim.core.router.TripRouter; -import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.core.population.algorithms.MutateActivityTimeAllocation; import org.matsim.core.utils.misc.Time; import org.matsim.testcases.MatsimTestUtils; /** * Tests the functionality of {@link TimeAllocationMutatorModule}, mainly that the - * correct mutation range is handed over to the underlying {@link PlanMutateTimeAllocationSimplified}. + * correct mutation range is handed over to the underlying {@link MutateActivityTimeAllocation}. * * @author mrieser */ @@ -64,8 +57,8 @@ public class TimeAllocationMutatorModuleTest { @Test public void testSimplifiedMutation() { boolean affectingDuration = true ; - runSimplifiedMutationRangeTest(new PlanMutateTimeAllocationSimplified( 750, affectingDuration, MatsimRandom.getLocalInstance(),24*3600,false,1), 750); - runSimplifiedMutationRangeTest(new PlanMutateTimeAllocationSimplified( 7200, affectingDuration, MatsimRandom.getLocalInstance(),24*3600,false,1), 7200); + runSimplifiedMutationRangeTest(new MutateActivityTimeAllocation( 750, affectingDuration, MatsimRandom.getLocalInstance(),24*3600,false,1), 750); + runSimplifiedMutationRangeTest(new MutateActivityTimeAllocation( 7200, affectingDuration, MatsimRandom.getLocalInstance(),24*3600,false,1), 7200); } /** diff --git a/matsim/src/test/java/org/matsim/population/algorithms/TripPlanMutateTimeAllocationTest.java b/matsim/src/test/java/org/matsim/population/algorithms/TripPlanMutateTimeAllocationTest.java index 9e60c754881..a7f0f07b22c 100644 --- a/matsim/src/test/java/org/matsim/population/algorithms/TripPlanMutateTimeAllocationTest.java +++ b/matsim/src/test/java/org/matsim/population/algorithms/TripPlanMutateTimeAllocationTest.java @@ -30,7 +30,7 @@ import org.matsim.api.core.v01.population.PlanElement; import org.matsim.core.population.PersonUtils; import org.matsim.core.population.PopulationUtils; -import org.matsim.core.population.algorithms.PlanMutateTimeAllocationSimplified; +import org.matsim.core.population.algorithms.MutateActivityTimeAllocation; import org.matsim.pt.PtConstants; import java.util.Random; @@ -66,8 +66,8 @@ public void testRun() { PopulationUtils.createAndAddActivityFromCoord(plan, "work", new Coord(0, 500)); boolean affectingDuration = true ; - PlanMutateTimeAllocationSimplified mutator = - new PlanMutateTimeAllocationSimplified( + MutateActivityTimeAllocation mutator = + new MutateActivityTimeAllocation( 3600., affectingDuration, new Random(2011),24*3600,false,1); mutator.run(plan); @@ -110,8 +110,8 @@ public void testRunLatestEndTime() { boolean affectingDuration = true; final double latestEndTime = 30. * 3600; - PlanMutateTimeAllocationSimplified mutator = - new PlanMutateTimeAllocationSimplified( + MutateActivityTimeAllocation mutator = + new MutateActivityTimeAllocation( 3600., affectingDuration, new Random(2011),latestEndTime,false,1);