import array import random try: import xlrd except: import os os.system('pip install xlrd') import xlrd def integer_random(upper_number): return int(random.random() * upper_number) def initial_role_list(producer_amount, consumer_amount): roles = [] for n in range(producer_amount): roles.append("Producer") for n in range(consumer_amount): roles.append("Consumer") return roles def allocate_role(producer_amount, consumer_amount): # Initialize market role temp_roles = initial_role_list(producer_amount, consumer_amount) total_number = producer_amount + consumer_amount role_index = array.array('I', range(0, total_number)) # Every element has the same probability appears in specific index while total_number > 0: index = integer_random(total_number) temp = role_index[index] last_index = total_number - 1 # Swap current element with the last element role_index[index] = role_index[last_index] role_index[last_index] = temp total_number = last_index # Randomize the roles roles = [] for index in role_index: roles.append(temp_roles[index]) return roles def u(x): beta = 2.6563 eta = 0.37851 return round(beta * (pow(x, 1 - eta) / (1 - eta)), 2) # for debug, list all the roles, see if random at all # print(allocate_role(1, 1)) def read_sequence_random_number(file_path): work_book = xlrd.open_workbook(filename=file_path) float_rows = work_book.sheet_by_index(0).col_values(1)[1:] int_rows = [] for d in float_rows: int_rows.append(int(d)) return int_rows def get_participant(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return int(sheet.col_values(2)[1]) def get_experiment_timeout(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return int(sheet.col_values(3)[1]) def get_block_length(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return int(sheet.col_values(4)[1]) def get_conversion_rate(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return round(sheet.col_values(5)[1], 2) def get_show_up_fee(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return sheet.col_values(6)[1] def get_critical_period_value(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return int(sheet.col_values(7)[1]) def get_critical_period_timeout_lower(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return int(sheet.col_values(8)[1]) def get_critical_period_timeout_upper(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return int(sheet.col_values(9)[1]) def get_block_check_timeout(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return int(sheet.col_values(10)[1]) def get_introduction_timeout(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return int(sheet.col_values(11)[1]) def get_decision_timeout(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return int(sheet.col_values(12)[1]) def get_starting_tokens(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return sheet.col_values(13)[1] def get_robot_rate(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return sheet.col_values(14)[1]