Skip to content

refactor(core): route Backward/Balanced optimization strategies through GreedyBased template method #996

@Kohei-Wada

Description

@Kohei-Wada

Survey finding from the #946#951 refactor sweep, verified against current main. Scope was narrowed after verification.

Background

GreedyBasedOptimizationStrategy already implements the optimize_tasks() outer loop as a template method (dict(existing)OptimizeResult_sort_tasks() → per-task _allocate_task()/record). Greedy / PriorityFirst / EarliestDeadline / DependencyAware already derive from it and only override _sort_tasks().

Problem (verified, narrowed scope)

BackwardOptimizationStrategy and BalancedOptimizationStrategy re-implement the identical outer loop instead of inheriting it. Their optimize_tasks() bodies are essentially line-for-line identical to the GreedyBased template (even comments match), despite already having their own _sort_tasks / _allocate_task.

Proposal

Make Backward and Balanced extend GreedyBasedOptimizationStrategy and drop their duplicated optimize_tasks(), overriding only the sort/allocate hooks. Low risk, removes two full copies of the outer loop.

Out of scope

The original survey suggested templating all 9 strategies. Verification showed this does not hold:

  • RoundRobin distributes per-day across active tasks — not a per-task prepare→allocate→record loop.
  • Genetic / MonteCarlo are meta-strategies that call GreedyOptimizationStrategy._allocate_task internally to search orderings; their outer loop is search order → greedy allocate → fitness.

These three do not fit the _sort_tasks/_allocate_task template and should be left alone here. (A separate "reuse greedy allocation in meta-strategies" cleanup could be considered independently.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    coretaskdog-core packagepriority: lowLow priority issuerefactoringCode refactoring and improvements

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions