def solve_functions(dp): global function_object, data_function data_function = dp _, function_object = Main.find_function_by_id(int(data_function['problem'])) function_object.set_n_dimension(int(data_function['dimension'])) isHybrid = data_function['isHybrid'] j = json.loads(open(os.path.dirname(__file__) + "/../JSON/functions-methods.json", 'r').read()) callable_method = j[data_function['firstMethod']['name-method']]['callable-method'] initial_time = time.time() result_first = globals()[callable_method](data_function['firstMethod'], None) result_first_done = {'decimal-best': {}, 'value-best': str(result_first[3]), 'time': str(time.time() - initial_time)} PLOTS = PLots() pl_3d, pl_contour = PLOTS.plot_function3d(function_object) j = 1 for i in result_first[2]: result_first_done['decimal-best'][j] = str(i) j += 1 if not isHybrid: err1 = PLOTS.plot_err(result_first[1]) return { 'problem':function_object.name, 'problem-description':str(function_object), 'isHybrid':isHybrid, 'result-first':result_first_done, '3d':pl_3d, 'contour':pl_contour, 'err1':err1 } initial_time = time.time() result_second = globals()[callable_method](data_function['firstMethod'], result_first[0]) result_second_done = {'decimal-best': {}, 'value-best': str(result_second[3]), 'time': str(time.time() - initial_time)} j = 1 for i in result_second[2]: result_second_done['decimal-best'][j] = str(i) j += 1 err1, err2, err3 = PLOTS.plot_err(result_first[1], result_second[1]) return { 'problem':function_object.name, 'problem-description':str(function_object), 'isHybrid':isHybrid, 'result-first':result_first_done, 'result-second':result_second_done, '3d': pl_3d, 'contour': pl_contour, 'err1':err1, 'err2':err2, 'err3':err3, 'hibridization-analysis':str('The FIRST hit the value SOMEVALUE in TIME seconds.\nStarting on the best found value, the SECOND *CONDITION got a improve DIFFERENCE in the solution, in TIME seconds. Hybridization reached a value of FINAL-VALUE in a total of FINAL-TIME seconds, considered a effective result, because one method support the other.') }
def simule_functions(dp, repetitions): global function_object, data_function data_function = dp _, function_object = Main.find_function_by_id(int(data_function['problem'])) function_object.set_n_dimension(int(data_function['dimension'])) isHybrid = data_function['isHybrid'] j = json.loads(open(os.path.dirname(__file__) + "/../JSON/functions-methods.json", 'r').read()) callable_method = j[data_function['firstMethod']['name-method']]['callable-method'] vec_times = [] vec_costs = [] for i in range(repetitions): initial_time = time.time() result_first = globals()[callable_method](data_function['firstMethod'], None) if isHybrid: result_second = globals()[callable_method](data_function['secondMethod'], result_first[0]) vec_costs.append(result_second[3]) else: vec_costs.append(result_first[3]) vec_times.append(time.time() - initial_time) PLOTS = PLots() pl_3d, pl_contour = PLOTS.plot_function3d(function_object) box_times, box_costs, scatter = PLOTS.plot_simulation(vec_times, vec_costs) return { 'problem':function_object.name, 'problem-description':str(function_object), 'isHybrid':isHybrid, 'times':vec_times, 'costs':vec_costs, '3d':pl_3d, 'contour':pl_contour, 'box_times':box_times, 'box_costs':box_costs, 'scatter':scatter }