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)
def active(self, skeleton, node): # Parallel mode -- owner of shared node from ooflib.SWIG.common import mpitools # Need to get neighboring nodes shared = node.sharedWith() remote_indices = [node.remoteIndex(s) for s in shared] mpitools.Isend_Ints(remote_indices, shared) positions = mpitools.Irecv_DoubleVecs(shared) # [[], [] ...] positions = reduce(lambda x, y: x + y, positions) # [] positions = [[positions[2 * i], positions[2 * i + 1]] for i in range(len(positions) / 2)] # Add my own neighbors nbrNodes = node.neighborNodes(skeleton) positions += [[ skeleton.nodePosition(n).x, skeleton.nodePosition(n).y ] for n in nbrNodes] # Averaging x = 0. y = 0. for p in positions: x += p[0] y += p[1] x /= len(positions) y /= len(positions) return primitives.Point(x, y)
def active(self, skeleton, node): from ooflib.SWIG.common import mpitools shared = node.sharedWith() # receiving coords opposite_ends = mpitools.Irecv_DoubleVecs(shared) opposite_ends = reduce(lambda x, y: x + y, opposite_ends) # create a list of points end_points = [] for i in range(len(opposite_ends) / 2): x = opposite_ends[2 * i] y = opposite_ends[2 * i + 1] end_points.append(primitives.Point(x, y)) # move candidates move_candidates = self.default(skeleton, node) # list of points move_candidates += self.addition(skeleton, node, end_points) # returns non-trivial ones return [mc for mc in move_candidates if mc]
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)