forked from georgevangelou/aloha_protocol_simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.py
80 lines (65 loc) · 2.73 KB
/
ui.py
1
'''ALOHA PROTOCOL SIMULATIONauthors: George Evangelou, Nikos Roussosdate: July 2019'''import inidef check_wrong_max(inp, min): return (inp<min)def check_wrong_prob(inp): return (inp <= 0 or inp > 1)def check_wrong(inp): return (inp <= 0)def get_input(): print('Now initializing simulation...') try: bw = float(input("\nSet the bandwidth of the channel in bps: ")) except Exception: bw = 0 #if an exception is raised, set a wrong value so that the default value is chosen instead if check_wrong(bw): print("Wrong input, defaulted to: ", ini.channel_bandwidth) else: ini.channel_bandwidth = bw try: bpp = int(input("\nSet the packet length (bits per packet): ")) except Exception: bpp = 0 #if an exception is raised, set a wrong value so that the default value is chosen instead if check_wrong(bpp): print("Wrong input, defaulted to: ", ini.packet_length) else: ini.packet_length = bpp try: min_prob = float(input("\nSet the minimum probability of packet generation for every station: ")) except Exception: min_prob = -1 #if an exception is raised, set a wrong value so that the default value is chosen instead if check_wrong_prob(min_prob): print("Wrong input, defaulted to: ", ini.min_probability) else: ini.min_probability = min_prob if (ini.max_probability<ini.min_probability): ini.max_probability = 1.1 * ini.min_probability if (ini.max_probability>1): ini.max_probability = 1 try: max_prob = float(input("\nSet the maximum probability of packet generation for every station: ")) except Exception: max_prob = 2 #if an exception is raised, set a wrong value so that the default value is chosen instead if ( check_wrong_prob(max_prob) or check_wrong_max(max_prob, ini.min_probability) ): #max_prob must not be outside [min_prob, 1] print("Wrong input, defaulted to: ", ini.max_probability) else: ini.max_probability = max_prob try: qsize = int(input("\nSet the max queue size of every station: ")) except Exception: qsize = -1 #if an exception is raised, set a wrong value so that the default value is chosen instead if check_wrong(qsize): print("Wrong input, defaulted to: ", ini.max_queue_size) else: ini.max_queue_size = qsize ini.bit_time = 1/ini.channel_bandwidth #seconds ini.time_slot = ini.bit_time * ini.packet_length #seconds print("\nSimulation was successfully configured") input("Press enter to start the simulation:") returndef runprogram(): option = input('Enter "y" if you want to run another simulation: ') return (option=='y')