1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

partially removed deprecated code (vehicle summery is still to do)

This commit is contained in:
Balázs Vissy 2017-06-29 23:42:15 +02:00
parent 4fb9f7d5d6
commit 1dd12467ff
37 changed files with 15 additions and 2133 deletions

3
.gitignore vendored
View file

@ -11,4 +11,5 @@
# Eclipse
.project
.classpath
.classpath
jsprit-core/src/main/java/com/graphhopper/jsprit/core/reporting/SolutionPrinter_depr.java

View file

@ -1,196 +0,0 @@
package com.graphhopper.jsprit.core.reporting.columndefinition;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import com.graphhopper.jsprit.core.reporting.AbstractPrinterColumn;
import com.graphhopper.jsprit.core.reporting.PrinterColumnList;
import com.graphhopper.jsprit.core.reporting.route.ActivityCostPrinterColumn;
import com.graphhopper.jsprit.core.reporting.route.ActivityDurationPrinterColumn;
import com.graphhopper.jsprit.core.reporting.route.ActivityLoadChangePrinterColumn;
import com.graphhopper.jsprit.core.reporting.route.ActivityTypePrinterColumn;
import com.graphhopper.jsprit.core.reporting.route.ArrivalTimePrinterColumn;
import com.graphhopper.jsprit.core.reporting.route.EndTimePrinterColumn;
import com.graphhopper.jsprit.core.reporting.route.JobNamePrinterColumn;
import com.graphhopper.jsprit.core.reporting.route.JobPriorityPrinterColumn;
import com.graphhopper.jsprit.core.reporting.route.JobTypePrinterColumn;
import com.graphhopper.jsprit.core.reporting.route.LoacationPrinterColumn;
import com.graphhopper.jsprit.core.reporting.route.OperationDurationPrinterColumn;
import com.graphhopper.jsprit.core.reporting.route.RouteCostPrinterColumn;
import com.graphhopper.jsprit.core.reporting.route.RouteLoadPrinterColumn;
import com.graphhopper.jsprit.core.reporting.route.RouteNumberPrinterColumn;
import com.graphhopper.jsprit.core.reporting.route.RoutePrinterContext;
import com.graphhopper.jsprit.core.reporting.route.SelectedTimeWindowPrinterColumn;
import com.graphhopper.jsprit.core.reporting.route.StartTimePrinterColumn;
import com.graphhopper.jsprit.core.reporting.route.TimeWindowsPrinterColumn;
import com.graphhopper.jsprit.core.reporting.route.TransportCostPrinterColumn;
import com.graphhopper.jsprit.core.reporting.route.TravelDurationPrinterColumn;
import com.graphhopper.jsprit.core.reporting.route.VehicleNamePrinterColumn;
import com.graphhopper.jsprit.core.reporting.route.WaitingDurationPrinterColumn;
/**
* Utility class to provide predefined column lists for Solution printing.
*
* @author balage
*
*/
public class SolutionPrintColumnLists {
/**
* The predefined column sets.
*
* @author balage
*
*/
public enum PredefinedList {
/**
* A minimal column set.
*/
MINIMAL,
/**
* A general, most often used column set.
*/
DEFAULT,
/**
* A verbose column set containing all columns.
*/
VERBOSE
}
private static final EnumMap<PredefinedList, List<Class<? extends AbstractPrinterColumn<RoutePrinterContext, ?, ?>>>> COLUMNS;
static {
COLUMNS = new EnumMap<>(PredefinedList.class);
List<Class<? extends AbstractPrinterColumn<RoutePrinterContext, ?, ?>>> minimalSet = new ArrayList<>();
minimalSet.add(RouteNumberPrinterColumn.class);
minimalSet.add(VehicleNamePrinterColumn.class);
minimalSet.add(ActivityTypePrinterColumn.class);
minimalSet.add(JobNamePrinterColumn.class);
minimalSet.add(ArrivalTimePrinterColumn.class);
minimalSet.add(EndTimePrinterColumn.class);
minimalSet.add(RouteCostPrinterColumn.class);
COLUMNS.put(PredefinedList.MINIMAL, minimalSet);
List<Class<? extends AbstractPrinterColumn<RoutePrinterContext, ?, ?>>> defaultSet = new ArrayList<>();
defaultSet.add(RouteNumberPrinterColumn.class);
defaultSet.add(VehicleNamePrinterColumn.class);
defaultSet.add(ActivityTypePrinterColumn.class);
defaultSet.add(JobNamePrinterColumn.class);
defaultSet.add(LoacationPrinterColumn.class);
defaultSet.add(ActivityLoadChangePrinterColumn.class);
defaultSet.add(OperationDurationPrinterColumn.class);
defaultSet.add(ArrivalTimePrinterColumn.class);
defaultSet.add(StartTimePrinterColumn.class);
defaultSet.add(EndTimePrinterColumn.class);
defaultSet.add(ActivityCostPrinterColumn.class);
defaultSet.add(RouteCostPrinterColumn.class);
COLUMNS.put(PredefinedList.DEFAULT, defaultSet);
List<Class<? extends AbstractPrinterColumn<RoutePrinterContext, ?, ?>>> verboseSet = new ArrayList<>();
verboseSet.add(RouteNumberPrinterColumn.class);
verboseSet.add(VehicleNamePrinterColumn.class);
verboseSet.add(ActivityTypePrinterColumn.class);
verboseSet.add(JobNamePrinterColumn.class);
verboseSet.add(JobTypePrinterColumn.class);
verboseSet.add(JobPriorityPrinterColumn.class);
verboseSet.add(LoacationPrinterColumn.class);
verboseSet.add(ActivityLoadChangePrinterColumn.class);
verboseSet.add(RouteLoadPrinterColumn.class);
verboseSet.add(TimeWindowsPrinterColumn.class);
verboseSet.add(OperationDurationPrinterColumn.class);
verboseSet.add(TravelDurationPrinterColumn.class);
verboseSet.add(WaitingDurationPrinterColumn.class);
verboseSet.add(ActivityDurationPrinterColumn.class);
verboseSet.add(ArrivalTimePrinterColumn.class);
verboseSet.add(StartTimePrinterColumn.class);
verboseSet.add(EndTimePrinterColumn.class);
verboseSet.add(SelectedTimeWindowPrinterColumn.class);
verboseSet.add(TransportCostPrinterColumn.class);
verboseSet.add(ActivityCostPrinterColumn.class);
verboseSet.add(RouteCostPrinterColumn.class);
COLUMNS.put(PredefinedList.VERBOSE, verboseSet);
}
/**
* Returns the predefined column set with all time, time window and duration
* columns printed as numbers.
*
* @param listType
* The predefined list id.
* @return The column list containing the predefined columns.
*/
public static PrinterColumnList<RoutePrinterContext> getNumeric(PredefinedList listType) {
return getList(listType, false, null);
}
/**
* Returns the predefined column set with all time, time window and duration
* columns printed with human readable format, using default formatting.
*
* @param listType
* The predefined list id.
* @return The column list containing the predefined columns.
*/
public static PrinterColumnList<RoutePrinterContext> getHumanReadable(PredefinedList listType) {
return getList(listType, true, null);
}
/**
* Returns the predefined column set with all time, time window and duration
* columns printed with human readable format, using the provided formatter.
*
* @param listType
* The predefined list id.
* @param timeFormatter
* the time formatter to use
* @return The column list containing the predefined columns.
*/
public static PrinterColumnList<RoutePrinterContext> getHumanReadable(PredefinedList listType,
HumanReadableTimeFormatter timeFormatter) {
return getList(listType, true, timeFormatter);
}
/**
* Generates the list.
*
* @param listType
* The id of the list.
* @param humanReadable
* Whether human readable format should be used
* @param timeFormatter
* The formatter to use (if null, the default will be used)
* @return The generated column list.
*/
private static PrinterColumnList<RoutePrinterContext> getList(PredefinedList listType, boolean humanReadable,
HumanReadableTimeFormatter timeFormatter) {
PrinterColumnList<RoutePrinterContext> res = new PrinterColumnList<>();
for (Class<? extends AbstractPrinterColumn<RoutePrinterContext, ?, ?>> c : COLUMNS.get(listType)) {
try {
AbstractPrinterColumn<RoutePrinterContext, ?, ?> col = c.newInstance();
if (humanReadable && col instanceof HumanReadableEnabled) {
HumanReadableEnabled<?> hrCol = (HumanReadableEnabled<?>) col;
hrCol.asHumanReadable();
if (timeFormatter != null) {
hrCol.withFormatter(timeFormatter);
}
}
res.addColumn(col);
} catch (InstantiationException | IllegalAccessException e) {
// Technically you can't get here as long as all column
// implementation has default constructor
throw new IllegalStateException(e);
}
}
return res;
}
}

