コード例 #1
0
    def activeProcess(self, index):
        node = self.skeleton.getNodeWithIndex(index)
        
        change = deputy.DeputyProvisionalChanges()
        move_to = self.mover(self.skeleton, node)
        change.moveNode(node,
                        move_to,
                        self.skeleton)  # moved the node

        # Building data to be sent to sharers.
        shared = node.sharedWith()
        nodeMoves = []
        for s in shared:
            nodeMoves.append(
                cfiddler.create_movedata(
                _rank,  # master process
                node.remoteIndex(s),  # remote index
                move_to.x,  # x
                move_to.y   # y
                ))
        # Sending move data to shared processes
        cfiddler.Isend_MoveData(nodeMoves, shared,
                                tag=self.move_channel)
##        REPORT("STARTED WORKING ON NODE #", index, "WITH", shared)
        # receiving illegality from shared processes
        illegal = mpitools.Irecv_Bools(shared,
                                       tag=self.illegal_channel)
        if True in illegal or change.illegal(self.skeleton):
            self.moveBack(node)
            return
        else:  # continue
            mpitools.Isend_Bool(True, shared, tag=self.verdict_channel)

        # Receiving report from shared processes
        reports = mpitools.Irecv_DoubleVecs(shared, tag=self.report_channel)

        homog0 = []
        shape0 = []
        homog1 = []
        shape1 = []
        for r in reports:
            n = len(r)/4
            homog0 += r[:n]
            shape0 += r[n:2*n]
            homog1 += r[2*n:3*n]
            shape1 += r[3*n:4*n]
        change.augmentData(homog0, homog1, shape0, shape1)

        # Now, the decision time
        bestchange = self.criterion([change], self.skeleton)
        if bestchange is not None:
            self.stay(node, bestchange)
        elif self.T > 0. and not self.criterion.hopeless():
            diffE = change.deltaE(self.skeleton, self.alpha)
            if math.exp(-diffE/self.T) > random.random():
                self.stay(node, change)
            else:
                self.moveBack(node)
        else:
            self.moveBack(node)
コード例 #2
0
    def activeProcess(self, index):
        node = self.skeleton.getNodeWithIndex(index)
        shared = node.sharedWith()
        # send the node (remote) index
        for s in shared:
            mpitools.Send_Int(node.remoteIndex(s), s, self.move_channel)

        move_candidates = self.mover.active(self.skeleton, node)
        mpitools.Isend_Int(len(move_candidates), shared, tag=self.move_channel)

        changes = []
        for mc in move_candidates:
            change = deputy.DeputyProvisionalChanges()
            change.moveNode(node, mc, self.skeleton)  # moved the node

            # Building data to be sent to sharers.
            nodeMoves = []
            for s in shared:
                nodeMoves.append(
                    cfiddler.create_movedata(
                        _rank,  # master process
                        node.remoteIndex(s),  # remote index
                        mc.x,  # x
                        mc.y  # y
                    ))
            # Sending move data to shared processes
            cfiddler.Isend_MoveData(nodeMoves, shared, tag=self.move_channel)

            ##            REPORT("STARTED WORKING ON NODE #", index, "WITH", shared)
            # receiving illegality from shared processes
            illegal = mpitools.Irecv_Bools(shared, tag=self.illegal_channel)
            legal = True not in illegal and not change.illegal(self.skeleton)
            mpitools.Isend_Bool(legal, shared, tag=self.verdict_channel)
            if not legal:
                continue

            # Receiving report from shared processes
            reports = mpitools.Irecv_DoubleVecs(shared,
                                                tag=self.report_channel)
            homog0 = []
            shape0 = []
            homog1 = []
            shape1 = []
            for r in reports:
                n = len(r) / 4
                homog0 += r[:n]
                shape0 += r[n:2 * n]
                homog1 += r[2 * n:3 * n]
                shape1 += r[3 * n:4 * n]
            change.augmentData(homog0, homog1, shape0, shape1)
            changes.append(change)

        # Now, the decision time
        bestchange = self.criterion(changes, self.skeleton)
        if bestchange is not None:
            self.nok += 1
            self.deltaE += bestchange.deltaE(self.skeleton, self.alpha)
            bestchange.accept(self.skeleton)
            mpitools.Isend_Bool(True, shared, tag=self.verdict_channel)
            theindex = changes.index(bestchange)
            x = move_candidates[theindex].x
            y = move_candidates[theindex].y
            mpitools.Isend_DoubleVec([x, y],
                                     shared,
                                     tag=self.move_channel,
                                     size=2)
        else:
            self.nbad += 1
            mpitools.Isend_Bool(False, shared, tag=self.verdict_channel)