nextmv Docs

Modeling Best Practices

Modeling Best Practices

"If a muscle doesn't make music, don't use it."

-- Emanuel Feuermann

Hop has a different way of approaching the world than previous technologies.

States & Transitions

Hop solvers operate by evaluating states and projecting the impacts of choices according to transition functions. Thus it makes sense to structure our model code and any helper functions as state machines.

For example, in a Hop vehicle routing model, the Next method makes a choice about whether a state transition can occur (e.g. does the driver have capacity?) and calls a method which generates a new state.

if s.Driver.State.Capacity > 0 {
for it := s.pickups.Iterator(); it.Next(); {
next = append(next, s.Pickup(it.Value()))

This makes models concise, easy to test, and easy to reason about.

Keeping Track of Decisions

The order in which we make decisions can have a major impact on the solutions we find. Some models have an obvious decision ordering. For instance, a routing model adapts a sequential ordering of decisions. The decision is always the same: "Where should we go next?"

Understanding Values & Bounds

Hop only requires a Value method when we want to maximize or minimize some objective. The Bounds method is optional.

However, if you can provide bounds on an objective, you should! It may greatly improve the search since Hop uses that information to prune states from its search tree. Try removing the Bounds methods from our templates and see how that changes their runtime. Pay special attention to the statistics section of the JSON output. This shows the number of states explored and deferred for later exploration.