Ejemplo n.º 1
0
 def setMatch(self, match, address):
     node = getNode(self.rules, address)
     if node["left"] is not None or node["right"] is not None:
         raise Exception(
             "Cant set rule at LogWatch {} since address {} is not a leaf".
             format(self.lwID, address))
     node["value"] = match
Ejemplo n.º 2
0
    def delMatch(self, address: tuple):
        node = getNode(self.rules, address)
        if node["left"] is not None or node["right"] is not None:
            raise Exception(
                "Cant delete rule at LogWatch {} since address {} is not a leaf"
                .format(self.lwID, address))
        if address == ():
            self.rules = createNode()
        else:
            parentNode = getNode(self.rules, address[:-1])
            if address[-1] == 0:
                survivorNode = parentNode["right"]
            else:
                survivorNode = parentNode["left"]

            parentNode["value"] = survivorNode["value"]
            parentNode["left"] = survivorNode["left"]
            parentNode["right"] = survivorNode["right"]
Ejemplo n.º 3
0
 def combineMatch(self, match, connector, address):
     node = getNode(self.rules, address)
     if node["left"] is not None or node["right"] is not None:
         raise Exception(
             "Cant combine rule at LogWatch {} since address {} is not a leaf"
             .format(self.lwID, address))
     node["left"] = createNode(node["value"])
     node["value"] = connector
     node["right"] = createNode(match)
Ejemplo n.º 4
0
 def test_getNode(self):
     rule = {
         'value': 'val2',
         'left': {
             'value': 'val1',
             'left': {'left'},
             'right': {'right'}
         },
         'right': {
             'value': 'val1',
             'left': {'left'},
             'right': {'right'}
         }
     }
     self.assertEqual(rule, getNode(rule, ()))
     self.assertEqual(rule['left'], getNode(rule, (0, )))
     self.assertEqual(rule['right'], getNode(rule, (1, )))
     self.assertEqual(rule['left']['left'], getNode(rule, (0, 0)))
     self.assertEqual(rule['left']['right'], getNode(rule, (0, 1)))
     self.assertEqual(rule['right']['left'], getNode(rule, (1, 0)))
     self.assertEqual(rule['right']['right'], getNode(rule, (1, 1)))
Ejemplo n.º 5
0
Archivo: main.py Proyecto: kiminh/GCOMB
    for step in range(0, k):
        print("step: ", step)
        # print("isSelected \n", graph.isSelected)

        # select node to be added
        probOfRandomSelection = max(pow(0.1, step), 0.8)
        # print("probOfRandomSelection is : ", probOfRandomSelection)

        if (step == 0):
            action_t = util.getRandomNode(
                episode, step
            )  #graphEnv.graphEnvironment[episode].top_tenpct_nodes[0] action_t=
# graphEnv.graphEnvironment[episode].top_tenpct_nodes[0]#util.getRandomNode(episode,step)#graphEnv.graphEnvironment[episode].top_tenpct_nodes[0]
# index of the selected node
        else:
            action_t = util.getNode(probOfRandomSelection, episode, step)
        print("Node selected: ", action_t)

        # add action_t to the partial solution
        graphEnv.graphEnvironment[episode].isSelected[action_t] = step
        graphEnv.graphEnvironment[episode].isCounted[action_t] = True
        neighbors_of_chosen_node = graphEnv.graphEnvironment[
            episode].dict_node_sampled_neighbors[
                action_t]  #neighbors(action_t))
        print("num nbrs of chosen node ", len(neighbors_of_chosen_node))
        new_neighbors_length = len(
            neighbors_of_chosen_node -
            graphEnv.graphEnvironment[episode].neighbors_chosen_till_now)
        graphEnv.graphEnvironment[
            episode].neighbors_chosen_till_now = graphEnv.graphEnvironment[
                episode].neighbors_chosen_till_now.union(