Example #1
0
    def sample(self):
        if self.valid_set is None:
            nodes = list(self.graph.nodes())
        else:
            assert len(self.valid_set) <= self.graph.number_of_nodes()
            nodes = list(self.valid_set)

        if len(nodes) > 0:
            return nodes[np_random.randint(len(nodes))]
        else:
            return None
Example #2
0
 def sample(self):
     return np_random.randint(self.n)
Example #3
0
 def sample(self, valid_list=None):
     # TODO: need a better implementation for O(1) sampling
     tmp_list = list(self.set)
     idx = np_random.randint(len(tmp_list))
     return tmp_list[idx]