Documentation ¶
Overview ¶
Package factory is a package containing factory functions for creating next-route models.
Index ¶
- func DefaultCustomResultStatistics(solution nextroute.Solution) schema.CustomResultStatistics
- func Format(ctx context.Context, options any, progressioner nextroute.Progressioner, ...) runSchema.Output
- func NewClusterSolution(ctx context.Context, input schema.Input, options Options, ...) (sdkNextRoute.Solution, error)
- func NewGreedySolution(ctx context.Context, input schema.Input, options Options, ...) (sdkNextRoute.Solution, error)
- func NewModel(input schema.Input, modelOptions Options) (nextroute.Model, error)
- func NewStartSolution(ctx context.Context, input schema.Input, factoryOptions Options, ...) (sdkNextRoute.Solution, error)
- type ClusterSolutionOptions
- type FilterAreaOptions
- type GreedySolutionOptions
- type ModelFactory
- type Options
- type StopCluster
- type StopClusterFilter
- func NewAndStopClusterFilter(filter StopClusterFilter, filters ...StopClusterFilter) StopClusterFilter
- func NewOrStopClusterFilter(filter StopClusterFilter, filters ...StopClusterFilter) StopClusterFilter
- func NewStopClusterFilterArea(maximumWidth common.Distance, maximumHeight common.Distance, ...) StopClusterFilter
- type StopClusterGenerator
- type StopClusterSorter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultCustomResultStatistics ¶ added in v0.26.0
func DefaultCustomResultStatistics(solution nextroute.Solution) schema.CustomResultStatistics
DefaultCustomResultStatistics creates default custom statistics for a given solution.
func Format ¶ added in v0.26.0
func Format( ctx context.Context, options any, progressioner nextroute.Progressioner, solutions ...nextroute.Solution, ) runSchema.Output
Format formats a solution in a basic format using the schema.Output to format a solution.
func NewClusterSolution ¶ added in v1.0.0
func NewClusterSolution( ctx context.Context, input schema.Input, options Options, stopClusterGenerator StopClusterGenerator, initialStopClusterSorter StopClusterSorter, additionalStopClusterSorter StopClusterSorter, stopClusterFilter StopClusterFilter, stopClusterOptions ClusterSolutionOptions, modelFactory ModelFactory, ) (sdkNextRoute.Solution, error)
NewClusterSolution returns a solution for the given input using the given options. The solution is constructed by first creating a solution for each vehicle and then adding stop groups to the vehicles in a greedy fashion.
- Raises an error if the input has initial stops on any of the vehicles.
- Uses haversine distance independent of the input's distance/duration matrix. Uses the correct distance matrix in the solution returned.
- Uses the speed of the vehicle if defined, otherwise the speed defined in the options.
- Ignores stop duration groups in construction but not in the solution returned.
The initial solution is created as following: ¶
Creates the clusters using the stopClusterGenerator In random order of the vehicles in the input: - Add a first cluster to the empty vehicle defined by the initialStopClusterSorter - If the vehicle is not solved, the cluster is removed and the next cluster will be added - If no clusters can be added, the vehicle will not be used - If a cluster has been added we continue adding clusters to the vehicle in the order defined by additionalStopClusterSorter until no more clusters can be added We repeat until no more vehicles or no more clusters to add to the solution.
func NewGreedySolution ¶ added in v1.0.0
func NewGreedySolution( ctx context.Context, input schema.Input, options Options, greedySolutionOptions GreedySolutionOptions, modelFactory ModelFactory, ) (sdkNextRoute.Solution, error)
NewGreedySolution returns a greedy solution for the given input.
func NewModel ¶
NewModel builds a ready-to-go vehicle routing problem. The difference with nextroute.NewModel is that NewModel processes the input and options to add all features to the model, such as constraints and objectives. On the other hand, nextroute.NewModel creates an empty vehicle routing model which must be built from the ground up.
func NewStartSolution ¶ added in v1.0.0
func NewStartSolution( ctx context.Context, input schema.Input, factoryOptions Options, modelFactory ModelFactory, solveOptions sdkNextRoute.ParallelSolveOptions, clusterSolutionOptions ClusterSolutionOptions, ) (sdkNextRoute.Solution, error)
NewStartSolution returns a start solution. It uses input, factoryOptions and modelFactory to create a model to create a start solution. The start solution is created using the given solveOptions and clusterSolutionOptions. The solveOptions is used to limit the duration and the number of parallel runs at the same time. The clusterSolutionOptions is used to create the clusters to create the start solution, see NewClusterSolution.
Types ¶
type ClusterSolutionOptions ¶ added in v1.0.0
type ClusterSolutionOptions struct { Depth int `json:"depth" usage:"maximum failed tries to add a cluster to a vehicle" default:"10" minimum:"0"` Speed float64 `json:"speed" usage:"speed of the vehicle in meters per second" default:"10" minimum:"0"` }
ClusterSolutionOptions configure how the NewGreedySolution function builds sdkNextRoute.Solution.
type FilterAreaOptions ¶ added in v1.0.0
type FilterAreaOptions struct {
MaximumSide float64 `json:"maximum_side" usage:"maximum side of the square area in meters" default:"100000" minimum:"0"`
}
FilterAreaOptions configure how the NewGreedySolution function builds sdkNextRoute.Solution. It limits the area one vehicle can cover during construction. This limit is only applied during the construction of the solution.
type GreedySolutionOptions ¶ added in v1.0.0
type GreedySolutionOptions struct { ClusterSolutionOptions ClusterSolutionOptions `json:"cluster_solution_options" usage:"options for the cluster solution"` FilterAreaOptions FilterAreaOptions `json:"filter_area_options" usage:"options for the filter area"` }
GreedySolutionOptions configure how the NewGreedySolution function builds sdkNextRoute.Solution.
type ModelFactory ¶ added in v1.0.0
type ModelFactory interface { // NewModel returns a new model for the given input and options. NewModel(schema.Input, Options) (sdkNextRoute.Model, error) }
ModelFactory returns a new model for the given input and options.
func NewDefaultModelFactory ¶ added in v1.0.0
func NewDefaultModelFactory() ModelFactory
NewDefaultModelFactory returns a default model factory.
type Options ¶ added in v0.23.1
type Options struct { Constraints struct { Disable struct { Attributes bool `json:"attributes" usage:"ignore the compatibility attributes constraint"` Capacity bool `json:"capacity" usage:"ignore the capacity constraint for all resources"` Capacities []string `json:"capacities" usage:"ignore the capacity constraint for the given resource names"` DistanceLimit bool `json:"distance_limit" usage:"ignore the distance limit constraint"` Groups bool `json:"groups" usage:"ignore the groups constraint"` MaximumDuration bool `json:"maximum_duration" usage:"ignore the maximum duration constraint"` MaximumStops bool `json:"maximum_stops" usage:"ignore the maximum stops constraint"` MaximumWaitStop bool `json:"maximum_wait_stop" usage:"ignore the maximum stop wait constraint"` MaximumWaitVehicle bool `json:"maximum_wait_vehicle" usage:"ignore the maximum vehicle wait constraint"` MixingItems bool `json:"mixing_items" usage:"ignore the do not mix items constraint"` Precedence bool `json:"precedence" usage:"ignore the precedence (pickups & deliveries) constraint"` VehicleStartTime bool `json:"vehicle_start_time" usage:"ignore the vehicle start time constraint"` VehicleEndTime bool `json:"vehicle_end_time" usage:"ignore the vehicle end time constraint"` StartTimeWindows bool `json:"start_time_windows" usage:"ignore the start time windows constraint"` } `json:"disable"` Enable struct { Cluster bool `json:"cluster" usage:"enable the cluster constraint"` } `json:"enable"` } `json:"constraints"` Objectives struct { Capacities string `` /* 126-byte string literal not displayed */ MinStops float64 `json:"min_stops" usage:"factor to weigh the min stops objective" default:"1.0"` EarlyArrivalPenalty float64 `json:"early_arrival_penalty" usage:"factor to weigh the early arrival objective" default:"1.0"` LateArrivalPenalty float64 `json:"late_arrival_penalty" usage:"factor to weigh the late arrival objective" default:"1.0"` VehicleActivationPenalty float64 `json:"vehicle_activation_penalty" usage:"factor to weigh the vehicle activation objective" default:"1.0"` TravelDuration float64 `json:"travel_duration" usage:"factor to weigh the travel duration objective" default:"0.0"` VehiclesDuration float64 `json:"vehicles_duration" usage:"factor to weigh the vehicles duration objective" default:"1.0"` UnplannedPenalty float64 `json:"unplanned_penalty" usage:"factor to weigh the unplanned objective" default:"1.0"` Cluster float64 `json:"cluster" usage:"factor to weigh the cluster objective" default:"0.0"` } `json:"objectives"` Properties struct { Disable struct { Durations bool `json:"durations" usage:"ignore the durations of stops"` StopDurationMultipliers bool `json:"stop_duration_multipliers" usage:"ignore the stop duration multipliers defined on vehicles"` DurationGroups bool `json:"duration_groups" usage:"ignore the durations groups of stops"` InitialSolution bool `json:"initial_solution" usage:"ignore the initial solution"` } `json:"disable"` } `json:"properties"` Validate struct { Disable struct { StartTime bool `json:"start_time" usage:"disable the start time validation" default:"false"` Resources bool `json:"resources" usage:"disable the resources validation" default:"false"` } `json:"disable"` Enable struct { Matrix bool `json:"matrix" usage:"enable matrix validation" default:"false"` MatrixAsymmetryTolerance int `` /* 132-byte string literal not displayed */ } `json:"enable"` } `json:"validate"` }
Options configure how the NewModel function builds nextroute.Model.
type StopCluster ¶ added in v1.0.0
type StopCluster interface { // Stops returns the stops in the stop cluster. Stops() []schema.Stop // Centroid returns the centroid of the stop cluster. Centroid() schema.Location }
StopCluster represents a group of stops that can be added to a vehicle.
func NewStopCluster ¶ added in v1.0.0
func NewStopCluster( stops []schema.Stop) StopCluster
NewStopCluster returns a new stop cluster for the given stops.
type StopClusterFilter ¶ added in v1.0.0
type StopClusterFilter interface { // Filter returns true if the given stop cluster should be filtered out. Filter( input schema.Input, cluster StopCluster, factory ModelFactory, ) (bool, error) }
StopClusterFilter returns true if the given stop cluster should be filtered out.
func NewAndStopClusterFilter ¶ added in v1.0.0
func NewAndStopClusterFilter( filter StopClusterFilter, filters ...StopClusterFilter, ) StopClusterFilter
NewAndStopClusterFilter returns a StopClusterFilter that filters out stop clusters that are filtered out by all the given filters.
func NewOrStopClusterFilter ¶ added in v1.0.0
func NewOrStopClusterFilter( filter StopClusterFilter, filters ...StopClusterFilter, ) StopClusterFilter
NewOrStopClusterFilter returns a StopClusterFilter that filters out stop clusters that are filtered out by any of the given filters.
func NewStopClusterFilterArea ¶ added in v1.0.0
func NewStopClusterFilterArea( maximumWidth common.Distance, maximumHeight common.Distance, maximumRadius common.Distance, ) StopClusterFilter
NewStopClusterFilterArea returns a StopClusterFilter that filters out stop clusters that result in an area larger than the dimensions specified. The area is approximated using haversine distance.
type StopClusterGenerator ¶ added in v1.0.0
type StopClusterGenerator interface { // Generate returns a list of stop clusters for the given input. // A cluster is a group of stops that can be added to a vehicle. If a stop // is added to a cluster all the stops belonging to the same plan units // must be added to the same cluster. Generate( input schema.Input, options Options, factory ModelFactory, ) ([]StopCluster, error) }
StopClusterGenerator returns a list of stop clusters for the given input.
func NewPlanUnitStopClusterGenerator ¶ added in v1.0.0
func NewPlanUnitStopClusterGenerator() StopClusterGenerator
NewPlanUnitStopClusterGenerator returns a list of stop clusters based upon unplanned plan units.
type StopClusterSorter ¶ added in v1.0.0
type StopClusterSorter interface { // Sort returns a sorted list of stop clusters for the given input. Sort( input schema.Input, clusters []StopCluster, factory ModelFactory, ) ([]StopCluster, error) }
StopClusterSorter returns a sorted list of stop clusters for the given input.
func NewSortStopClustersOnDistanceFromCentroid ¶ added in v1.0.0
func NewSortStopClustersOnDistanceFromCentroid() StopClusterSorter
NewSortStopClustersOnDistanceFromCentroid sorts the stop clusters based upon the distance from the centroid of the stop cluster to the centroid of all stops. Can be used to select the order of the stop clusters assigned to the vehicles as the first cluster.
func NewSortStopClustersRandom ¶ added in v1.0.0
func NewSortStopClustersRandom() StopClusterSorter
NewSortStopClustersRandom returns StopClusterSorter which sorts the stop clusters randomly. Can be used to randomize the order of the stop clusters assigned to the vehicles as the first cluster.