class Locomotion(object): ''' classdocs ''' def __init__(self): ''' Constructor ''' self.Stop = Stop() self.goStraight = GoStraight() self.Turn = Turn() self.FullTurn = FullTurn() self.Approach = Approach() def action(self, input, states, parameters): if states["locomotionType"] == "Stop": self.Stop.action(input, states, parameters) elif states["locomotionType"] == "GoStraight": self.goStraight.action(input, states, parameters) elif states["locomotionType"] == "Turn": self.Turn.action(input, states, parameters) elif states["locomotionType"] == "FullTurn": if input.has_key("orientation") and input["orientation"]!=None: self.FullTurn.action(input, states, parameters) elif states["locomotionType"] == "Approach": self.Approach.action(input, states, parameters) elif states["locomotionType"] == "Carry": pass
def __init__(self, budget, time, userList): Approach.__init__(self, budget, time) self.beta = 0.1 self.userList = userList self.active_users = {} self.pre_active_users = {} self.status_last_time = 0.0 self.matrix = self.init_matrix()
def __init__(self): ''' Constructor ''' self.Stop = Stop() self.goStraight = GoStraight() self.Turn = Turn() self.FullTurn = FullTurn() self.Approach = Approach()
def update_Approach(self): #Selection/Creation Phase aOtherActors = self.select_Approach_Actors(); for otherActor in aOtherActors: nOtherTrackId = otherActor.nTrackId; self.approach[nOtherTrackId] = Approach(self.actor, otherActor); for nOtherTrackId in self.approach: #Initialization Phase otherActor = self.aActors[nOtherTrackId]; if not(self.approach[nOtherTrackId].bStarted) and self.actor.nAvgVel>0: if not(otherActor.activityMngr.loiter.bStarted): continue; #TEMPORAL CODE [Later make an ApproachToLoiter activity] nPastDist = self.actor.points_to_Dist(self.actor.aPastPos, otherActor.aPastPos); nNewDist = self.actor.points_to_Dist(self.actor.aPos, otherActor.aPos); nDistOtherActor = self.actor.getDist(otherActor); bApproachZone = nDistOtherActor<100 and nDistOtherActor>30; bClosingDist = nNewDist<nPastDist; if bApproachZone and bClosingDist: # print self.nFrame, "Person", self.actor.nTrackId, "Approaching to:", otherActor.nTrackId, nDistOtherActor;#"Pos:", otherActor.aPos; #, aActorTracksId; self.approach[nOtherTrackId].startAct(self.nFrame); #Updating Phase bMissing_OtherActor = otherActor.bMissing; bNotChase2 = not(self.chase2.has_key(otherActor)) or not(self.chase2[otherActor].bActive); if bMissing_OtherActor and bNotChase2: #If the other subject dissapeared, then Kill this Approach (copied from Meet activity) self.approach[nOtherTrackId].nProb = 0; self.approach[nOtherTrackId].checkBelief_Threshold(self.nFrame); # print "Killing actor", nTrackId; continue; if self.actor.bMissing: #If the subject dissapeared from screen self.approach[nOtherTrackId].update_Missing_Actor(self.nFrame); elif self.approach[nOtherTrackId].bStarted: #elif has started self.approach[nOtherTrackId].updateAct(self.nFrame);
def setupWindows(self): ''' Setup all the Windows and put them in self.windows ''' self.ScanControl = ScanControl.Window(self.reactor, None) self.LabRAD = LabRADConnect.Window(self.reactor, None) self.DeviceSelect = DeviceSelect.Window(self.reactor, None) self.nSOTChar = nSOTCharacterizer.Window(self.reactor, None) self.PlottingModule = PlottingModule.CommandCenter(self.reactor, None) self.TFChar = TFCharacterizer.Window(self.reactor, None) self.Approach = Approach.Window(self.reactor, None) self.ApproachMonitor = ApproachMonitor.Window(self.reactor, None) self.PosCalibration = PositionCalibration.Window(self.reactor, None) self.FieldControl = FieldControl.Window(self.reactor, None) self.TempControl = TemperatureControl.Window(self.reactor,None) self.QRreader = QRreader.Window(self.reactor,None) self.GoToSetpoint = gotoSetpoint.Window(self.reactor, None) self.SampleCharacterizer = SampleCharacterizer.Window(self.reactor,None) self.AttocubeCoarseControl = CoarseAttocubeControl.Window(self.reactor,None) self.windows = [self.LabRAD, self.DeviceSelect, self.ScanControl, self.nSOTChar, self.PlottingModule, self.TFChar, self.Approach, self.ApproachMonitor, self.PosCalibration, self.FieldControl, self.TempControl, self.QRreader, self.GoToSetpoint, self.SampleCharacterizer, self.AttocubeCoarseControl] #This module should always be initialized last, and have the modules #That are desired to be scriptable be input self.Simulate = Simulation.ScriptSimulator(self.reactor, self, None) self.Scripting = Scripting.Window(self.reactor, None, self.ScanControl, self.Approach, self.nSOTChar, self.FieldControl, self.TempControl, self.SampleCharacterizer, self.GoToSetpoint, self.Simulate) self.windows.append(self.Scripting) self.windows.append(self.Simulate) #Connect signals between modules #When LabRAD Connect module emits all the local and remote labRAD connections, it goes to the device #select module. This module selects appropriate devices for things. That is then emitted and is distributed #among all the other modules self.LabRAD.cxnLocal.connect(self.DeviceSelect.connectLabRAD) self.LabRAD.cxnRemote.connect(self.DeviceSelect.connectRemoteLabRAD) self.DeviceSelect.newDeviceInfo.connect(self.distributeDeviceInfo) self.LabRAD.cxnDisconnected.connect(self.disconnectLabRADConnections) self.LabRAD.newSessionFolder.connect(self.distributeSessionFolder) self.TFChar.workingPointSelected.connect(self.distributeWorkingPoint) self.nSOTChar.newToeField.connect(self.FieldControl.updateToeField) self.Approach.newPLLData.connect(self.ApproachMonitor.updatePLLPlots) self.Approach.newAux2Data.connect(self.ApproachMonitor.updateAux2Plot) self.Approach.newZData.connect(self.ApproachMonitor.updateZPlot) self.Approach.updateFeedbackStatus.connect(self.ScanControl.updateFeedbackStatus) self.Approach.updateConstantHeightStatus.connect(self.ScanControl.updateConstantHeightStatus) self.PosCalibration.newTemperatureCalibration.connect(self.setVoltageCalibration) self.ScanControl.updateScanningStatus.connect(self.Approach.updateScanningStatus)
def update_OtherMissing(self, nFrame): #Prob Run nProbRun = self.actor1.activityMngr.run.nProb; #Prob Approach thisApproach = self.actor1.activityMngr.approach; if not(thisApproach.has_key(self.actor2)): thisApproach[self.actor2] = Approach(self.actor1, self.actor2); if not(thisApproach[self.actor2].bStarted): thisApproach[self.actor2].startAct(nFrame); thisApproach[self.actor2].updateAct(nFrame); nProbApproach = thisApproach[self.actor2].nProb; #Final Prob Belief self.nProb = nProbRun*nProbApproach; print nFrame, self.actor1.nTrackId, self.actor2.nTrackId, "nProbRun: %.2f" % (nProbRun*100), \ "nProbApproach: %.2f" % (nProbApproach), "Prob: %.2f" % (self.nProb*100);
import matplotlib.pyplot as plt K = 10 def plot(results): fig = plt.figure() x = np.arange(0, K + 1, 1) for item in results: plt.plot(x, [0] + results[item], 'bs') plt.legend(results.keys()) plt.xlabel('Seed set size') plt.ylabel('Number of activated users') plt.show() if __name__ == '__main__': results = dict() IC = ICModel() app = Approach(IC, k=K) # start = time.time() # app.greedy() # print('\n'+str(time.time()-start)) start = time.time() results['CELF'] = app.celf() print('\n' + str(time.time() - start)) plot(results) # print(len(users), len(edges))
def __init__(self, budget, time, userList): Approach.__init__(self, budget, time) self.userList = userList