View file

@ -1,53 +0,0 @@
package com.graphhopper.jsprit.core.reporting.job;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.problem.job.AbstractJob;
import com.graphhopper.jsprit.core.problem.job.Job;
import com.graphhopper.jsprit.core.reporting.AbstractPrinterColumn;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
import com.graphhopper.jsprit.core.reporting.columndefinition.StringColumnType;
/**
* Name (id) of the job.
*
* <p>
* This column provides the {@linkplain Job#getId()} of the associated job of
* the activity for job activities and null for other route activities.
* </p>
*
* @author balage
*/
public class JobNamePrinterColumn<T extends JobPrinterContext> extends AbstractPrinterColumn<T, String, JobNamePrinterColumn<T>> {
/**
* Constructor.
*/
public JobNamePrinterColumn() {
super();
}
/**
* Constructor with a post creation decorator provided.
*/
public JobNamePrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
public ColumnDefinition.Builder getColumnBuilder() {
return new ColumnDefinition.Builder(new StringColumnType("-"));
}
@Override
protected String getDefaultTitle() {
return "job name";
}
@Override
public String getData(T context) {
AbstractJob job = context.getJob();
return job == null ? null : job.getId();
}
}

View file

@ -1,58 +0,0 @@
package com.graphhopper.jsprit.core.reporting.job;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.problem.job.AbstractJob;
import com.graphhopper.jsprit.core.problem.job.Job;
import com.graphhopper.jsprit.core.reporting.AbstractPrinterColumn;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnAlignment;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
import com.graphhopper.jsprit.core.reporting.columndefinition.StringColumnType;
/**
* Priority of the job.
*
* <p>
* This column provides the named (LOW, MEDIUM, HIGH) representation of
* {@linkplain Job#getPriority()} of the associated job of the activity for job
* activities and null for other route activities.
* </p>
*
* @author balage
*/
public class JobPriorityPrinterColumn<T extends JobPrinterContext>
extends AbstractPrinterColumn<T, String, JobPriorityPrinterColumn<T>> {
private static final String[] PRIORITY_NAMES = new String[] { "", "HIGH", "MEDIUM", "LOW" };
/**
* Constructor.
*/
public JobPriorityPrinterColumn() {
super();
}
/**
* Constructor with a post creation decorator provided.
*/
public JobPriorityPrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
public ColumnDefinition.Builder getColumnBuilder() {
return new ColumnDefinition.Builder(new StringColumnType("-")).withAlignment(ColumnAlignment.CENTER);
}
@Override
protected String getDefaultTitle() {
return "priority";
}
@Override
public String getData(T context) {
AbstractJob job = context.getJob();
return job == null ? null : PRIORITY_NAMES[job.getPriority()];
}
}

View file

@ -1,52 +0,0 @@
package com.graphhopper.jsprit.core.reporting.job;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.problem.job.AbstractJob;
import com.graphhopper.jsprit.core.reporting.AbstractPrinterColumn;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
import com.graphhopper.jsprit.core.reporting.columndefinition.StringColumnType;
/**
* Priority of the job.
*
* <p>
* This column provides the simple class name of the associated job of the
* activity for job activities and null for other route activities.
* </p>
*
* @author balage
*/
public class JobTypePrinterColumn<T extends JobPrinterContext> extends AbstractPrinterColumn<T, String, JobTypePrinterColumn<T>> {
/**
* Constructor.
*/
public JobTypePrinterColumn() {
super();
}
/**
* Constructor with a post creation decorator provided.
*/
public JobTypePrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
public ColumnDefinition.Builder getColumnBuilder() {
return new ColumnDefinition.Builder(new StringColumnType("-"));
}
@Override
protected String getDefaultTitle() {
return "job type";
}
@Override
public String getData(JobPrinterContext context) {
AbstractJob job = context.getJob();
return job == null ? null : job.getClass().getSimpleName();
}
}

View file

@ -1,38 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.reporting.AbstractPrinterColumn;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnAlignment;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
import com.graphhopper.jsprit.core.reporting.columndefinition.IntColumnType;
/**
* Abstract base class for cost calculators.
*
* <p>
* this implementation only defines the ColumnDefinition as a right aligned
* integer column.
* </p>
*
* @author balage
*
*/
public abstract class AbstractCostPrinterColumn
extends AbstractPrinterColumn<RoutePrinterContext, Integer, AbstractCostPrinterColumn>
implements CostAndTimeExtractor {
public AbstractCostPrinterColumn() {
super();
}
public AbstractCostPrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
public ColumnDefinition.Builder getColumnBuilder() {
return new ColumnDefinition.Builder(new IntColumnType()).withAlignment(ColumnAlignment.RIGHT);
}
}

View file

