Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 38 additions & 15 deletions check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,13 @@ func (m *checkImpl) checkSolutionPlanUnits(
planUnitsObserver := newObserver()
moveObserver := newObserver()

if int(m.verbosity) >= int(Medium) {
defer func() {
m.solution.Model().RemoveSolutionObserver(planUnitsObserver)
m.solution.Model().RemoveSolutionObserver(moveObserver)
}()
defer func() {
m.solution.Model().RemoveSolutionObserver(planUnitsObserver)
m.solution.Model().RemoveSolutionObserver(moveObserver)
}()

m.solution.Model().AddSolutionObserver(planUnitsObserver)
m.solution.Model().AddSolutionObserver(moveObserver)
}
m.solution.Model().AddSolutionObserver(planUnitsObserver)
m.solution.Model().AddSolutionObserver(moveObserver)

SolutionPlanUnitLoop:
for solutionPlanUnitIdx, solutionPlanUnit := range solutionPlanUnits {
Expand Down Expand Up @@ -209,7 +207,8 @@ SolutionPlanUnitLoop:
}

moveMinimumValue := math.MaxFloat64
moveIsImprovement := false
hasImprovingMove := false
hasWorseMove := false
movesFailed := false
VehicleLoop:
for solutionVehicleIdx, solutionVehicle := range m.solution.Vehicles() {
Expand All @@ -219,6 +218,8 @@ SolutionPlanUnitLoop:
continue
}

m.output.PlanUnits[solutionPlanUnitIdx].HasExecutableBestMove = true

if m.output.PlanUnits[solutionPlanUnitIdx].VehiclesHaveMoves != nil {
*m.output.PlanUnits[solutionPlanUnitIdx].VehiclesHaveMoves++
}
Expand All @@ -228,6 +229,7 @@ SolutionPlanUnitLoop:
VehicleID: solutionVehicle.ModelVehicle().ID(),
DeltaObjectiveEstimate: &value,
FailedConstraints: []string{},
WasExecutable: true,
Comment thread
merschformann marked this conversation as resolved.
Resolved
}

if solutionMoveStops, ok := bestMove.(nextroute.SolutionMoveStops); ok {
Expand All @@ -242,6 +244,21 @@ SolutionPlanUnitLoop:
}
}

if bestSolutionMoveStops, ok := bestMove.(nextroute.SolutionMoveStops); ok && int(m.verbosity) >= int(High) {
currentObjectiveTerms := []schema.ObjectiveTermDelta{}
for _, term := range m.solution.Model().Objective().Terms() {
deltaValue := term.Objective().EstimateDeltaValue(bestSolutionMoveStops)
currentObjectiveTerms = append(
currentObjectiveTerms,
schema.ObjectiveTermDelta{
Name: fmt.Sprintf("%v", term.Objective()),
DeltaValue: deltaValue,
},
)
}
vehicleDetails.ObjectiveDeltas = currentObjectiveTerms
}
Comment thread
merschformann marked this conversation as resolved.
Resolved

if m.output.PlanUnits[solutionPlanUnitIdx].VehiclesWithMoves != nil {
m.output.PlanUnits[solutionPlanUnitIdx].VehiclesWithMoves = append(
m.output.PlanUnits[solutionPlanUnitIdx].VehiclesWithMoves,
Expand All @@ -258,16 +275,23 @@ SolutionPlanUnitLoop:
return err
}

failedForConstraint := false
for _, constraint := range moveObserver.OnPlanFailedConstraints() {
name := fmt.Sprintf("%v", constraint)
vehicleDetails.FailedConstraints = append(
vehicleDetails.FailedConstraints,
name,
)
failedForConstraint = true
vehicleDetails.WasExecutable = false
}

if !planned && !failedForConstraint {
Comment thread
merschformann marked this conversation as resolved.
Resolved
hasWorseMove = true
}

if planned {
moveIsImprovement = true
hasImprovingMove = true
vehicleDetails.WasPlannable = true
deltaObjective := statistics.Float64(m.solution.Score() - actualScoreBeforeMove)
vehicleDetails.DeltaObjective = &deltaObjective
Expand Down Expand Up @@ -325,12 +349,12 @@ SolutionPlanUnitLoop:
}
}

