Skip to content

Commit

Permalink
Disregard washer rules for now
Browse files Browse the repository at this point in the history
  • Loading branch information
cgokmen committed Sep 2, 2023
1 parent cbc7cc3 commit 4f9c149
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
36 changes: 21 additions & 15 deletions bddl/knowledge_base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,23 +357,29 @@ def transition_subgraph(self):
return nx.relabel_nodes(G, lambda x: (x.name if isinstance(x, Synset) else f'recipe: {x.name}'), copy=True)

def is_produceable_from(self, synsets):
# If it's already available, then we're good.
if self in synsets:
return True, set()

# Otherwise, are there any recipes that I can use to obtain it?
recipe_alternatives = set()
for recipe in self.produced_by_transition_rules:
producabilities_and_recipe_sets = [ingredient.is_produceable_from(synsets) for ingredient in recipe.input_synsets]
producabilities, recipe_sets = zip(*producabilities_and_recipe_sets)
if all(producabilities):
recipe_alternatives.add(recipe)
recipe_alternatives.update(ingredient_recipe for recipe_set in recipe_sets for ingredient_recipe in recipe_set)
def _is_produceable_from(_self, _synsets, _seen):
if _self in _seen:
return False, set()

# If it's already available, then we're good.
if _self in _synsets:
return True, set()

# Otherwise, are there any recipes that I can use to obtain it?
recipe_alternatives = set()
for recipe in _self.produced_by_transition_rules:
producabilities_and_recipe_sets = [_is_produceable_from(ingredient, _synsets, _seen | {self}) for ingredient in recipe.input_synsets]
producabilities, recipe_sets = zip(*producabilities_and_recipe_sets)
if all(producabilities):
recipe_alternatives.add(recipe)
recipe_alternatives.update(ingredient_recipe for recipe_set in recipe_sets for ingredient_recipe in recipe_set)

if not recipe_alternatives:
return False, set()

if not recipe_alternatives:
return False, set()
return True, recipe_alternatives

return True, recipe_alternatives
return _is_produceable_from(self, synsets, set())


@dataclass(eq=False, order=False)
Expand Down
14 changes: 11 additions & 3 deletions bddl/knowledge_base/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,16 +309,24 @@ def create_transitions(self):
json_paths = glob.glob(str(GENERATED_DATA_DIR / "transition_map/tm_jsons/*.json"))
transitions = []
for jp in json_paths:
if "washer_" in jp:
continue
with open(jp) as f:
transitions.extend(json.load(f))

# Create the transition objects
for transition_data in self.tqdm(transitions):
transition = TransitionRule.create(name=transition_data["rule_name"])
for synset_name in transition_data["input_objects"].keys():
rule_name = transition_data["rule_name"]
transition = TransitionRule.create(name=rule_name)
inputs = set(transition_data["input_objects"].keys())
assert inputs, f"Transition {transition.name} has no inputs!"
outputs = set(transition_data["output_objects"].keys())
assert outputs, f"Transition {transition.name} has no outputs!"
assert inputs & outputs == set(), f"Inputs and outputs of {transition.name} overlap!"
for synset_name in inputs:
synset = Synset.get(name=synset_name)
transition.input_synsets.add(synset)
for synset_name in transition_data["output_objects"].keys():
for synset_name in outputs:
synset = Synset.get(name=synset_name)
transition.output_synsets.add(synset)

Expand Down

0 comments on commit 4f9c149

Please sign in to comment.