From dd2c7625b44ee10b00a019ea20a29b4d67a7c4f1 Mon Sep 17 00:00:00 2001 From: oblonski <4sschroeder@gmail.com> Date: Thu, 4 Sep 2014 19:19:49 +0200 Subject: [PATCH] move core.problem.misc.JobInsertionContext.ActivityContext to new type --- .../recreate/ShipmentInsertionCalculator.java | 3 +- .../core/problem/misc/ActivityContext.java | 94 +++++++++++++++++++ .../problem/misc/JobInsertionContext.java | 78 +-------------- .../problem/misc/JobInsertionContextTest.java | 2 +- 4 files changed, 98 insertions(+), 79 deletions(-) create mode 100644 jsprit-core/src/main/java/jsprit/core/problem/misc/ActivityContext.java diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ShipmentInsertionCalculator.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ShipmentInsertionCalculator.java index 33d8fa8e..d7b20881 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ShipmentInsertionCalculator.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ShipmentInsertionCalculator.java @@ -23,6 +23,7 @@ import jsprit.core.problem.cost.VehicleRoutingTransportCosts; import jsprit.core.problem.driver.Driver; import jsprit.core.problem.job.Job; import jsprit.core.problem.job.Shipment; +import jsprit.core.problem.misc.ActivityContext; import jsprit.core.problem.misc.JobInsertionContext; import jsprit.core.problem.solution.route.VehicleRoute; import jsprit.core.problem.solution.route.activity.End; @@ -115,7 +116,7 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{ End end = End.newInstance(newVehicle.getEndLocationId(), 0.0, newVehicle.getLatestArrival()); - JobInsertionContext.ActivityContext pickupContext = new JobInsertionContext.ActivityContext(); + ActivityContext pickupContext = new ActivityContext(); TourActivity prevAct = start; double prevActEndTime = newVehicleDepartureTime; diff --git a/jsprit-core/src/main/java/jsprit/core/problem/misc/ActivityContext.java b/jsprit-core/src/main/java/jsprit/core/problem/misc/ActivityContext.java new file mode 100644 index 00000000..ea64de7d --- /dev/null +++ b/jsprit-core/src/main/java/jsprit/core/problem/misc/ActivityContext.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (C) 2014 Stefan Schroeder + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + ******************************************************************************/ + +package jsprit.core.problem.misc; + +/** + * Provides insertion context information about a particular activity. + */ +public class ActivityContext { + + private double arrivalTime; + + private double endTime; + + private int insertionIndex; + + /** + * Returns arrival time at associated activity. + * + * @return arrival time + */ + public double getArrivalTime() { + return arrivalTime; + } + + /** + * Returns end time of associated activity. + * + * @return end time + */ + public double getEndTime() { + return endTime; + } + + /** + * Returns the insertion index of the associated vehicle. + * + *

The associated activity is not inserted yet. The actual insertion position is still to be evaluated. + * Thus this insertion index is related to the potential insertion index which is the position before + * the activity at this index in the existing route. + * + * if insertionIndex == 0, the associated activity will be inserted between start of vehicle and the first + * activity in activity sequence. + * + * if insertionIndex == relatedRoute.getActivities().size(), the associated activity will be inserted between + * the last activity in the activity sequence and the end of vehicle. + * + * @return insertion index + */ + public int getInsertionIndex() { + return insertionIndex; + } + + /** + * Sets arrivalTime of associated vehicle at activity. + * + * @param arrivalTime arrival time of associated vehicle at activity + */ + public void setArrivalTime(double arrivalTime) { + this.arrivalTime = arrivalTime; + } + + /** + * Sets end time of associated activity. + * + * @param endTime end time + */ + public void setEndTime(double endTime) { + this.endTime = endTime; + } + + /** + * Sets insertion index of associated activity. + * + * @param insertionIndex insertion index of associated activity + */ + public void setInsertionIndex(int insertionIndex) { + this.insertionIndex = insertionIndex; + } +} diff --git a/jsprit-core/src/main/java/jsprit/core/problem/misc/JobInsertionContext.java b/jsprit-core/src/main/java/jsprit/core/problem/misc/JobInsertionContext.java index 9be74548..749ee8a7 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/misc/JobInsertionContext.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/misc/JobInsertionContext.java @@ -31,83 +31,7 @@ import java.util.List; */ public class JobInsertionContext { - /** - * Provides insertion context information about a particular activity. - */ - public static class ActivityContext { - - private double arrivalTime; - - private double endTime; - - private int insertionIndex; - - /** - * Returns arrival time at associated activity. - * - * @return arrival time - */ - public double getArrivalTime() { - return arrivalTime; - } - - /** - * Returns end time of associated activity. - * - * @return end time - */ - public double getEndTime() { - return endTime; - } - - /** - * Returns the insertion index of the associated vehicle. - * - *

The associated activity is not inserted yet. The actual insertion position is still to be evaluated. - * Thus this insertion index is related to the potential insertion index which is the position before - * the activity at this index in the existing route. - * - * if insertionIndex == 0, the associated activity will be inserted between start of vehicle and the first - * activity in activity sequence. - * - * if insertionIndex == relatedRoute.getActivities().size(), the associated activity will be inserted between - * the last activity in the activity sequence and the end of vehicle. - * - * @return insertion index - */ - public int getInsertionIndex() { - return insertionIndex; - } - - /** - * Sets arrivalTime of associated vehicle at activity. - * - * @param arrivalTime arrival time of associated vehicle at activity - */ - public void setArrivalTime(double arrivalTime) { - this.arrivalTime = arrivalTime; - } - - /** - * Sets end time of associated activity. - * - * @param endTime end time - */ - public void setEndTime(double endTime) { - this.endTime = endTime; - } - - /** - * Sets insertion index of associated activity. - * - * @param insertionIndex insertion index of associated activity - */ - public void setInsertionIndex(int insertionIndex) { - this.insertionIndex = insertionIndex; - } - } - - private VehicleRoute route; + private VehicleRoute route; private Job job; diff --git a/jsprit-core/src/test/java/jsprit/core/problem/misc/JobInsertionContextTest.java b/jsprit-core/src/test/java/jsprit/core/problem/misc/JobInsertionContextTest.java index 91b04b6e..37f6cb44 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/misc/JobInsertionContextTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/misc/JobInsertionContextTest.java @@ -88,7 +88,7 @@ public class JobInsertionContextTest { @Test public void relatedActivityContextShouldBeAssigned(){ - context.setRelatedActivityContext(mock(JobInsertionContext.ActivityContext.class)); + context.setRelatedActivityContext(mock(ActivityContext.class)); assertNotNull(context.getRelatedActivityContext()); }