Skip to content

Commit

Permalink
Merge pull request #5 from ataitler/StructureBranch
Browse files Browse the repository at this point in the history
method naming
  • Loading branch information
ataitler authored Feb 15, 2023
2 parents 72db3d2 + 9aa896c commit 761de84
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
8 changes: 4 additions & 4 deletions rddl-repository/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

def main():
manager = RDDLRepoManager(rebuild=True)
# manager.ListProblems()
# envInfo = manager.GetProblem('CooperativeRecon_ippc2018')
envInfo = manager.GetProblem('RaceCar')
# envInfo.list_instances()
manager.list_problems()
# envInfo = manager.get_problem('CooperativeRecon_ippc2018')
envInfo = manager.get_problem('RaceCar')
envInfo.list_instances()
envInfo.get_domain()
envInfo.get_instance(0)
envInfo.get_visualizer()
Expand Down
1 change: 0 additions & 1 deletion rddl-repository/Manager/ProblemInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def get_visualizer(self):
if self.viz == 'None':
return None

viz_backend_package_name = 'pyRDDLGym'
spec = importlib.util.find_spec(viz_backend_package_name)
if spec is None:
raise RDDLRepoUnresolvedDependency(viz_backend_package_name + " is not installed")
Expand Down
32 changes: 16 additions & 16 deletions rddl-repository/Manager/RDDLRepoManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@

class RDDLRepoManager:
def __init__(self, rebuild=False):
self.Archiver_Dict = {}
self.archiver_dict= {}
self.manager_path = os.path.dirname(os.path.abspath(__file__))
if os.path.isfile(self.manager_path+'/manifest.csv') and not rebuild:
self._LoadRepo() # load repo to dict
self._load_repo() # load repo to dict
else:
self._BuildRepo() # build repo and load to dict
self._build_repo() # build repo and load to dict

def ListProblems(self):
for key, values in self.Archiver_Dict.items():
def list_problems(self):
for key, values in self.archiver_dict.items():
print(key + ": " + values[1])

def GetProblem(self, name):
if name in self.Archiver_Dict.keys():
return ProblemInfo(self.Archiver_Dict[name])
def get_problem(self, name):
if name in self.archiver_dict.keys():
return ProblemInfo(self.archiver_dict[name])

def _BuildRepo(self):
def _build_repo(self):
root_path = os.path.dirname(os.path.abspath(__file__))
path_to_manifest = os.path.join(root_path, 'manifest.csv')
root_path = root_path.split('/')
Expand All @@ -48,7 +48,7 @@ def _BuildRepo(self):
d = dir.split('/')
module = 'Archive' + '.'.join(d)
mymodule = importlib.import_module(module)
if mymodule.info['name'] in self.Archiver_Dict.keys():
if mymodule.info['name'] in self.archiver_dict.keys():
raise RDDLRepoProblemDuplication()
if 'domain.rddl' not in files:
raise RDDLRepoDomainNotExist()
Expand All @@ -58,7 +58,7 @@ def _BuildRepo(self):
if context:
context = '_' + context
name = mymodule.info['name'] + context
self.Archiver_Dict[name] = [mymodule.info['name'],
self.archiver_dict[name] = [mymodule.info['name'],
mymodule.info['description'],
root,
instances,
Expand All @@ -72,21 +72,21 @@ def _BuildRepo(self):
writer.writerow(HEADER)

# iterate through the dictionary
for keys, values in self.Archiver_Dict.items():
for keys, values in self.archiver_dict.items():
values[3] = ','.join(values[3])
writer.writerow(values)

def _LoadRepo(self):
def _load_repo(self):
root_path = os.path.dirname(os.path.abspath(__file__))
path_to_manifest = os.path.join(root_path, 'manifest.csv')
if not os.path.isfile(path_to_manifest):
return {}

self.Archiver_Dict = {}
self.archiver_dict= {}
with open(path_to_manifest) as file:
reader = csv.reader(file, delimiter=',')
for i, row in enumerate(reader):
if i > 0:
name, *entries = row
self.Archiver_Dict[name] = dict(zip(HEADER[1:], entries))
return self.Archiver_Dict
self.archiver_dict[name] = dict(zip(HEADER[1:], entries))
return self.archiver_dict

0 comments on commit 761de84

Please sign in to comment.