check plausibility of job/ machine numbers of JobShopProblem

contributes to #3
This commit is contained in:
Trolli Schmittlauch 2017-06-28 09:57:49 +02:00
parent 58047569f8
commit ba91f321e2

View file

@ -1,5 +1,6 @@
from typing import List, Tuple, Sequence, Optional, Union from typing import List, Tuple, Sequence, Optional, Union
import arpeggio import arpeggio
from itertools import chain
__all__ = ["jobshop1_parser", "jobshop2_parser"] __all__ = ["jobshop1_parser", "jobshop2_parser"]
@ -42,6 +43,12 @@ class ParseError(Exception):
class JobShopProblem: class JobShopProblem:
def __init__(self, jobs: int, machines: int, problem_data: List[List[Tuple[int, int]]], name: str = 'unnamed', description: str = '') -> None: def __init__(self, jobs: int, machines: int, problem_data: List[List[Tuple[int, int]]], name: str = 'unnamed', description: str = '') -> None:
# check plausibility of input
if len(problem_data) != jobs:
raise ParseError("Given number of jobs for problem \"{}\" differs from actual job data.".format(name))
if max([machine for (duration, machine) in chain.from_iterable(problem_data)]) > machines-1:
raise ParseError("Higher machine number found in problem data than specified at problem head")
self.description = description self.description = description
self.name = name self.name = name
self.problem_data = problem_data self.problem_data = problem_data