add function for parsing inputdata strings
This commit is contained in:
parent
252e7d6ee0
commit
901472e8b5
|
@ -33,14 +33,19 @@ class JobShop1Visitor(JobShopVisitor):
|
||||||
def visit_trim_ws(self, node:arpeggio.ParseTreeNode, children: arpeggio.SemanticActionResults) -> None:
|
def visit_trim_ws(self, node:arpeggio.ParseTreeNode, children: arpeggio.SemanticActionResults) -> None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def parse_jobshop1_string(inputdata: str) -> JobShopProblem:
|
||||||
|
"""parse string with jobshop1-formatted data (multiple problem instances)
|
||||||
|
and return list of JobShopProblem s"""
|
||||||
|
parse_tree = parser.parse(inputdata)
|
||||||
|
return arpeggio.visit_parse_tree(parse_tree, JobShop1Visitor())
|
||||||
|
|
||||||
def parse_jobshop1_file(filename: Union[str, bytes]) -> List[JobShopProblem]:
|
def parse_jobshop1_file(filename: Union[str, bytes]) -> List[JobShopProblem]:
|
||||||
"""Open file with jobshop1-formatted data (multiple problem instances),
|
"""Open file with jobshop1-formatted data (multiple problem instances),
|
||||||
parse it and return list of JobShopProblem s"""
|
parse it and return list of JobShopProblem s"""
|
||||||
|
|
||||||
with open(filename) as datafile:
|
with open(filename) as datafile:
|
||||||
inputdata: str = datafile.read()
|
inputdata: str = datafile.read()
|
||||||
parse_tree = parser.parse(inputdata)
|
return parse_jobshop1_string(inputdata)
|
||||||
return arpeggio.visit_parse_tree(parse_tree, JobShop1Visitor())
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
|
@ -14,14 +14,19 @@ class JobShop2Visitor(JobShopVisitor):
|
||||||
print("returning a", type(problem))
|
print("returning a", type(problem))
|
||||||
return problem
|
return problem
|
||||||
|
|
||||||
|
def parse_jobshop2_string(inputdata: str) -> JobShopProblem:
|
||||||
|
"""parse string of jobshop2-formatted data (single problem instance, no name & description)
|
||||||
|
and return JobShopProblem"""
|
||||||
|
parse_tree = parser.parse(inputdata)
|
||||||
|
return arpeggio.visit_parse_tree(parse_tree, JobShop2Visitor())
|
||||||
|
|
||||||
def parse_jobshop2_file(filename: Union[str, bytes]) -> JobShopProblem:
|
def parse_jobshop2_file(filename: Union[str, bytes]) -> JobShopProblem:
|
||||||
"""Open file with jobshop2-formatted data (single problem instance, no name & description),
|
"""Open file with jobshop2-formatted data (single problem instance, no name & description),
|
||||||
parse it and return JobShopProblem"""
|
parse it and return JobShopProblem"""
|
||||||
|
|
||||||
with open(filename) as datafile:
|
with open(filename) as datafile:
|
||||||
inputdata: str = datafile.read()
|
inputdata: str = datafile.read()
|
||||||
parse_tree = parser.parse(inputdata)
|
return parse_jobshop2_string(inputdata)
|
||||||
return arpeggio.visit_parse_tree(parse_tree, JobShop2Visitor())
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print(type(parse_jobshop2_file('../inputdata/jobshop2/ta13')))
|
print(type(parse_jobshop2_file('../inputdata/jobshop2/ta13')))
|
||||||
|
|
Loading…
Reference in a new issue