예제 #1
0
 def solve(self):
     graph = main.generateGraph(self.grid)
     t = time.time()
     self.path = graph.bfs_path((self.robot_pos, self.robot_ori), self.goal)
     end = time.time() - t
     print("Duration : ", end)
     self.path_cases = list([x[0] for x in self.path])
     cases = self.path_cases[:]
     self.path_interpolate = []
     for n in (0,1):
         for i in range(0, len(cases)-1):
             if cases[i+1][n] - cases[i][n] > 0:
                 for k in range(cases[i][n], cases[i+1][n]):
                     if n == 0:
                         self.path_interpolate.append((k, cases[i][1-n]))
                     else:
                         self.path_interpolate.append((cases[i][1-n], k))
             else:
                 for k in range(cases[i+1][n], cases[i][n]):
                     if n == 0:
                         self.path_interpolate.append((k, cases[i][1-n]))
                     else:
                         self.path_interpolate.append((cases[i][1-n], k))
     self.path_interpolate = list(set(self.path_interpolate) - set(self.path_cases))
     self.path_cases = list(set(self.path_cases))
     self.path_str = main.format_path(self.path)
def mainf(iters,Nmax=None,Mmax=None,Omax=None):
    exectime = []
    tailles = range(10,60,10)

    for K in tailles:
        endmoy = 0
        N = Nmax if Nmax is not None else K
        M = Mmax if Mmax is not None else K
        O = Omax if Omax is not None else K
        for i in range(iters):
            g = instances.generate_grid(N,M,O)
            p, goal, o = instances.generate_robot(g)
            #START COUNTING
            t = time.time()
            g = main.generateGraph(g)
            g.bfs_path((p,o), goal)
            #END
            end = time.time() - t
            endmoy += end
        exectime.append(endmoy/iters)
        print((N,M), O, endmoy/iters)

    if isinstance(Nmax, int) and Omax is None:
        l = "N=M={}, O".format(Nmax)
    elif Nmax is None and isinstance(Omax, int):
        l = "N=M, O={}".format(Omax)
    else:
        l = "N=M=O"

    fig = plt.figure()
    ax = plt.subplot(111)
    ax.plot([i for i in tailles], exectime, label=l)
    ax.legend()
    plt.ylabel('Overall time (graph conversion + bfs resolution)')
    plt.xlabel('Obstacles amount')