Ejemplo n.º 1
0
def print_map(win_map, path, start_row, start_col):
    """
    Prints a map of paths that lead to treasure
    :param start_row: The starting row of the map
    :param start_col: The starting column of the map
    :param path: the stack of directions that have been made
    :param win_map: The map that has the winning paths on it
    :return: none
    """
    if path.size() == 0:
        return
    else:
        path = copy.deepcopy(path)
        path.items.reverse()
        winner = Explorer(start_row, start_col)
        print(
            "The following is the total paths to treasure. Underscore's denote the path to a treasure:"
        )
        for i in range(path.size() - 1):
            forward = path.pop()
            if forward == "north":
                winner.move_n()
            elif forward == "south":
                winner.move_s()
            elif forward == "east":
                winner.move_e()
            elif forward == "west":
                winner.move_w()
            win_map[winner.row][winner.col] = "_"
    for i in win_map:
        print(i)
Ejemplo n.º 2
0
 def Run(self):
     self._universe = Universe()
     w = Explorer(self._universe, 0, self._maze._entrance, self._maze, {},
                  "")
     self._universe.AddWorldsForEvaluation([w])
     solutionWorld = self._universe.Run()
     print(f"Short path to solution is {solutionWorld._generation}.")
     return solutionWorld._generation
Ejemplo n.º 3
0
def explore(fs):
    from Explorer import Explorer

    renderer = Explorer()
    renderer.render(fs.root())

    gtk.mainloop()

    return
Ejemplo n.º 4
0
def main():
    cave_map = parse_file("cave_2.txt")
    win_map = copy.deepcopy(cave_map)
    start_row, start_col = find_start(cave_map)
    test = Explorer(start_row, start_col)
    path = Stack()
    not_finished = True
    while not_finished:
        not_finished = advance(test, cave_map, path, win_map, start_row,
                               start_col)
    print("There was no more treasure.")
Ejemplo n.º 5
0
    def __init__(self,
                 x_min,
                 y_min,
                 x_max,
                 y_max,
                 show_gui=False,
                 url="http://localhost:50000"):
        self.__robot = Robot(url)
        self.__robot_drive = RobotDrive(self.__robot)

        # Map grid size in meters per square (robot is 450 x 400 x 243 (LxWxH))
        MAP_GRID_SIZE = .2

        # Set coordinates and dimensions of local map area within the world coordinate system
        width_wcs = x_max - x_min
        height_wcs = y_max - y_min
        width_grid = math.ceil(width_wcs / MAP_GRID_SIZE)
        height_grid = math.ceil(height_wcs / MAP_GRID_SIZE)

        self.__local_map = OccupancyGrid(x_min, y_min, MAP_GRID_SIZE,
                                         height_grid, width_grid)
        self.__laser = LaserSensorModel(self.__robot, self.__local_map)
        self.__show_map = ShowMap(height_grid, width_grid, show_gui)
        self.__explorer = Explorer(self.__robot, self.__local_map)
        self.__path_planner = WavefrontPlanner(self.__robot, self.__local_map)
        self.__obstacle_avoider = ObstacleAvoider(self.__robot,
                                                  self.__local_map)

        # Keep track of number of steps taken in the main_loop
        self.__SCAN_FREQUENCY = 10
        self.__cycles = 0
        self.__loop_running = False
        self.__take_a_scan = False
        self.__determine_frontiers = False
        self.__in_reactive_state = False
        self.__in_warning = False
        self.__in_danger = False
        self.__in_reactive = False
Ejemplo n.º 6
0
def main():
    parser = argparse.ArgumentParser(
        description='Creates a classification dataset from a segmentation one.'
    )
    parser.add_argument(
        'path',
        type=str,
        help='Absolute path containing the images and masks folders.')
    parser.add_argument('--patch_size',
                        type=int,
                        default=224,
                        help='Size of each patch.')
    parser.add_argument('--max_patches_per_image',
                        type=int,
                        default=100,
                        help='How many patches to extract from each image.')
    args = parser.parse_args()

    explorer = Explorer(args.path)
    converter = Converter(explorer,
                          patch_size=args.patch_size,
                          max_patches_per_image=args.max_patches_per_image)
    converter.process_images()
