diff --git a/src/JobShopParser/__init__.py b/src/Parser/__init__.py similarity index 94% rename from src/JobShopParser/__init__.py rename to src/Parser/__init__.py index 654ecb6..1238fa4 100644 --- a/src/JobShopParser/__init__.py +++ b/src/Parser/__init__.py @@ -1,4 +1,4 @@ -from typing import List, Tuple, Sequence, Optional, Union +from typing import List, Tuple, Sequence, Optional, Union, Any import arpeggio from itertools import chain @@ -40,7 +40,7 @@ class ParseError(Exception): def __init__(self, message: str) -> None: self.message = message -class JobShopProblem: +class JobShopProblem(list): def __init__(self, jobs: int, machines: int, problem_data: List[List[Tuple[int, int]]], name: str = 'unnamed', description: str = '') -> None: # check plausibility of input @@ -51,12 +51,12 @@ class JobShopProblem: self.description = description self.name = name - self.problem_data = problem_data self.machines = machines self.jobs = jobs + super().__init__(problem_data) def __str__(self) -> str: - return self.name + return "JobShopProblem " + str(self.name) class JobShopVisitor(arpeggio.PTNodeVisitor): """contains visitor functions needed for both jobshop1 (list of instances) @@ -94,7 +94,7 @@ class JobShopVisitor(arpeggio.PTNodeVisitor): print("problem_data\nchildren:", children) # filter out newlines or other strings cleaned_data = list(filter(lambda x: type(x) is not str, children)) - problem_data: List[List[Tuple(int, int)]] = [ cleaned_data[i] for i in range(2, len(cleaned_data))] + problem_data: List[List] = [ cleaned_data[i] for i in range(2, len(cleaned_data))] problem = JobShopProblem(children[0], children[1], problem_data) if self.debug: print("\nreturning a", type(problem), "\n") diff --git a/src/JobShopParser/jobshop1_parser.py b/src/Parser/js1_style.py similarity index 100% rename from src/JobShopParser/jobshop1_parser.py rename to src/Parser/js1_style.py diff --git a/src/JobShopParser/jobshop2_parser.py b/src/Parser/js2_style.py similarity index 92% rename from src/JobShopParser/jobshop2_parser.py rename to src/Parser/js2_style.py index a9399e9..25ae6c5 100644 --- a/src/JobShopParser/jobshop2_parser.py +++ b/src/Parser/js2_style.py @@ -2,7 +2,7 @@ import arpeggio from arpeggio.cleanpeg import ParserPEG from typing import List, Tuple, Sequence, Optional, Union -from . import grammar, JobShopVisitor, JobShopProblem +from . import grammar, JobShopVisitor, JobShopProblem, ParseError class JobShop2Visitor(JobShopVisitor): @@ -34,7 +34,7 @@ def parse_jobshop2_file(filename: Union[str, bytes]) -> JobShopProblem: return parse_jobshop2_string(inputdata) def main(): - print(type(parse_jobshop2_file('../inputdata/jobshop2/ta13'))) + print(parse_jobshop2_file('../inputdata/jobshop2/ta13')) parser = ParserPEG(grammar, "job_shop2", skipws=False)