Documentation
¶
Overview ¶
Package nextroute is a package
Index ¶
- Constants
- Variables
- func DeltaValue(stop SolutionStop, candidate SolutionStop, expression ModelExpression) float64
- func NewModelConstraintIndex() int
- func NewModelExpressionIndex() int
- func NewModelObjectiveIndex() int
- type AttributesConstraint
- type BinaryExpression
- func NewAddExpression(left ModelExpression, right ModelExpression) BinaryExpression
- func NewMaximumExpression(left ModelExpression, right ModelExpression) BinaryExpression
- func NewMinimumExpression(left ModelExpression, right ModelExpression) BinaryExpression
- func NewMultiplyExpression(left ModelExpression, right ModelExpression) BinaryExpression
- func NewOperatorExpression(left ModelExpression, right ModelExpression, operator BinaryFunction) BinaryExpression
- type BinaryFunction
- type CheckedAt
- type Complexity
- type ComputationalEffort
- type ConstantExpression
- type ConstraintDataUpdater
- type ConstraintReporter
- type Copier
- type Cost
- type DefaultExpression
- type DistanceExpression
- type DurationExpression
- type FromStopExpression
- type FromToExpression
- type IntParameterOptions
- type InwardnessConstraint
- type LatestEnd
- type LatestStart
- type MaximumConstraint
- type MaximumStopsConstraint
- type Model
- type ModelConstraint
- type ModelConstraints
- type ModelExpression
- type ModelExpressions
- type ModelObjective
- type ModelObjectiveSum
- type ModelObjectives
- type ModelPlanCluster
- type ModelPlanClusters
- type ModelPlanSingleStop
- type ModelStop
- type ModelStops
- type ModelVehicle
- type ModelVehicleType
- type ModelVehicleTypes
- type ModelVehicles
- type Move
- type ObjectiveDataUpdater
- type ParallelSolveOptions
- type ParallelSolver
- type PerformanceObserver
- type PlanClusterType
- type RegisteredModelExpressions
- type Solution
- type SolutionObserved
- type SolutionObserver
- type SolutionObservers
- type SolutionPlanCluster
- type SolutionPlanClusterCollection
- type SolutionPlanClusters
- type SolutionStop
- type SolutionStopViolationCheck
- type SolutionStops
- type SolutionVehicle
- type SolutionVehicleViolationCheck
- type SolutionVehicles
- type SolutionViolationCheck
- type Solutions
- type SolveOptions
- type Solver
- type SolverFactory
- type SolverOptions
- type StopExpression
- type StopPosition
- type StopPositions
- type StopPositionsHint
- type SumExpression
- type TermExpression
- type TravelDurationExpression
- type TravelDurationObjective
- type UnPlannedObjective
- type VehicleFromToExpression
- type VehicleTypeExpression
- type VehiclesObjective
Constants ¶
const ( // AtEachStop indicates that the constraint should be checked at each stop. // A constraint that is registered to be checked at each stop will be // checked as soon as all values for the expressions a stop are known. The // stops later in a vehicle will not been updated yet. AtEachStop CheckedAt = 0 // AtEachVehicle indicates that the constraint should be checked at each // vehicle. A constraint that is registered to be checked at each vehicle // will be checked as soon as all values for the expressions of the stops // of a vehicle are known. The stops of other vehicles will not been // updated yet. AtEachVehicle = 1 // AtEachSolution indicates that the constraint should be checked at each // solution. A constraint that is registered to be checked at each solution // will be checked as soon as all values for the expressions of the stops // of all vehicles are known, which is by definition all the stops. AtEachSolution = 2 // Never indicates that the constraint should never be checked. A constraint // that is registered to be checked never relies completely on its estimate // of allowed moves to be correct. Also, not checking a constraint can // result in solutions that are not valid when un-planning stops. Never = 3 )
const ( // Constant is a constant cost function. Constant Cost = 0 // LinearVehicle is a linear cost function with respect to the number of // vehicles. LinearVehicle = 1 // LinearStop is a linear cost function with respect to the number of stops. LinearStop = 2 // QuadraticVehicle is a quadratic cost function with respect to the number // of vehicles. QuadraticVehicle = 3 // QuadraticStop is a quadratic cost function with respect to the number of // stops. QuadraticStop = 4 // ExponentialVehicle is an exponential cost function with respect to the // number of vehicles. ExponentialVehicle = 5 // ExponentialStop is an exponential cost function with respect to the // number of stops. ExponentialStop = 6 // CrazyExpensive is a function that is so expensive that it should never // be used. CrazyExpensive = 7 )
Variables ¶
var CheckViolations = []CheckedAt{ AtEachStop, AtEachVehicle, AtEachSolution, Never, }
CheckViolations is a list of all possible values for CheckedAt.
Functions ¶
func DeltaValue ¶
func DeltaValue( stop SolutionStop, candidate SolutionStop, expression ModelExpression, ) float64
DeltaValue is a helper function which returns the difference in expression value if candidate would be positioned after stop. Will panic if stop is not planned.
The difference is calculated as follows:
v1 = expression.Value(vehicle, stop.ModelStop(), candidateStop) v2 = expression.Value(vehicle, candidateStop, stop.Next().ModelStop()) v3 = expression.Value(vehicle, stop.ModelStop(), stop.Next().ModelStop()) return v1 + v2 - v3
func NewModelConstraintIndex ¶
func NewModelConstraintIndex() int
NewModelConstraintIndex returns the next unique constraint index. This function can be used to create a unique index for a custom constraint.
func NewModelExpressionIndex ¶
func NewModelExpressionIndex() int
NewModelExpressionIndex returns the next unique expression index. This function can be used to create a unique index for a custom expression.
func NewModelObjectiveIndex ¶
func NewModelObjectiveIndex() int
NewModelObjectiveIndex returns the next unique objective index. This function can be used to create a unique index for a custom objective.
Types ¶
type AttributesConstraint ¶
type AttributesConstraint interface {
ModelConstraint
// SetStopAttributes sets the attributes for the given stop. The attributes
// are specified as a list of strings. The attributes are not interpreted
// in any way. They are only used to determine compatibility between stops
// and vehicle types.
SetStopAttributes(
stop ModelStop,
stopAttributes []string,
)
// SetVehicleTypeAttributes sets the attributes for the given vehicle type.
// The attributes are specified as a list of strings. The attributes are not
// interpreted in any way. They are only used to determine compatibility
// between stops and vehicle types.
SetVehicleTypeAttributes(
vehicle ModelVehicleType,
vehicleAttributes []string,
)
// StopAttributes returns the attributes for the given stop. The attributes
// are specified as a list of strings.
StopAttributes(stop ModelStop) []string
// VehicleTypeAttributes returns the attributes for the given vehicle type.
// The attributes are specified as a list of strings.
VehicleTypeAttributes(vehicle ModelVehicleType) []string
}
AttributesConstraint is a constraint that limits the vehicles a plan cluster can be added to. The Attribute constraint configures compatibility attributes for stops and vehicles separately. This is done by specifying a list of attributes for stops and vehicles, respectively. Stops that have configured attributes are only compatible with vehicles that match at least one of them. Stops that do not have any specified attributes are compatible with any vehicle. Vehicles that do not have any specified attributes are only compatible with stops without attributes.
func NewAttributesConstraint ¶
func NewAttributesConstraint() (AttributesConstraint, error)
NewAttributesConstraint creates a new attributes constraint. The constraint needs to be added to the model to be taken into account.
type BinaryExpression ¶
type BinaryExpression interface {
ModelExpression
// Left returns the left expression.
Left() ModelExpression
// Right returns the right expression.
Right() ModelExpression
}
BinaryExpression is an expression that takes two expressions as input and returns a value.
func NewAddExpression ¶
func NewAddExpression( left ModelExpression, right ModelExpression, ) BinaryExpression
NewAddExpression returns a new BinaryExpression that adds the values of the two expressions.
func NewMaximumExpression ¶
func NewMaximumExpression( left ModelExpression, right ModelExpression, ) BinaryExpression
NewMaximumExpression returns a new BinaryExpression that returns the maximum of the values of the two expressions.
func NewMinimumExpression ¶
func NewMinimumExpression( left ModelExpression, right ModelExpression, ) BinaryExpression
NewMinimumExpression returns a new BinaryExpression that returns the minimum of the values of the two expressions.
func NewMultiplyExpression ¶
func NewMultiplyExpression( left ModelExpression, right ModelExpression, ) BinaryExpression
NewMultiplyExpression returns a new BinaryExpression that multiplies the values of the two expressions.
func NewOperatorExpression ¶
func NewOperatorExpression( left ModelExpression, right ModelExpression, operator BinaryFunction, ) BinaryExpression
NewOperatorExpression returns a new BinaryExpression that uses the given operator function.
type BinaryFunction ¶
BinaryFunction is a function that takes two float64 values and returns a float64 value.
type CheckedAt ¶
type CheckedAt int64
CheckedAt is the type indicating when to check a constraint when a move it's consequences are being propagated.
type Complexity ¶
type Complexity interface {
// CheckCost returns the cost of the Check function.
CheckCost() Cost
// EstimationCost returns the cost of the Estimation function.
EstimationCost() Cost
}
Complexity is the interface for constraints that have a complexity.
type ComputationalEffort ¶
type ComputationalEffort interface {
ComputationalEffortForCheck() Cost
}
ComputationalEffort is the interface that can be implemented by a constraint to indicate the computational effort of checking the constraint.
type ConstantExpression ¶
type ConstantExpression interface {
ModelExpression
// SetValue sets the value of the expression.
SetValue(value float64)
}
ConstantExpression is an expression that always returns the same value.
func NewConstantExpression ¶
func NewConstantExpression( name string, value float64, ) ConstantExpression
NewConstantExpression returns an expression that always returns the same value.
type ConstraintDataUpdater ¶
type ConstraintDataUpdater interface {
// UpdateConstraintData is called when a stop is added to a solution.
// The solutionStop has all it's expression values set and this function
// can use them to update the constraint data for the stop. The data
// returned can be used by the estimate function and can be retrieved by the
// SolutionStop.ConstraintValue function.
UpdateConstraintData(s SolutionStop) Copier
}
ConstraintDataUpdater is the interface than can be used by a constraint if it wants to store data with each stop in a solution.
type ConstraintReporter ¶
type ConstraintReporter interface {
ReportConstraint(SolutionStop) map[string]any
}
type Copier ¶
type Copier interface {
// Copy returns a copy of the object.
Copy() Copier
}
Copier is the interface that all objects that can be copied must implement.
type DefaultExpression ¶
type DefaultExpression interface {
ModelExpression
// DefaultValue returns the default value of the expression.
DefaultValue() float64
}
DefaultExpression is an expression that has a default value if no other values are defined.
type DistanceExpression ¶
type DistanceExpression interface {
ModelExpression
// Distance returns the distance for the given vehicle type, start and
// end stop.
Distance(ModelVehicleType, ModelStop, ModelStop) common.Distance
}
DistanceExpression is an expression that returns a distance.
func NewDistanceExpression ¶
func NewDistanceExpression( name string, modelExpression ModelExpression, unit common.DistanceUnit, ) DistanceExpression
NewDistanceExpression turns a model expression into a distance expression. The parameter unit is the unit of the model expression.
func NewHaversineExpression ¶
func NewHaversineExpression(buffer bool) DistanceExpression
NewHaversineExpression returns a new DistanceExpression that calculates the distance between two stops using the Haversine formula.
type DurationExpression ¶
type DurationExpression interface {
ModelExpression
// Duration returns the duration for the given vehicle type, start and
// end stop.
Duration(ModelVehicleType, ModelStop, ModelStop) time.Duration
}
DurationExpression is an expression that returns a duration.
func NewConstantDurationExpression ¶
func NewConstantDurationExpression( name string, duration time.Duration, ) DurationExpression
NewConstantDurationExpression creates a new constant duration expression.
func NewDurationExpression ¶
func NewDurationExpression( expression ModelExpression, multiplier time.Duration, ) DurationExpression
NewDurationExpression creates a new duration expression.
type FromStopExpression ¶
type FromStopExpression interface {
DefaultExpression
// SetValue sets the value of the expression for the given from stop.
SetValue(
stop ModelStop,
value float64,
)
}
FromStopExpression is an expression that has a value for each from stop.
func NewFromStopExpression ¶
func NewFromStopExpression( name string, defaultValue float64, ) FromStopExpression
NewFromStopExpression returns an expression whose value is based on the from stop in Value method. Expression values are calculated by calling the expression's Value method which takes a vehicle type, a from stop and a to stop as arguments.
type FromToExpression ¶
type FromToExpression interface {
DefaultExpression
// SetValue sets the value of the expression for the given
// from and to stops.
SetValue(
from ModelStop,
to ModelStop,
value float64,
)
}
FromToExpression is an expression that has a value for each combination of from and to stop.
func NewFromToExpression ¶
func NewFromToExpression( name string, defaultValue float64, ) FromToExpression
NewFromToExpression returns an expression whose value is based on the from and to stops in Value method. Expression values are calculated by calling the expression's Value method which takes a vehicle type, a from stop and a to stop as arguments.
type IntParameterOptions ¶
type IntParameterOptions struct {
StartValue int `json:"start_value" usage:"start value"`
DeltaAfterIterations int `json:"delta_after_iterations" usage:"delta after each iterations"`
Delta int `json:"delta" usage:"delta"`
MinValue int `json:"min_value" usage:"min value of parameter"`
MaxValue int `json:"max_value" usage:"max value of parameter"`
SnapBackAfterImprovement bool `json:"snap_back_after_improvement" usage:"snap back to start value after improvement of best solution"`
Zigzag bool `json:"zigzag" usage:"zigzag between min and max value lik a jig saw"`
}
type InwardnessConstraint ¶
type InwardnessConstraint interface {
ConstraintDataUpdater
ModelConstraint
}
InwardnessConstraint is a constraint that limits the vehicles a plan cluster can be added to. A plan cluster can only be added to a vehicles whose centroid is closer to the plan cluster than the centroid of any other vehicle.
func NewInwardnessConstraint ¶
func NewInwardnessConstraint() (InwardnessConstraint, error)
NewInwardnessConstraint creates a new inwardness constraint. The constraint needs to be added to the model to be taken into account.
type LatestEnd ¶
type LatestEnd interface {
ConstraintReporter
ModelConstraint
ModelObjective
// Latest returns the latest end expression which defines the latest
// end of a stop.
Latest() StopExpression
// Lateness returns the lateness of a stop. The lateness is the difference
Lateness(stop SolutionStop) float64
}
LatestEnd is a construct that can be added to the model as a constraint or as an objective. The latest end of a stop is the latest time a stop can end at the location of the stop.
func NewLatestEnd ¶
func NewLatestEnd( latestEnd StopExpression, ) (LatestEnd, error)
NewLatestEnd creates a new latest end construct. The latest end of a stop is the latest time a stop can end at the location of the stop. The LatestEnd can be added to the model as a constraint or as an objective.
type LatestStart ¶
type LatestStart interface {
ConstraintReporter
ModelConstraint
ModelObjective
// Latest returns the latest start expression which defines the latest
// start of a stop.
Latest() StopExpression
// Lateness returns the lateness of a stop. The lateness is the difference
Lateness(stop SolutionStop) float64
}
LatestStart is a construct that can be added to the model as a constraint or as an objective. The latest start of a stop is the latest time a stop can start at the location of the stop.
func NewLatestStart ¶
func NewLatestStart( latest StopExpression, ) (LatestStart, error)
NewLatestStart creates a construct that can be added to the model as a constraint or as an objective. The latest start of a stop is the latest time a stop can start at the location of the stop.
type MaximumConstraint ¶
type MaximumConstraint interface {
ModelConstraint
// Expression returns the expression which defines the cumulative value
// that can be assigned to a vehicle type.
Expression() StopExpression
// Maximum returns the maximum expression which defines the maximum
// cumulative value that can be assigned to a vehicle type.
Maximum() VehicleTypeExpression
}
MaximumConstraint is a constraint that limits the maximum cumulative value can be assigned to a vehicle type. The maximum cumulative value is defined by the expression and the maximum value is defined by the maximum expression.
func NewMaximumConstraint ¶
func NewMaximumConstraint( expression StopExpression, maximum VehicleTypeExpression, ) (MaximumConstraint, error)
NewMaximumConstraint creates a new maximum constraint. The constraint needs to be added to the model to be taken into account.
type MaximumStopsConstraint ¶
type MaximumStopsConstraint interface {
ModelConstraint
// MaximumStops returns the maximum stops expression which defines the
// maximum number of stops a vehicle type can have.
MaximumStops() VehicleTypeExpression
}
MaximumStopsConstraint is a constraint that limits the maximum number of stops a vehicle type can have. The maximum number of stops is defined by the maximum stops expression. The first stop of a vehicle is not counted as a stop and the last stop of a vehicle is not counted as a stop.
func NewMaximumStopsConstraint ¶
func NewMaximumStopsConstraint( maximumStops VehicleTypeExpression, ) (MaximumStopsConstraint, error)
NewMaximumStopsConstraint creates a new maximum stops constraint. The constraint needs to be added to the model to be taken into account.
type Model ¶
type Model interface {
SolutionObserved
// AddConstraint adds a constraint to the model. The constraint is
// checked at the specified violation.
AddConstraint(constraint ModelConstraint) error
// Constraints returns all constraints of the model.
Constraints() ModelConstraints
// ConstraintsCheckedAt returns all constraints of the model that
// are checked at the specified time of having calculated the new
// information for the changed solution.
ConstraintsCheckedAt(violation CheckedAt) ModelConstraints
// DistanceUnit returns the unit of distance used in the model. The
// unit is used to convert distances to values and vice versa. This is
// also used for reporting.
DistanceUnit() common.DistanceUnit
// DurationUnit returns the unit of duration used in the model. The
// unit is used to convert durations to values and vice versa. This is
// also used for reporting.
DurationUnit() time.Duration
// DurationToValue converts the specified duration to a value as it used
// internally in the model.
DurationToValue(duration time.Duration) float64
// Epoch returns the epoch of the model. The epoch is used to convert
// time.Time to float64 and vice versa. All float64 values are relative
// to the epoch.
Epoch() time.Time
// Expressions returns all expressions of the model for which a solution
// has to calculate values. The expressions are sorted by their index. The
// constraints register their expressions with the model.
Expressions() ModelExpressions
// IsImmutable returns true if the model is immutable. The model is
// immutable after a solution has been created using the model.
IsImmutable() bool
// NewPlanSingleStop creates a new plan single stop. A plan single stop
// is a plan cluster of a single stop. A plan cluster is a collection of
// stops which are always planned and unplanned as a single entity.
NewPlanSingleStop(stop ModelStop) ModelPlanSingleStop
// NewStop creates a new stop. The stop is used to create plan clusters.
NewStop(location common.Location) (ModelStop, error)
// NewVehicle creates a new vehicle. The vehicle is used to create
// solutions.
NewVehicle(
vehicleType ModelVehicleType,
start time.Time,
first ModelStop,
last ModelStop,
) (ModelVehicle, error)
// NewVehicleType creates a new vehicle type. The vehicle type is used
// to create vehicles.
NewVehicleType(
travelDuration TravelDurationExpression,
processDuration DurationExpression,
) (ModelVehicleType, error)
// NumberOfStops returns the number of stops in the model.
NumberOfStops() int
// Objective returns the objective of the model.
Objective() ModelObjectiveSum
// PlanClusters returns all plan clusters of the model. A plan cluster
// is a collection of stops which are always planned and unplanned as a
// single entity.
PlanClusters() ModelPlanClusters
// Random returns a random number generator.
Random() *rand.Rand
// SetDistanceUnit sets the distance unit of the model.
SetDistanceUnit(distanceUnit common.DistanceUnit)
// SetDurationUnit sets the duration unit of the model.
SetDurationUnit(durationUnit time.Duration)
// SetEpoch sets the epoch of the model. The epoch is used to convert
// time.Time to float64 and vice versa. All float64 values are relative
// to the epoch.
SetEpoch(epoch time.Time)
// SetRandom sets the random number generator of the model.
SetRandom(random *rand.Rand)
// SetSeed sets the seed of the random number generator of the model.
SetSeed(seed int64)
// Stops returns all stops of the model.
Stops() ModelStops
// Stop returns the stop with the specified index.
Stop(index int) ModelStop
// TimeFormat returns the time format used for reporting.
TimeFormat() string
// Vehicles returns all vehicles of the model.
Vehicles() ModelVehicles
// VehicleTypes returns all vehicle types of the model.
VehicleTypes() ModelVehicleTypes
// Vehicle returns the vehicle with the specified index.
Vehicle(index int) ModelVehicle
}
Model defines routing problem.
type ModelConstraint ¶
type ModelConstraint interface {
RegisteredModelExpressions
// EstimateIsViolated estimates if the solution is changed by the given
// new positions described in stopPositions if it will be violated or not.
// The stopPositions is not allowed to be nil. Should be a pure function,
// i.e. not change any state of the constraint. The stopPositionsHint can
// The stopPositionsHint can be used to speed up the estimation of the
// constraint violation.
EstimateIsViolated(
stopPositions StopPositions,
) (isViolated bool, stopPositionsHint StopPositionsHint)
// Index returns the index of the constraint. The index should be
// unique for each constraint.
Index() int
// Name returns the name of the constraint.
Name() string
}
ModelConstraint is the interface that all constraints must implement. Constraints are used to estimate if a move is allowed and can be used to check if a solution is valid after a move is executed or plan clusters have been unplanned.
type ModelConstraints ¶
type ModelConstraints []ModelConstraint
ModelConstraints is a slice of ModelConstraint.
type ModelExpression ¶
type ModelExpression interface {
// Index returns the unique index of the expression.
Index() int
// Name returns the name of the expression.
Name() string
// Value returns the value of the expression for the given vehicle type,
// from stop and to stop.
Value(ModelVehicleType, ModelStop, ModelStop) float64
}
ModelExpression is an expression that can be used in a model to define values for constraints and objectives. The expression is evaluated for each stop in the solution by invoking the Value() method. The value of the expression is then used in the constraints and objective.
func NewMeasureByIndexExpression ¶
func NewMeasureByIndexExpression(m measure.ByIndex) ModelExpression
NewMeasureByIndexExpression returns a new MeasureByIndexExpression. A MeasureByIndexExpression is a ModelExpression that uses a measure.ByIndex to calculate the cost between two stops. The index of the measure have to be the same as the index of the stops in the model.
func NewMeasureByPointExpression ¶
func NewMeasureByPointExpression(m measure.ByPoint) ModelExpression
NewMeasureByPointExpression returns a new MeasureByPointExpression. A MeasureByPointExpression is a ModelExpression that uses a measure.ByPoint to calculate the cost between two stops.
type ModelExpressions ¶
type ModelExpressions []ModelExpression
ModelExpressions is a slice of ModelExpression.
type ModelObjective ¶
type ModelObjective interface {
RegisteredModelExpressions
// EstimateDeltaValue returns the estimated change in the score if the given
// visit positions are changed.
EstimateDeltaValue(visitPositions StopPositions) float64
// Index returns the index of the objective. The index is unique for each
// objective. The index is used to identify the objective in the
// solution.
Index() int
// Value returns the value of the objective for the given solution.
Value(solution Solution) float64
}
ModelObjective is an objective function that can be used to optimize a solution.
type ModelObjectiveSum ¶
type ModelObjectiveSum interface {
ModelObjective
// Add adds an objective to the sum.
Add(factor float64, objective ModelObjective) error
// ModelObjectives returns the model objectives that are part of the sum.
ModelObjectives() ModelObjectives
}
ModelObjectiveSum is a sum of model objectives.
type ModelObjectives ¶
type ModelObjectives []ModelObjective
ModelObjectives is a slice of model objectives.
type ModelPlanCluster ¶
type ModelPlanCluster interface {
// Centroid returns the centroid of the cluster. The centroid is the
// average location of all stops in the cluster.
Centroid() common.Location
// Index returns the index of the cluster.
Index() int
// Stops returns the stops in the cluster.
Stops() ModelStops
// Type returns the type of the cluster.
Type() PlanClusterType
}
ModelPlanCluster is a cluster of stops in a plan. A cluster is a set of stops that are required to be planned together. For example, a cluster can be a pickup and a delivery stop that are required to be planned together.
type ModelPlanClusters ¶
type ModelPlanClusters []ModelPlanCluster
ModelPlanClusters is a slice of plan clusters.
type ModelPlanSingleStop ¶
type ModelPlanSingleStop interface {
ModelPlanCluster
}
ModelPlanSingleStop is a plan that uses a single stop as a plan.
type ModelStop ¶
type ModelStop interface {
// ClosestStops returns a slice containing the closest stops to the
// invoking stop. The slice is sorted by increasing distance to the
// location. The slice first stop is the stop itself. The distance used
// is the common.Haversine distance between the stops. All the stops
// in the model are used in the slice. Slice with similar distance are
// sorted by their index (increasing).
ClosestStops() ModelStops
// Data returns the arbitrary data associated with the stop. Can be set
// using the StopData StopOption.
Data() any
// HasPlanCluster returns true if the stop belongs to a plan cluster.
HasPlanCluster() bool
// Index returns the index of the stop.
Index() int
// Location returns the location of the stop.
Location() common.Location
// Name returns the name of the stop.
Name() string
// EarliestStart returns the earliest start time of the stop. Can be set
// using the EarliestStart StopOption or using SetEarliestStart.
EarliestStart() time.Time
// EarliestStartValue returns the earliest start time of the stop as a
// float64. The float64 value is the number of time units since the epoch
// both possibly set at the construction of the Model. Can be set using
// the EarliestStart StopOption or using SetEarliestStart.
EarliestStartValue() float64
// PlanCluster returns the plan cluster of the stop. A stop belongs to at
// most one plan cluster. Can be nil if the stop is not part of a plan
// cluster.
PlanCluster() ModelPlanCluster
// SetData sets the arbitrary data associated with the stop.
SetData(data any)
// SetEarliestStart sets the earliest start time of the stop.
SetEarliestStart(time time.Time)
// SetName sets the name of the stop.
SetName(name string)
}
ModelStop is a stop to be assigned to a vehicle.
type ModelVehicle ¶
type ModelVehicle interface {
// VehicleType returns the vehicle type of the vehicle.
VehicleType() ModelVehicleType
// First returns the first stop of the vehicle.
First() ModelStop
// Index returns the index of the vehicle.
Index() int
// Last returns the last stop of the vehicle.
Last() ModelStop
// Name returns the name of the vehicle.
Name() string
// SetName sets the name of the vehicle.
SetName(string)
// Start returns the start time of the vehicle.
Start() time.Time
}
ModelVehicle is a vehicle in the model. A vehicle is a sequence of stops.
type ModelVehicleType ¶
type ModelVehicleType interface {
// Data returns the arbitrary data associated with the vehicle type. Can be
// set using the VehicleTypeData VehicleTypeOption in the factory method
// Model.NewVehicleType.
Data() any
// Index returns the index of the vehicle type.
Index() int
// Model returns the model of the vehicle type.
Model() Model
// ProcessDurationExpression returns the process duration expression of the
// vehicle type. Is set in the factory method of the vehicle type
// Model.NewVehicleType.
ProcessDurationExpression() ModelExpression
// SetData sets the arbitrary data associated with the vehicle type.
SetData(data any)
// TravelDurationExpression returns the travel duration expression of the
// vehicle type. Is set in the factory method of the vehicle type
// Model.NewVehicleType.
TravelDurationExpression() ModelExpression
// Vehicles returns the vehicles of this vehicle type.
Vehicles() ModelVehicles
}
ModelVehicleType is a vehicle type. A vehicle type is a definition of a vehicle. It contains the process duration and travel duration expressions that are used to calculate the travel and process duration of a stop assignment to a vehicle of this type.
type ModelVehicleTypes ¶
type ModelVehicleTypes []ModelVehicleType
ModelVehicleTypes is a slice of vehicle types.
type Move ¶
type Move interface {
// Execute executes the move. Returns true if the move was executed
// successfully, false if the move was not executed successfully. A
// move is not successful if it did not result in a change in the
// solution without violating any hard constraints. A move can be
// marked executable even if it is not successful in executing.
Execute(context.Context) (bool, error)
// IsExecutable returns true if the move is executable, false if the
// move is not executable. A move is executable if the estimates believe
// the move will result in a change in the solution without violating
// any hard constraints.
IsExecutable() bool
// PlanCluster returns the plan cluster that is affected by the move.
PlanCluster() SolutionPlanCluster
// StopPositions returns the stop positions that define the move and
// how it will change the solution.
StopPositions() StopPositions
// TakeBest returns the best move between the given move and the
// current move. The best move is the move with the lowest score. If
// the scores are equal, a random uniform distribution is used to
// determine the move to use.
TakeBest(that Move) Move
// Value returns the score of the move. The score is the difference
// between the score of the solution before the move and the score of
// the solution after the move. The score is based on the estimates and
// the actual score of the solution after the move should be retrieved
// using Solution.Score after the move has been executed.
Value() float64
}
Move is a move in a solution. A move is a change in the solution that can be executed. A move can be executed if it is executable.
func NewEmptyMove ¶
func NewEmptyMove() Move
NewEmptyMove returns a new empty move. An empty move is a move that does not change the solution and it is not executable.
type ObjectiveDataUpdater ¶
type ObjectiveDataUpdater interface {
// UpdateObjectiveData is called when a stop is added to a solution. The solutionStop
// has all it's expression values set and this function can use them to
// update the objective data for the stop. The data returned can be used
// by the estimate function and can be retrieved by the
// SolutionStop.ObjectiveValue function.
UpdateObjectiveData(s SolutionStop) Copier
}
ObjectiveDataUpdater is the interface than can be used by an objective if it wants to store data with each stop in a solution.
type ParallelSolveOptions ¶
type ParallelSolveOptions struct {
MaximumDuration time.Duration `json:"maximum_duration" usage:"maximum duration of solver in seconds"`
MaximumParallelRuns int `json:"maximum_parallel_runs" usage:"maximum number of parallel runs, -1 implies using all available resources"`
StartSolutions int `` /* 152-byte string literal not displayed */
IterationMultiplier int `` /* 139-byte string literal not displayed */
RunDeterministically bool `json:"run_deterministically" usage:"run the parallel solver deterministically"`
}
type ParallelSolver ¶
type ParallelSolver interface {
alns.Progressioner
Solve(ctx context.Context, solveOptions ParallelSolveOptions) (Solution, error)
}
ParallelSolver is the interface for parallel solver. The parallel solver will run multiple solver in parallel and return the best solution. The parallel solver will stop when the maximum duration is reached.
func NewParallelSolver ¶
func NewParallelSolver( model Model, ) (ParallelSolver, error)
NewParallelSolver creates a new parallel solver for the given work solutions.
type PerformanceObserver ¶
type PerformanceObserver interface {
SolutionObserver
Duration() time.Duration
Marshal() ([]byte, error)
Report() string
}
PerformanceObserver is an interface that is used to observe the performance of the model, and it's subsequent use.
func NewPerformanceObserver ¶
func NewPerformanceObserver(model Model) PerformanceObserver
type PlanClusterType ¶
type PlanClusterType int
PlanClusterType is the type of the plan cluster.
const ( // SingleStop is a cluster that contains a single stop. SingleStop PlanClusterType = iota )
type RegisteredModelExpressions ¶
type RegisteredModelExpressions interface {
// ModelExpressions registers the expressions that are registered with the
// model.
ModelExpressions() ModelExpressions
}
RegisteredModelExpressions is the interface that exposes the expressions that should be registered with the model.
type Solution ¶
type Solution interface {
alns.Solution[Solution]
// BestMove returns the best move for the given solution plan cluster. The
// best move is the move that has the lowest score. If there are no moves
// available for the given solution plan cluster, a move is returned which
// is not executable, Move.IsExecutable.
BestMove(context.Context, SolutionPlanCluster) Move
// EstimateDeltaScore estimates the delta score of the solution if the given
// stop positions are moved. The delta score is the difference between the
// score of the solution before the move and the score of the solution after
// the move. The delta score is an estimate as the score of the solution
// after the move is not calculated but estimated. The estimate is based on
// ModelObjective.EstimateDeltaScore.
EstimateDeltaScore(
stopPositions StopPositions,
) (deltaScore float64,
feasible bool,
planPositionsHint StopPositionsHint,
)
// Model returns the model of the solution.
Model() Model
// ObjectiveValue returns the objective value of the solution. The objective
// value is the sum of the objective values defined in Model.Objective.
ObjectiveValue() float64
// PlannedPlanClusters returns the solution plan clusters that are planned.
PlannedPlanClusters() SolutionPlanClusters
// SolutionPlanCluster returns the solution plan cluster for the given
// model plan cluster.
SolutionPlanCluster(planCluster ModelPlanCluster) SolutionPlanCluster
// SolutionStop returns the solution stop for the given model stop.
SolutionStop(stop ModelStop) SolutionStop
// UnplannedPlanClusters returns the solution plan clusters that are not
// planned.
UnplannedPlanClusters() SolutionPlanClusters
// Vehicles returns the vehicles of the solution.
Vehicles() SolutionVehicles
// ToJSONSolution converts the solution to a JSON solution.
ToJSONSolution() schema.JsonSolution
}
Solution is a solution to a model.
func NewSolution ¶
NewSolution creates a new solution. The solution is created from the given model. The solution starts with all plan clusters unplanned. Once a solution has been created the model can no longer be changed, it becomes immutable.
type SolutionObserved ¶
type SolutionObserved interface {
SolutionObserver
// AddSolutionObserver adds the given solution observer to the solution
// observed.
AddSolutionObserver(observer SolutionObserver)
}
SolutionObserved is an interface that can be implemented to observe the solution manipulation process.
type SolutionObserver ¶
type SolutionObserver interface {
// OnNewSolution is called when a new solution is going to be created.
OnNewSolution(model Model)
// OnNewSolutionCreated is called when a new solution has been created.
OnNewSolutionCreated(solution Solution)
// OnCopySolution is called when a solution is going to be copied.
OnCopySolution(solution Solution)
// OnCopiedSolution is called when a solution has been copied.
OnCopiedSolution(solution Solution)
// OnCheckConstraint is called when a constraint is going to be checked.
OnCheckConstraint(
constraint ModelConstraint,
violation CheckedAt,
)
// OnCheckedConstraint is called when a constraint has been checked.
OnCheckedConstraint(
constraint ModelConstraint,
feasible bool,
)
// OnEstimateIsViolated is called when the delta constraint is going to be
// estimated if it will be violated
OnEstimateIsViolated(
constraint ModelConstraint,
)
// OnEstimatedIsViolated is called when the delta constraint score
// has been estimated.
OnEstimatedIsViolated(
constraint ModelConstraint,
isViolated bool,
planPositionsHint StopPositionsHint,
)
// OnEstimateDeltaObjectiveScore is called when the delta objective score is
// going to be estimated.
OnEstimateDeltaObjectiveScore()
// OnEstimatedDeltaObjectiveScore is called when the delta objective score
// has been estimated.
OnEstimatedDeltaObjectiveScore(
estimate float64,
)
// OnBestMove is called when the solution is asked for it's best move.
OnBestMove(solution Solution)
// OnBestMoveFound is called when the solution has found it's best move.
OnBestMoveFound(move Move)
// OnPlan is called when a move is going to be planned.
OnPlan(move Move)
// OnPlanFailed is called when a move has failed to be planned.
OnPlanFailed(move Move)
// OnPlanSucceeded is called when a move has succeeded to be planned.
OnPlanSucceeded(move Move)
}
SolutionObserver is an interface that can be implemented to observe the solution manipulation process.
type SolutionObservers ¶
type SolutionObservers []SolutionObserver
SolutionObservers is a slice of SolutionObserver.
type SolutionPlanCluster ¶
type SolutionPlanCluster interface {
// AddAfterFirst creates a move that adds the invoking stop after the first
// stop of the given vehicle. The move is not necessarily executable,
// Move.IsExecutable.
AddAfterFirst(vehicle SolutionVehicle) Move
// AddBeforeLast creates a move that adds the invoking stop before the last
// stop of the given vehicle. The move is not necessarily executable,
// Move.IsExecutable. Will panic if the invoking stop is already planned.
AddBeforeLast(vehicle SolutionVehicle) Move
// IsPlanned returns true if the cluster is planned.
IsPlanned() bool
// ModelPlanCluster returns the ModelPlanCluster this clustes is
// based upon.
ModelPlanCluster() ModelPlanCluster
// Solution returns the solution this cluster is part of.
Solution() Solution
// SolutionStop returns the solution stop for the given model stop.
// Will panic if the stop is not part of the cluster.
SolutionStop(stop ModelStop) SolutionStop
// SolutionStops returns the solution stops in this cluster.
SolutionStops() SolutionStops
// UnPlan un-plans the cluster by removing the underlying solution stops
// from the solution. Returns true if the cluster was unplanned
// successfully, false if the cluster was not unplanned successfully. A
// cluster is not successful if it did not result in a change in the
// solution without violating any hard constraints.
UnPlan() (bool, error)
}
SolutionPlanCluster is a cluster of stops that are planned to be visited by a vehicle.
type SolutionPlanClusterCollection ¶
type SolutionPlanClusterCollection interface {
// RandomDraw returns a random sample of n different solution plan clusters.
RandomDraw(n int) SolutionPlanClusters
// RandomElement returns a random solution plan cluster.
RandomElement() SolutionPlanCluster
// Remove removes a solution plan cluster from the collection.
Remove(cluster SolutionPlanCluster)
// Size return the number of solution plan clusters in the collection.
Size() int
}
SolutionPlanClusterCollection is a collection of solution plan clusters.
func NewSolutionPlanClusterCollection ¶
func NewSolutionPlanClusterCollection( source *rand.Rand, planClusters SolutionPlanClusters, ) SolutionPlanClusterCollection
type SolutionPlanClusters ¶
type SolutionPlanClusters []SolutionPlanCluster
SolutionPlanClusters is a slice of SolutionPlanCluster.
type SolutionStop ¶
type SolutionStop interface {
// Arrival returns the arrival time of the stop. If the stop is unplanned,
// the arrival time has no semantic meaning.
Arrival() time.Time
// ArrivalValue returns the arrival time of the stop as a float64. If the
// stop is unplanned, the arrival time has no semantic meaning.
ArrivalValue() float64
// ConstraintData returns the value of the constraint for the stop. The
// constraint value of a stop is set by the ConstraintDataUpdater.Update
// method of the constraint. If the constraint is not set on the stop,
// nil is returned. If the stop is unplanned, the constraint value has no
// semantic meaning.
ConstraintData(constraint ModelConstraint) any
// CumulativeTravelDurationValue returns the cumulative travel duration of
// the stop as a float64. The cumulative travel duration is the sum of the
// travel durations of all stops that are visited before the stop. If the
// stop is unplanned, the cumulative travel duration has no semantic
// meaning. The returned value is the number of Model.DurationUnit units.
CumulativeTravelDurationValue() float64
// CumulativeTravelDuration returns the cumulative value of the expression
// for the stop as a time.Duration. The cumulative travel duration is the
// sum of the travel durations of all stops that are visited before the
// stop and the stop itself. If the stop is unplanned, the cumulative
// travel duration has no semantic meaning.
CumulativeTravelDuration() time.Duration
// CumulativeValue returns the cumulative value of the expression for the
// stop as a float64. The cumulative value is the sum of the values of the
// expression for all stops that are visited before the stop and the stop
// itself. If the stop is unplanned, the cumulative value has no semantic
// meaning.
CumulativeValue(expression ModelExpression) float64
// End returns the end time of the stop. If the stop is unplanned, the end
// time has no semantic meaning.
End() time.Time
// EndValue returns the end time of the stop as a float64. If the stop is
// unplanned, the end time has no semantic meaning. The returned value is
// the number of Model.DurationUnit units since Model.Epoch.
EndValue() float64
// Index returns the index of the stop in the Solution.
Index() int
// IsFixed returns true if the stop is fixed. A fixed stop is a stop that
// that can not transition form being planned to unplanned or vice versa.
IsFixed() bool
// IsFirst returns true if the stop is the first stop of a vehicle.
IsFirst() bool
// IsLast returns true if the stop is the last stop of a vehicle.
IsLast() bool
// IsPlanned returns true if the stop is planned. A planned stop is a stop
// that is visited by a vehicle. An unplanned stop is a stop that is not
// visited by a vehicle.
IsPlanned() bool
// ModelStop returns the ModelStop that is the basis of the SolutionStop.
ModelStop() ModelStop
// ModelStopIndex is the index of the ModelStop in the Model.
ModelStopIndex() int
// Next returns the next stop the vehicle will visit after the stop. If
// the stop is the last stop of a vehicle, the solution stop itself is
// returned. If the stop is unplanned, the next stop has no semantic
// meaning and the stop itself is returned.
Next() SolutionStop
// NextIndex returns the index of the next solution stop the vehicle will
// visit after the stop. If the stop is the last stop of a vehicle,
// the index of the stop itself is returned. If the stop is unplanned,
// the next stop has no semantic meaning and the index of the stop itself
// is returned.
NextIndex() int
// ObjectiveData returns the value of the objective for the stop. The
// objective value of a stop is set by the ObjectiveDataUpdater.Update
// method of the objective. If the objective is not set on the stop,
// nil is returned. If the stop is unplanned, the objective value has no
// semantic meaning.
ObjectiveData(objective ModelObjective) any
// PlanCluster returns the SolutionPlanCluster that the stop is part of.
PlanCluster() SolutionPlanCluster
// Previous returns the previous stop the vehicle visited before the stop.
// If the stop is the first stop of a vehicle, the solution stop itself is
// returned. If the stop is unplanned, the previous stop has no semantic
// meaning and the stop itself is returned.
Previous() SolutionStop
// PreviousIndex returns the index of the previous solution stop the
// vehicle visited before the stop. If the stop is the first stop of a
// vehicle, the index of the stop itself is returned. If the stop is
// unplanned, the previous stop has no semantic meaning and the index of
// the stop itself is returned.
PreviousIndex() int
// Vehicle returns the SolutionVehicle that visits the stop. If the stop
// is unplanned, the vehicle has no semantic meaning and a panic will be
// raised.
Vehicle() SolutionVehicle
// VehicleIndex returns the index of the SolutionVehicle that visits the
// stop. If the stop is unplanned, a panic will be raised.
VehicleIndex() int
// Solution returns the Solution that the stop is part of.
Solution() Solution
// Start returns the start time of the stop. If the stop is unplanned, the
// start time has no semantic meaning.
Start() time.Time
// StartValue returns the start time of the stop as a float64. If the stop
// is unplanned, the start time has no semantic meaning. The returned
// value is the number of Model.DurationUnit units since Model.Epoch.
StartValue() float64
// Position returns the position of the stop in the vehicle starting with
// 0 for the first stop. If the stop is unplanned, a panic will be raised.
Position() int
// TravelDuration returns the travel duration of the stop as a
// time.Duration. If the stop is unplanned, the travel duration has no
// semantic meaning. The travel duration is the time it takes to get to
// the invoking stop.
TravelDuration() time.Duration
// TravelDurationValue returns the travel duration of the stop as a
// float64. If the stop is unplanned, the travel duration has no semantic
// meaning. The travel duration is the time it takes to get to the
// invoking stop. The returned value is the number of
// Model.DurationUnit units.
TravelDurationValue() float64
// Value returns the value of the expression for the stop as a float64.
// If the stop is unplanned, the value has no semantic meaning.
Value(expression ModelExpression) float64
}
A SolutionStop is a stop that is planned to be visited by a vehicle. It is part of a SolutionPlanCluster and is based on a ModelStop.
type SolutionStopViolationCheck ¶
type SolutionStopViolationCheck interface {
ComputationalEffort
// DoesStopHaveViolations returns true if the stop violates the constraint.
// The stop is not allowed to be nil. The stop must be part of the solution.
// This method is only called if CheckedAt returns AtEachStop.
DoesStopHaveViolations(stop SolutionStop) bool
}
SolutionStopViolationCheck is the interface that will be invoked on every update of a planned solution stop. The method DoesStopHaveViolations will be called to check if the stop violates the constraint. If the method returns true the solution will not be accepted. If un-planning can result in a violation of the constraint one of the violation checks must be implemented.
type SolutionVehicle ¶
type SolutionVehicle interface {
// AddAfterFirst creates a move that adds the given plan cluster to the
// vehicle after the first solution stop of the vehicle. The move is
// not necessarily executable, Move.IsExecutable.
AddAfterFirst(SolutionPlanCluster) Move
// AddBeforeLast creates a move that adds the given plan cluster to the
// vehicle before the last solution stop of the vehicle. The move is
// not necessarily executable, Move.IsExecutable.
AddBeforeLast(SolutionPlanCluster) Move
// BestMove returns the best move for the given solution plan cluster on
// the invoking vehicle. The best move is the move that has the lowest
// score. If there are no moves available for the given solution plan
// cluster, a move is returned which is not executable, Move.IsExecutable.
BestMove(context.Context, SolutionPlanCluster) Move
// Centroid returns the centroid of the vehicle. The centroid is the
// average location of all stops in the vehicle excluding the start and
// end stops.
Centroid() common.Location
// EndTime returns the end time of the vehicle. The end time is the time
// the vehicle ends at the end stop.
EndTime() time.Time
// First returns the first stop of the vehicle. The first stop is the
// start stop.
First() SolutionStop
// Index returns the index of the vehicle in the solution.
Index() int
// IsEmpty returns true if the vehicle is empty, false otherwise. A
// vehicle is empty if it does not have any stops. The start and end
// stops are not considered.
IsEmpty() bool
// Last returns the last stop of the vehicle. The last stop is the end
// stop.
Last() SolutionStop
// NumberOfStops returns the number of stops in the vehicle. The start
// and end stops are not considered.
NumberOfStops() int
// SolutionStops returns the stops in the vehicle. The start and end
// stops are included in the returned stops.
SolutionStops() SolutionStops
// StartTime returns the start time of the vehicle. The start time is
// the time the vehicle starts at the start stop, it has been set
// in the factory method of the vehicle Solution.NewVehicle.
StartTime() time.Time
// ModelVehicle returns the modeled vehicle type of the vehicle.
ModelVehicle() ModelVehicle
}
SolutionVehicle is a vehicle in a solution.
type SolutionVehicleViolationCheck ¶
type SolutionVehicleViolationCheck interface {
ComputationalEffort
// DoesVehicleHaveViolations returns true if the vehicle violates the
// constraint. The vehicle is not allowed to be nil. The vehicle must be
// part of the solution. This method is only called if CheckedAt returns
// AtEachVehicle.
DoesVehicleHaveViolations(vehicle SolutionVehicle) bool
}
SolutionVehicleViolationCheck is the interface that will be invoked on every update of a last planned solution stop of a vehicle. The method DoesVehicleHaveViolations will be called to check if the vehicle violates the constraint. If the method returns true the solution will not be accepted. If un-planning can result in a violation of the constraint one of the violation checks must be implemented.
type SolutionVehicles ¶
type SolutionVehicles []SolutionVehicle
SolutionVehicles is a slice of solution vehicles.
type SolutionViolationCheck ¶
type SolutionViolationCheck interface {
ComputationalEffort
// DoesSolutionHaveViolations returns true if the solution violates the
// constraint. The solution is not allowed to be nil. This method is only
// called if CheckedAt returns AtEachSolution.
DoesSolutionHaveViolations(solution Solution) bool
}
SolutionViolationCheck is the interface that will be invoked once all updates on a solution have been executed. The method DoesSolutionHaveViolations will be called to check if the vehicle violates the constraint. If the method returns true the solution will not be accepted. If un-planning can result in a violation of the constraint one of the violation checks must be implemented.
type SolveOptions ¶
type Solver ¶
type Solver interface {
alns.Progressioner
// Solve solves the problem usint the solve-options.
Solve(ctx context.Context, solveOptions SolveOptions) (Solution, error)
// SolverOptions returns the solver-options used to create the solver. The
// returned options are a copy of the options used to create the solver.
// They can be used to create a new solver and changes will have no effect
// on this invoked solver.
SolverOptions() SolverOptions
SetStartSolution(solution Solution)
}
Solver is the interface for a solver.
type SolverFactory ¶
type SolverFactory interface {
// NewSolver creates a new solver.
NewSolver(model Model) (Solver, error)
}
SolverFactory is the interface for a solver-factory.
func NewSolverFactory ¶
func NewSolverFactory() SolverFactory
type SolverOptions ¶
type SolverOptions struct {
Unplan IntParameterOptions `json:"unplan" usage:"unplan parameter"`
Plan IntParameterOptions `json:"plan" usage:"plan parameter"`
Restart IntParameterOptions `json:"restart" usage:"restart parameter"`
}
type StopExpression ¶
type StopExpression interface {
DefaultExpression
// SetValue sets the value of the expression for the given to stop.
SetValue(
stop ModelStop,
value float64,
)
}
StopExpression is an expression that has a value for each to stop.
func NewStopExpression ¶
func NewStopExpression( name string, defaultValue float64, ) StopExpression
NewStopExpression returns an expression whose value is based on the to stop in Value method. Expression values are calculated by calling the expression's Value method which takes a vehicle type, a from stop and a to stop as arguments.
type StopPosition ¶
type StopPosition interface {
// BeforeStop returns the stop which is already part of the solution.
BeforeStop() SolutionStop
// Stop returns the stop which is not yet part of the solution.
Stop() SolutionStop
}
StopPosition is the definition of the change in the solution for a specific stop. The change is defined by a BeforeStop and a Stop. The BeforeStop is a stop which is already part of the solution (it is planned) and the Stop is a stop which is not yet part of the solution (it is not planned). A stop position states that the stop should be moved from the unplanned set to the planned set by positioning it directly before the BeforeStop.
type StopPositionsHint ¶
type StopPositionsHint interface {
// HasNextStop returns true if the hint contains a next stop. If the hint
// does not contain a next stop the solver will try to find the next stop.
HasNextStop() bool
// NextStop returns the next stop. The stop must be part of the solution.
// The solver will use the hint if HasNextStop returns true.
NextStop() SolutionStop
// SkipVehicle returns true if the solver should skip the vehicle. The
// solver will use the hint if it is available.
SkipVehicle() bool
}
StopPositionsHint is an interface that can be used to give a hint to the solver about the next stop position. This can be used to speed up the solver. The solver will use the hint if it is available. Hints are generated by the estimate function of a constraint.
func NewNoStopPositionsHint ¶
func NewNoStopPositionsHint() StopPositionsHint
NewNoStopPositionsHint returns a new StopPositionsHint that does not skip the vehicle and does not contain a next stop. The solver will try to find the next stop.
func NewSkipVehiclePositionsHint ¶
func NewSkipVehiclePositionsHint(skipVehicle bool) StopPositionsHint
NewSkipVehiclePositionsHint returns a new StopPositionsHint that skips the vehicle if skipVehicle is true. Is skipVehicle is false the solver will try to find the next stop.
type SumExpression ¶
type SumExpression interface {
ModelExpression
// AddExpression adds an expression to the sum.
AddExpression(expression ModelExpression)
// Expressions returns the expressions that are part of the sum.
Expressions() ModelExpressions
}
SumExpression is an expression that returns the sum of the values of the given expressions.
func NewSumExpression ¶
func NewSumExpression(expressions ModelExpressions) SumExpression
NewSumExpression returns a new SumExpression that calculates the sum of the values of the given expressions.
type TermExpression ¶
type TermExpression interface {
ModelExpression
// Expression returns the expression.
Expression() ModelExpression
// Factor returns the factor.
Factor() float64
}
TermExpression is an expression that returns the product of the given factor and the value of the given expression.
func NewTermExpression ¶
func NewTermExpression( factor float64, expression ModelExpression, ) TermExpression
NewTermExpression returns a new TermExpression that calculates the product of the given factor and the value of the given expression.
type TravelDurationExpression ¶
type TravelDurationExpression interface {
DurationExpression
// DistanceExpression returns the distance expression.
DistanceExpression() DistanceExpression
// Speed returns the speed.
Speed() common.Speed
}
TravelDurationExpression is an expression that returns a duration based on a distance and a speed.
func NewTravelDurationExpression ¶
func NewTravelDurationExpression( distanceExpression DistanceExpression, speed common.Speed, ) TravelDurationExpression
NewTravelDurationExpression creates a new travel duration expression.
type TravelDurationObjective ¶
type TravelDurationObjective interface {
ModelObjective
}
TravelDurationObjective is an objective that uses the travel duration as an objective.
func NewTravelDurationObjective ¶
func NewTravelDurationObjective() TravelDurationObjective
NewTravelDurationObjective returns a new TravelDurationObjective that uses the travel duration as an objective.
type UnPlannedObjective ¶
type UnPlannedObjective interface {
ModelObjective
}
UnPlannedObjective is an objective that uses the un-planned stops as an objective. Each unplanned stop is scored by the given expression.
func NewUnPlannedObjective ¶
func NewUnPlannedObjective(expression StopExpression) UnPlannedObjective
NewUnPlannedObjective returns a new UnPlannedObjective that uses the un-planned stops as an objective. Each unplanned stop is scored by the given expression.
type VehicleFromToExpression ¶
type VehicleFromToExpression interface {
DefaultExpression
// SetValue sets the value of the expression for the given vehicle type,
// from and to stops.
SetValue(
vehicle ModelVehicleType,
from ModelStop,
to ModelStop,
value float64,
)
}
VehicleFromToExpression is an expression that has a value for each combination of vehicle type, from and to stop.
func NewVehicleTypeFromToExpression ¶
func NewVehicleTypeFromToExpression( name string, defaultValue float64, ) VehicleFromToExpression
NewVehicleTypeFromToExpression returns an expression whose value is based on the vehicle type, from and to stops in Value method. Expression values are calculated by calling the expression's Value method which takes a vehicle type, a from stop and a to stop as arguments.
type VehicleTypeExpression ¶
type VehicleTypeExpression interface {
DefaultExpression
// SetValue sets the value of the expression for the given vehicle type.
SetValue(
vehicle ModelVehicleType,
value float64,
)
}
VehicleTypeExpression is an expression that has a value for each vehicle type.
func NewVehicleTypeExpression ¶
func NewVehicleTypeExpression( name string, defaultValue float64, ) VehicleTypeExpression
NewVehicleTypeExpression returns a VehicleTypeExpression whose value is based on the vehicle type in Value method. Expression values are calculated by calling the expression's Value method which takes a vehicle type, a from stop and a to stop as arguments.
type VehiclesObjective ¶
type VehiclesObjective interface {
ModelObjective
}
VehiclesObjective is an objective that uses the number of vehicles as an objective. Each vehicle that is not empty is scored by the given expression. A vehicle is empty if it has no stops assigned to it (except for the first and last visit).
func NewVehiclesObjective ¶
func NewVehiclesObjective(expression VehicleTypeExpression) VehiclesObjective
NewVehiclesObjective returns a new VehiclesObjective that uses the number of vehicles as an objective. Each vehicle that is not empty is scored by the given expression. A vehicle is empty if it has no stops assigned to it (except for the first and last visit).
Source Files
¶
- engine.go
- model.go
- model_checkedat.go
- model_complexity.go
- model_constraint.go
- model_constraint_attributes.go
- model_constraint_inwardness.go
- model_constraint_maximum.go
- model_constraint_maximumstops.go
- model_expression.go
- model_expression_binary.go
- model_expression_custom.go
- model_expression_duration.go
- model_expression_haversine.go
- model_expression_measure_byindex.go
- model_expression_measure_bypoint.go
- model_expression_sum.go
- model_expression_unary.go
- model_latestend.go
- model_lateststart.go
- model_objective.go
- model_objective_travelduration.go
- model_objective_unplanned.go
- model_objective_vehicles.go
- model_plancluster.go
- model_plansinglestop.go
- model_position_hint.go
- model_stop.go
- model_vehicle.go
- model_vehicle_type.go
- performance_observer.go
- solution.go
- solution_move.go
- solution_observer.go
- solution_plancluster.go
- solution_plancluster_collection.go
- solution_stop.go
- solution_vehicle.go
- solver.go
- solver_parallel.go