def main(): ''' i: Iterating variable nt: Maximum timesteps ''' print("Reading parameters and variables") init.init() print("Initialization finished. Start calculation.") #print(var.h[:,:,0]) for i in range(1, param.nt): print("Integrating for timesstep t = " + str(i) + " of " + str(param.nt - 1)) swe_rk4.__init__() swe_rk4.swe_rk4(i) dio.output_netcdf() print("Simulation all completed. Enjoy your work!")
def basic(): #INITIALIZATION #schedules initialization S = ini.init() #map initialization mapp = {} for user_id in S: mapp[user_id] = [] #loop to create an event and do feedback # pprint(S) events = ev.generateEvents(S,mapp) # S_copy = S.copy() S_copy = ev.placeEvents(copy.deepcopy(S), events, mapp) pprint(S) # pprint(S_copy) pprint(events) ap.assignment(S,events)
import initialization as ini import exchs_data import matching import json import random from pprint import pprint botconf = json.load(open('bot_config.json')) pairs = botconf['symbols'] limit = botconf['limit'] conffile = botconf['config_file'] exchsfile = botconf['exchs_credentials'] exchs, minvolumes = ini.init(pairs, conffile, exchsfile) while True: balances = ini.get_balances(pairs, conffile) order_books = exchs_data.get_order_books(pairs, limit, conffile) for key in balances.keys(): for kkey in balances[key].keys(): balances[key][kkey] = random.randint(0, 10000) pprint(balances) our_orders = matching.get_arb_opp(order_books, balances) pprint(our_orders) break
def main(argv): try: opts, args = getopt.getopt(argv, "his:lr:g:t", ["init", "store=", "list"]) except getopt.GetoptError: logger.error(getopt.GetoptError) print("Must be in the following format") print( "Options are [-i or --init to initialize and create backup folder]" ) print( " [-s or --store <directory_path> to create a backup of directory in backup folder]" ) print( " [-r or --restore <destination_directory> to restore entire backup into destination]" ) print( " [-l or --list to list all files currently in backup folder]" ) print( " [-g or --get <'filename'> restores individual file to current directory]" ) print(" [-t Tests for errors in the archive]") sys.exit() for opt, arg in opts: if opt == "-h": print( "Options are [-i or --init to initialize and create backup folder]" ) print( " [-s or --store <directory_path> to create a backup of directory in backup folder]" ) print( " [-r or --restore <destination_directory> to restore entire backup into destination]" ) print( " [-l or --list to list all files currently in backup folder]" ) print( " [-g or -get <'filename'> restores individual file to current directory]" ) print(" [-t or Tests for errors in the archive]") sys.exit() elif opt in ("-i", "--init"): initialization.init(myArchive, logger) elif opt in ("-l", "--list"): list_all_items() elif opt in ("-r", "--restore"): restore_files(arg) elif opt in ("-s", "--store"): print("Store") stored_directory = arg update_index() store.store_backup(stored_directory) elif opt in "-t": test() elif opt in ("-g" or "--get"): if not type(arg) is str: print("-g or --get <'filename'> (filename must be in quotes)") sys.exit() get_file(arg) else: logger.error("Command not found, type -h for help")
def test(RTS_enable, suspend_enable, reserved_data_size, d_max): PRAWs_duration = 5.3 * 1000 BI = 500 * 1000 #STA_number=20 CWmin = 16 CWmax = 16 * (2**6) # 1024 #packet_arrival_rate=1.0/150000 #in us end_time = 10**7 * 2 data_size = reserved_data_size #in bytes, this parameter is also need to be changed in packets.py STA_list = [] radius = 1000 amount = 500 # the total number of stations, it is used to read the corresponding files # d_max=1900 for times in range(20): print("system end time=" + str(end_time)) ############## initialization ########### timer = system_timer.SystemTimer(end_time) # file=open("./results/d_max="+str(d_max)+"_amount="+str(amount)+"/CWmax="+str(CWmax)+\ # "_suspend="+str(suspend_enable)+"_round="+str(times)+"_new.txt","w") folder_name = "./results/d_max=" + str(d_max) + "_amount=" + str( amount) if not os.path.isdir(folder_name): os.makedirs(folder_name) file = open( folder_name + "/data_size=" + str(data_size) + "_round=" + str(times) + ".txt", "w") # file=open("./results/CWmax/CWmax="+str(CWmax)+\ # "_suspend="+str(suspend_enable)+"_round="+str(times)+".txt","w") # file=open("./results/d_max="+str(d_max)+"_amount="+str(amount)+"/CWmax=unlimited"+"_suspend="+str(suspend_enable)+"_round="+str(times)+".txt","w") statistics_collection.collector.set_output_file(file) system_channel = channel.channel() system_AP, STA_list = initialization.init(amount, d_max, timer, RTS_enable, suspend_enable, CWmax, system_channel, data_size=data_size) system_AP.block_list = initialization.AID_assignment(STA_list) system_channel.register_devices(STA_list + [system_AP]) system_AP.channel = system_channel system_AP.max_data_size = reserved_data_size statistics_collection.collector.end_time = end_time ############# excute the simualtion #################### while timer.events: #simulation starts current_events = timer.get_next_events() for each_event in current_events: if each_event.type != "backoff": print("The event type is " + each_event.type + " at " + str(timer.current_time)) if each_event.time > timer.end_time: # end the pragram break each_event.execute(STA_list + [system_AP], timer, system_channel) #### !!!!! if each_event.type != "backoff": counter = [] for each in STA_list: # how many STAs stay awake if each.status != "Sleep": counter.append(each.AID) print("There are " + str(counter.__len__()) + " STAs stays awake at " + str(timer.current_time)) counter = [] backoff_timer = [] for each in STA_list: if not (each.backoff_status == "Off" or not each.queue or each.status != "Listen"): counter.append(each.AID) backoff_timer.append(each.backoff_timer) print("There are " + str(counter.__len__()) + " STAs are competing for the channel at " + str(timer.current_time)) print("The backoff timers are " + str(backoff_timer) + "\n ") if statistics_collection.collector.number_of_packet == statistics_collection.collector.successful_transmissions.__len__( ): # stop the simulation if not [ x for x in timer.events if x.type == "Polling round end" ]: statistics_collection.collector.end_time = timer.current_time timer.events = [] # for each in STA_list: # if each.has_pending_packet(): # statistics_collection.collector.register_backoff_times(each.number_of_attempts,each.number_of_backoffs) if system_channel.packet_list: # renew the channel busy time statistics_collection.collector.channel_busy_time += timer.end_time - statistics_collection.collector.last_time_idle statistics_collection.collector.print_statistics_of_delays() statistics_collection.collector.print_polling_info() statistics_collection.collector.print_other_statistics( end_time, data_size) statistics_collection.collector.clear() os.system('cls' if os.name == 'nt' else 'clear') file.close()
""" import initialization import evaluation import survivor_selection import parent_selection import recombination import constraints from visulization import Visulization import matplotlib.pyplot as plt import time import os import random # Call the initialization script to collect configuration data from csv files and build the # population for generation 0 init_items = initialization.init(constraints.pop_size) pop = init_items[0] courses = init_items[1] rooms = init_items[2] profs = init_items[3] times = init_items[4] best_fitness = 0 generation = constraints.numgenmax viable_gen = -1 record_fitness = 0 fit_log = [] # Visualization setup plt.show() axes = plt.gca()
def test(d_max, threshold, detection_time): end_time = 10**7 packet_size = 100 STA_list = [] amount = 500 CWmax = 1024 for times in range(10): sys.stdout = open("log_file_Thr=" + str(threshold) + ".txt", 'w') timer = system_timer.SystemTimer(end_time) folder_name = "./Parameter_test/Thr=" + str(threshold) + "_T=" + str( detection_time / 10**3) if not os.path.isdir(folder_name): os.makedirs(folder_name) file = open( folder_name + "/d_max=" + str(d_max) + "_round=" + str(times) + ".txt", 'w') statistics_collection.collector.set_output_file(file) system_channel = channel.channel() AP, STA_list = initialization.init(amount, d_max, timer, False, False, CWmax, system_channel, threshold, detection_time) AP.block_list = initialization.AID_assignment(STA_list) system_channel.register_devices(STA_list + [AP]) AP.channel = system_channel AP.max_data_size = packet_size statistics_collection.collector.end_time = end_time ################# start the simulation ################## while timer.events: current_events = timer.get_next_events() for each_event in current_events: if each_event.type != "backoff": print("The event type is " + each_event.type + " at " + str(timer.current_time)) if each_event.time > timer.end_time: break each_event.execute(STA_list + [AP], timer, system_channel) if each_event.type != "backoff": counter = [] for each in STA_list: # how many STAs stay awake if each.status != "Sleep": counter.append(each.AID) print("There are " + str(counter.__len__()) + " STAs stays awake at " + str(timer.current_time)) counter = [] backoff_timer = [] for each in STA_list: if not (each.backoff_status == "Off" or not each.queue or each.status != "Listen"): counter.append(each.AID) backoff_timer.append(each.backoff_timer) print("There are " + str(counter.__len__()) + " STAs are competing for the channel at " + str(timer.current_time) + "\n") # print("The backoff timers are "+str(backoff_timer)+"\n ") if (statistics_collection.collector.number_of_packet == statistics_collection.collector.successful_transmissions. __len__()): if not [ x for x in timer.events if x.type == "Polling round end" ]: # stop the simulation statistics_collection.collector.end_time = timer.current_time timer.events = [] if system_channel.packet_list: # renew the channel busy time statistics_collection.collector.channel_busy_time += ( timer.end_time - statistics_collection.collector.last_time_idle) statistics_collection.collector.print_statistics_of_delays() statistics_collection.collector.print_polling_info() statistics_collection.collector.print_other_statistics( end_time, packet_size) statistics_collection.collector.clear() file.close() os.system('cls' if os.name == 'nt' else 'clear')
db_name = botconf['database'] except KeyError as e: Time = datetime.datetime.utcnow() EventType = "KeyError" Function = "main" Explanation = "Some of bot_config.json's required keys are not set" EventText = e ExceptionType = type(e) print("{}|{}|{}|{}|{}|{}|{}".format(Time, EventType, Function, File, Explanation, EventText, ExceptionType)) exit(1) else: print2console('Parsing successful', last=True) print2console('Initialization') exchs, minvolumes = ini.init(pairs, conffile, exchsfile, exchanges_names) requests = ini.get_urls(pairs, conffile, limit) while len(exchs) <= 1: time.sleep(60) exchs, minvolumes = ini.init(pairs, conffile, exchsfile, exchanges_names) continue currency_list = set() for pair in pairs: for cur in pair.split('_'): currency_list.add(cur) print2console('Initialization successful', last=True) print2console('Connecting to Mongo') ok_mongo = False
main_command = [ ('Play',play,[dungeon[0]]), ('Credits',play,[credits_scene]), ('Quit',game.close,[]) ] main_scene = cocos.scene.Scene() menu = MainMenu(main_command) #Title label = cocos.text.Label(TITLE,position = (400,500), font_name = 'Drakoheart Leiend', font_size = 45, anchor_x = 'center') main_scene.add(label) main_scene.add(menu) #music bgm = ServerConnection.getMusic('bgm/main_screen.ogg') bgm_player = pyglet.media.Player() bgm_player.queue(bgm) bgm_player.eos_action = bgm_player.EOS_LOOP bgm_player.play() cocos.director.director.run(main_scene) except UDungeonException as ude: print ude.message if __name__ == "__main__": init() test()
# _*_coding:utf-8 _*_ # author: hsh # file name: app.py # data: 2019/8/26 14:46 from initialization import init if __name__ == '__main__': init()
em_data = open("em_data", "r") data = np.loadtxt(em_data) em_data.close() print('Data shape:', data.shape) #2D plot of imported data x, y = data.T plt.plot(x, y, 'x') plt.axis('equal') plt.show() print('Data shape:', data.shape) #Initializtion of parameters for EM algorithm delta = 4 mu_, sig_, pi_c = ini.init(data, C, delta) #Convergence condition conv = 0.000001 #Compute parameters using EM algorithm log_a, mu_new, sig_new, pic_new = em.gaussian(data, mu_, sig_, pi_c, conv) #Print results iterations = np.array(log_a.shape) print('\n Number of iterations:', iterations[0]) print('\n New Means: \n', mu_new) print('New covariance matrices: \n', sig_new) print('New prior probabilities: \n', pic_new) #Save results