Пример #1
0
    def start(self, filename):
        self.time = time()
        # destroy menu when algorithm illustrations begins
        self.destroy_menu()
        self.nodes = {}

        variable_dict, constraints = input_handler.read_file(filename)
        initial_state = CSPState(constraints, variable_dict, GACVertexColoring())
        initial_state.gac.init_revise_queue(initial_state.constraints, initial_state.variable_dict)
        initial_state.gac.domain_filtering_loop(initial_state.variable_dict)
        initial_state.h_value = initial_state.calculate_h()

        self.screen_width = self.winfo_screenwidth() - 100
        self.screen_height = self.winfo_screenheight() - 200
        self.normalize_coordinates(initial_state)
        self.canvas = tk.Canvas(self, width=self.screen_width, height=self.screen_height + 20, borderwidth=0, highlightthickness=0)
        self.canvas.pack(side="top", fill="both", expand="true")

        # add back and cancel buttons to display
        self.backButton = tk.Button(self,text='back', command=self.back)
        self.cancelButton = tk.Button(self,text='Cancel', command=self.cancel)
        self.backButton.pack()
        self.cancelButton.pack()

        self.draw_board(initial_state)

        if not initial_state.is_solution_or_contradictory():
            self.a_star = AStarTree()
            self.a_star.add_start_state_to_open(initial_state)
            self.run_a_star()
        else:
            print "Failed"
Пример #2
0
    def start(self, scenario):
        self.time = time()
        self.cells = {}
        self.destroy_menu()
        self.dimensions, self.variable_dict, self.constraints = input_handler.read_file(scenario)

        self.screen_width = (self.dimensions[0] + 2)*self.cell_width
        self.screen_height = (self.dimensions[1] + 2)*self.cell_height
        self.canvas = tk.Canvas(self, width=self.screen_width, height=self.screen_height + 60, borderwidth=0, highlightthickness=0)
        self.canvas.pack(side="top", fill="both", expand="true")
        self.draw_board()

        self.backButton = tk.Button(self,text='back', command=self.back)
        self.cancelButton = tk.Button(self,text='Cancel', command=self.cancel)
        self.backButton.pack()
        self.cancelButton.pack()

        initial_state = CSPState(self.constraints, self.variable_dict, GACNonogram())
        initial_state.gac.init_revise_queue(initial_state.constraints, initial_state.variable_dict)
        initial_state.gac.domain_filtering_loop(initial_state.variable_dict)

        self.update_board(initial_state)

        if not initial_state.is_solution_or_contradictory():
            self.a_star = AStarTree()
            self.a_star.add_start_state_to_open(initial_state)
            self.run_a_star()