parent
ba91f321e2
commit
92ddb2740e
|
@ -1,4 +1,4 @@
|
||||||
from typing import List, Tuple, Sequence, Optional, Union
|
from typing import List, Tuple, Sequence, Optional, Union, Any
|
||||||
import arpeggio
|
import arpeggio
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ class ParseError(Exception):
|
||||||
def __init__(self, message: str) -> None:
|
def __init__(self, message: str) -> None:
|
||||||
self.message = message
|
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:
|
def __init__(self, jobs: int, machines: int, problem_data: List[List[Tuple[int, int]]], name: str = 'unnamed', description: str = '') -> None:
|
||||||
# check plausibility of input
|
# check plausibility of input
|
||||||
|
@ -51,12 +51,12 @@ class JobShopProblem:
|
||||||
|
|
||||||
self.description = description
|
self.description = description
|
||||||
self.name = name
|
self.name = name
|
||||||
self.problem_data = problem_data
|
|
||||||
self.machines = machines
|
self.machines = machines
|
||||||
self.jobs = jobs
|
self.jobs = jobs
|
||||||
|
super().__init__(problem_data)
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return self.name
|
return "JobShopProblem " + str(self.name)
|
||||||
|
|
||||||
class JobShopVisitor(arpeggio.PTNodeVisitor):
|
class JobShopVisitor(arpeggio.PTNodeVisitor):
|
||||||
"""contains visitor functions needed for both jobshop1 (list of instances)
|
"""contains visitor functions needed for both jobshop1 (list of instances)
|
||||||
|
@ -94,7 +94,7 @@ class JobShopVisitor(arpeggio.PTNodeVisitor):
|
||||||
print("problem_data\nchildren:", children)
|
print("problem_data\nchildren:", children)
|
||||||
# filter out newlines or other strings
|
# filter out newlines or other strings
|
||||||
cleaned_data = list(filter(lambda x: type(x) is not str, children))
|
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)
|
problem = JobShopProblem(children[0], children[1], problem_data)
|
||||||
if self.debug:
|
if self.debug:
|
||||||
print("\nreturning a", type(problem), "\n")
|
print("\nreturning a", type(problem), "\n")
|
|
@ -2,7 +2,7 @@ import arpeggio
|
||||||
from arpeggio.cleanpeg import ParserPEG
|
from arpeggio.cleanpeg import ParserPEG
|
||||||
from typing import List, Tuple, Sequence, Optional, Union
|
from typing import List, Tuple, Sequence, Optional, Union
|
||||||
|
|
||||||
from . import grammar, JobShopVisitor, JobShopProblem
|
from . import grammar, JobShopVisitor, JobShopProblem, ParseError
|
||||||
|
|
||||||
class JobShop2Visitor(JobShopVisitor):
|
class JobShop2Visitor(JobShopVisitor):
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ def parse_jobshop2_file(filename: Union[str, bytes]) -> JobShopProblem:
|
||||||
return parse_jobshop2_string(inputdata)
|
return parse_jobshop2_string(inputdata)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print(type(parse_jobshop2_file('../inputdata/jobshop2/ta13')))
|
print(parse_jobshop2_file('../inputdata/jobshop2/ta13'))
|
||||||
|
|
||||||
parser = ParserPEG(grammar, "job_shop2", skipws=False)
|
parser = ParserPEG(grammar, "job_shop2", skipws=False)
|
||||||
|
|
Loading…
Reference in a new issue