diff --git a/test_ttp_to_stn.py b/test_ttp_to_stn.py deleted file mode 100644 index d196caef1..000000000 --- a/test_ttp_to_stn.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env python - -from unified_planning.shortcuts import * - -up.shortcuts.get_environment().credits_stream = None - -from unified_planning.plans.ttp_to_stn import * -from unified_planning.test.examples import get_example_problems -import pylab -import matplotlib.pyplot as plt - - -if __name__ == "__main__": - - problems = get_example_problems() - problem = problems["matchcellar"].problem - with OneshotPlanner(problem_kind=problem.kind) as planner: - plan = planner.solve(problem).plan - ttp_to_stn = TTP_to_STN(plan, problem) - print("PLAN :", plan) - graph = ttp_to_stn.run() - - options = { - "node_color": "blue", - "node_size": 1000, - "width": 3, - } - pos = nx.spring_layout(ttp_to_stn.stn) - edge_labels = dict( - [ - ( - ( - u, - v, - ), - [float(d["interval"][0]), float(d["interval"][1])], - ) - for u, v, d in ttp_to_stn.stn.edges(data=True) - ] - ) - nx.draw_networkx_edge_labels(ttp_to_stn.stn, pos, edge_labels=edge_labels) - nx.draw_networkx( - ttp_to_stn.stn, - pos, - with_labels=True, - arrows=True, - **options, - edge_cmap=plt.cm.Reds - ) - pylab.show() - - print("Done...") diff --git a/unified_planning/test/test_ttp_to_stn.py b/unified_planning/test/test_ttp_to_stn.py new file mode 100644 index 000000000..b6bd6909d --- /dev/null +++ b/unified_planning/test/test_ttp_to_stn.py @@ -0,0 +1,54 @@ + +from unified_planning.shortcuts import * + +from unified_planning.plans.ttp_to_stn import * +from unified_planning.test.examples import get_example_problems +import pylab +import matplotlib.pyplot as plt +from unified_planning.test import TestCase + + +class TestTTPToSTN(TestCase): + def setUp(self) -> None: + TestCase.setUp(self) + problems = get_example_problems() + self.problem = problems["matchcellar"].problem + with OneshotPlanner(problem_kind=self.problem.kind) as planner: + self.plan = planner.solve(self.problem).plan + print("PLAN :", self.plan) + + def test_matchcellar_to_stn(self): + self.ttp_to_stn = TTP_to_STN(self.plan, self.problem) + + self.ttp_to_stn.run() + + options = { + "node_color": "blue", + "node_size": 1000, + "width": 3, + } + pos = nx.spring_layout(self.ttp_to_stn.stn) + edge_labels = dict( + [ + ( + ( + u, + v, + ), + [float(d["interval"][0]), float(d["interval"][1])], + ) + for u, v, d in self.ttp_to_stn.stn.edges(data=True) + ] + ) + nx.draw_networkx_edge_labels(self.ttp_to_stn.stn, pos, edge_labels=edge_labels) + nx.draw_networkx( + self.ttp_to_stn.stn, + pos, + with_labels=True, + arrows=True, + **options, + edge_cmap=plt.cm.Reds + ) + #pylab.show() + # Each actions has start and end in the stn plus Start and End's nodes + self.assertTrue(len(self.ttp_to_stn.stn) == len(self.plan.timed_actions)*2 + 2)