diff --git a/src/JobShopParser/__init__.py b/src/JobShopParser/__init__.py index 9ac12e1..654ecb6 100644 --- a/src/JobShopParser/__init__.py +++ b/src/JobShopParser/__init__.py @@ -1,5 +1,6 @@ from typing import List, Tuple, Sequence, Optional, Union import arpeggio +from itertools import chain __all__ = ["jobshop1_parser", "jobshop2_parser"] @@ -42,6 +43,12 @@ class ParseError(Exception): class JobShopProblem: 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.name = name self.problem_data = problem_data