コードリーディング

概要

http://docs.jboss.org/optaplanner/release/latest/optaplanner-docs/html_single/index.html#methodologyOverview

http://docs.jboss.org/optaplanner/release/latest/optaplanner-docs/html_single/index.html#scopeOverview

  • クライアントコードから見る
  • CloudBalance
  • solve()
    • phase step/move
    • score
    • algorithm
  • build / config は後回しでいいか

Breakpoint

config

CloudBalancingHelloWorld [line: 32] - main(String[])
-> ここから config

ConstructionHeuristicPhaseConfig [line: 112] - buildPhase(int, HeuristicConfigPolicy, BestSolutionRecaller, Termination)
-> constructionHeuristicType を元に、EntitySorterManner を決定。

ConstructionHeuristicType [line: 82] - getDefaultEntitySorterManner()
-> 例えば FIRST_FIT_DECREASING は EntitySorterManner.DECREASING_DIFFICULTY

solve

CloudBalancingHelloWorld [line: 38] - main(String[])
-> ここから solve

DefaultSolver [line: 213] - runPhases()
-> Phase を順次実行する。普通は 1. ConstructionHeuristicPhase 2. LocalSearchPhase.

ConstructionHeuristic

DefaultConstructionHeuristicPhase [line: 65] - solve(DefaultSolverScope)
-> entityPlacer が持っている Placement をひとつずつ評価。QueuedEntityPlacer が MimicRecordingEntitySelector を保持している

ConstructionHeuristicDecider [line: 71] - decideNextStep(ConstructionHeuristicStepScope, Placement)
-> Placement が持っている Move をひとつずつ評価

ConstructionHeuristicDecider [line: 85] - decideNextStep(ConstructionHeuristicStepScope, Placement)
-> Step になる Move を決定

DroolsScoreDirector [line: 87] - calculateScore()
-> fireAllRules() でスコアを計算。insert() は DroolsScoreDirector.afterEntityAdded() で

LocalSearch

DefaultLocalSearchPhase [line: 63] - solve(DefaultSolverScope)
-> LocalSearch のメインループ

LocalSearchDecider [line: 113] - decideNextStep(LocalSearchStepScope)
-> moveSelector が持っている Move をひとつずつ評価

AbstractTabuAcceptor [line: 131] - isAccepted(LocalSearchMoveScope)
-> Tabu Search. 意外とややこしい実装。後で

my example

branch officeSeat
/home/tkobayas/usr/git/tkobayas/optaplanner/optaplanner-examples
jbds800_tkobayas_optaplanner
OfficeSeatApp