def __init__(self, emule, mode): self.win = False self.running = True self.emule = emule self.c = True self.grill = Grill() self.matrix = Matrix() if not self.emule: self.machine = Machine() self.strategy = IA(self.matrix)
def pcompile_and_run(filename): code = pcompile(filename) if len(code) == 0: return 1 try: m = Machine(code) except Exception: print("Cannot initialize Machine") try: m.run() except SyntaxError as e: print("Machine runtime error. Reason:{}".format(e.msg)) except IndexError: print("Machine runtime error. Reason:StackError") except ZeroDivisionError: print("Machine runtime error. Reason:ZeroDivisionError")
def __init__(self): # Initializing window and UI QMainWindow.__init__(self) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.setWindowTitle("Time Calculation App") # Initializing Results Section headers = [ 'Machine', 'Planet', 'Labor (Hrs)', 'Machine Time (Hrs)', 'Setup (Hrs)', 'Test Run (Hrs)', 'Coating (Hrs)', 'Quantity', 'Yield', 'Scrap', '' ] self.results = TableView(headers, self, 0, len(headers)) self.results.setParent(self.ui.resultsContainer) # self.results.setFixedWidth(1265) self.results.setFixedWidth(self.ui.resultsContainer.width()) self.results.setFixedHeight(self.ui.resultsContainer.height()) # Initialize variables needed self.machines = [ Machine(), Machine(), Machine() ] # TODO: restructure to have planets w workorders in machines self.techID = None self.theme = 1 # Initialize pie chart widgets and set theme self.initPieCharts() self.toggleTheme() # Connect Signals and Slots self.ui.addWorkOrderButton.clicked.connect( lambda: self.showWOInitDialog()) self.ui.planetConfigButton.clicked.connect( lambda: self.showPlanetConfigDialog()) self.ui.randomButton.clicked.connect( lambda: self.loadRandomWorkOrders()) self.ui.clearButton.clicked.connect(lambda: self.reInit()) self.ui.themeButton.clicked.connect(lambda: self.toggleTheme()) self.themeChanged.connect(lambda: self.results.setBG()) self.ui.actionSave.triggered.connect(self.browseForFile_save) self.ui.actionLoad.triggered.connect(self.browseForFile_load) self.ui.techIDbutton.toggled.connect(self.setTechID) self.connectMachineSignals()
def __init__(self, strategy="random") -> None: self.config = WORLD self.initial_wuzzle_population = self.config[ "initial_wuzzle_population"] self.initial_candy_population = self.config["initial_candy_population"] self.nights = 0 self.lick_counter = 0 self.nightly_lick_counter = 0 self.reward = 10 self.punishment = -100 self.hunger_rate = float(self.config["hunger_rate"]) self.machine = Machine(reward=self.reward, punishment=self.punishment, strategy=strategy) self.generate_wuzzles() self.generate_candies() for wuzzle in self.wuzzles: wuzzle.find_candies(self.candies) wuzzle.generate_cookbooks()
class Game: def __init__(self, emule, mode): self.win = False self.running = True self.emule = emule self.c = True self.grill = Grill() self.matrix = Matrix() if not self.emule: self.machine = Machine() self.strategy = IA(self.matrix) def change_turn(self): self.turn = 3 - self.turn def get_choice(self): if self.turn == Refr.PLAYER: if self.emule: self.choice = self.grill.get_position() else: self.choice = self.machine.wait_player() elif self.turn == Refr.COMPUTER: self.choice = self.strategy.get_choice() def state(self): if self.choice == Refr.QUIT: self.running = False #if self.matrix.control_victory(): # self.win = True def go_turn(self): self.matrix.show() self.get_choice() y = self.matrix.add(self.turn, self.choice) self.grill.token(self.turn, self.choice, y) self.change_turn() self.state() def run(self, starter): self.turn = starter while not self.win and self.running: if self.c: self.go_turn() else: sleep(0.1) return self.turn
def solve_task(task): time_list = list() iter_param = list() block_param = list() schedule_list = list() start = time.time() machines = list() for i in range(task.machine_count): machines.append(Machine(i)) schedule = Schedule(task.jobs, machines) # try some parameters to compare wich is faster for i in range(from_iteration, to_iterations): for block in range(from_block_time, to_block_time): start = time.time() schedule_list.append(solve(schedule, i, block)) end = time.time() time_list.append(end - start) iter_param.append(i) block_param.append(block) # print(f"Iteration with {i} Iterations is over") shortest_schedule = min(schedule_list) shortest_schedule_indizes = list() # search for all the schedules that have same (minimal) length for x in schedule_list: if shortest_schedule == x: shortest_schedule_indizes.append(schedule_list.index(x)) # list the times that the shortest schedules needed to compute shortest_times = list() for i in range(0, len(time_list) - 1): if i in shortest_schedule_indizes: shortest_times.append(time_list[i]) # get shortest needed time shortest_time = min(shortest_times) # get shortest schedule with smallest time needed fastest_schedule_index = time_list.index(shortest_time) stop = time.time() print(f"finisch task {task.name} in {stop-start}s") print(f"Fastest Schedule drawn took {shortest_time}s " + f"to calculate and had follwoing params:") print(f"Iterations: {iter_param[fastest_schedule_index]}") print(f"Block length: {block_param[fastest_schedule_index]}") print(schedule_list[fastest_schedule_index])
def RandomMachine(): return Machine()
class World(): ''' The World object is what contains all the other things in Wuzzlopolis. Wuzzles, Candies, Candy Machines... etc. This is where days become nights, and history gets written. ''' def __init__(self, strategy="random") -> None: self.config = WORLD self.initial_wuzzle_population = self.config[ "initial_wuzzle_population"] self.initial_candy_population = self.config["initial_candy_population"] self.nights = 0 self.lick_counter = 0 self.nightly_lick_counter = 0 self.reward = 10 self.punishment = -100 self.hunger_rate = float(self.config["hunger_rate"]) self.machine = Machine(reward=self.reward, punishment=self.punishment, strategy=strategy) self.generate_wuzzles() self.generate_candies() for wuzzle in self.wuzzles: wuzzle.find_candies(self.candies) wuzzle.generate_cookbooks() def wuzzles_eat_dinner(self): for wuzzle in self.wuzzles: if wuzzle.life == 1: wuzzle.find_candies(self.candies) self.machine.recommend_for_wuzzle(wuzzle, self.candies, self.config["menu_size"]) wuzzle.check_menu(self.candies, self.machine) if wuzzle.nightly_lick_counter > 0: self.lick_counter += wuzzle.nightly_lick_counter self.nightly_lick_counter += wuzzle.nightly_lick_counter self.machine.save_model() def night(self): ''' a day has passed, lick, and update hunger ''' self.nightly_lick_counter = 0 self.wuzzles_eat_dinner() for candy in self.candies: candy.hunger += self.hunger_rate if candy.hunger >= self.config['hunger_death']: candy.life = 0 for wuzzle in self.wuzzles: wuzzle.hunger += self.hunger_rate if wuzzle.hunger >= self.config['hunger_death']: wuzzle.life = 0 self.nights += 1 def generate_wuzzles(self): ''' This is where we keep our Wuzzles ''' self.wuzzles = [] for i in range(self.initial_wuzzle_population): self.wuzzles.append(Wuzzle()) def generate_candies(self): ''' This is where all the CANDY individuals live. ''' self.candies = [] for i in range(self.initial_candy_population): self.candies.append(Candy()) def objects_report(self): w_report = {} w_list = [] c_list = [] f_list = [] for wuzzle in self.wuzzles: w_list.append(wuzzle.name) for candy in self.candies: c_list.append(candy.name) w_report["wuzzles"] = w_list w_report["candies"] = c_list w_report["flavors"] = self.config["flavors"] return w_report def population_status(self) -> dict: status = {} status["nightly_lick_counter"] = self.nightly_lick_counter status["lick_counter"] = self.lick_counter status["population_wuzzle"] = 0 status["dead_wuzzle"] = 0 status["live_wuzzle"] = 0 status["total_hunger_wuzzle"] = 0 for wuzzle in self.wuzzles: status["population_wuzzle"] += 1 if wuzzle.life == 1: status["live_wuzzle"] += 1 status["total_hunger_wuzzle"] += wuzzle.hunger self.wuzzle_population = status["live_wuzzle"] status["dead_wuzzle"] = status["population_wuzzle"] - status[ "live_wuzzle"] status["population_candy"] = 0 status["dead_candy"] = 0 status["live_candy"] = 0 status["total_hunger_candy"] = 0 for candy in self.candies: status["population_candy"] += 1 if candy.life == 1: status["live_candy"] += 1 status["total_hunger_candy"] += candy.hunger status[ "dead_candy"] = status["population_candy"] - status["live_candy"] status["machine_accuracy"] = self.machine.report_accuracy() return (status)