Exemplo n.º 1
0
    def test_constraints(self):
        solver = Solver(**self.solve_params)
        solver.initialize()

        # Only 3 is isolated selected:
        print("solver_v_selected", solver.v_selected)
        v_selected = list(set([solver.t_to_center[t] for s in solver.v_selected for t in s]))
        print("V_selected", v_selected)
        self.assertTrue(len(v_selected) == 1)
        self.assertTrue(v_selected[0] == 3)

        # No isolated edges:
        self.assertTrue(len(solver.e_selected) == 0)
Exemplo n.º 2
0
    def test_solve(self):
        solver = Solver(**self.solve_params)
        solver.initialize()
        solver.solve()
        graph = self.solve_params["graph"]
        selected_edges = [(e[0], e[1]) for e in graph.edges(data=True) if e[2]["selected"]]
        selected_nodes = [v[0] for v in graph.nodes(data=True) if v[1]["selected"]]

        self.assertTrue(len(selected_edges) == len(self.edges))
        self.assertTrue(len(selected_nodes) == len(self.nodes))
Exemplo n.º 3
0
    def test_solve(self):
        # y: 1|   0--1--2
        # x:      1  2 3
        # Test all combinations of
        # s/ns

        combinations = [(False, False), (False, True), (True, True)]

        for v0 in combinations:
            for v1 in combinations:
                for v2 in combinations:
                    for e0 in combinations:
                        for e1 in combinations:
                            self.nodes = [
                                    {'id': 0, 'z': 1, 'y': 1, 'x': 1, 'selected': v0[0], 'solved': v0[1]},
                                    {'id': 1, 'z': 1, 'y': 1, 'x': 2, 'selected': v1[0], 'solved': v1[1]},
                                    {'id': 2, 'z': 1, 'y': 1, 'x': 3, 'selected': v2[0], 'solved': v2[1]},
                                    ]

                            self.edges = [{'u': 0, 'v': 1, 'evidence': 0.5, 'selected': e0[0], 'solved': e0[1]},
                                          {'u': 1, 'v': 2, 'evidence': 0.5, 'selected': e1[0], 'solved': e1[1]}]

                            self.db_name = 'micron_test_solver'
                            config = configparser.ConfigParser()
                            config.read(os.path.expanduser("../mongo.ini"))
                            self.db_host = "mongodb://{}:{}@{}:{}".format(config.get("Credentials", "user"),
                                                                          config.get("Credentials", "password"),
                                                                          config.get("Credentials", "host"),
                                                                          config.get("Credentials", "port"))

                            self.graph_provider = MongoDbGraphProvider(self.db_name,
                                                                       self.db_host,
                                                                       mode='w',
                                                                       position_attribute=['z', 'y', 'x'])
                            self.roi = daisy.Roi((0,0,0), (4,4,4))
                            self.graph = self.graph_provider[self.roi]
                            self.graph.add_nodes_from([(node['id'], node) for node in self.nodes])
                            self.graph.add_edges_from([(edge['u'], edge['v'], edge) for edge in self.edges])
                            
                            self.solve_params = {"graph": self.graph, 
                                                 "evidence_factor": 12,
                                                 "comb_angle_factor": 14,
                                                 "start_edge_prior": 180,
                                                 "selection_cost": -80}

                            solver = Solver(**self.solve_params)
                            solver.initialize()
                            solver.solve()
                            graph = self.solve_params["graph"]
                            selected_edges = [(e[0], e[1]) for e in graph.edges(data=True) if e[2]["selected"]]
                            selected_nodes = [v[0] for v in graph.nodes(data=True) if v[1]["selected"]]

                            client = pymongo.MongoClient(self.db_host)
                            client.drop_database(self.db_name)
Exemplo n.º 4
0
    def test_solve(self):
        print("ISOLATEDNOTSOLVED")
        solver = Solver(**self.solve_params)
        solver.initialize()
        solver.solve()
        graph = self.solve_params["graph"]
        selected_edges = [(e[0], e[1]) for e in graph.edges(data=True) if e[2]["selected"]]
        selected_nodes = [v[0] for v in graph.nodes(data=True) if v[1]["selected"]]

        solved_nodes = [v[0] for v in graph.nodes(data=True) if v[1]["solved"]]
        solved_edges = [(e[0], e[1]) for e in graph.edges(data=True) if e[2]["solved"]]

        print("Solved:")
        print(solved_nodes)
        print(solved_edges)

        print("Selected:")
        print(selected_nodes)
        print(selected_edges)
Exemplo n.º 5
0
    def test_solve(self):
        solver = Solver(**self.solve_params)
        solver.initialize()
        solver.solve()
        graph = self.solve_params["graph"]
        selected_edges = [(e[0], e[1]) for e in graph.edges(data=True) if e[2]["selected"]]
        selected_nodes = [v[0] for v in graph.nodes(data=True) if v[1]["selected"]]
        solved_edges = [(e[0], e[1]) for e in graph.edges(data=True) if e[2]["solved"]]
 

        self.assertTrue(len(selected_nodes) == len(self.nodes))
        self.assertTrue(set(selected_nodes) == set([v for v in range(10)]))

        self.assertTrue(len(selected_edges) == len(self.edges) - 2)
        self.assertTrue(set(selected_edges) == set([(0,1), (1,2), (3,4), (4,5), (6,7), (7,8)]))

        self.assertTrue(len(solved_edges) == len(self.edges))
        self.assertTrue(set(solved_edges) == set([(0,1), (1,2), (3,4), (4,5), (6,7), (7,8), (7,9), (4,9)]))


        print(selected_edges)
        print(selected_nodes)
        print("Solved", solved_edges)
Exemplo n.º 6
0
 def test_constraints(self):
     solver = Solver(**self.solve_params)
     solver.initialize()
Exemplo n.º 7
0
 def test_constraints(self):
     solver = Solver(**self.solve_params)
     solver.initialize()
     self.assertTrue(len(solver.v_selected) == 0)