コード例 #1
0
    def onCycleEnd(self, agt):
        if agt.name != self.root:
            return

        ccg = self.ccg
        vertex_cover = [u for u in ccg.nodes() if self.values[u] >= 0.5]
        for var in self.variables:
            set_var_value(var, vertex_cover, self.var_ccg_nodes[var.name],
                          self.prng)
コード例 #2
0
    def onCycleEnd(self, agt):
        if agt.name != self.root:
            return

        ccg = self.ccg
        weights = nx.get_node_attributes(ccg, 'weight')
        vertex_cover = []
        for u in ccg.nodes():
            sum_msgs = np.sum(self.msgs[t][u] for t in ccg.neighbors(u))
            if sum_msgs[0] > sum_msgs[1] + weights[u]:
                vertex_cover.append(u)

        for var in self.variables:
            set_var_value(var, vertex_cover, self.var_ccg_nodes[var.name], self.prng)
コード例 #3
0
    def onStart(self, agt):
        #agt.setRandomAssignment()

        self.msgs = {u: {v: self.prng.randint(10, size=2)
                         for v in self.ccg.neighbors(u)} for u in self.ccg.nodes()}

        if agt.name is self.root:
            for var in self.variables:
                v_val = var.value
                # Set associated node to 0 and all others to 1
                vc = []
                for (u, r) in self.var_ccg_nodes[var.name]:
                    if v_val == 0 or v_val != 0 and r != v_val:
                        vc.append(u)
                set_var_value(var, vc, self.var_ccg_nodes[var.name], self.prng)
コード例 #4
0
    def onStart(self, agt):
        #agt.setRandomAssignment()
        ccg = self.agt_ccg[agt.name]
        self.agt_ccg_nodes[agt.name] = [
            u for u, data in ccg.nodes(data=True)
            if 'owner' in data and data['owner'] == agt.name
        ]

        for var in agt.variables:
            v_val = var.value
            vc = []
            # Set associated node to 0 and all others to 1
            for (u, r) in self.var_ccg_nodes[var.name]:
                if v_val == 0 or v_val != 0 and r != v_val:
                    vc.append(u)
            set_var_value(var, vc, self.var_ccg_nodes[var.name], self.prng)
コード例 #5
0
    def onCycleEnd(self, agt):
        ccg = self.agt_ccg[agt.name]
        weights = nx.get_node_attributes(ccg, 'weight')
        type = nx.get_node_attributes(ccg, 'type')

        vertex_cover = []
        for u in ccg.nodes():
            sum_msgs = np.sum(self.msgs[t][u] for t in ccg.neighbors(u))

            if sum_msgs[0] > sum_msgs[1] + weights[u]:
                vertex_cover.append(u)
            # if weights[u] < sum_msgs:
            #     vertex_cover.append(u)

        for var in agt.variables:
            set_var_value(var, vertex_cover, self.var_ccg_nodes[var.name],
                          self.prng)