Ejemplo n.º 7
0
    def sample(self, keep=None):
        """
        Sample the posterior and return the weighted average result of the
        Model.

        The more sensible result of this method is a SampleList which contains
        samples taken from the posterior distribution.

        Parameters
        ----------
        keep : None or dict of {int:float}
            Dictionary of indices (int) to be kept at a fixed value (float)
            Hyperparameters follow model parameters
            The values will override those at initialization.
            They are only used in this call of fit.

        """
        if keep is None:
            keep = self.keep
        fitlist = self.makeFitlist(keep=keep)

        self.initWalkers(fitlist=fitlist)
        for eng in self.engines:
            eng.walkers = self.walkers

        self.distribution.ncalls = 0  #  reset number of calls

        self.plotData()

        if self.verbose >= 1:
            print("Fit", ("all" if keep is None else fitlist), "parameters of")
            print(" ", self.model._toString("  "))
            print("Using a", self.distribution, "with")
            np = self.model.npchain
            for name, hyp in zip(self.distribution.PARNAMES,
                                 self.distribution.hyperpar):
                print("  %-7.7s   " % name, end="")
                if np in fitlist:
                    print("unknown")
                else:
                    print("  (fixed)  ", hyp.hypar)
#                    print( "%7.2f  (fixed)" % hyp.hypar )
                np += 1
            print("Moving the walkers with")
            for eng in self.engines:
                print(" ", eng)

        if self.verbose >= 2:
            print("Iteration   logZ        H     LowL     npar    parameters")

        explorer = Explorer(self)

        self.logZ = -sys.float_info.max
        self.info = 0

        logWidth = math.log(1.0 -
                            math.exp((-1.0 * self.discard) / self.ensemble))

        if self.optionalRestart():
            logWidth -= self.iteration * (1.0 * self.discard) / self.ensemble

        while self.iteration < self.getMaxIter():

            #  find worst walker(s) in ensemble
            worst = self.findWorst()
            worstLogW = logWidth + self.walkers[worst[-1]].logL

            # Keep posterior samples
            self.storeSamples(worst, worstLogW - math.log(self.discard))

            # Update Evidence Z and Information H
            logZnew = numpy.logaddexp(self.logZ, worstLogW)

            self.info = (math.exp(worstLogW - logZnew) * self.lowLhood +
                         math.exp(self.logZ - logZnew) *
                         (self.info + self.logZ) - logZnew)
            self.logZ = logZnew

            if self.verbose >= 3 or (self.verbose >= 2
                                     and self.iteration % 100 == 0):
                kw = worst[0]
                pl = self.walkers[kw].parlist[self.walkers[kw].fitIndex]
                np = len(pl)
                print(
                    "%8d %8.1f %8.1f %8.1f %6d " %
                    (self.iteration, self.logZ, self.info, self.lowLhood, np),
                    fmt(pl))

                self.plotResult(worst[0], self.iteration)

            self.samples.weed(self.maxsize)  # remove overflow in samplelist

            self.copyWalker(worst)

            # Explore the copied walker(s)
            explorer.explore(worst, self.lowLhood, fitlist)

            # Shrink the interval
            logWidth -= (1.0 * self.discard) / self.ensemble
            self.iteration += 1

            self.optionalSave()

        # End of Sampling
        self.addEnsembleToSamples(logWidth)

        # Calculate weighted average and stdevs for the parameters;
        self.samples.LogZ = self.logZ
        self.samples.info = self.info
        self.samples.normalize()

        # put the info into the model
        self.model.parameters = self.samples.parameters
        self.model.stdevs = self.samples.stdevs

        if self.verbose >= 1:
            self.report()

        return self.samples.average(self.xdata)
Ejemplo n.º 8
0
 def __init__(self):
     self.explorer = Explorer(True)
Ejemplo n.º 9
0
#! /usr/bin/env python

'''
Robot side
'''

import rospy

from Drive import Drive_Keys
from Explorer import Explorer
from Runner import Runner

if __name__ == "__main__":
    rospy.init_node('drive_bot')
    explorer = Explorer()
    runner = Runner()
    drive_keys = Drive_Keys()
    rospy.spin()