def calCommitStep(initGrid, target1, target2, trajectory): initGrid = trajectory[0] distanceDiff = abs(calculateGridDis(initGrid, target1) - calculateGridDis(initGrid, target2)) minDisToTarget = min([calculateGridDis(selfGrid, target) for target in[target1, target2]]) currentSteps = trajectory.index(selfGrid) return commitStep
def __call__(self, selfGrid, target1, target2, trajectory): initGrid = trajectory[0] goal = trajectory[-1] midpoint = calMidPoints(selfGrid, target1, target2) zone = calculateAvoidCommitmnetZoneAll(initGrid, target1, target2) if midpoint: disToMidPoint = calculateGridDis(selfGrid, midpoint) disToTargets = [calculateGridDis(selfGrid, target) for target in[target1, target2]] isInDeliberationArea = 1 if disToMidPoint < min(disToTargets) else 0 if isInDeliberationArea: actionDis = self.goalPolicy(selfGrid, midpoint) else: actionDis = self.goalPolicy(selfGrid, goal) else: actionDis = self.goalPolicy(selfGrid, goal) return actionDis
def calDisToMidPointTrajLen(trajectory, target1, target2): trajectory = list(map(tuple, trajectory)) playerGrid = trajectory[0] midPoint = calMidPoints(playerGrid, target1, target2) disToMidPointTraj = [ calculateGridDis(grid, midPoint) for grid in trajectory ] meanDis = np.mean(disToMidPointTraj) return meanDis
def calDisToMidPointTraj(trajectory, target1, target2): trajectory = list(map(tuple, trajectory)) playerGrid = trajectory[0] midPoint = calMidPoints(playerGrid, target1, target2) disToMidPointTraj = [ calculateGridDis(grid, midPoint) for grid in trajectory ] x = np.divide(np.arange(len(disToMidPointTraj)), len(disToMidPointTraj) - 1) y = np.array(disToMidPointTraj) f = interp1d(x, y, kind='nearest') xnew = np.linspace(0., 1., 30) posterior = f(xnew) return posterior
def isCommited(selfGrid, target1, target2): distanceDiff = abs( calculateGridDis(selfGrid, target1) - calculateGridDis(selfGrid, target2)) pAvoidCommit = 1 / (distanceDiff + 1) return 1 - pAvoidCommit