@ -1,36 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
import com.graphhopper.jsprit.core.reporting.columndefinition.HumanReadableDurationFormatter;
/**
* Abstract base class for duration columns.
*
* @author balage
*
* @param <T>
* Self reference.
* @See {@linkplain AbstractTimePrinterColumn}
*/
public abstract class AbstractDurationPrinterColumn<T extends AbstractDurationPrinterColumn<T>>
extends AbstractTimePrinterColumn<T> {
/**
* Constructor to define a numeric format column.
*/
public AbstractDurationPrinterColumn() {
this(null);
}
/**
* Constructor to define a numeric format column, with a post creation
* decorator provided.
*/
public AbstractDurationPrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
withFormatter(new HumanReadableDurationFormatter());
}
}

View file

@ -1,85 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import com.graphhopper.jsprit.core.problem.SizeDimension;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
import com.graphhopper.jsprit.core.reporting.AbstractPrinterColumn;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
import com.graphhopper.jsprit.core.reporting.columndefinition.HumanReadableTimeFormatter;
import com.graphhopper.jsprit.core.reporting.columndefinition.StringColumnType;
/**
* Abstract base class for size columns.
*
* <p>
* The representation of a size is the dimension values listed comma separated
* and wrapped by brackets. (For example: [2, 0, -1])
* </p>
*
* @author balage
*
* @See {@linkplain HumanReadableTimeFormatter}
*/
public abstract class AbstractSizeDimensionPrinterColumn
extends AbstractPrinterColumn<RoutePrinterContext, String, AbstractSizeDimensionPrinterColumn> {
/**
* Constructor.
*/
public AbstractSizeDimensionPrinterColumn() {
super();
}
/**
* Constructor with a post creation decorator provided.
*/
public AbstractSizeDimensionPrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
public ColumnDefinition.Builder getColumnBuilder() {
return new ColumnDefinition.Builder(new StringColumnType());
}
/**
* {@inheritDoc}
*
* <p>
* The result is a string representation of the size (the dimension values
* listed comma separated and wrapped by brackets) or null.
* </p>
*/
@Override
public String getData(RoutePrinterContext context) {
SizeDimension sd = getSizeDimension(context);
if (sd != null) {
return IntStream.range(0, sd.getNuOfDimensions()).mapToObj(i -> "" + sd.get(i))
.collect(Collectors.joining(", ", "[", "]"));
} else {
return null;
}
}
/**
* Extracts the size dimension.
*
* @param context
* The context.
* @return The size dimension or null.
*/
protected abstract SizeDimension getSizeDimension(RoutePrinterContext context);
protected SizeDimension calculateInitialLoad(RoutePrinterContext context) {
SizeDimension sd = SizeDimension.EMPTY;
for (TourActivity a : context.getRoute().getActivities()) {
sd = sd.add(a.getLoadChange());
}
sd = sd.getNegativeDimensions().abs();
return sd;
}
}

View file

@ -1,125 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.reporting.AbstractPrinterColumn;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
import com.graphhopper.jsprit.core.reporting.columndefinition.HumanReadableEnabled;
import com.graphhopper.jsprit.core.reporting.columndefinition.HumanReadableTimeFormatter;
import com.graphhopper.jsprit.core.reporting.columndefinition.StringColumnType;
/**
* Abstract base class for time and (technically) duration columns.
*
* <p>
* Each columns derived from this abstract base has two variants: a numerical
* (an integer value) and a human readable. The numerical value displays the
* integer value representing the time values internally. The human readable
* value converts this value into a calendar (date and time) value.
* </p>
*
* @author balage
*
* @param <T>
* Self reference.
* @See {@linkplain HumanReadableTimeFormatter}
*/
public abstract class AbstractTimePrinterColumn<T extends AbstractTimePrinterColumn<T>>
extends AbstractPrinterColumn<RoutePrinterContext, String, AbstractTimePrinterColumn<T>>
implements HumanReadableEnabled<T> {
// The time formatter to use (only used when humanReadable flag is true)
private HumanReadableTimeFormatter formatter;
// Whether to use human readable form
private boolean humanReadable = false;
/**
* Constructor to define a numeric format column.
*/
public AbstractTimePrinterColumn() {
this(null);
}
/**
* Constructor to define a numeric format column, with a post creation
* decorator provided.
*/
public AbstractTimePrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
formatter = new HumanReadableTimeFormatter();
}
/**
* {@inheritDoc}
*
*/
@Override
@SuppressWarnings("unchecked")
public T withFormatter(HumanReadableTimeFormatter formatter) {
this.formatter = formatter;
return (T) this;
}
/**
* {@inheritDoc}
*
*/
@Override
@SuppressWarnings("unchecked")
public T asHumanReadable() {
this.humanReadable = true;
return (T) this;
}
/**
* {@inheritDoc}
*
* <p>
* The column builder returned will be a string column with the null value
* represented by a hyphen ("-").
* </p>
*
*/
@Override
public ColumnDefinition.Builder getColumnBuilder() {
return new ColumnDefinition.Builder(new StringColumnType("-"));
}
/**
* {@inheritDoc}
*
* <p>
* The implementation delegates the value extracting to the abstract method
* {@linkplain #getValue(RoutePrinterContext)}.
* <p>
* <p>
* If the value is null, returns null, otherwise it returns the string
* representation of the numeric value or the human readable format based on
* the humanReadable flag.
* </p>
*
*/
@Override
public String getData(RoutePrinterContext context) {
Long timeValue = getValue(context);
if (timeValue == null) {
return null;
}
if (humanReadable) {
return formatter.format(timeValue);
} else {
return ""+timeValue;
}
}
/**
* Extracts the numerical value for this time or duration column.
*
* @param context
* The context.
* @return The numerical value or null.
*/
protected abstract Long getValue(RoutePrinterContext context);
}

View file

