-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add problems page in advanced section
- Loading branch information
1 parent
fd1a327
commit 34cdae6
Showing
4 changed files
with
199 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Timespan = Annotated[int, Interval(ge=0, le=(2**64 - 1) / 5)] | ||
Machine = Annotated[int, Interval(ge=1, le=5)] | ||
|
||
|
||
class Instance(InstanceModel): | ||
"""The Scheduling problem class.""" | ||
|
||
job_lengths: list[Timespan] | ||
|
||
@property | ||
def size(self) -> int: | ||
return len(self.job_lengths) |
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,41 @@ | ||
"""The Scheduling problem class.""" | ||
from typing import Annotated | ||
|
||
from algobattle.problem import Problem, InstanceModel, SolutionModel, minimize | ||
from algobattle.types import Interval, SizeLen | ||
from algobattle.util import Role | ||
|
||
|
||
Timespan = Annotated[int, Interval(ge=0, le=(2**64 - 1) / 5)] | ||
Machine = Annotated[int, Interval(ge=1, le=5)] | ||
|
||
|
||
class Instance(InstanceModel): | ||
"""The Scheduling problem class.""" | ||
|
||
job_lengths: list[Timespan] | ||
|
||
@property | ||
def size(self) -> int: | ||
return len(self.job_lengths) | ||
|
||
|
||
class Solution(SolutionModel[Instance]): | ||
"""A solution to a Job Shop Scheduling problem.""" | ||
|
||
assignments: Annotated[list[Machine], SizeLen] | ||
|
||
@minimize | ||
def score(self, instance: Instance, role: Role) -> float: | ||
finish_time = [0] * 5 | ||
for duration, machine in zip(instance.job_lengths, self.assignments): | ||
finish_time[machine - 1] += duration * machine | ||
return max(finish_time) | ||
|
||
|
||
Scheduling = Problem( | ||
name="Job Shop Scheduling", | ||
min_size=5, | ||
instance_cls=Instance, | ||
solution_cls=Solution, | ||
) |
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,15 @@ | ||
Timespan = Annotated[int, Interval(ge=0, le=(2**64 - 1) / 5)] | ||
Machine = Annotated[int, Interval(ge=1, le=5)] | ||
|
||
|
||
class Solution(SolutionModel[Instance]): | ||
"""A solution to a Job Shop Scheduling problem.""" | ||
|
||
assignments: Annotated[list[Machine], SizeLen] | ||
|
||
@minimize | ||
def score(self, instance: Instance, role: Role) -> float: | ||
finish_time = [0] * 5 | ||
for duration, machine in zip(instance.job_lengths, self.assignments): | ||
finish_time[machine - 1] += duration * machine | ||
return max(finish_time) |