Пример #1
0
    def controller(self, opt=1, num=8, col=0):
        self.option = opt
        self.number = num
        self.column = col
        print('option: ', self.option, '\nqueens: ', self.number)

        if self.option == 1:
            print('Executing Breadth-First Search to 8 queens')
            bf = BreadthFirstSearch.BreadthFirst(8)
            bf.bfs()

        elif self.option == 2:
            print('Executing Breadth-First Search to %d queens' % self.number)
            bf = BreadthFirstSearch.BreadthFirst(self.number)
            bf.bfs()
 def run(self):
     with open('data.csv', 'w', newline='') as csvfile:
         writer = csv.writer(csvfile,
                             delimiter=',',
                             quotechar='|',
                             quoting=csv.QUOTE_MINIMAL)
         writer.writerow(
             ["turns", "numTurns", "time", "numGears", "type", "positions"])
     for x in range(1000):
         self.GenerateGears()
         search = DepthFirstSearch()
         self.runSearch(search, "Depth First")
         search = BreadthFirstSearch()
         self.runSearch(search, "Breadth First")
         search = LimitedDepthFirstSearch()
         self.runSearch(search, "LDFS")
         search = AStarSearch()
         result_exists = self.runSearch(search, "A*")
         if result_exists:  # skips hill climb if there will be no result for it as hill climb will never finish
             search = HillClimbingSearch()
             self.runSearch(search, "Hill Climb")
Пример #3
0
                foody = round(random.choice([i for i in range(0,DIS_HEIGHT-BLOCK_SIZE) if i not in snake_y]) / 10.0) * 10.0
                length_of_snake += 1

            # Delete the last cell since we just added a head for moving, unless we ate a food
            if len(snake_list) > length_of_snake:
                del snake_list[0]

            # Next Frame
            clock.tick(50)
    if dead:
        print(reason)
        return time

if __name__ == '__main__':
    # initiate all the objects
    bfs = BreadthFirstSearch.ShortestPathBFSSolver(DIS_WIDTH, DIS_HEIGHT, BLOCK_SIZE)
    dfs = DepthFirstSearch.ShortestPathDFSSolver(DIS_WIDTH, DIS_HEIGHT, BLOCK_SIZE)
    a_star = Astar.ShortestPathAstarSolver(DIS_WIDTH, DIS_HEIGHT, BLOCK_SIZE)
    arg = sys.argv[1]
    all_time =[]

    #run according to the args
    if arg == '-q':
        run_q_learning()
    if arg == '-dfs':
        time = general_Gameloop(dfs)
        print(f"Time taken: {time}", True, (255,255,0))
    if arg == '-bfs':
        time = general_Gameloop(bfs)
        print(f"Time taken: {time}", True, (255,255,0))
    if arg == '-astar':
 def test_example(self):
     start_state = State(0, (0, 0), (1, 2))
     target_state = State(3, (3, 3), (3, 3))
     output = BreadthFirstSearch.BreadthFirstSearch().find_distance(
         start_state, target_state)
     self.assertEqual(11, output)
 def test_real_b(self):
     start_state = State(0, (0, 0, 0, 0, 2, 1, 1), (0, 0, 0, 0, 1, 1, 1))
     target_state = State(3, (3, 3, 3, 3, 3, 3, 3), (3, 3, 3, 3, 3, 3, 3))
     output = BreadthFirstSearch.BreadthFirstSearch().find_distance(
         start_state, target_state)
     self.assertEqual(61, output)
Пример #6
0
if len(sys.argv) != 6:
    print("Wprowadzono nieprawidlowa liczbe argumentow wywolania programu")
    sys.exit()

method_code = sys.argv[1]
method_parameter = sys.argv[2]
THT = TextFileHandler(sys.argv[3])
solutionFilename = sys.argv[4]
infoFilename = sys.argv[5]

THT.readFile()
print(THT.array)
GeneratePattern(THT.line_number, THT.col_number)
solver = BreadthFirstSearch(THT.array, method_parameter, THT.col_number,
                            THT.line_number,
                            GeneratePattern(THT.line_number, THT.col_number))

CheckNumbers(THT.array)

if method_code == "bfs":
    print("Wybrano metode breadth-first search")
    CheckPermutation(method_parameter)

elif method_code == "dfs":
    print("Wybrano metode depth-first search")
    CheckPermutation(method_parameter)
    solver = DepthFirstSearch(THT.array, method_parameter,
                              GeneratePattern(THT.line_number, THT.col_number),
                              THT.col_number, THT.line_number)
Пример #7
0
import graph
import networkimport
import BreadthFirstSearch
from matplotlib import pyplot
import time

undirected_er_graph = graph.make_undirected_graph(1239, .002)   # make the undirected graph with 1239 nodes, ~3049 edges
network_graph = networkimport.load_graph(networkimport.NETWORK_URL) # make the undirected network graph with 1239 nodes, ~3100 edges
upa_graph = graph.upa(1239, 3)    # make the undirected upa graph with 1239 nodes, ~3700 edges

undirected_er_graph_attack_order = graph.random_order(undirected_er_graph)
undirected_er_graph_resilience = BreadthFirstSearch.compute_resilience(undirected_er_graph, undirected_er_graph_attack_order)

network_graph_attack_order = graph.random_order(network_graph)
network_graph_resilience = BreadthFirstSearch.compute_resilience(network_graph, network_graph_attack_order)

upa_graph_attack_order = graph.random_order(upa_graph)
upa_graph_resilience = BreadthFirstSearch.compute_resilience(upa_graph, upa_graph_attack_order)

print(undirected_er_graph_resilience)
print(network_graph_resilience)
print(upa_graph_resilience)

num_nodes_removed = range(1240)
print len(num_nodes_removed)
print len(undirected_er_graph_resilience)
print len(upa_graph_resilience)
print len(network_graph_resilience)

pyplot.plot(num_nodes_removed, undirected_er_graph_resilience, '-b', label='ER Graph, p: .0019')
pyplot.plot(num_nodes_removed, upa_graph_resilience, '-r', label='UPA Graph, m: 3')