@ -1,145 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.Collection;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
import com.graphhopper.jsprit.core.reporting.AbstractPrinterColumn;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
import com.graphhopper.jsprit.core.reporting.columndefinition.HumanReadableEnabled;
import com.graphhopper.jsprit.core.reporting.columndefinition.HumanReadableTimeFormatter;
import com.graphhopper.jsprit.core.reporting.columndefinition.StringColumnType;
/**
* Abstract base class for time window columns.
*
* <p>
* Each columns derived from this abstract base has two variants: a numerical
* (an integer value) and a human readable. The numerical value displays the
* integer value pair representing the time windows, the same the algorithm used
* internally. The human readable value converts this value into a calendar
* (date and time) value pair.
* </p>
*
* @author balage
*
* @param <T>
* Self reference.
* @See {@linkplain HumanReadableTimeFormatter}
*/
public abstract class AbstractTimeWindowPrinterColumn<T extends AbstractTimeWindowPrinterColumn<T>>
extends AbstractPrinterColumn<RoutePrinterContext, String, AbstractTimeWindowPrinterColumn<T>>
implements HumanReadableEnabled<T> {
// The time formatter to use (only used when humanReadable flag is true)
private HumanReadableTimeFormatter formatter;
// Whether to use human readable form
private boolean humanReadable = false;
/**
* Constructor to define a numeric format column.
*/
public AbstractTimeWindowPrinterColumn() {
this(null);
}
/**
* Constructor to define a numeric format column, with a post creation
* decorator provided.
*/
public AbstractTimeWindowPrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
formatter = new HumanReadableTimeFormatter();
}
@Override
@SuppressWarnings("unchecked")
public T withFormatter(HumanReadableTimeFormatter formatter) {
this.formatter = formatter;
return (T) this;
}
@Override
@SuppressWarnings("unchecked")
public T asHumanReadable() {
this.humanReadable = true;
return (T) this;
}
@Override
public ColumnDefinition.Builder getColumnBuilder() {
return new ColumnDefinition.Builder(new StringColumnType("-"));
}
/**
* {@inheritDoc}
*
* <p>
* The implementation delegates the value extracting to the abstract method
* {@linkplain #getValue(RoutePrinterContext)}.
* <p>
* <p>
* If the value is null or empty, returns null, otherwise it returns the
* string representation of the numeric value or the human readable format
* based on the humanReadable flag.
* </p>
*
*/
@Override
public String getData(RoutePrinterContext context) {
Collection<TimeWindow> timeWindows = getValue(context);
if (timeWindows == null || timeWindows.isEmpty()) {
return null;
}
return timeWindows.stream().map(tw -> formatTimeWindow(tw)).collect(Collectors.joining());
}
/**
* Formats the time window.
*
* <p>
* The implementation returns the two (start, end) values sepratated by
* hyphen (-) and wrapped within brackets. When the end value is
* {@linkplain Double#MAX_VALUE} it omits the value indicating open
* interval.
* </p>
*
* @param tw
* The time window to format.
* @return The string representation of the time window.
*/
protected String formatTimeWindow(TimeWindow tw) {
String res = "";
if (humanReadable) {
res = "[" + formatter.format((long) tw.getStart()) + "-";
if (tw.getEnd() == Double.MAX_VALUE) {
res += "";
} else {
res += formatter.format((long) tw.getEnd());
}
res += "]";
} else {
res = "[" + (long) tw.getStart() + "-";
if (tw.getEnd() == Double.MAX_VALUE) {
res += "";
} else {
res += (long) tw.getEnd();
}
res += "]";
}
return res;
}
/**
* Extracts the collection of time windows from the context.
*
* @param context
* The context.
* @return The collection of time windows.
*/
protected abstract Collection<TimeWindow> getValue(RoutePrinterContext context);
}

View file

@ -1,40 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
/**
* Cost of the activity.
*
* @author balage
*
*/
public class ActivityCostPrinterColumn extends AbstractCostPrinterColumn {
/**
* Constructor.
*/
public ActivityCostPrinterColumn() {
super();
}
/**
* Constructor with a post creation decorator provided.
*/
public ActivityCostPrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
protected String getDefaultTitle() {
return "actCost";
}
@Override
public Integer getData(RoutePrinterContext context) {
return (int) getActivityCost(context);
}
}

View file

@ -1,66 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.problem.solution.route.activity.Start;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
/**
* Activity duration column.
* <p>
* The activity duration is the sum of the activity operation (service) time and
* the transport time to the location.
* </p>
* <p>
* This column is stateful and stores the previous activity.
* </p>
*
* @author balage
*
* @see {@linkplain ArrivalTimePrinterColumn}
* @see {@linkplain StartTimePrinterColumn}
* @see {@linkplain EndTimePrinterColumn}
* @see {@linkplain TravelDurationPrinterColumn}
* @see {@linkplain WaitingDurationPrinterColumn}
* @see {@linkplain OperationDurationPrinterColumn}
*/
public class ActivityDurationPrinterColumn extends AbstractDurationPrinterColumn<ActivityDurationPrinterColumn>
implements CostAndTimeExtractor {
// The previous activity
private TourActivity prevAct;
/**
* Constructor.
*/
public ActivityDurationPrinterColumn() {
super();
}
/**
* Constructor with a post creation decorator provided.
*/
public ActivityDurationPrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
protected String getDefaultTitle() {
return "duration";
}
@Override
public Long getValue(RoutePrinterContext context) {
TourActivity act = context.getActivity();
if (act instanceof Start) {
prevAct = null;
}
long val = (long) (getTransportTime(context, prevAct) + act.getOperationTime());
prevAct = act;
return val;
}
}

View file

@ -1,65 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.problem.SizeDimension;
import com.graphhopper.jsprit.core.problem.solution.route.activity.Start;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
/**
* The load change value (signed size) of the activity.
*
* <p>
* If the activity is a route start, the returned value is the initial load,
* otherwise the loadChange value of the activity.
* </p>
*
* @author balage
*
*/
public class ActivityLoadChangePrinterColumn extends AbstractSizeDimensionPrinterColumn {
/**
* Constructor.
*/
public ActivityLoadChangePrinterColumn() {
super();
}
/**
* Constructor with a post creation decorator provided.
*/
public ActivityLoadChangePrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
public ColumnDefinition.Builder getColumnBuilder() {
return super.getColumnBuilder().withMinWidth(10);
}
@Override
protected String getDefaultTitle() {
return "load change";
}
/**
* {@inheritDoc}
* <p>
* If the activity is a route start, the returned value is the initial load,
* otherwise the loadChange value of the activity.
* </p>
*/
@Override
protected SizeDimension getSizeDimension(RoutePrinterContext context) {
TourActivity act = context.getActivity();
if (act instanceof Start) {
return calculateInitialLoad(context);
} else {
return act.getLoadChange();
}
}
}

View file

@ -1,47 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.problem.solution.route.activity.AbstractActivity;
import com.graphhopper.jsprit.core.reporting.AbstractPrinterColumn;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
import com.graphhopper.jsprit.core.reporting.columndefinition.StringColumnType;
/**
* The type of the activity.
*
* @author balage
*
*/
public class ActivityTypePrinterColumn extends AbstractPrinterColumn<RoutePrinterContext, String, ActivityTypePrinterColumn> {
/**
* Constructor.
*/
public ActivityTypePrinterColumn() {
super();
}
/**
* Constructor with a post creation decorator provided.
*/
public ActivityTypePrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
public ColumnDefinition.Builder getColumnBuilder() {
return new ColumnDefinition.Builder(new StringColumnType());
}
@Override
public String getData(RoutePrinterContext context) {
return ((AbstractActivity) context.getActivity()).getType();
}
@Override
protected String getDefaultTitle() {
return "activity";
}
}

