def scenario_A(file_in, file_out=None): print("Input file: {}".format(file_in)) reader = FileReader(file_in) problem = reader.read() solver = Pizza(problem) print("Description:") print(solver.description()) slices = solver.solve() is_valid, result = problem.validate_solution(slices) if is_valid: print("Solution for problem {} is correct. Score is {}".format( file_in, result)) solution = Solution(problem) solution.load_slices(slices) if DEBUG: solution.print_solution() if file_out: writer = FileWriter(file_in + ".out") writer.write(solution) else: print("Incorrect solution. Please check the error messages below") for msg in result: print(msg)
def scenario_A(file_in): print("Input file: {}".format(file_in)) global DEBUG reader = FileReader(file_in) problem = reader.read() solver = Solver(problem) print("Description:") print(solver.description()) solution = solver.initial_solution() # print(solver.initial_solution().print_free()) # print("-------") # print(solver.initial_solution().print_solution()) # print("here") # print("\n".join(str(i) for i in solver.initial_solution().slices)) # print("here2") print("Initial solution score: {}".format(solution.score())) if DEBUG: solution.print_solution() optimized_solution = solver.search(solution, time_limit=60) print("Optimized solution score: {}".format(optimized_solution.score())) # print("\n".join(str(i) for i in optimized_solution.slices)) if DEBUG: optimized_solution.print_solution() trace = solver.get_search_trace() if trace is not None: print("Trace:") print("\n".join([str(x) for x in trace]))
def main(): """Main function for commandline call """ # end user version for user_input # args = user_input(sys.argv[1:]) # add your own args = user_input() for testing and debugging so that you # don't have to call the script with full command line input args = user_input(['Input/Task1/', '-o', 'Output/Task2/']) # read files reader = FileReader(args.path) input_df = reader.read() # perform statistical analysis stat_ana = analysis.Statistical_Analysis(args.output) stat_ana.correlation(input_df['npop.t']) stat_ana.eucl_distance(input_df['table.dat']) # perfomr numerical analysis num_ana = analysis.Numerical_Analysis(args.output) # return new df with the desired columns df_efield_relevant = num_ana.remove_low_variance(input_df['efield.t']) # fft with freq of the df df_efield_fft = num_ana.fft_with_freq_analysis(df_efield_relevant, "y") # disabled plot to not have it get on my nerves num_ana.plot_and_save(df_efield_fft, "freq", "intensitys", "efield_fft_analysis", xlabel="Freq", show_graph=False) df_autocorr = num_ana.autocorrelation(input_df["nstate_i.t"], "time") num_ana.plot_and_save(df_autocorr, "time", ["autocorr_abs", "autocorr_real", "autocorr_imag"], "nstate_autocorr_analysis", xlabel="time", show_graph=False) df_autocorr_fft = num_ana.fft_with_freq_analysis(df_autocorr, "autocorr", type="complex") # adding abs**2 to the dataframe df_autocorr_fft["intensitys_squared"] = np.abs( df_autocorr_fft["intensitys"].values)**2 num_ana.plot_and_save(df_autocorr_fft, "freq", ["intensitys", "intensitys_squared"], "nstate_autocorr_fft_analysis", xlabel="Freq", show_graph=True, crop_edge=3)
def scenario_A(file_in, file_out): global DEBUG reader = FileReader(file_in) problem = reader.read() init_solver = InitSolverSilly() solution = init_solver.run(problem) print("Initial solution score: {}".format(solution.score())) if DEBUG: solution.print_solution() writer = FileWriter(file_out) writer.write(solution)
def scenario_C(file_in, file_out, file_par=None): global DEBUG reader = FileReader(file_in) problem = reader.read() init_solver = ParallelInitSolver(InitSolverSillyParameterized, file_output=file_out) solution = init_solver.run(problem, file_par) print("Initial solution score: {}".format(solution.score())) if DEBUG: solution.print_solution() writer = FileWriter(file_out) writer.write(solution)
def scenario_A(file_in): print("Input file: {}".format(file_in)) global DEBUG reader = FileReader(file_in) problem = reader.read() solver = Solver(problem) print("Description:") print(solver.description()) solution = solver.initial_solution() print("Initial solution score: {}".format(solution.score())) if DEBUG: solution.print_solution() optimized_solution = solver.search(solution, time_limit=60) print("Optimized solution score: {}".format(optimized_solution.score())) if DEBUG: optimized_solution.print_solution() trace = solver.get_search_trace()
def scenario_B(file_in, file_out): global DEBUG reader = FileReader(file_in) problem = reader.read() init_solver = InitSolverSilly() solution = init_solver.run(problem) print("Initial solution score: {}".format(solution.score())) if DEBUG: solution.print_solution() optimizer = Tabu(problem, solution, Neighbourhood_ChangeFormats, debug=True) optimized_solution = optimizer.run(time_limit=100) print("optimized solution score: {}".format(optimized_solution.score())) if DEBUG: optimized_solution.print_solution() writer = FileWriter(file_out) writer.write(optimized_solution)
def scenario_D(file_in, file_out, file_par=None): global DEBUG reader = FileReader(file_in) problem = reader.read() init_solver = ParallelInitSolver(InitSolverSillyParameterized, file_output=file_out) solution = init_solver.run(problem, file_par) print("Initial solution score: {}".format(solution.score())) if DEBUG: solution.print_solution() optimizer = ParallelTabu(problem, solution, Neighbourhood_ChangeFormats, debug=True) optimized_solution = optimizer.run(time_limit=1000) print("optimized solution score: {}".format(optimized_solution.score())) if DEBUG: optimized_solution.print_solution() writer = FileWriter(file_out) writer.write(solution)
class Controller(object): def __init__(self): self.val = Validator() self.db = DatabaseMaker() self.reader = FileReader() self.py = PyGal() self.converted_file = None self.file_count = 1 def read_file(self, filename): try: self.converted_file = self.reader.read(filename) for dict in self.converted_file: print("FILE_DATA:", self.file_count, "\n", dict) self.file_count += 1 except Exception as err: print("The exception is: ", err) def valid(self, flag): try: if flag == '': self.validate() if flag == '-f': file = input("Validate which file?:") self.read_file(file) self.validate() if flag == '-v': self.view_valid() if flag == '-fv': file = input("Validate which file?:") self.read_file(file) self.validate() else: raise Exception("Not a valid flag") except Exception as err: print("The exception is: ", err) def validate(self): try: for dict in self.converted_file: self.val.valid(dict) return self.view_valid() except Exception as err: print("The exception is: No file specified") def view_valid(self): print("\n VALID DATA:") for dict in self.val.get(): print(dict) def db_table(self, flag): try: if flag == "-d": self.db_drop_table() elif flag == '-c': self.db_create_table() elif flag == '-dc': self.db_drop_table() self.db_create_table() elif flag == '-i': for i in self.db_insert(): print(i) elif flag == '-v': value = input("What column do you want to\ see from the employee table?") self.db_view(value) elif flag == '-if': file = input("Input which file?:") self.read_file(file) self.validate() self.db_insert() elif flag == '': self.db_view("*") else: raise Exception("Not a valid flag") except Exception as err: print("The exception is: ", err) def db_drop_table(self): self.db.drop_table("employee") def db_create_table(self): self.db.create_table() def db_insert(self): try: list_of_dictionaries = self.val.get() if list_of_dictionaries: for dict in list_of_dictionaries: self.db.insert(dict["id"], dict["gender"], dict["age"], dict["sales"], dict["bmi"], dict["salary"], dict["birthday"]) return self.db.get("*") else: raise Exception("Cannot add invalid data to the database") except Exception as err: print("The exception is: ", err) def db_view(self, value): for v in self.db.get(value): print(v) def database_close(self): self.db.close() def pygal(self, flag): try: if flag == '': value = input("Which data do you want to see a bar graph of?") self.py_view(value) if flag == '-d': value = input("Input first bar graph comparison:") value2 = input("Input second bar graph comparison:") self.py_view(value, value2) return else: raise Exception("Not a valid flag") except Exception as err: print("The exception is: ", err) def py_view(self, value, value2=None): try: data = self.db.bar_get(value) id = self.db.bar_get('id') if value2 is not None: data2 = self.db.bar_get(value2) self.py.bar_char(id, value, data, value2, data2) else: self.py.bar_char(id, value, data) except Exception as err: print("The exception is: ", err) def pickled(self, flag): try: if flag == '': name = input("Name of pickle file?:") if name == '': raise Exception("Not a valid filename") else: self.pickled_write(name) elif flag == '-r': name = input("Name of pickle file?:") if name == '': raise Exception("Not a valid filename") else: self.pickled_read(name) else: raise Exception("Not a valid flag") except Exception as err: print("The exception is: ", err) def pickled_write(self, name): import pickle with open('{name}.pickle'.format(name=name), 'wb') as f: pickle.dump(self.converted_file, f) def pickled_read(self, name): import pickle with open('{name}.pickle'.format(name=name), 'rb') as f: data = pickle.load(f) print(data)
import argparse from analyzer import Analyzer from chart import BarGraph from reader import FileReader if __name__ == "__main__": parser = argparse.ArgumentParser(description='Лабораторная №5') parser.add_argument('--path=', action="store", required=True, dest="path", help="путь до файла") args = parser.parse_args() data = FileReader.read(args.path) analyzer = Analyzer(data) spammers = analyzer.spammer_list if not spammers: print('Спамеры не обнаружены') else: print('Список спамеров:') for spammer in spammers: print(spammer) BarGraph.draw(analyzer.info)