コード例 #1
0
 def __init__(self, name, atr, mbudget, intelli, type):
     'constructor'
     Girl.__init__(self, name, atr, mbudget, intelli, type)
     self.status = 'single'
     '''@ivar: relationship status of desperate girl'''
     self.bfname = ''
     '''@ivar: boyfriend name of desperate girl'''
     self.happiness = 0
     '''@ivar: happiness of desperate girl'''
コード例 #2
0
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)
コード例 #3
0
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)
コード例 #4
0
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]))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]))for row in reader]
        csvfile.close()

    logging.info('Profile Matching start:\n')
    G = sorted(G, key=lambda item: item.bud)
    B = sorted(B, key=lambda item: item.atr)
    flag = 0
    i = 0
    p = G[0]
    while (i < 51):
        if flag == 0:
            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)
                        flag = 1;
                        break
                if flag == 1:
                  break
                
        if flag == 1:
            for b in B:
                f = 0
                if(b.status == 'single'):
                    for g in G:
                        if (f < g.atr and g.status == 'single'):
                            p = g
                            f = g.atr
                break
            flag = 0
            p.status = 'commited'
            b.status = 'commited'
            p.bname = b.name
            b.gname = p.name
            logging.info('Commitment Girl: '+g.name+' got commited with boy: '+b.name)
        i += 1
    logging.info("Happiest Couple \n")
    for g in G:
        if g.status == 'commited':
            logging.info('Girl: ' + g.name + '  is commited with  Boy: ' + g.bname)
コード例 #5
0
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)
コード例 #6
0
def allocate():

    f = open('Girls.csv', 'r')  #read girls data
    read = reader(f, delimiter=',')
    Girls = [
        Girl(str(row[0]), int(row[1]), int(row[2]), int(row[3]))
        for row in read
    ]
    f.close()

    f = open('Boys.csv', 'r')  #read boys data
    read = reader(f, delimiter=',')
    Boys = [
        Boy(str(row[0]), int(row[1]), int(row[2]), int(row[3]), int(row[4]))
        for row in read
    ]
    f.close()

    info('Profile Matching started: ')

    #matching boys and  girls

    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.bf_name = boy.name
                boy.gf_name = girl.name
                info('Commitment Girl: ' + girl.name +
                     ' got commited with boy: ' + boy.name)
                break


#print the couples formed

    print("Couples formed")
    for girl in Girls:
        if girl.status == 'single':
            print(girl.name + '  is not commited to anyone')
        else:
            print(girl.name + '  is commited with ' + girl.bf_name)
コード例 #7
0
from generator import generate
import logging

g = []
b = []
logging.basicConfig(filename='log.log',
                    filemode='w',
                    format='%(asctime)s %(levelname) s: %(message)s',
                    datefmt='%d/%m/%Y %I:%M:%S %p',
                    level=logging.INFO)
generate()
with open('girls.csv') as csvfile:
    reader = csv.DictReader(csvfile)
    for row in reader:
        g.append(
            Girl(row['Name'], row['Attractiveness'], row['Intelligence'],
                 row['Budget']))

with open('boys.csv') as csvfile1:
    reader = csv.DictReader(csvfile1)
    for row in reader:
        b.append(
            Boy(row['Name'], row['Attractiveness'], row['Intelligence'],
                row['Minimum_req'], row['Budget']))
for i in g:
    for j in b:
        logging.info('Checking: ' + i.name + ' with ' + j.name)
        if i.checkElligible(j) and j.checkElligible(i):
            i.relationshipStatus = 'committed'
            j.relationshipStatus = 'committed'
            j.girlFriendName = i.name
            i.boyFriendName = j.name