-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added satisfy implementation for fjsp, added UT
- Loading branch information
Showing
3 changed files
with
132 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Copyright (c) 2024 AIRBUS and its affiliates. | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
import logging | ||
|
||
from discrete_optimization.fjsp.flex_job_shop_problem import ( | ||
Job, | ||
SolutionFJobshop, | ||
Subjob, | ||
) | ||
from discrete_optimization.fjsp.solvers.cpsat_fjsp_problem import ( | ||
CPSatFJspSolver, | ||
FJobShopProblem, | ||
) | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
|
||
|
||
def create_dummy_fjsp_and_sol(): | ||
job_0 = Job( | ||
job_id=0, | ||
sub_jobs=[ | ||
[Subjob(0, 1), Subjob(1, 2)], | ||
[Subjob(3, 1), Subjob(4, 2)], | ||
[Subjob(1, 1), Subjob(2, 2)], | ||
], | ||
) | ||
job_1 = Job( | ||
job_id=1, | ||
sub_jobs=[ | ||
[Subjob(0, 1), Subjob(1, 2)], | ||
[Subjob(3, 1), Subjob(4, 2)], | ||
[Subjob(1, 4), Subjob(2, 2)], | ||
], | ||
) | ||
problem = FJobShopProblem( | ||
list_jobs=[job_0, job_1], n_jobs=2, n_machines=5, horizon=30 | ||
) | ||
sol = SolutionFJobshop( | ||
problem=problem, | ||
schedule=[[(0, 1, 0), (1, 2, 3), (2, 4, 2)], [(0, 2, 1), (2, 4, 4), (4, 6, 2)]], | ||
) | ||
return problem, sol | ||
|
||
|
||
def test_fjsp_satisfy(): | ||
problem, sol = create_dummy_fjsp_and_sol() | ||
assert problem.satisfy(sol) | ||
# Overlap of machine 0 at time 0 ! | ||
sol = SolutionFJobshop( | ||
problem=problem, | ||
schedule=[[(0, 1, 0), (1, 2, 3), (2, 4, 2)], [(0, 1, 0), (2, 4, 4), (4, 6, 2)]], | ||
) | ||
assert not problem.satisfy(sol) | ||
|
||
# Wrong machine on job (1, 0) | ||
|
||
sol = SolutionFJobshop( | ||
problem=problem, | ||
schedule=[[(0, 1, 0), (1, 2, 3), (2, 4, 2)], [(0, 2, 5), (2, 4, 4), (4, 6, 2)]], | ||
) | ||
assert not problem.satisfy(sol) | ||
|
||
# Precedence constraint broken between (1, 2) and (1, 1) | ||
sol = SolutionFJobshop( | ||
problem=problem, | ||
schedule=[[(0, 1, 0), (1, 2, 3), (2, 4, 2)], [(0, 2, 1), (4, 6, 4), (2, 4, 2)]], | ||
) | ||
assert not problem.satisfy(sol) |