66import java .util .function .Function ;
77
88import ai .timefold .solver .core .api .domain .solution .PlanningSolution ;
9+ import ai .timefold .solver .core .api .solver .event .FinalBestSolutionEvent ;
10+ import ai .timefold .solver .core .api .solver .event .FirstInitializedSolutionEvent ;
11+ import ai .timefold .solver .core .api .solver .event .NewBestSolutionEvent ;
12+ import ai .timefold .solver .core .api .solver .event .SolverJobStartedEvent ;
913
1014import org .jspecify .annotations .NonNull ;
1115import org .jspecify .annotations .NullMarked ;
@@ -57,41 +61,82 @@ public interface SolverJobBuilder<Solution_, ProblemId_> {
5761 SolverJobBuilder <Solution_ , ProblemId_ >
5862 withProblemFinder (@ NonNull Function <? super ProblemId_ , ? extends Solution_ > problemFinder );
5963
64+ /**
65+ * As defined by {@link #withBestSolutionEventConsumer(Consumer)}.
66+ *
67+ * @deprecated Use {@link #withBestSolutionEventConsumer(Consumer)} instead.
68+ */
69+ @ Deprecated (forRemoval = true , since = "1.28.0" )
70+ @ NonNull
71+ default SolverJobBuilder <Solution_ , ProblemId_ >
72+ withBestSolutionConsumer (@ NonNull Consumer <? super Solution_ > bestSolutionConsumer ) {
73+ return withBestSolutionEventConsumer (event -> bestSolutionConsumer .accept (event .solution ()));
74+ }
75+
6076 /**
6177 * Sets the best solution consumer, which may be called multiple times during the solving process.
6278 * <p>
6379 * Don't apply any changes to the solution instance while the solver runs.
6480 * The solver's best solution instance is the same as the one in the event,
6581 * and any modifications may lead to solver corruption due to its internal reuse.
6682 *
67- * @param bestSolutionConsumer called multiple times for each new best solution on a consumer thread
83+ * @param bestSolutionEventConsumer called multiple times for each new best solution on a consumer thread
6884 * @return this
6985 */
7086 @ NonNull
71- SolverJobBuilder <Solution_ , ProblemId_ > withBestSolutionConsumer (@ NonNull Consumer <? super Solution_ > bestSolutionConsumer );
87+ SolverJobBuilder <Solution_ , ProblemId_ >
88+ withBestSolutionEventConsumer (@ NonNull Consumer <NewBestSolutionEvent <Solution_ >> bestSolutionEventConsumer );
89+
90+ /**
91+ * As defined by {@link #withFinalBestSolutionEventConsumer}.
92+ *
93+ * @deprecated Use {@link #withFinalBestSolutionEventConsumer(Consumer)} instead.
94+ */
95+ @ Deprecated (forRemoval = true , since = "1.28.0" )
96+ @ NonNull
97+ default SolverJobBuilder <Solution_ , ProblemId_ >
98+ withFinalBestSolutionConsumer (@ NonNull Consumer <? super Solution_ > finalBestSolutionConsumer ) {
99+ return withFinalBestSolutionEventConsumer (event -> finalBestSolutionConsumer .accept (event .solution ()));
100+ }
72101
73102 /**
74103 * Sets the final best solution consumer, which is called at the end of the solving process and returns the final
75104 * best solution.
76105 *
77- * @param finalBestSolutionConsumer called only once at the end of the solving process on a consumer thread
106+ * @param finalBestSolutionEventConsumer called only once at the end of the solving process on a consumer thread
78107 * @return this
79108 */
80109 @ NonNull
81110 SolverJobBuilder <Solution_ , ProblemId_ >
82- withFinalBestSolutionConsumer (@ NonNull Consumer <? super Solution_ > finalBestSolutionConsumer );
111+ withFinalBestSolutionEventConsumer (
112+ @ NonNull Consumer <FinalBestSolutionEvent <Solution_ >> finalBestSolutionEventConsumer );
83113
84114 /**
85- * As defined by #withFirstInitializedSolutionConsumer(FirstInitializedSolutionConsumer) .
115+ * As defined by {@link #withFirstInitializedSolutionEventConsumer(Consumer)} .
86116 *
87- * @deprecated Use {@link #withFirstInitializedSolutionConsumer(FirstInitializedSolutionConsumer )} instead.
117+ * @deprecated Use {@link #withFirstInitializedSolutionEventConsumer(Consumer )} instead.
88118 */
89119 @ Deprecated (forRemoval = true , since = "1.19.0" )
90120 @ NonNull
91121 default SolverJobBuilder <Solution_ , ProblemId_ >
92122 withFirstInitializedSolutionConsumer (@ NonNull Consumer <? super Solution_ > firstInitializedSolutionConsumer ) {
93- return withFirstInitializedSolutionConsumer (
94- (solution , isTerminatedEarly ) -> firstInitializedSolutionConsumer .accept (solution ));
123+ return withFirstInitializedSolutionEventConsumer (event -> firstInitializedSolutionConsumer .accept (event .solution ()));
124+ }
125+
126+ /**
127+ * As defined by {@link #withFirstInitializedSolutionEventConsumer(Consumer)}.
128+ *
129+ * @deprecated Use {@link #withFirstInitializedSolutionEventConsumer(Consumer)} instead.
130+ *
131+ * @param firstInitializedSolutionConsumer called only once before starting the first Local Search phase
132+ * @return this
133+ */
134+ @ Deprecated (forRemoval = true , since = "1.28.0" )
135+ @ NonNull
136+ default SolverJobBuilder <Solution_ , ProblemId_ > withFirstInitializedSolutionConsumer (
137+ @ NonNull FirstInitializedSolutionConsumer <? super Solution_ > firstInitializedSolutionConsumer ) {
138+ return withFirstInitializedSolutionEventConsumer (
139+ event -> firstInitializedSolutionConsumer .accept (event .solution (), event .isTerminatedEarly ()));
95140 }
96141
97142 /**
@@ -100,20 +145,31 @@ public interface SolverJobBuilder<Solution_, ProblemId_> {
100145 * First initialized solution is the solution at the end of the last phase
101146 * that immediately precedes the first local search phase.
102147 *
103- * @param firstInitializedSolutionConsumer called only once before starting the first Local Search phase
148+ * @param firstInitializedSolutionEventConsumer called only once before starting the first Local Search phase
104149 * @return this
105150 */
106- @ NonNull
107- SolverJobBuilder <Solution_ , ProblemId_ > withFirstInitializedSolutionConsumer (
108- @ NonNull FirstInitializedSolutionConsumer <? super Solution_ > firstInitializedSolutionConsumer );
151+ SolverJobBuilder <Solution_ , ProblemId_ > withFirstInitializedSolutionEventConsumer (
152+ @ NonNull Consumer <FirstInitializedSolutionEvent <Solution_ >> firstInitializedSolutionEventConsumer );
153+
154+ /**
155+ * As defined by {@link #withSolverJobStartedEventConsumer(Consumer)}.
156+ *
157+ * @deprecated Use {@link #withSolverJobStartedEventConsumer(Consumer)} instead.
158+ */
159+ @ Deprecated (forRemoval = true , since = "1.28.0" )
160+ default SolverJobBuilder <Solution_ , ProblemId_ >
161+ withSolverJobStartedConsumer (Consumer <? super Solution_ > solverJobStartedConsumer ) {
162+ return withSolverJobStartedEventConsumer (event -> solverJobStartedConsumer .accept (event .solution ()));
163+ }
109164
110165 /**
111166 * Sets the consumer for when the solver starts its solving process.
112167 *
113168 * @param solverJobStartedConsumer never null, called only once when the solver is starting the solving process
114169 * @return this, never null
115170 */
116- SolverJobBuilder <Solution_ , ProblemId_ > withSolverJobStartedConsumer (Consumer <? super Solution_ > solverJobStartedConsumer );
171+ SolverJobBuilder <Solution_ , ProblemId_ >
172+ withSolverJobStartedEventConsumer (Consumer <SolverJobStartedEvent <Solution_ >> solverJobStartedConsumer );
117173
118174 /**
119175 * Sets the custom exception handler.
@@ -166,5 +222,4 @@ interface FirstInitializedSolutionConsumer<Solution_> {
166222 void accept (Solution_ solution , boolean isTerminatedEarly );
167223
168224 }
169-
170225}
0 commit comments