22
33import java .util .ArrayList ;
44import java .util .List ;
5- import java .util .function .BooleanSupplier ;
65
76import ai .timefold .solver .benchmarks .examples .flowshop .domain .Job ;
87import ai .timefold .solver .benchmarks .examples .flowshop .domain .JobScheduleSolution ;
9- import ai .timefold .solver .core . api . score . director . ScoreDirector ;
8+ import ai .timefold .solver .benchmarks . examples . flowshop . domain . Machine ;
109import ai .timefold .solver .core .api .solver .phase .PhaseCommand ;
10+ import ai .timefold .solver .core .api .solver .phase .PhaseCommandContext ;
11+ import ai .timefold .solver .core .preview .api .domain .metamodel .PlanningListVariableMetaModel ;
12+ import ai .timefold .solver .core .preview .api .move .builtin .Moves ;
1113
1214/**
1315 * This custom phase implements the NEH construction heuristic with the Taillard acceleration strategy.
2022public class NEHCustomPhase implements PhaseCommand <JobScheduleSolution > {
2123
2224 @ Override
23- public void changeWorkingSolution (ScoreDirector <JobScheduleSolution > scoreDirector , BooleanSupplier isPhaseTerminated ) {
25+ public void changeWorkingSolution (PhaseCommandContext <JobScheduleSolution > phaseCommandContext ) {
2426 // The enrichment step, after loading the solution,
2527 // will sort the jobs by the sum of processing times in decreasing order
26- var workingSolution = scoreDirector .getWorkingSolution ();
28+ var workingSolution = phaseCommandContext .getWorkingSolution ();
2729 var jobs = workingSolution .getJobs ();
2830 var currentJobSchedule = new ArrayList <Job >(jobs .size ());
2931 currentJobSchedule .add (jobs .get (0 ));
@@ -45,16 +47,13 @@ public void changeWorkingSolution(ScoreDirector<JobScheduleSolution> scoreDirect
4547 }
4648 currentJobSchedule .add (minIndex , jobs .get (k ));
4749 }
48- scoreDirector .beforeListVariableChanged (workingSolution .getMachine (), "jobs" , 0 , 0 );
50+ var listVariableMetaModel =
51+ (PlanningListVariableMetaModel <JobScheduleSolution , Machine , Job >) phaseCommandContext
52+ .getSolutionMetaModel ().entity (Machine .class ).<Job > variable ("jobs" );
4953 for (var job : currentJobSchedule ) {
50- scoreDirector .beforeListVariableElementAssigned (workingSolution .getMachine (), "jobs" , job );
54+ phaseCommandContext .execute (Moves .assign (listVariableMetaModel , job , workingSolution .getMachine (),
55+ workingSolution .getMachine ().getJobs ().size ()));
5156 }
52- workingSolution .getMachine ().setJobs (currentJobSchedule );
53- scoreDirector .afterListVariableChanged (workingSolution .getMachine (), "jobs" , 0 , currentJobSchedule .size ());
54- for (var job : currentJobSchedule ) {
55- scoreDirector .afterListVariableElementAssigned (workingSolution .getMachine (), "jobs" , job );
56- }
57- scoreDirector .triggerVariableListeners ();
5857 }
5958
6059 /**
0 commit comments