MATSIM
PlanMutateTimeAllocationSimplified.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * PlanMutateTimeAllocation.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2007, 2008 by the members listed in the COPYING, *
8  * LICENSE and WARRANTY file. *
9  * email : info at matsim dot org *
10  * *
11  * *********************************************************************** *
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * See also COPYING, LICENSE and WARRANTY file *
18  * *
19  * *********************************************************************** */
20 
21 package org.matsim.core.population.algorithms;
22 
23 import java.util.Random;
24 
29 
39 public final class PlanMutateTimeAllocationSimplified implements PlanAlgorithm {
40 
42  private final double mutationRange;
43  private final Random random;
44  private final boolean affectingDuration;
45 
52  public PlanMutateTimeAllocationSimplified(final double mutationRange, boolean affectingDuration, final Random random) {
54  }
61  public PlanMutateTimeAllocationSimplified(final StageActivityHandling stageActivityHandling, final double mutationRange, boolean affectingDuration, final Random random) {
62  this.stageActivityHandling = stageActivityHandling;
63  this.mutationRange = mutationRange;
64  this.affectingDuration = affectingDuration;
65  this.random = random;
66  }
67 
68  @Override
69  public void run(final Plan plan) {
70  for ( Activity act : TripStructureUtils.getActivities( plan , stageActivityHandling ) ) {
71  // this is deliberately simplistic. Cleanup up of the time information should be done somewhere else.
72  if (act.getEndTime().isDefined()) {
73  act.setEndTime(mutateTime(act.getEndTime().seconds()));
74  }
75  if ( affectingDuration ) {
76  if ( act.getMaximumDuration().isDefined()) {
77  act.setMaximumDuration(mutateTime(act.getMaximumDuration().seconds()));
78  }
79  }
80  }
81  // the legs are not doing anything. kai, jun'12
82  }
83 
84  private double mutateTime(final double time) {
85  double t = time;
86  t = t + (int)((this.random.nextDouble() * 2.0 - 1.0) * this.mutationRange);
87 
88  if (t < 0) {
89  t = 0;
90  }
91  // note that this also affects duration
92 
93  return t;
94  }
95 
96 }
static List< Activity > getActivities(final Plan plan, final StageActivityHandling stageActivityHandling)
PlanMutateTimeAllocationSimplified(final double mutationRange, boolean affectingDuration, final Random random)
PlanMutateTimeAllocationSimplified(final StageActivityHandling stageActivityHandling, final double mutationRange, boolean affectingDuration, final Random random)