View file

@ -1,59 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.problem.solution.route.activity.Start;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
/**
* Arrival time of the activity.
* <p>
* For route start the value is undefined (null), for other activities, it is
* the earliest time the location of the activity is reached. (Note, that it is
* not the time the activity is started, there may be an idle time before.)
* </p>
*
* @author balage
*
* @see {@linkplain StartTimePrinterColumn}
* @see {@linkplain EndTimePrinterColumn}
* @see {@linkplain TravelDurationPrinterColumn}
* @see {@linkplain WaitingDurationPrinterColumn}
* @see {@linkplain OperationDurationPrinterColumn}
* @see {@linkplain ActivityDurationPrinterColumn}
*/
public class ArrivalTimePrinterColumn extends AbstractTimePrinterColumn<ArrivalTimePrinterColumn> {
/**
* Constructor.
*/
public ArrivalTimePrinterColumn() {
super();
}
/**
* Constructor with a post creation decorator provided.
*/
public ArrivalTimePrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
protected String getDefaultTitle() {
return "arrTime";
}
@Override
public Long getValue(RoutePrinterContext context) {
TourActivity act = context.getActivity();
if (act instanceof Start) {
return null;
} else {
return (long) act.getArrTime();
}
}
}

View file

@ -1,55 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
/**
* Utility interface for extracting cost and time values from problem.
*
* @author balage
*
*/
public interface CostAndTimeExtractor {
/**
* Returns the activity cost extracted from the context.
*
* @param context
* The context.
* @return The activity cost.
*/
default double getActivityCost(RoutePrinterContext context) {
return context.getProblem().getActivityCosts().getActivityCost(context.getActivity(),
context.getActivity().getArrTime(), context.getRoute().getDriver(), context.getRoute().getVehicle());
}
/**
* Returns the transport cost extracted from the context.
*
* @param context
* The context.
* @return The transport cost.
*/
default double getTransportCost(RoutePrinterContext context, TourActivity prevAct) {
return prevAct == null ? 0d
: context.getProblem().getTransportCosts().getTransportCost(prevAct.getLocation(),
context.getActivity().getLocation(),
context.getActivity().getArrTime(), context.getRoute().getDriver(),
context.getRoute().getVehicle());
}
/**
* Returns the transport time extracted from the context.
*
* @param context
* The context.
* @return The transpoert time.
*/
default double getTransportTime(RoutePrinterContext context, TourActivity prevAct) {
return prevAct == null ? 0d
: context.getProblem().getTransportCosts().getTransportTime(prevAct.getLocation(),
context.getActivity().getLocation(),
context.getActivity().getArrTime(), context.getRoute().getDriver(),
context.getRoute().getVehicle());
}
}

View file

@ -1,58 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.problem.solution.route.activity.End;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
/**
* End time of the activity.
* <p>
* For route end the value is undefined (null), for other activities, it is the
* time when the activity is finished and the vehicle could progress toward the
* next activity.
* </p>
*
* @author balage
*
* @see {@linkplain ArrivalTimePrinterColumn}
* @see {@linkplain StartTimePrinterColumn}
* @see {@linkplain TravelDurationPrinterColumn}
* @see {@linkplain WaitingDurationPrinterColumn}
* @see {@linkplain OperationDurationPrinterColumn}
* @see {@linkplain ActivityDurationPrinterColumn}
*/
public class EndTimePrinterColumn extends AbstractTimePrinterColumn<EndTimePrinterColumn> {
/**
* Constructor.
*/
public EndTimePrinterColumn() {
super();
}
/**
* Constructor with a post creation decorator provided.
*/
public EndTimePrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
protected String getDefaultTitle() {
return "endTime";
}
@Override
public Long getValue(RoutePrinterContext context) {
TourActivity act = context.getActivity();
if (act instanceof End) {
return null;
} else {
return (long) act.getEndTime();
}
}
}

View file

@ -1,53 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.problem.job.AbstractJob;
import com.graphhopper.jsprit.core.problem.job.Job;
import com.graphhopper.jsprit.core.reporting.AbstractPrinterColumn;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
import com.graphhopper.jsprit.core.reporting.columndefinition.StringColumnType;
/**
* Name (id) of the job.
*
* <p>
* This column provides the {@linkplain Job#getId()} of the associated job of
* the activity for job activities and null for other route activities.
* </p>
*
* @author balage
*/
public class JobNamePrinterColumn extends AbstractPrinterColumn<RoutePrinterContext, String, JobNamePrinterColumn> {
/**
* Constructor.
*/
public JobNamePrinterColumn() {
super();
}
/**
* Constructor with a post creation decorator provided.
*/
public JobNamePrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
public ColumnDefinition.Builder getColumnBuilder() {
return new ColumnDefinition.Builder(new StringColumnType("-"));
}
@Override
protected String getDefaultTitle() {
return "job name";
}
@Override
public String getData(RoutePrinterContext context) {
AbstractJob job = context.getJob();
return job == null ? null : job.getId();
}
}

View file

@ -1,57 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.problem.job.AbstractJob;
import com.graphhopper.jsprit.core.problem.job.Job;
import com.graphhopper.jsprit.core.reporting.AbstractPrinterColumn;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnAlignment;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
import com.graphhopper.jsprit.core.reporting.columndefinition.StringColumnType;
/**
* Priority of the job.
*
* <p>
* This column provides the named (LOW, MEDIUM, HIGH) representation of
* {@linkplain Job#getPriority()} of the associated job of the activity for job
* activities and null for other route activities.
* </p>
*
* @author balage
*/
public class JobPriorityPrinterColumn extends AbstractPrinterColumn<RoutePrinterContext, String, JobPriorityPrinterColumn> {
private static final String[] PRIORITY_NAMES = new String[] { "", "HIGH", "MEDIUM", "LOW" };
/**
* Constructor.
*/
public JobPriorityPrinterColumn() {
super();
}
/**
* Constructor with a post creation decorator provided.
*/
public JobPriorityPrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
public ColumnDefinition.Builder getColumnBuilder() {
return new ColumnDefinition.Builder(new StringColumnType("-")).withAlignment(ColumnAlignment.CENTER);
}
@Override
protected String getDefaultTitle() {
return "priority";
}
@Override
public String getData(RoutePrinterContext context) {
AbstractJob job = context.getJob();
return job == null ? null : PRIORITY_NAMES[job.getPriority()];
}
}

View file

