예제 #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 coreProcess(self, context):
        ## NOTE FOR DEVELOPERS:
        #### if a change is made to this function,
        #### make sure that the SAME changes are made, in a
        #### consistent way in fiddlenodesbaseParallel.py
        skeleton = context.getObject()

        prog = self.makeProgress()
        self.totalE = skeleton.energyTotal(self.criterion.alpha)
        self.nok = self.nbad = 0
        self.deltaE = 0.
        # TODO: If the Skeleton is periodic and a node and its partner
        # are both active, only one of them should be in activenodes.
        activenodes = self.targets(context)
        random.shuffle(activenodes)
        j = 0
        context.begin_writing()
        try:
            #             start_time = time.time()
            for node in activenodes:
                change = deputy.DeputyProvisionalChanges()
                change.moveNode(node, self.movedPosition(skeleton, node),
                                skeleton)
                bestchange = self.criterion([change], skeleton)

                if bestchange is not None:
                    self.nok += 1
                    self.deltaE += bestchange.deltaE(skeleton,
                                                     self.criterion.alpha)
                    bestchange.accept(skeleton)
                # Failed to meet the specified criterion ... but
                elif (self.T > 0.0 and not change.illegal(skeleton)
                      and not self.criterion.hopeless()):
                    diffE = change.deltaE(skeleton, self.criterion.alpha)
                    if math.exp(-diffE / self.T) > random.random():
                        self.nok += 1
                        self.deltaE += diffE
                        change.accept(skeleton)
                    else:
                        self.nbad += 1
                else:
                    self.nbad += 1

                if prog.stopped():
                    return

            skeleton.timestamp.increment()
        finally:
            prog.finish()
            context.end_writing()
            switchboard.notify("redraw")
예제 #3
0
 def soloProcess(self, index):
     ##        REPORT("WORKING SOLO ON NODE #", index)
     node = self.skeleton.getNodeWithIndex(index)
     change = deputy.DeputyProvisionalChanges()
     change.moveNode(node, self.mover(self.skeleton, node),
                     self.skeleton)  # moved
     # 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)
예제 #4
0
    def soloProcess(self, index):
##        REPORT("WORKING SOLO ON NODE #", index)
        node = self.skeleton.getNodeWithIndex(index)
        move_candidates = self.mover(self.skeleton, node)  # list of points
        move_candidates = [mc for mc in move_candidates if mc]  # removes "None"
        changes = []

        for mc in move_candidates:
            change = deputy.DeputyProvisionalChanges()
            change.moveNode(node, mc, self.skeleton)  # moved the node
            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)
        else:
            self.nbad += 1
예제 #5
0
    def coreProcess(self, context):
        skeleton = context.getObject()
        prog = self.makeProgress()
        self.totalEnergy = skeleton.energyTotal(self.criterion.alpha)
        self.nok = self.nbad = 0
        self.deltaE = 0.
        activenodes = self.targets(context)
        random.shuffle(activenodes)
        j = 0
        context.begin_writing()
        try:
            for node in activenodes:
                # obtain transition points
                tps = self.movedPosition(skeleton, node)
                changes = []
                for tp in tps:
                    if tp:
                        change = deputy.DeputyProvisionalChanges()
                        change.moveNode(node, tp, skeleton)
                        changes.append(change)

                bestchange = self.criterion(changes, skeleton)
                if bestchange is not None:
                    self.nok += 1
                    self.deltaE += bestchange.deltaE(skeleton,
                                                     self.criterion.alpha)
                    bestchange.accept(skeleton)
                else:
                    self.nbad += 1

                if prog.stopped():
                    return
            skeleton.timestamp.increment()
        finally:
            context.end_writing()
            switchboard.notify("redraw")
예제 #6
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)