Skip to content

●  optimaru Engine

One search loop for every use case.

Every use case runs the same search: build a first solution, then improve it one move at a time, each move judged by an acceptor, with perturbation to restart progress when the search stalls, until a limit is reached.

← optimaru Engine

Assemble a solver for one use case and get the Python: the solver builder in the developer portal (opens in a new window)

The loop

How a solve runs

Construction runs once. Everything in the dashed frame is one step, repeated until a stop condition holds; the best solution is kept apart, so a step that makes things worse never loses it.

Each box names the file its step is in; the links open it on GitHub.

  1. Begin
  2. Construction → s₀Each unassigned entity gets its best placement. A solution you pass in is kept; only the rest is built.The code of this step: construct/construction.hpp (opens in a new window)
  3. Each step, until a stop condition holds

    1. Stop condition met?Time limit, step limit, no new best for a while, or a target scoreThe code of this step: stop/stop_condition.hpp (opens in a new window)
      Yes
      Return s_best
      No
    2. Search stalled?No new best for as many steps as it usually takes, and at least the triggerThe code of this step: solver.hpp (opens in a new window)
      Yes
      PerturbationTo get the search moving again, the solver removes part of the solution (10–30% by default), reinserts the removed items, and briefly improves the result with hill climbing. This becomes the current solution s even if its score is worse. When late acceptance runs in stages, a stall can advance it to the next stage.The code of this step: search/perturbation/stagnation_kick.hpp (opens in a new window)
      No
    3. Built-in strategy drawn?In a fixed order, the solver draws once per strategy at its own probability (0–1) and uses the first strategy drawnThe code of this step: search/strategies/strategies.hpp (opens in a new window)
      Yes
      That strategy makes s′The strategy explores more changes than a basic move, such as repeatedly improving the solution, removing a route, or removing and reinserting several items.
      No
    4. Use-case moves’ turn?On a set share of the steps left, if the use case adds moves of its own
      Yes
      An adaptive selector picks the moveOne of the use case’s moves, or the move mix, by what each has found so farThe code of this step: search/operators.hpp (opens in a new window)
      No
    5. Move mix: draw one move → s′By relative weight; what it moves is chosen by the selection rules (nearby first, the use case’s hints)The code of this step: search/move_mix/move_mix.hpp (opens in a new window)
    6. Score s′ incrementallyOnly what the move touched is recomputedThe code of this step: solution/editor.hpp (opens in a new window)
    7. Acceptor takes s′?Late acceptance is the default. It compares the candidate with the current score and a score from an earlier step.The code of this step: accept/ (opens in a new window)
      No
      Undo the move
      Yes · s := s′
    8. Yes
      s_best := s

    Next step

  4. End
Construction
An empty or partial solution becomes complete. A solution you pass in is kept as it is. In the code (opens in a new window)
Moves
Each step asks, in this order, for a built-in strategy (a large neighbourhood), then for one of the use case’s own moves, and otherwise draws an ordinary small move. Only what the move touched is re-scored, which is what makes a step cheap. In the code (opens in a new window)
Acceptor
Late acceptance by default: a move is taken if it is no worse than the current solution or than the one a fixed number of steps ago. The engine has seven rules; some use cases let you choose one. In the code (opens in a new window)
Perturbation
When the best solution stops improving, the engine removes and reinserts some items to explore alternatives. The engine adjusts how it selects removal operators based on their past results. Most use cases enable perturbation by default. In the code (opens in a new window)

Contributing

Follow it in the code, and add to it

The engine’s code is on GitHub. The loop above is Solver::run in core/optimaru/solver.hpp, and the parts a contribution adds to (moves, ruins, constraints) are plugins with an interface of their own, so most contributions plug into one use case without touching the engine.

How a solve runs, in the code: each step above with its file, its settings and how to add to it (opens in a new window)