def objective_maximize(self): self.update_objective_function() for row, column in enumerate(self.basic_vars[1:]): if self.coeff_matrix[0][column] != 0: self.coeff_matrix[0] = add_row(self.coeff_matrix[0], multiply_const_row(-self.coeff_matrix[0][column], self.coeff_matrix[row + 1])) key_column = min_index(self.coeff_matrix[0]) condition = self.coeff_matrix[0][key_column] < 0 print_table(self.coeff_matrix) solution = {} while condition is True: key_row = self.find_key_row(key_column=key_column) self.basic_vars[key_row] = key_column pivot = self.coeff_matrix[key_row][key_column] self.pivot(key_row, pivot) self.make_key_column_zero(key_column, key_row) key_column = min_index(self.coeff_matrix[0]) condition = self.coeff_matrix[0][key_column] < 0 print_table(self.coeff_matrix) for i, var in enumerate(self.basic_vars[1:]): if var < self.num_vars: solution['x_' + str(var + 1)] = self.coeff_matrix[i + 1][-1] for i in range(0, self.num_vars): if i not in self.basic_vars[1:]: solution['x_' + str(i + 1)] = Fraction("0/1") return solution
def get_common_ne(entity_name_cnt, lower): """ Prints the 20 most common tagged entities. """ header = '{:<5}{:<6}{:<30}{}'.format('Rank', 'Count', 'Entity', 'Category') rows = [] for ix, (ent_name, cnt) in enumerate(entity_name_cnt.most_common(20)): rows.append('{:<5}{:<6}{:<30}{}'.format(ix + 1, cnt, ent_name[0], ent_name[1])) print_table(header, rows)
def get_cat_stats(bio_cnt, entity_cnt): """ Computes statistics about the entity category distribution in the data. """ header = '{:<13}{}'.format('NE category', '#') rows = [] for ent, cnt in entity_cnt.items(): rows.append('{:<13}{}'.format(ent, cnt)) pad_size = len(header) + 2 rows.append('-' * pad_size) rows.append('{:<13}{}'.format('All', bio_cnt['B'])) print_table(header, rows)
def get_span_stats(len_cnt): """ Computes statistics about span, that is whether entities consist of single or multiple tokens. """ multi_tkn = sum( [cnt for ent_len, cnt in len_cnt.items() if int(ent_len) > 1]) header = '{:<15}{:<5}'.format('NE span', '#') rows = [ '{:<15}{:<5}'.format('Single-tkn', len_cnt['1']), '{:<15}{:<5}'.format('Multi-tkn', multi_tkn) ] print_table(header, rows)
def get_general_stats(bio_cnt, entity_name_cnt): """ Computes general statistics: number of entities, unique entities, percentage of entity tokens and total nr. of tokens. """ ne_tkns = bio_cnt['B'] + bio_cnt['I'] ent_perc = ne_tkns / bio_cnt['O'] * 100 rows = [ '{:<15}{:<5}'.format('# NE', bio_cnt['B']), '{:<15}{:<5}'.format('# NE (unique)', len(entity_name_cnt.keys())), '{:<15}{:<5} ({:<5.2f}%)'.format('# NE tkns', ne_tkns, ent_perc), '{:<15}{:<5}'.format('# All tkns', bio_cnt['B'] + bio_cnt['I'] + bio_cnt['O']) ] print_table('{:<15}{:<5}{:<10}'.format('General info', '', ''), rows)
def p1(self): print_table(self.coeff_matrix) r_index = self.num_vars + self.num_s_vars for i in range(r_index, len(self.coeff_matrix[0]) - 1): # Artificial self.coeff_matrix[0][i] = Fraction("-1/1") for i in self.r_rows: self.coeff_matrix[0] = add_row(self.coeff_matrix[0], self.coeff_matrix[i]) self.basic_vars[i] = r_index r_index += 1 s_index = self.num_vars for i in range(1, len(self.basic_vars)): if self.basic_vars[i] == 0: self.basic_vars[i] = s_index s_index += 1 # Run the simplex iterations key_column = max_index(self.coeff_matrix[0]) condition = self.coeff_matrix[0][key_column] > 0 print_table(self.coeff_matrix) while condition is True: key_row = self.find_key_row(key_column=key_column) self.basic_vars[key_row] = key_column pivot = self.coeff_matrix[key_row][key_column] self.pivot(key_row, pivot) self.make_key_column_zero(key_column, key_row) key_column = max_index(self.coeff_matrix[0]) condition = self.coeff_matrix[0][key_column] > 0 print_table(self.coeff_matrix)
from fabric import Connection import getpass import yaml from helpers import print_color_text, print_log, print_table, run_commands with open("hosts.yml") as file: data = yaml.load(file, Loader=yaml.FullLoader) hosts = data["hosts"] print_table(hosts) selected_host = None while selected_host is None: id_host = int(input("Selecciona el host: ")) if id_host < len(hosts): selected_host = hosts[id_host] else: print("Host no valido") password = getpass.getpass("Ingresa la contraseña: ") try: with Connection( host=selected_host["host"], user=selected_host["user"], connect_kwargs={ "password": password, }, ) as c: run_commands(c, selected_host) print(print_color_text("Done!", 'green'))
# Init `option` variable option = None try: # Prompt user to choose an option option = int(input(menu)) except ValueError: # If user entered a letter print('Please enter a number') # If user entered a valid option we make it here if option == exit_option: # Break out the loop if user selects `exit_option` break elif option == 1: print_table(people, "people") # Show list of ppl elif option == 2: print_table(drinks, "drinks") # Show list of drinks elif option == 3: print_table(prefs, "prefs") # Show list of prefs elif option == 4: create_person() save_people() # Update saved ppl file (optional) elif option == 5: create_drink() save_drinks() # Update saved drinks file (optional) elif option == 6: # Create Preference Object: { person: Person, drink: Drink } # ============================================================= #