def allocate(): with open('Boys.csv', 'r') as csvfile: reader = csv.reader(csvfile, delimiter = ',') B = [Boy(row[0],int(row[1]),int(row[2]),int(row[3]),int(row[4]),row[5])for row in reader] csvfile.close() with open('Girls.csv', 'r') as csvfile: reader = csv.reader(csvfile, delimiter = ',') G = [Girl(row[0],int(row[1]),int(row[2]),int(row[3]),row[4])for row in reader] csvfile.close() CP = [] logging.info('Profile Matching start:\n') for g in G: for b in B: logging.info('Commitment: Girl ' + g.name +' is checking profile of Boy '+b.name) if (b.is_elligible(g.bud,g.atr)) and (g.is_elligible(b.bud)) and g.status == 'single' and b.status == 'single': g.status = 'commited' b.status = 'commited' g.bname = b.name b.gname = g.name logging.info('Commitment Girl: '+g.name+' got commited with boy: '+b.name) CP += [(b,g)] break print("Couples formed \n") for g in G: if g.status == 'single': print('Girl: ' + g.name + ' is not commited to anyone') else: print('Girl: ' + g.name + ' is commited with Boy: ' + g.bname) print("-"*100) C = [Couple(c[0],c[1]) for c in CP] calculate_happiness(C)
def allocate(): with open('Boys.csv', 'r') as csvfile: reader = csv.reader(csvfile, delimiter=',') B = [ Boy(row[0], int(row[1]), int(row[2]), int(row[3]), int(row[4]), row[5]) for row in reader ] csvfile.close() with open('Girls.csv', 'r') as csvfile: reader = csv.reader(csvfile, delimiter=',') G = [ Girl(row[0], int(row[1]), int(row[2]), int(row[3]), row[4]) for row in reader ] csvfile.close() CP = [] logging.info('Before valentine couple formation:') for g in G: for b in B: if (b.is_elligible(g.bud, g.atr)) and (g.is_elligible( b.bud)) and g.status == 'single' and b.status == 'single': g.status = 'commited' b.status = 'commited' g.bname = b.name b.gname = g.name logging.info('Commitment Girl: ' + g.name + ' got commited with boy: ' + b.name) CP += [(b, g)] break C = [Couple(c[0], c[1]) for c in CP] calculate_happiness(C, G, B)
def test(): 'Main method for calling all other functions' with open('./boys_list.csv', 'r') as csvfile: fp1 = csv.reader(csvfile, delimiter = ',') boy_lists =[] for i in fp1: if(i[5] == 'Miser') : boy_lists += [Miser(i[0], int(i[1]), int(i[2]), int(i[3]), int(i[4]), i[5])] elif (i[5] == 'Generous') : boy_lists += [Generous(i[0], int(i[1]), int(i[2]), int(i[3]), int(i[4]), i[5])] elif (i[5] == 'Geek') : boy_lists += [Geek(i[0], int(i[1]), int(i[2]), int(i[3]), int(i[4]), i[5])] csvfile.close() with open('./girls_list.csv', 'r') as csvfile: fp2 = csv.reader(csvfile, delimiter = ',') girl_lists=[] for j in fp2: if(j[4] == 'Choosy') : girl_lists += [Choosy(j[0], int(j[1]), int(j[2]), int(j[3]), j[4])] elif(j[4] == 'Normal') : girl_lists += [Normal(j[0], int(j[1]), int(j[2]), int(j[3]), j[4])] elif(j[4] == 'Desperate') : girl_lists += [Desperate(j[0], int(j[1]), int(j[2]), int(j[3]), j[4])] csvfile.close() Couple_list = [] logging.warning('\n\nGirls are searching boys for relationship.\n') for k in girl_lists: for l in boy_lists: log_maker(k.name + ' is searching ' + l.name) if l.relationship_status == 'single' and k.relationship_status == 'single' and (k.is_eligible(l.boys_girlfriend_budget)) and (l.is_eligible(k.maintenance_budget, k.attractiveness)) : k.relationship_status = 'in_a_relationship' l.relationship_status = 'in_a_relationship' k.boyfriend = l.name l.girlfriend = k.name log_maker(k.name + ' is in relationship with ' + l.name) logging.warning('Beware from Bajrang Dal.') Couple_list = Couple_list+[(l, k)] break logging.warning('***Beware from Bajrang dal members***\n') print ('\n\nCouples in Relationship are :\n') for m in girl_lists: if m.relationship_status == 'single': print (m.name + ' is still single.Not commited with any boy.\n') else: print (m.name + ' is in relationship with ' + m.boyfriend+'\n') print('***Beware from Bajrang dal members***\n') H=[] for i in Couple_list: H += [Couple(i[0],i[1])] calc_happiness(H)
def allocate(): f = open('Boys.csv', 'r') read = reader(f, delimiter=',') Boys = [ Boy(row[0], int(row[1]), int(row[2]), int(row[3]), int(row[4]), row[5]) for row in read ] f.close() f = open('Girls.csv', 'r') read = reader(f, delimiter=',') Girls = [ Girl(row[0], int(row[1]), int(row[2]), int(row[3]), row[4]) for row in read ] f.close() CP = [] info('Profile Matching start:\n') for girl in Girls: for boy in Boys: info('Commitment: Girl ' + girl.name + ' is checking profile of Boy ' + boy.name) if (boy.is_elligible(girl.budget, girl.attribute)) and ( girl.is_elligible(boy.budget) ) and girl.status == 'single' and boy.status == 'single': girl.status = 'commited' boy.status = 'commited' girl.bname = boy.name boy.gname = girl.name info('Commitment Girl: ' + girl.name + ' got commited with boy: ' + boy.name) CP += [(boy, girl)] break print("Couples formed \n") for girl in Girls: if girl.status == 'single': print('Girl: ' + girl.name + ' single') else: print('Girl: ' + girl.name + ' is commited with Boy: ' + girl.bname) print("-" * 100) C = [Couple(c[0], c[1]) for c in CP] calculate_happiness(C)
def break_up(c, p, G, B): A = sorted(c, key=lambda item: item.happiness) logging.info("Couple Breakup start") for i in c: if i.happiness < p: logging.info("Commitment Girl: " + i.girl.name + " Breaked up to the boy: " + i.boy.name) for j in range(0, len(G)): if (i.girl == G[j].name): G[j].status = 'single' G[j].bname = '' G[j].happiness = 0 break for j in range(0, len(B)): if (i.girl.name == B[j].name): B[j].status = 'single' B[j].gname = '' B[j].happiness = 0 break c.remove(i) CP = [] for g in G: for b in B: if (b.is_elligible(g.bud, g.atr)) and (g.is_elligible( b.bud)) and g.status == 'single' and b.status == 'single': g.status = 'commited' b.status = 'commited' g.bname = b.name b.gname = g.name CP += [(b, g)] break for i in CP: c.append(Couple(i[0], i[1])) logging.info('Again Profile Matching start After Breakup:\n') for i in c: logging.info('Commitment Girl: ' + i.girl.name + ' got commited with boy: ' + i.boy.name)
def test(): 'Function to test all other functions.' with open('./boys_list.csv', 'r') as csvfile: fp1 = csv.reader(csvfile, delimiter=',') boy_lists = [] for i in fp1: if (i[5] == 'Miser'): boy_lists += [ Miser(i[0], int(i[1]), int(i[2]), int(i[3]), int(i[4]), i[5]) ] elif (i[5] == 'Generous'): boy_lists += [ Generous(i[0], int(i[1]), int(i[2]), int(i[3]), int(i[4]), i[5]) ] elif (i[5] == 'Geek'): boy_lists += [ Geek(i[0], int(i[1]), int(i[2]), int(i[3]), int(i[4]), i[5]) ] csvfile.close() with open('./girls_list.csv', 'r') as csvfile: fp2 = csv.reader(csvfile, delimiter=',') girl_lists = [] for j in fp2: if (j[4] == 'Choosy'): girl_lists += [ Choosy(j[0], int(j[1]), int(j[2]), int(j[3]), j[4]) ] elif (j[4] == 'Normal'): girl_lists += [ Normal(j[0], int(j[1]), int(j[2]), int(j[3]), j[4]) ] elif (j[4] == 'Desperate'): girl_lists += [ Desperate(j[0], int(j[1]), int(j[2]), int(j[3]), j[4]) ] csvfile.close() print("Choose allotment algorithm :\n1.Algorithm1\n2.Algorithm2\n") ch = int(input()) Couple_list = [] girl_lists = sorted(girl_lists, key=lambda girl: girl.maintenance_budget, reverse=True) boy_lists = sorted(boy_lists, key=lambda boy: boy.attractiveness, reverse=True) countg = 0 countb = 0 count = 0 limitg = len(girl_lists) limitb = len(boy_lists) if (ch == 1): while 1: if (count % 2 != 0 and countb != len(boy_lists)): l = boy_lists[countb] logging.warning('Boy chooses girl') for f in girl_lists: if l.relationship_status == 'single' and f.relationship_status == 'single': f.relationship_status = 'in_a_relationship' l.relationship_status = 'in_a_relationship' f.boyfriend = l.name l.girlfriend = k.name log_maker(l.name + ' is in relationship with ' + f.name) Couple_list = Couple_list + [(l, f)] break countb += 1 if (count % 2 == 0 and countg != len(girl_lists)): logging.warning('Girl chooses boy') k = girl_lists[countg] for l in boy_lists: if l.relationship_status == 'single' and k.relationship_status == 'single' and ( k.is_eligible( l.boys_girlfriend_budget)) and (l.is_eligible( k.maintenance_budget, k.attractiveness)): k.relationship_status = 'in_a_relationship' l.relationship_status = 'in_a_relationship' k.boyfriend = l.name l.girlfriend = k.name log_maker(k.name + ' is in relationship with ' + l.name) Couple_list = Couple_list + [(l, k)] break countg += 1 count += 1 if (countb == limitb and countg == limitg): break elif (ch == 2): logging.warning('\n\nGirls are searching boys for relationship.\n') for k in girl_lists: for l in boy_lists: log_maker(k.name + ' is searching ' + l.name) if l.relationship_status == 'single' and k.relationship_status == 'single' and ( k.is_eligible( l.boys_girlfriend_budget)) and (l.is_eligible( k.maintenance_budget, k.attractiveness)): k.relationship_status = 'in_a_relationship' l.relationship_status = 'in_a_relationship' k.boyfriend = l.name l.girlfriend = k.name log_maker(k.name + ' is in relationship with ' + l.name) logging.warning('Beware from Anti-romeo squad.') Couple_list = Couple_list + [(l, k)] break logging.warning('***Beware from Anti-romeo squad***\n') print('\n\nCouples in Relationship are :\n') for m in girl_lists: if m.relationship_status == 'in_a_relationship': print(m.name + ' is in relationship with ' + m.boyfriend + '\n') print('***Beware from Anti-romeo squad***\n') H = [] for i in Couple_list: H += [Couple(i[0], i[1])] calc_happiness(H)
def test(): 'Function to drive all the other functions' with open('./boys_list.csv', 'r') as csvfile: fp1 = csv.reader(csvfile, delimiter=',') boy_lists = [] for i in fp1: if (i[5] == 'Miser'): boy_lists += [ Miser(i[0], int(i[1]), int(i[2]), int(i[3]), int(i[4]), i[5]) ] elif (i[5] == 'Generous'): boy_lists += [ Generous(i[0], int(i[1]), int(i[2]), int(i[3]), int(i[4]), i[5]) ] elif (i[5] == 'Geek'): boy_lists += [ Geek(i[0], int(i[1]), int(i[2]), int(i[3]), int(i[4]), i[5]) ] csvfile.close() with open('./girls_list.csv', 'r') as csvfile: fp2 = csv.reader(csvfile, delimiter=',') girl_lists = [] for j in fp2: if (j[4] == 'Choosy'): girl_lists += [ Choosy(j[0], int(j[1]), int(j[2]), int(j[3]), j[4]) ] elif (j[4] == 'Normal'): girl_lists += [ Normal(j[0], int(j[1]), int(j[2]), int(j[3]), j[4]) ] elif (j[4] == 'Desperate'): girl_lists += [ Desperate(j[0], int(j[1]), int(j[2]), int(j[3]), j[4]) ] csvfile.close() Couple_list = [] logging.warning('\n\nGirls are searching boys for relationship.\n') for k in girl_lists: for l in boy_lists: log_maker(k.name + ' is searching ' + l.name) if l.relationship_status == 'single' and k.relationship_status == 'single' and ( k.is_eligible( l.boys_girlfriend_budget)) and (l.is_eligible( k.maintenance_budget, k.attractiveness)): k.relationship_status = 'in_a_relationship' l.relationship_status = 'in_a_relationship' k.boyfriend = l.name l.girlfriend = k.name log_maker(k.name + ' is in relationship with ' + l.name) logging.warning('Beware from Anti-romeo squad.') Couple_list = Couple_list + [(l, k)] break logging.warning('***Beware from Anti-romeo squad***\n') print('\n\nCouples in Relationship are :\n') for m in girl_lists: if m.relationship_status == 'single': print(m.name + ' is still single.Not commited with any boy.\n') else: print(m.name + ' is in relationship with ' + m.boyfriend + '\n') print('***Beware from Anti-romeo squad***\n') H = [] for i in Couple_list: H += [Couple(i[0], i[1])] calc_happiness(H) new = [] k = random.randint(1, len(H) - 1) for i in range(k): new.append(H[i]) for h in H[0:k]: print(" break up : " + h.boy.name + " and " + h.girl.name) h.boy.relationship_status = 'single' h.girl.relationship_status = 'single' H.pop(0) for g in new: k = g.girl for l in boy_lists: log_maker(k.name + ' is searching ' + l.name) if l.name != g.boy.name and l.relationship_status == 'single' and k.relationship_status == 'single' and ( k.is_eligible( l.boys_girlfriend_budget)) and (l.is_eligible( k.maintenance_budget, k.attractiveness)): k.relationship_status = 'in_a_relationship' l.relationship_status = 'in_a_relationship' k.boyfriend = l.name l.girlfriend = k.name log_maker(k.name + ' is in relationship with ' + l.name) logging.warning('Beware from Anti-romeo squad.') Couple_list = Couple_list + [(l, k)] break for k in girl_lists: for l in boy_lists: log_maker(k.name + ' is searching ' + l.name) if l.relationship_status == 'single' and k.relationship_status == 'single' and ( k.is_eligible( l.boys_girlfriend_budget)) and (l.is_eligible( k.maintenance_budget, k.attractiveness)): k.relationship_status = 'in_a_relationship' l.relationship_status = 'in_a_relationship' k.boyfriend = l.name l.girlfriend = k.name log_maker(k.name + ' is in relationship with ' + l.name) logging.warning('Beware from Anti-romeo squad.') Couple_list = Couple_list + [(l, k)] break logging.warning('***Beware from Anti-romeo squad***\n') print('\n\nCouples in Relationship are :\n') for m in girl_lists: if m.relationship_status == 'single': print(m.name + ' is still single.Not commited with any boy.\n') else: print(m.name + ' is in relationship with ' + m.boyfriend + '\n') print('***Beware from Anti-romeo squad***\n')
def make_couple(): 'Function to make couples' with open('./boys_list.csv', 'r') as csvfile: fp1 = csv.reader(csvfile, delimiter=',') boy_lists = [] for i in fp1: if (i[5] == 'Miser'): boy_lists += [ Miser(i[0], int(i[1]), int(i[2]), int(i[3]), int(i[4]), i[5]) ] elif (i[5] == 'Generous'): boy_lists += [ Generous(i[0], int(i[1]), int(i[2]), int(i[3]), int(i[4]), i[5]) ] elif (i[5] == 'Geek'): boy_lists += [ Geek(i[0], int(i[1]), int(i[2]), int(i[3]), int(i[4]), i[5]) ] csvfile.close() with open('./girls_list.csv', 'r') as csvfile: fp2 = csv.reader(csvfile, delimiter=',') girl_lists = [] for j in fp2: if (j[4] == 'Choosy'): girl_lists += [ Choosy(j[0], int(j[1]), int(j[2]), int(j[3]), j[4]) ] elif (j[4] == 'Normal'): girl_lists += [ Normal(j[0], int(j[1]), int(j[2]), int(j[3]), j[4]) ] elif (j[4] == 'Desperate'): girl_lists += [ Desperate(j[0], int(j[1]), int(j[2]), int(j[3]), j[4]) ] csvfile.close() Couple_list = [] logging.warning('\n\nCoupling again..\n') for k in girl_lists: for l in boy_lists: log_maker(k.name + ' is searching ' + l.name) if l.relationship_status == 'single' and k.relationship_status == 'single' and ( k.is_eligible( l.boys_girlfriend_budget)) and (l.is_eligible( k.maintenance_budget, k.attractiveness)): k.relationship_status = 'in_a_relationship' l.relationship_status = 'in_a_relationship' k.boyfriend = l.name l.girlfriend = k.name log_maker(k.name + ' is in relationship with ' + l.name) logging.warning('Beware from Bajrang Dal.') Couple_list = Couple_list + [(l, k)] break H = [] for i in Couple_list: H += [Couple(i[0], i[1])] print("\nGiting started again.\n") log_maker("\nGiting started again.\n") gifts_details(H) print('\n\nCouples again in Relationship are :\n') for m in girl_lists: if m.relationship_status == 'in_a_relationship': print(m.name + ' is in relationship with ' + m.boyfriend + '\n')