if !hasImprovingMove && hasWorseMove {
m.output.PlanUnits[solutionPlanUnitIdx].PlanningMakesObjectiveWorse = true
m.output.Summary.NumberOfPlanUnitsMakingObjectiveWorse++
}
if m.output.PlanUnits[solutionPlanUnitIdx].HasPlannableBestMove {
m.output.Summary.PlanUnitsBestMoveFound++
if !moveIsImprovement {
m.output.PlanUnits[solutionPlanUnitIdx].PlanningMakesObjectiveWorse = true
m.output.Summary.NumberOfPlanUnitsMakingObjectiveWorse++
}
} else {
m.output.Summary.PlanUnitsHaveNoMove++
constraints := make(map[string]int, len(m.solution.Model().Constraints()))
Expand Down Expand Up @@ -364,7 +388,6 @@ func (m *checkImpl) Check() {
localCtx,
m.solution.UnPlannedPlanUnits().SolutionPlanUnits(),
)

if err != nil {
errorStr := err.Error()
m.output.Error = &errorStr
Expand Down
27 changes: 26 additions & 1 deletion check/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ type PlanUnit struct {
// execute it, it wasn't executable - this is an error in the constraint
// estimation.
HasPlannableBestMove bool `json:"has_plannable_best_move"`
// HasExecutableBestMove is true if a best move is found for the plan unit
// and that best move is executable (i.e. it can be executed). A move might
// be executable but not plannable if it makes the objective worse or if
// its execution later fails.
HasExecutableBestMove bool `json:"has_executable_best_move"`
// PlanningMakesObjectiveWorse is true if the best move for the plan unit
// increases the objective.
PlanningMakesObjectiveWorse bool `json:"planning_makes_objective_worse"`
Expand All @@ -115,6 +120,18 @@ type PlanUnit struct {
Constraints map[string]int `json:"constraints,omitempty"`
}

// ObjectiveTermDelta contains information about the improvement of an objective
// term caused by a move. A negative delta means the move improves the value for
// the given term, a positive delta means the move worsens the value for the
// given term.
type ObjectiveTermDelta struct {
// Name is the name of the objective term.
Name string `json:"name"`
// DeltaValue is the difference in value of the objective term (without the
// factor).
DeltaValue float64 `json:"delta_value"`
}

// VehiclesWithMovesDetail shows details of the vehicles that have moves.
type VehiclesWithMovesDetail struct {
// Vehicle is the ID of the vehicle.
Expand All @@ -125,10 +142,18 @@ type VehiclesWithMovesDetail struct {
// DeltaObjective is the actual delta of the objective of that will be
// incurred by the move.
DeltaObjective *statistics.Float64 `json:"delta_objective,omitempty"`
// ObjectiveDeltas is the estimate of the objective value deltas of the
// move. I.e., the difference in value of the individual terms of the
// objective. This is only calculated if the verbosity is high.
ObjectiveDeltas []ObjectiveTermDelta `json:"objective_deltas,omitempty"`
// FailedConstraints are the constraints that are violated for the move.
FailedConstraints []string `json:"failed_constraints,omitempty"`
// WasPlannable is true if the move was plannable, false otherwise.
// WasPlannable is true if the move was plannable, false otherwise. A move
// can be planned if it is executable and does not make the objective worse.
WasPlannable bool `json:"was_plannable"`
// WasExecutable is true if the move was executable, false otherwise. A move
// can be executed if constraints are not violated.
WasExecutable bool `json:"was_executable"`
// Positions defines where the stop should be inserted.
Positions []Position `json:"positions"`
}
Expand Down
Loading
Loading