@ -1,52 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.problem.job.AbstractJob;
import com.graphhopper.jsprit.core.reporting.AbstractPrinterColumn;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
import com.graphhopper.jsprit.core.reporting.columndefinition.StringColumnType;
/**
* Priority of the job.
*
* <p>
* This column provides the simple class name of the associated job of the
* activity for job activities and null for other route activities.
* </p>
*
* @author balage
*/
public class JobTypePrinterColumn extends AbstractPrinterColumn<RoutePrinterContext, String, JobTypePrinterColumn> {
/**
* Constructor.
*/
public JobTypePrinterColumn() {
super();
}
/**
* Constructor with a post creation decorator provided.
*/
public JobTypePrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
public ColumnDefinition.Builder getColumnBuilder() {
return new ColumnDefinition.Builder(new StringColumnType("-"));
}
@Override
protected String getDefaultTitle() {
return "job type";
}
@Override
public String getData(RoutePrinterContext context) {
AbstractJob job = context.getJob();
return job == null ? null : job.getClass().getSimpleName();
}
}

View file

@ -1,54 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.problem.Location;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
import com.graphhopper.jsprit.core.reporting.AbstractPrinterColumn;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
import com.graphhopper.jsprit.core.reporting.columndefinition.StringColumnType;
/**
* Priority of the job.
*
* <p>
* This column provides the simple class name of the associated job of the
* activity for job activities and null for other route activities.
* </p>
*
* @author balage
*/
public class LoacationPrinterColumn extends AbstractPrinterColumn<RoutePrinterContext, String, LoacationPrinterColumn> {
/**
* Constructor.
*/
public LoacationPrinterColumn() {
super();
}
/**
* Constructor with a post creation decorator provided.
*/
public LoacationPrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
public ColumnDefinition.Builder getColumnBuilder() {
return new ColumnDefinition.Builder(new StringColumnType("-"));
}
@Override
protected String getDefaultTitle() {
return "location";
}
@Override
public String getData(RoutePrinterContext context) {
TourActivity act = context.getActivity();
Location loc = act.getLocation();
return loc == null ? null : loc.getId();
}
}

View file

@ -1,53 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.problem.solution.route.activity.AbstractActivity;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
/**
* Duration of the activity.
* <p>
* The time it takes to complete the on-site task of the activity. This is the
* value from {@linkplain AbstractActivity#getOperationTime()}.
* </p>
*
* @author balage
*
* @see {@linkplain ArrivalTimePrinterColumn}
* @see {@linkplain StartTimePrinterColumn}
* @see {@linkplain EndTimePrinterColumn}
* @see {@linkplain TravelDurationPrinterColumn}
* @see {@linkplain WaitingDurationPrinterColumn}
* @see {@linkplain ActivityDurationPrinterColumn}
*/
public class OperationDurationPrinterColumn extends AbstractDurationPrinterColumn<OperationDurationPrinterColumn> {
/**
* Constructor.
*/
public OperationDurationPrinterColumn() {
super();
}
/**
* Constructor with a post creation decorator provided.
*/
public OperationDurationPrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
protected String getDefaultTitle() {
return "opTime";
}
@Override
public Long getValue(RoutePrinterContext context) {
TourActivity act = context.getActivity();
return (long) act.getOperationTime();
}
}

View file

@ -1,62 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.problem.solution.route.activity.Start;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
/**
* The aggregated cost of the route from start till the current activity.
*
* <p>
* This column sumarizes the cost of all activities from start till the current
* activity.
* </p>
* <p>
* This column is stateful and stores the sum from the prior activities on the
* route.
* </p>
*
* @author balage
*/
public class RouteCostPrinterColumn extends TransportCostPrinterColumn {
// The aggregated cost of the route so far.
private int aggregatedCost = 0;
/**
* Constructor.
*/
public RouteCostPrinterColumn() {
super();
}
/**
* Constructor with a post creation decorator provided.
*/
public RouteCostPrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
protected String getDefaultTitle() {
return "routeCost";
}
@Override
public Integer getData(RoutePrinterContext context) {
if (context.getActivity() instanceof Start) {
aggregatedCost = 0;
}
Integer res = super.getData(context);
if (res != null) {
aggregatedCost += res;
}
aggregatedCost += getActivityCost(context);
return aggregatedCost;
}
}

View file

@ -1,61 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.problem.SizeDimension;
import com.graphhopper.jsprit.core.problem.solution.route.activity.Start;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
/**
* The load of the vehicle after the current activity is finished.
*
* <p>
* This column represents the current load of the vehicle on the route after the
* cargo load/unload performed on the activity. For the start activity (at the
* start of the route) the value is the initialLoad.
* </p>
* <p>
* This column is stateful and stores the vehicle load from the prior activity
* on the route.
* </p>
*
* @author balage
*/
public class RouteLoadPrinterColumn extends AbstractSizeDimensionPrinterColumn {
// The current vehicle load
private SizeDimension aggregated;
/**
* Constructor.
*/
public RouteLoadPrinterColumn() {
super();
}
/**
* Constructor with a post creation decorator provided.
*/
public RouteLoadPrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
protected String getDefaultTitle() {
return "load";
}
@Override
protected SizeDimension getSizeDimension(RoutePrinterContext context) {
TourActivity act = context.getActivity();
if (act instanceof Start) {
aggregated = calculateInitialLoad(context);
} else {
aggregated = aggregated.add(act.getLoadChange());
}
return aggregated;
}
}

View file

@ -1,49 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.reporting.AbstractPrinterColumn;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
import com.graphhopper.jsprit.core.reporting.columndefinition.IntColumnType;
/**
* The order number of the route.
*
* <p>
* This is the ordinal of the route.
* </p>
*
* @author balage
*/
public class RouteNumberPrinterColumn extends AbstractPrinterColumn<RoutePrinterContext, Integer, RouteNumberPrinterColumn> {
/**
* Constructor.
*/
public RouteNumberPrinterColumn() {
super();
}
/**
* Constructor with a post creation decorator provided.
*/
public RouteNumberPrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
public ColumnDefinition.Builder getColumnBuilder() {
return new ColumnDefinition.Builder(new IntColumnType());
}
@Override
protected String getDefaultTitle() {
return "route";
}
@Override
public Integer getData(RoutePrinterContext context) {
return context.getRoute().getId();
}
}

View file

@ -1,83 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
import com.graphhopper.jsprit.core.problem.job.AbstractJob;
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
import com.graphhopper.jsprit.core.problem.solution.route.activity.JobActivity;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
import com.graphhopper.jsprit.core.reporting.job.JobPrinterContext;
/**
* The context of the detailed route printer columns.
*
* <p>
* This is a semi-mutable class: only the activity could be altered. Therefore
* for each route a new instance should be created.
* </p>
*
* @author balage
*
*/
public class RoutePrinterContext implements JobPrinterContext {
// The route itself
private VehicleRoute route;
// The current activity
private TourActivity activity;
// The problem
private VehicleRoutingProblem problem;
/**
* Constructor.
*
* @param routeNr
* route id
* @param route
* the route
* @param activity
* current activity
* @param problem
* problem
*/
public RoutePrinterContext(VehicleRoute route, TourActivity activity, VehicleRoutingProblem problem) {
super();
this.route = route;
this.activity = activity;
this.problem = problem;
}
/**
* @return The route itself.
*/
public VehicleRoute getRoute() {
return route;
}
/**
* @return The current activity.
*/
public TourActivity getActivity() {
return activity;
}
/**
* @param activity
* The current activity.
*/
public void setActivity(TourActivity activity) {
this.activity = activity;
}
/**
* @return The problem.
*/
public VehicleRoutingProblem getProblem() {
return problem;
}
@Override
public AbstractJob getJob() {
return (getActivity() instanceof JobActivity) ? ((JobActivity) getActivity()).getJob() : null;
}
}

