Пример #1
0
    def getFullPath(self, mapref, start, goal, poss_goals, heatmap):
        #returns cost and path
        all_goal_coords = [goal] + poss_goals
        goal_obs = d.generateGoalObs(mapref, start, all_goal_coords)
        rmp, argmin = d.rmp(mapref, start, goal_obs)
        cost1, path1 = mapref.optPath(start, argmin.coord, 2)
        cost2, path2 = mapref.optPath(argmin.coord, goal, 2)

        return cost1 + cost2, path1[1:] + path2[1:]
Пример #2
0
    def step_gen(self):
        #print "running generator"
        all_goal_coords = [self.real_goal] + self.poss_goals
        goal_obs = d.generateGoalObs(self.mapref, self.start, all_goal_coords)
        rmp, argmin = d.rmp(self.mapref, self.start, goal_obs)
        path1 = self.mapref.optPath(self.start, argmin.coord)
        path2 = self.mapref.optPath(argmin.coord, self.real_goal)
        path = path1[1:] + path2[1:]

        for step in path:
            yield step
Пример #3
0
    def getFullPath(self, mapref, start, goal, poss_goals, heatmap):
        #returns cost and path
        all_goal_coords = [goal] + poss_goals
        goal_obs = d.generateGoalObs(mapref, start, all_goal_coords)
        rmp, argmin = d.rmp(mapref, start, goal_obs)
        target = d.findTarget(mapref, rmp, argmin, goal, heatmap)        
        
        #return self.customAstar(mapref, start, target, argmin.coord, goal, True) #returns to rmp only
        cost1, path1 = self.customAstar(mapref, start, target, argmin.coord, goal, True)
        cost2, path2  = mapref.optPath(target, goal, 2)

        return cost1 + cost2, path1[1:] + path2[1:]
    def step_gen(self):
        #print "running generator"
        all_goal_coords = [self.real_goal] + self.poss_goals
        goal_obs = d.generateGoalObs(self.mapref, self.start, all_goal_coords)
        rmp, argmin = d.rmp(self.mapref, self.start, goal_obs)

        heatmap = d.HeatMap(self.mapref, goal_obs)
        target = d.findTarget(self.mapref, rmp, argmin, self.real_goal, heatmap)
    
        path1 = self.mapref.optPath(self.start,target)
        path2 = self.mapref.optPath(target, self.real_goal)
        path = path1[1:] + path2[1:]
        self.path2 = path2
        
        for step in path:
            yield step     
    def runBatch(self):
        """
        Read problems, generate observed path and run agents corresponding to each strategy number.
        """
        print "Running batch..."

        #Directly modify prior to run - e.g. limit to one quality, one density, etc.
        densities = (10, 25, 50, 75, 90, 99)  #percentage of path
        #strategyNums = (0,1,2,3,4)        #strategy zero is Astar
        strategyNums = (1, 2)  #strategy zero is Astar

        with open(self.infile, 'r') as f:
            reader = csv.reader(f)
            next(reader)  #skip header row
            counter = 1

            for problem in reader:
                print "Processing problem " + str(counter)
                counter = counter + 1
                map, optcost = problem[:2]  #first two elements
                optcost = float(optcost)
                problem_ints = [int(i) for i in problem[2:]
                                ]  #remaining elements, all integers
                numgoals, scol, srow, gcol, grow = problem_ints[:5]
                start = (scol, srow)
                realgoal = (gcol, grow)

                possgoals = []
                for i in range(numgoals):
                    possgoals.append(
                        (problem_ints[5 + i * 2], problem_ints[6 + i * 2]))

                if not self.map == map:
                    model = LogicalMap(MAP_PATH + map)
                    self.map = map

                #initialise deceptor
                all_goal_coords = [realgoal] + possgoals
                goal_obs = d.generateGoalObs(model, start, all_goal_coords)
                heatmap = d.HeatMap(model, goal_obs)

                #one loop to generate paths, extract obs, get probabilities, and write to csv
                for s in strategyNums:
                    print "strategy" + str(s)
                    #get path and its cost - depends on obs_agent - i.e. strat1, strat2, strat3, strat4
                    if not s:  #strategy zero (astar)
                        clockstart = timer()
                        pathcost, fullpath = model.optPath(start, realgoal, 2)
                        clockend = timer()
                        """ add this code to return path up to rmp only
                        # rmp, argmin = d.rmp(model, start, goal_obs)
                        # target = pathcost-rmp
                        # prev = start
                        # cost = 0
                        # stepnum = 0
                        # while cost < target:      
                            # stepnum = stepnum + 1
                            # step = fullpath[stepnum]
                            # cost = cost + model.getCost(step, prev)
                            # prev = step
                            
                        # fullpath = fullpath[:stepnum]"""

                    else:
                        clockstart = timer()
                        pathcost, fullpath = self.strategies[s].getFullPath(
                            model, start, realgoal, possgoals, heatmap)
                        clockend = timer()

                    gentime = clockend - clockstart
                    writearray = [map, start, s, pathcost, gentime]
                    for density in densities:
                        print "Density", str(density)
                        #find node at that pos
                        density = float(density)
                        totlength = len(fullpath) - 1
                        pathpos = int(density / 100 * totlength)
                        #check deceptivity
                        stepdecept = heatmap.isTruthful(fullpath[pathpos])
                        writearray.append(stepdecept)
                    self.outputLine(self.outfile, writearray)

        print "Results written to " + self.outfile