6
6
import pytest
7
7
from dataclasses import dataclass , field
8
8
from typing import Annotated , List
9
- from copy import deepcopy
10
9
11
10
12
11
def test_solve ():
@@ -83,8 +82,6 @@ def do_change(self, solution: Solution, problem_change_director: ProblemChangeDi
83
82
)
84
83
problem : Solution = Solution ([Entity ('A' ), Entity ('B' ), Entity ('C' )], [Value (1 ), Value (2 ), Value (3 )],
85
84
SimpleScore .ONE )
86
- impossible_problem : Solution = Solution ([Entity ('A' )], [Value (1 ), Value (2 ), Value (3 )],
87
- SimpleScore .ONE )
88
85
89
86
def assert_solver_run (solver_manager , solver_job ):
90
87
assert solver_manager .get_solver_status (1 ) != SolverStatus .NOT_SOLVING
@@ -113,25 +110,21 @@ def assert_problem_change_solver_run(solver_manager, solver_job):
113
110
for solver_manager in (
114
111
SolverManager .create (solver_config ),
115
112
SolverManager .create (SolverFactory .create (solver_config )),
116
- SolverManager .create (solver_config , SolverManagerConfig (parallel_solver_count = 1 )),
113
+ SolverManager .create (solver_config , SolverManagerConfig (parallel_solver_count = 4 )),
117
114
SolverManager .create (SolverFactory .create (solver_config ), SolverManagerConfig (parallel_solver_count = 'AUTO' ))
118
115
):
119
116
with solver_manager :
120
117
lock .acquire ()
121
- solver_job = solver_manager .solve (1 , deepcopy ( problem ) )
118
+ solver_job = solver_manager .solve (1 , problem )
122
119
assert_solver_run (solver_manager , solver_job )
123
120
124
121
lock .acquire ()
125
- solver_job = solver_manager .solve (1 , deepcopy ( impossible_problem ) )
122
+ solver_job = solver_manager .solve (1 , problem )
126
123
assert_problem_change_solver_run (solver_manager , solver_job )
127
124
128
125
def get_problem (problem_id ):
129
126
assert problem_id == 1
130
- return deepcopy (problem )
131
-
132
- def get_impossible_problem (problem_id ):
133
- assert problem_id == 1
134
- return deepcopy (impossible_problem )
127
+ return problem
135
128
136
129
lock .acquire ()
137
130
solver_job = (solver_manager .solve_builder ()
@@ -142,7 +135,7 @@ def get_impossible_problem(problem_id):
142
135
lock .acquire ()
143
136
solver_job = (solver_manager .solve_builder ()
144
137
.with_problem_id (1 )
145
- .with_problem_finder (get_impossible_problem )).run ()
138
+ .with_problem_finder (get_problem )).run ()
146
139
assert_problem_change_solver_run (solver_manager , solver_job )
147
140
148
141
solution_list = []
@@ -166,7 +159,7 @@ def on_best_solution_changed(solution):
166
159
lock .acquire ()
167
160
solver_job = (solver_manager .solve_builder ()
168
161
.with_problem_id (1 )
169
- .with_problem_finder (get_impossible_problem )
162
+ .with_problem_finder (get_problem )
170
163
.with_best_solution_consumer (on_best_solution_changed )
171
164
).run ()
172
165
assert_problem_change_solver_run (solver_manager , solver_job )
@@ -192,7 +185,7 @@ def on_best_solution_changed(solution):
192
185
lock .acquire ()
193
186
solver_job = (solver_manager .solve_builder ()
194
187
.with_problem_id (1 )
195
- .with_problem_finder (get_impossible_problem )
188
+ .with_problem_finder (get_problem )
196
189
.with_best_solution_consumer (on_best_solution_changed )
197
190
.with_final_best_solution_consumer (on_best_solution_changed )
198
191
).run ()
@@ -260,7 +253,7 @@ def my_exception_handler(problem_id, exception):
260
253
try :
261
254
(solver_manager .solve_builder ()
262
255
.with_problem_id (1 )
263
- .with_problem (deepcopy ( problem ) )
256
+ .with_problem (problem )
264
257
.with_exception_handler (my_exception_handler )
265
258
.run ().get_final_best_solution ())
266
259
except :
@@ -275,7 +268,7 @@ def my_exception_handler(problem_id, exception):
275
268
try :
276
269
(solver_manager .solve_builder ()
277
270
.with_problem_id (1 )
278
- .with_problem (deepcopy ( problem ) )
271
+ .with_problem (problem )
279
272
.with_best_solution_consumer (lambda solution : None )
280
273
.with_exception_handler (my_exception_handler )
281
274
.run ().get_final_best_solution ())
0 commit comments