View file

@ -1,74 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.problem.solution.route.activity.JobActivity;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
/**
* The time window used in activity.
*
* <p>
* This is the time window which was choosen by the algorithm. The start time of
* the activity is within this time window and the end time is within or matches
* the end value of this time window.
* </p>
*
* @author balage
*
* @see {@linkplain TimeWindowsPrinterColumn}
* @see {@linkplain StartTimePrinterColumn}
*/
public class SelectedTimeWindowPrinterColumn extends AbstractTimeWindowPrinterColumn<SelectedTimeWindowPrinterColumn> {
/**
* Constructor.
*/
public SelectedTimeWindowPrinterColumn() {
super();
}
/**
* Constructor with a post creation decorator provided.
*/
public SelectedTimeWindowPrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
protected String getDefaultTitle() {
return "selTimeWindow";
}
/**
* {@inheritDoc}
*
* <p>
* This implementation returns at most one time window: the one the activity
* start time is within.
* </p>
*/
@Override
protected Collection<TimeWindow> getValue(RoutePrinterContext context) {
TourActivity act = context.getActivity();
if (act instanceof JobActivity) {
Optional<TimeWindow> optTw = ((JobActivity) act).getTimeWindows().stream()
.filter(tw -> tw.contains(act.getEndTime() - act.getOperationTime()))
.findAny();
if (optTw.isPresent()) {
return Collections.singleton(optTw.get());
} else {
return null;
}
} else {
return null;
}
}
}

View file

@ -1,57 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.problem.solution.route.activity.End;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
/**
* Start time of the activity.
* <p>
* For route end the value is undefined (null), for other activities, it is the
* time when the task on location is effectively started.
* </p>
*
* @author balage
*
* @see {@linkplain ArrivalTimePrinterColumn}
* @see {@linkplain EndTimePrinterColumn}
* @see {@linkplain TravelDurationPrinterColumn}
* @see {@linkplain WaitingDurationPrinterColumn}
* @see {@linkplain OperationDurationPrinterColumn}
* @see {@linkplain ActivityDurationPrinterColumn}
*/
public class StartTimePrinterColumn extends AbstractTimePrinterColumn<StartTimePrinterColumn> {
/**
* Constructor.
*/
public StartTimePrinterColumn() {
super();
}
/**
* Constructor with a post creation decorator provided.
*/
public StartTimePrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
protected String getDefaultTitle() {
return "startTime";
}
@Override
public Long getValue(RoutePrinterContext context) {
TourActivity act = context.getActivity();
if (act instanceof End) {
return null;
} else {
return (long) (act.getEndTime() - act.getOperationTime());
}
}
}

View file

@ -1,54 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.Collection;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.problem.solution.route.activity.JobActivity;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
/**
* The time windows of the activity.
*
* <p>
* Returns all time windows assigned to the activity.
* </p>
*
* @author balage
*
* @see {@linkplain SelectedTimeWindowPrinterColumn}
*/
public class TimeWindowsPrinterColumn extends AbstractTimeWindowPrinterColumn<TimeWindowsPrinterColumn> {
/**
* Constructor.
*/
public TimeWindowsPrinterColumn() {
super();
}
/**
* Constructor with a post creation decorator provided.
*/
public TimeWindowsPrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
protected String getDefaultTitle() {
return "timeWindows";
}
@Override
protected Collection<TimeWindow> getValue(RoutePrinterContext context) {
TourActivity act = context.getActivity();
if (act instanceof JobActivity) {
return ((JobActivity) act).getTimeWindows();
} else {
return null;
}
}
}

View file

@ -1,58 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.problem.solution.route.activity.Start;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
/**
* The cost of travelling to the activity.
*
* <p>
* This is the cost of the transport from the previous to this activity. For the
* start of the route this value is undefined (null).
* </p>
* <p>
* This column is stateful and stores the previous activity.
* </p>
*
* @author balage
*/
public class TransportCostPrinterColumn extends AbstractCostPrinterColumn {
// The previous activity
private TourActivity prevAct;
/**
* Constructor.
*/
public TransportCostPrinterColumn() {
super();
}
/**
* Constructor with a post creation decorator provided.
*/
public TransportCostPrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
protected String getDefaultTitle() {
return "transCost";
}
@Override
public Integer getData(RoutePrinterContext context) {
TourActivity act = context.getActivity();
if (act instanceof Start) {
prevAct = null;
}
double res = getTransportCost(context, prevAct);
prevAct = act;
return (int) res;
}
}

View file

@ -1,66 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.problem.solution.route.activity.Start;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
/**
* Travel duration toward the location of the activity.
* <p>
* The time it takes to travel to the location of the activity. The value is
* undefined for route start activity (null).
* </p>
* <p>
* This column is stateful and stores the previous activity.
* </p>
*
* @author balage
*
* @see {@linkplain ArrivalTimePrinterColumn}
* @see {@linkplain StartTimePrinterColumn}
* @see {@linkplain EndTimePrinterColumn}
* @see {@linkplain WaitingDurationPrinterColumn}
* @see {@linkplain OperationDurationPrinterColumn}
* @see {@linkplain ActivityDurationPrinterColumn}
*/
public class TravelDurationPrinterColumn extends AbstractDurationPrinterColumn<TravelDurationPrinterColumn>
implements CostAndTimeExtractor {
// The previous activity
private TourActivity prevAct;
/**
* Constructor.
*/
public TravelDurationPrinterColumn() {
super();
}
/**
* Constructor with a post creation decorator provided.
*/
public TravelDurationPrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
protected String getDefaultTitle() {
return "travel";
}
@Override
public Long getValue(RoutePrinterContext context) {
TourActivity act = context.getActivity();
if (act instanceof Start) {
prevAct = null;
}
long val = (long) (getTransportTime(context, prevAct));
prevAct = act;
return val;
}
}

View file

