mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
add option to get activities from job
This commit is contained in:
parent
47566d750c
commit
dd3f29b5cc
6 changed files with 147 additions and 24 deletions
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Licensed to GraphHopper GmbH under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with this work for
|
||||
* additional information regarding copyright ownership.
|
||||
*
|
||||
* GraphHopper GmbH licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.graphhopper.jsprit.core.problem.job;
|
||||
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class Activity {
|
||||
|
||||
public enum Type {
|
||||
PICKUP, DELIVERY, SERVICE
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private final Type activityType;
|
||||
|
||||
private Location location;
|
||||
|
||||
Collection<TimeWindow> timeWindows;
|
||||
|
||||
private double serviceTime;
|
||||
|
||||
public Builder(Location location, Type activityType) {
|
||||
this.location = location;
|
||||
this.activityType = activityType;
|
||||
}
|
||||
|
||||
public Builder setTimeWindows(Collection<TimeWindow> timeWindows) {
|
||||
this.timeWindows = timeWindows;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setServiceTime(double serviceTime) {
|
||||
this.serviceTime = serviceTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Activity build() {
|
||||
return new Activity(this);
|
||||
}
|
||||
}
|
||||
|
||||
private Location location;
|
||||
|
||||
private Collection<TimeWindow> timeWindows;
|
||||
|
||||
private double serviceTime;
|
||||
|
||||
private Activity.Type activityType;
|
||||
|
||||
Activity(Builder builder) {
|
||||
location = builder.location;
|
||||
timeWindows = builder.timeWindows;
|
||||
serviceTime = builder.serviceTime;
|
||||
activityType = builder.activityType;
|
||||
}
|
||||
|
||||
public Type getActivityType() {
|
||||
return activityType;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public Collection<TimeWindow> getTimeWindows() {
|
||||
return timeWindows;
|
||||
}
|
||||
|
||||
public double getServiceTime() {
|
||||
return serviceTime;
|
||||
}
|
||||
}
|
||||
|
|
@ -23,6 +23,8 @@ import com.graphhopper.jsprit.core.problem.HasId;
|
|||
import com.graphhopper.jsprit.core.problem.HasIndex;
|
||||
import com.graphhopper.jsprit.core.problem.Skills;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Basic interface for all jobs.
|
||||
*
|
||||
|
|
@ -36,23 +38,23 @@ public interface Job extends HasId, HasIndex {
|
|||
*
|
||||
* @return id
|
||||
*/
|
||||
public String getId();
|
||||
String getId();
|
||||
|
||||
/**
|
||||
* Returns size, i.e. capacity-demand, of this job which can consist of an arbitrary number of capacity dimensions.
|
||||
*
|
||||
* @return Capacity
|
||||
*/
|
||||
public Capacity getSize();
|
||||
Capacity getSize();
|
||||
|
||||
public Skills getRequiredSkills();
|
||||
Skills getRequiredSkills();
|
||||
|
||||
/**
|
||||
* Returns name.
|
||||
*
|
||||
* @return name
|
||||
*/
|
||||
public String getName();
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Get priority of job. Only 1 (very high) to 10 (very low) are allowed.
|
||||
|
|
@ -61,8 +63,10 @@ public interface Job extends HasId, HasIndex {
|
|||
*
|
||||
* @return priority
|
||||
*/
|
||||
public int getPriority();
|
||||
int getPriority();
|
||||
|
||||
public double getMaxTimeInVehicle();
|
||||
double getMaxTimeInVehicle();
|
||||
|
||||
List<Activity> getActivities();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,9 @@ import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindows;
|
|||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindowsImpl;
|
||||
import com.graphhopper.jsprit.core.util.Coordinate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Service implementation of a job.
|
||||
|
|
@ -93,6 +95,8 @@ public class Service extends AbstractJob {
|
|||
|
||||
protected double maxTimeInVehicle = Double.MAX_VALUE;
|
||||
|
||||
private Activity activity;
|
||||
|
||||
Builder(String id){
|
||||
this.id = id;
|
||||
timeWindows = new TimeWindowsImpl();
|
||||
|
|
@ -209,6 +213,7 @@ public class Service extends AbstractJob {
|
|||
this.setType("service");
|
||||
capacity = capacityBuilder.build();
|
||||
skills = skillBuilder.build();
|
||||
activity = new Activity.Builder(location, Activity.Type.SERVICE).setServiceTime(serviceTime).setTimeWindows(timeWindows.getTimeWindows()).build();
|
||||
return (T) new Service(this);
|
||||
}
|
||||
|
||||
|
|
@ -282,6 +287,8 @@ public class Service extends AbstractJob {
|
|||
|
||||
private final double maxTimeInVehicle;
|
||||
|
||||
private List<Activity> activities = new ArrayList<>();
|
||||
|
||||
Service(Builder<?> builder) {
|
||||
setUserData(builder.userData);
|
||||
id = builder.id;
|
||||
|
|
@ -294,6 +301,7 @@ public class Service extends AbstractJob {
|
|||
timeWindows = builder.timeWindows;
|
||||
priority = builder.priority;
|
||||
maxTimeInVehicle = builder.maxTimeInVehicle;
|
||||
activities.add(builder.activity);
|
||||
}
|
||||
|
||||
public Collection<TimeWindow> getTimeWindows(){
|
||||
|
|
@ -414,4 +422,9 @@ public class Service extends AbstractJob {
|
|||
return this.maxTimeInVehicle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Activity> getActivities() {
|
||||
return activities;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,9 @@ import com.graphhopper.jsprit.core.problem.Skills;
|
|||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindowsImpl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -46,8 +48,6 @@ import java.util.Collection;
|
|||
public class Shipment extends AbstractJob {
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Builder that builds the shipment.
|
||||
*
|
||||
|
|
@ -89,6 +89,10 @@ public class Shipment extends AbstractJob {
|
|||
|
||||
public double maxTimeInVehicle = Double.MAX_VALUE;
|
||||
|
||||
private Activity pickup;
|
||||
|
||||
private Activity delivery;
|
||||
|
||||
/**
|
||||
* Returns new instance of this builder.
|
||||
*
|
||||
|
|
@ -252,6 +256,8 @@ public class Shipment extends AbstractJob {
|
|||
if (deliveryLocation_ == null) throw new IllegalArgumentException("The delivery location is missing.");
|
||||
capacity = capacityBuilder.build();
|
||||
skills = skillBuilder.build();
|
||||
pickup = new Activity.Builder(pickupLocation_, Activity.Type.PICKUP).setServiceTime(pickupServiceTime).setTimeWindows(pickupTimeWindows.getTimeWindows()).build();
|
||||
delivery = new Activity.Builder(deliveryLocation_, Activity.Type.DELIVERY).setServiceTime(deliveryServiceTime).setTimeWindows(deliveryTimeWindows.getTimeWindows()).build();
|
||||
return new Shipment(this);
|
||||
}
|
||||
|
||||
|
|
@ -368,6 +374,8 @@ public class Shipment extends AbstractJob {
|
|||
|
||||
private final double maxTimeInVehicle;
|
||||
|
||||
private List<Activity> activities = new ArrayList<>();
|
||||
|
||||
Shipment(Builder builder) {
|
||||
setUserData(builder.userData);
|
||||
this.id = builder.id;
|
||||
|
|
@ -382,6 +390,8 @@ public class Shipment extends AbstractJob {
|
|||
this.pickupTimeWindows = builder.pickupTimeWindows;
|
||||
this.priority = builder.priority;
|
||||
this.maxTimeInVehicle = builder.maxTimeInVehicle;
|
||||
activities.add(builder.pickup);
|
||||
activities.add(builder.delivery);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -520,4 +530,9 @@ public class Shipment extends AbstractJob {
|
|||
public double getMaxTimeInVehicle() {
|
||||
return maxTimeInVehicle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Activity> getActivities() {
|
||||
return activities;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,9 +31,9 @@ import com.graphhopper.jsprit.core.problem.job.Job;
|
|||
*/
|
||||
public interface TourActivity extends HasIndex {
|
||||
|
||||
public void setTheoreticalEarliestOperationStartTime(double earliest);
|
||||
void setTheoreticalEarliestOperationStartTime(double earliest);
|
||||
|
||||
public void setTheoreticalLatestOperationStartTime(double latest);
|
||||
void setTheoreticalLatestOperationStartTime(double latest);
|
||||
|
||||
/**
|
||||
* Basic interface of job-activies.
|
||||
|
|
@ -42,14 +42,14 @@ public interface TourActivity extends HasIndex {
|
|||
*
|
||||
* @author schroeder
|
||||
*/
|
||||
public interface JobActivity extends TourActivity {
|
||||
interface JobActivity extends TourActivity {
|
||||
|
||||
/**
|
||||
* Returns the job that is involved with this activity.
|
||||
*
|
||||
* @return job
|
||||
*/
|
||||
public Job getJob();
|
||||
Job getJob();
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -58,14 +58,14 @@ public interface TourActivity extends HasIndex {
|
|||
*
|
||||
* @return name
|
||||
*/
|
||||
public abstract String getName();
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Returns location.
|
||||
*
|
||||
* @return location
|
||||
*/
|
||||
public abstract Location getLocation();
|
||||
Location getLocation();
|
||||
|
||||
/**
|
||||
* Returns the theoretical earliest operation start time, which is the time that is just allowed
|
||||
|
|
@ -73,7 +73,7 @@ public interface TourActivity extends HasIndex {
|
|||
*
|
||||
* @return earliest start time
|
||||
*/
|
||||
public abstract double getTheoreticalEarliestOperationStartTime();
|
||||
double getTheoreticalEarliestOperationStartTime();
|
||||
|
||||
/**
|
||||
* Returns the theoretical latest operation start time, which is the time that is just allowed
|
||||
|
|
@ -81,7 +81,7 @@ public interface TourActivity extends HasIndex {
|
|||
*
|
||||
* @return latest start time
|
||||
*/
|
||||
public abstract double getTheoreticalLatestOperationStartTime();
|
||||
double getTheoreticalLatestOperationStartTime();
|
||||
|
||||
/**
|
||||
* Returns the operation-time this activity takes.
|
||||
|
|
@ -91,35 +91,35 @@ public interface TourActivity extends HasIndex {
|
|||
*
|
||||
* @return operation time
|
||||
*/
|
||||
public abstract double getOperationTime();
|
||||
double getOperationTime();
|
||||
|
||||
/**
|
||||
* Returns the arrival-time of this activity.
|
||||
*
|
||||
* @return arrival time
|
||||
*/
|
||||
public abstract double getArrTime();
|
||||
double getArrTime();
|
||||
|
||||
/**
|
||||
* Returns end-time of this activity.
|
||||
*
|
||||
* @return end time
|
||||
*/
|
||||
public abstract double getEndTime();
|
||||
double getEndTime();
|
||||
|
||||
/**
|
||||
* Sets the arrival time of that activity.
|
||||
*
|
||||
* @param arrTime
|
||||
*/
|
||||
public abstract void setArrTime(double arrTime);
|
||||
void setArrTime(double arrTime);
|
||||
|
||||
/**
|
||||
* Sets the end-time of this activity.
|
||||
*
|
||||
* @param endTime
|
||||
*/
|
||||
public abstract void setEndTime(double endTime);
|
||||
void setEndTime(double endTime);
|
||||
|
||||
/**
|
||||
* Returns the capacity-demand of that activity, in terms of what needs to be loaded or unloaded at
|
||||
|
|
@ -127,13 +127,13 @@ public interface TourActivity extends HasIndex {
|
|||
*
|
||||
* @return capacity
|
||||
*/
|
||||
public abstract Capacity getSize();
|
||||
Capacity getSize();
|
||||
|
||||
/**
|
||||
* Makes a deep copy of this activity.
|
||||
*
|
||||
* @return copied activity
|
||||
*/
|
||||
public abstract TourActivity duplicate();
|
||||
TourActivity duplicate();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import com.graphhopper.jsprit.analysis.toolbox.GraphStreamViewer.Label;
|
|||
import com.graphhopper.jsprit.analysis.toolbox.Plotter;
|
||||
import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
import com.graphhopper.jsprit.core.algorithm.box.Jsprit;
|
||||
import com.graphhopper.jsprit.core.algorithm.box.SchrimpfFactory;
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
||||
import com.graphhopper.jsprit.core.problem.job.Service;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue