From ba91f321e2d2089efa318233ef715db809b7f31b Mon Sep 17 00:00:00 2001 From: Trolli Schmittlauch Date: Wed, 28 Jun 2017 09:57:49 +0200 Subject: [PATCH] check plausibility of job/ machine numbers of JobShopProblem contributes to #3 --- src/JobShopParser/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) 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