@ -1,49 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.reporting.AbstractPrinterColumn;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
import com.graphhopper.jsprit.core.reporting.columndefinition.StringColumnType;
/**
* The name of the vehicle associated by this route.
*
* <p>
* This colum returns the id of the vehicle of the route.
* </p>
*
* @author balage
*/
public class VehicleNamePrinterColumn extends AbstractPrinterColumn<RoutePrinterContext, String, VehicleNamePrinterColumn> {
/**
* Constructor.
*/
public VehicleNamePrinterColumn() {
super();
}
/**
* Constructor with a post creation decorator provided.
*/
public VehicleNamePrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
public ColumnDefinition.Builder getColumnBuilder() {
return new ColumnDefinition.Builder(new StringColumnType());
}
@Override
protected String getDefaultTitle() {
return "vehicle";
}
@Override
public String getData(RoutePrinterContext context) {
return context.getRoute().getVehicle().getId();
}
}

View file

@ -1,61 +0,0 @@
package com.graphhopper.jsprit.core.reporting.route;
import java.util.function.Consumer;
import com.graphhopper.jsprit.core.problem.solution.route.activity.End;
import com.graphhopper.jsprit.core.problem.solution.route.activity.Start;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
/**
* Idle duration before starting the activity.
* <p>
* This is the time duration between the vehicle arrives to the location (
* {@linkplain ArrivalTimePrinterColumn}) and the activity could be started (
* {@linkplain StartTimePrinterColumn}). For route start and end this value is
* not defined (null).
* </p>
*
* @author balage
*
* @see {@linkplain ArrivalTimePrinterColumn}
* @see {@linkplain StartTimePrinterColumn}
* @see {@linkplain EndTimePrinterColumn}
* @see {@linkplain TravelDurationPrinterColumn}
* @see {@linkplain OperationDurationPrinterColumn}
* @see {@linkplain ActivityDurationPrinterColumn}
*/
public class WaitingDurationPrinterColumn extends AbstractDurationPrinterColumn<WaitingDurationPrinterColumn> {
/**
* Constructor.
*/
public WaitingDurationPrinterColumn() {
super();
}
/**
* Constructor with a post creation decorator provided.
*/
public WaitingDurationPrinterColumn(Consumer<ColumnDefinition.Builder> decorator) {
super(decorator);
}
@Override
protected String getDefaultTitle() {
return "waiting";
}
@Override
public Long getValue(RoutePrinterContext context) {
TourActivity act = context.getActivity();
if (act instanceof Start || act instanceof End) {
return null;
} else {
return (long) (act.getEndTime() - act.getOperationTime() - act.getArrTime());
}
}
}

View file

@ -8,7 +8,6 @@ import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
import com.graphhopper.jsprit.core.reporting.columndefinition.HumanReadableDurationFormatter;
import com.graphhopper.jsprit.core.reporting.columndefinition.HumanReadableTimeFormatter;
import com.graphhopper.jsprit.core.reporting.columndefinition.StringColumnType;
import com.graphhopper.jsprit.core.reporting.route.RoutePrinterContext;
/**
* Abstract base class for time and (technically) duration columns.
@ -111,9 +110,8 @@ extends AbstractPrinterColumn<VehicleSummaryContext, String, AbstractVehicleDura
*/
@SuppressWarnings("unchecked")
public T withPercentDecimalDigits(int digits) {
if (digits < 0) {
if (digits < 0)
throw new IllegalArgumentException("Decimal digit count should be non-negative.");
}
this.percentDecimals = digits;
return (T) this;
}
@ -142,7 +140,6 @@ extends AbstractPrinterColumn<VehicleSummaryContext, String, AbstractVehicleDura
*
* <p>
* The implementation delegates the value extracting to the abstract method
* {@linkplain #getValue(RoutePrinterContext)}.
* <p>
* <p>
* If the value is null, returns null, otherwise it returns the string
@ -154,9 +151,8 @@ extends AbstractPrinterColumn<VehicleSummaryContext, String, AbstractVehicleDura
@Override
public String getData(VehicleSummaryContext context) {
Long timeValue = getValue(context);
if (timeValue == null) {
if (timeValue == null)
return null;
}
switch (mode) {
case NUMERIC:
return "" + timeValue;

View file

@ -10,7 +10,6 @@ import com.graphhopper.jsprit.core.reporting.columndefinition.ColumnDefinition;
import com.graphhopper.jsprit.core.reporting.columndefinition.HumanReadableEnabled;
import com.graphhopper.jsprit.core.reporting.columndefinition.HumanReadableTimeFormatter;
import com.graphhopper.jsprit.core.reporting.columndefinition.StringColumnType;
import com.graphhopper.jsprit.core.reporting.route.RoutePrinterContext;
/**
* Abstract base class for time window columns.
@ -86,7 +85,6 @@ implements HumanReadableEnabled<T> {
*
* <p>
* The implementation delegates the value extracting to the abstract method
* {@linkplain #getValue(RoutePrinterContext)}.
* <p>
* <p>
* If the value is null or empty, returns null, otherwise it returns the
@ -98,9 +96,8 @@ implements HumanReadableEnabled<T> {
@Override
public String getData(VehicleSummaryContext context) {
Collection<TimeWindow> timeWindows = getValue(context);
if (timeWindows == null || timeWindows.isEmpty()) {
if (timeWindows == null || timeWindows.isEmpty())
return null;
}
return timeWindows.stream().map(tw -> formatTimeWindow(tw)).collect(Collectors.joining());
}

View file

@ -29,6 +29,10 @@ import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolutio
import com.graphhopper.jsprit.core.reporting.SolutionPrinter;
import com.graphhopper.jsprit.core.reporting.SolutionPrinter.Print;
import com.graphhopper.jsprit.core.reporting.SolutionPrinter2;
import com.graphhopper.jsprit.core.reporting.SolutionPrinter_depr;
import com.graphhopper.jsprit.core.reporting.vehicle.AbstractVehicleDurationPrinterColumn.Mode;
import com.graphhopper.jsprit.core.reporting.vehicle.VehicleSummaryColumnLists;
import com.graphhopper.jsprit.core.reporting.vehicle.VehicleSummaryColumnLists.PredefinedList;
import com.graphhopper.jsprit.core.util.ChristofidesReader;
import com.graphhopper.jsprit.core.util.JobType;
import com.graphhopper.jsprit.core.util.Solutions;
@ -48,6 +52,12 @@ public class CVRPwithDeliveries_IT {
SolutionPrinter.print(vrp, bestSolution, Print.VERBOSE);
System.out.println(
"\n\n================================================================================\n\n");
SolutionPrinter_depr.printVehicleSummary(vrp, bestSolution,
VehicleSummaryColumnLists.getMultiple(PredefinedList.VERBOSE, Mode.values()));
System.out.println(
"\n\n================================================================================\n\n");
try {
SolutionPrinter2.print(vrp, bestSolution);
} catch (Exception e) {