Exemplo n.º 1
0
def CA(E, P, base_P, full_E=None):
    utl = Utils.Instance()
    print "number of events", len(E)
    for event in E:
        removeEvent(event.id, E, P, base_P, full_E)
        [max_day, max_slot] = findPlace(event, P)
        placeEvent(event, P)
Exemplo n.º 2
0
def clustered(base_E, base_P, depts):
    utl = Utils.Instance()
    #COPY OF EVENTS AND PERSONS
    temp_E, temp_P = copy.deepcopy(base_E), copy.deepcopy(base_P)
    #CREATE EMPTY CLUSTERS WITH CENTRIOD
    C = core.initClusters(temp_P, utl.K_CLUSTERS, depts)  # utl.K_CLUSTERS
    #TRAIN CLUSTERS
    #******TODO******
    #PLACE PERSONS IN CLUSTERS
    C = core.placePeople(base_P, C)

    max_sched = 0
    #FOR EACH CLUSTER
    for c in C:
        #CREATE A CLEAN COPY FOR EACH CLUSTER
        ctemp_E, ctemp_P = copy.deepcopy(temp_E), copy.deepcopy(temp_P)

        start = time.time()  #start time
        c.scheduleClusterP1(ctemp_E, ctemp_P, base_P)  #perform TS and CA
        end = time.time()  #end time
        #SAVE MAX TIME ACROSS ALL c IN C
        max_sched = max(end - start, max_sched)

    start = time.time()
    #USE C {all clusters, now with events placed} TO CHOOSE BEST PLACEMENTS FOR E
    group.evaluateClusterPlacements(temp_E, temp_P, C)
    for e in temp_E:
        evman.placeEvent(e, temp_P)
    end = time.time()

    clustered_time = (end - start) + max_sched
    clustered_weight = evman.totalSum(temp_P)
    print clustered_time
    return [clustered_time, clustered_weight]
Exemplo n.º 3
0
def totalSum(P):
    utl = Utils.Instance()
    sum = 0
    for d in range(utl.DAY):
        for t in range(utl.SLOT):
            for person in P:
                sum += person.SCHEDULE[d][t]

    return sum
Exemplo n.º 4
0
def genE(utl, P, depts):
    utl = Utils.Instance()
    E = []

    #TYPE A
    for i in range(utl.DEPT_COUNT):
        for j in range(utl.DEPT_EVENTS_A):
            event = Event(id=len(E),
                          weight=random.randint(utl.PERSONAL_VALUE_BOUND + 1,
                                                10))
            event.inviteA(P=P, dept=depts[i])
            E.append(event)

    return E
Exemplo n.º 5
0
def extendEvents(E, P, depts, k):
    utl = Utils.Instance()
    k = k / len(depts)
    print 'k', k
    #for each department
    for d_i in range(len(depts)):
        #for each new event being added to department d_i
        for e_i_t in range(k):
            # e_i = len(P) + e_i_t
            event = Event(id=len(E),
                          weight=random.randint(utl.PERSONAL_VALUE_BOUND + 1,
                                                10))
            event.inviteA(P=P, dept=depts[d_i])
            E.append(event)

        #each time we add k events to a dept we need to record it
        utl.DEPT_EVENTS_A = utl.DEPT_EVENTS_A + k
Exemplo n.º 6
0
def varyEvents():
    utl = Utils.Instance()

    #GENERATE PERSONS base_P, ASSIGN TO DEPARTMENTS depts
    [base_P, depts] = gen.genP()

    #GENERATE DEPARTMENT LEVEL EVENTS base_E
    base_E = gen.genE(utl, base_P, depts)

    #SIMULATION VARIABLES
    clusters_count = [2**c for c in range(1, 4)
                      ]  #[2^1, 2^2, 2^3] - different cluster amounts
    event_increment = 30  #the amount of events to add
    iterations = 2  #number of iterations - how many times we increase by event_increment

    #DATASTRUCTURES FOR RESULTS
    # results [ k clusters ] [iteration of k] - using k clusters, what is the value created for every K, K being set of event amounts
    cluster_times = [[0] * iterations
                     for i in range((len(clusters_count) + 1))]
    cluster_weights = [[0] * iterations
                       for i in range((len(clusters_count) + 1))]

    #RUN THE SIMULATION 'iterations' TIMES
    for i in range(iterations):

        #UNCLUSTERED
        [curr_time, curr_weight] = unclustered(base_E, base_P)
        cluster_times[0][i] = curr_time
        cluster_weights[0][i] = curr_weight

        #CLUSTERED
        for c in range(len(clusters_count)):
            #SET NUMBER OF CLUSTERS TO RUN WITH
            utl.K_CLUSTERS = clusters_count[
                c]  # c is the index of the number of clusters
            [curr_time, curr_weight] = clustered(base_E, base_P, depts)
            cluster_times[c + 1][i] = curr_time
            cluster_weights[c + 1][i] = curr_weight

        extend.extendEvents(E=base_E, P=base_P, depts=depts, k=event_increment)

    return [cluster_times, cluster_weights]
Exemplo n.º 7
0
def findPlace(event, P):
    utl = Utils.Instance()
    max_sum = 0
    max_day = 0
    max_slot = 0
    for d in range(utl.DAY):  #for each day
        for t in range(utl.SLOT):  # for each slot
            diff = 0
            for p_i in event.invited:  # p_i is person's index or id
                if event.weight > P[p_i].SCHEDULE[d][t]:
                    #add what the difference WOULD be
                    diff += event.weight - P[p_i].SCHEDULE[d][t]
            if diff > max_sum:
                max_sum = diff
                max_day = d
                max_slot = t

    event.day = max_day
    event.slot = max_slot
    return [max_day, max_slot]
Exemplo n.º 8
0
def genP():
    utl = Utils.Instance()
    P = []
    #creating departments
    depts = [0] * utl.DEPT_COUNT

    #for each department
    for i in range(utl.DEPT_COUNT):
        depts[i] = [
        ]  #each department's population; list containing id's referencing actual population

        #for each person in the department
        for p in range(utl.PER_DEPT):
            #Create Person
            person = Person(id=len(P), dept=i)
            #Add person to population
            P.append(person)
            #Add's reference of this person to current department
            depts[i].append(person.id)

    return [P, depts]
Exemplo n.º 9
0
from Config import Utils
import random

utl = Utils.Instance()


class Person(object):
    def __init__(self, id, dept):

        self.id = id
        self.events = []
        self.dept = dept
        self.role = None
        self.SCHEDULE = None
        self.fillSchedule()
        self.cluster = None

    def fillSchedule(self):
        self.SCHEDULE = [[utl.PERSONAL_VALUE_BOUND for i in range(utl.SLOT)]
                         for i in range(utl.DAY)]

        # number of personal events
        personal_e_count = random.randint(utl.PERSONAL_E_MIN,
                                          utl.PERSONAL_E_MAX)
        i = 0
        while i < personal_e_count:
            day = random.randint(0, utl.DAY - 1)
            slot = random.randint(0, utl.SLOT - 1)
            if self.SCHEDULE[day][slot] == utl.PERSONAL_VALUE_BOUND:
                val = random.randint(utl.PERSONAL_VALUE_BOUND + 1, 10)
                self.SCHEDULE[day][slot] = val
Exemplo n.º 10
0
def TS(E, P):
    utl = Utils.Instance()
    for event in E:
        [max_day, max_slot] = findPlace(event, P)
        placeEvent(event, P)