コード例 #1
0
    def resolve_consistency(self, data, seed):
	print data.varnames
        actList = []
	actListJoint = []

        data.sort([self.activityAttribs.hidName,
                   self.activityAttribs.pidName,
                   self.activityAttribs.scheduleidName])

        # Create Index Matrix
        self.create_indices(data)
        self.create_col_numbers(data._colnames)

	#if self.childDepProcessingType == 'Dummy':
	#    return data

        for hhldIndex in self.hhldIndicesOfPersons:
	    ti = time.time()
            firstPersonRec = hhldIndex[1]
            lastPersonRec = hhldIndex[2]

            persIndicesForActsForHhld = self.personIndicesOfActs[firstPersonRec:
                                                                     lastPersonRec,
                                                                 :]
	    #if hhldIndex[0] not in [8843,20008,20440,30985,48365,54850,60085,64006,68037,73093,77192,84903,84963]:
		# 1047
	    #	continue
            householdObject = Household(hhldIndex[0])

            for perIndex in persIndicesForActsForHhld:
                personObject = Person(perIndex[0], perIndex[1])
                schedulesForPerson = data.data[perIndex[2]:perIndex[3],:]
                activityList = self.return_activity_list_for_person(schedulesForPerson)
                personObject.add_episodes(activityList)
                workStatus, schoolStatus, childDependency = self.return_status_dependency(schedulesForPerson)
                personObject.add_status_dependency(workStatus, schoolStatus, 
                                                   childDependency)
                householdObject.add_person(personObject)

		
            #print 'household object created in - %.4f' %(time.time()-ti)
	    if self.specification.terminalEpisodesAllocation:
		householdObject.allocate_terminal_dependent_activities(seed)
	    elif self.childDepProcessingType == 'Allocation':
		householdObject.allocate_dependent_activities(seed)
	    elif self.childDepProcessingType == 'Resolution':
		householdObject.lineup_activities(seed)
	    elif self.childDepProcessingType == 'Fix Trip Purpose':
		householdObject.fix_trippurpose(seed)
	    elif self.childDepProcessingType == 'Extract Tour Attributes':
		householdObject.extract_tripattributes(seed)

		#raw_input('extract tour attributes')
	
		pass

	    reconciledSchedules = householdObject._collate_results()
            actList += reconciledSchedules
            #print 'created and reconciled in - %.4f' %(time.time()-ti)
	return DataArray(actList, self.colNames)
    def resolve_consistency(self, data, seed):
        print data.varnames
        actList = []
        actListJoint = []

        data.sort([self.activityAttribs.hidName,
                   self.activityAttribs.pidName,
                   self.activityAttribs.scheduleidName])

        # Create Index Matrix
        self.create_indices(data)
        self.create_col_numbers(data._colnames)

        #if self.childDepProcessingType == 'Dummy':
        #    return data

        for hhldIndex in self.hhldIndicesOfPersons:
            ti = time.time()
            firstPersonRec = hhldIndex[1]
            lastPersonRec = hhldIndex[2]

            persIndicesForActsForHhld = self.personIndicesOfActs[firstPersonRec:
                                                                     lastPersonRec,
                                                                 :]
            #if hhldIndex[0] not in [8843,20008,20440,30985,48365,54850,60085,64006,68037,73093,77192,84903,84963]:
                # 1047
            #   continue
            householdObject = Household(hhldIndex[0])

            for perIndex in persIndicesForActsForHhld:
                personObject = Person(perIndex[0], perIndex[1])
                schedulesForPerson = data.data[perIndex[2]:perIndex[3],:]
                activityList = self.return_activity_list_for_person(schedulesForPerson)
                personObject.add_episodes(activityList)
                workStatus, schoolStatus, childDependency = self.return_status_dependency(schedulesForPerson)
                personObject.add_status_dependency(workStatus, schoolStatus,
                                                   childDependency)
                householdObject.add_person(personObject)


            #print 'household object created in - %.4f' %(time.time()-ti)
            if self.specification.terminalEpisodesAllocation:
                householdObject.allocate_terminal_dependent_activities(seed)
            elif self.childDepProcessingType == 'Allocation':
                householdObject.allocate_dependent_activities(seed)
            elif self.childDepProcessingType == 'Resolution':
                householdObject.lineup_activities(seed)
            elif self.childDepProcessingType == 'Fix Trip Purpose':
                householdObject.fix_trippurpose(seed)
            elif self.childDepProcessingType == 'Extract Tour Attributes':
                householdObject.extract_tripattributes(seed)

                #raw_input('extract tour attributes')

                pass

            reconciledSchedules = householdObject._collate_results()
            actList += reconciledSchedules
            #print 'created and reconciled in - %.4f' %(time.time()-ti)
        return DataArray(actList, self.colNames)
コード例 #3
0
def process_dependency(args):
    data = args[0]
    seed = args[1]
    activityAttribs = args[2]
    dailyStatusAttribs = args[3]
    dependencyAttribs = args[4]
    specification = args[5]

    t = time.time()
    data["actobjects"] = data.apply(lambda x: return_act(x, activityAttribs),
                                    axis=1)

    hschedulesGrouped = data.groupby(level=0, sort=False)
    pschedulesGrouped = data.groupby(level=[0, 1], sort=False)

    workStatus_df = pschedulesGrouped[dailyStatusAttribs.workStatusName].min()
    schoolStatus_df = pschedulesGrouped[
        dailyStatusAttribs.schoolStatusName].min()
    childDependency_df = pschedulesGrouped[
        dependencyAttribs.childDependencyName].min()

    #print workStatus_df.shape
    #print workStatus_df
    print "Size is %d and time taken to run the df apply - %.4f" % (
        data.shape[0], time.time() - t)

    t = time.time()
    actList = []
    for hid, hidSchedules in hschedulesGrouped:
        householdObject = Household(hid)
        for pid, pidSchedules in hidSchedules.groupby(level=1, axis=0):
            personObject = Person(hid, pid)

            activityList = list(pidSchedules["actobjects"].values)
            personObject.add_episodes(activityList)

            workStatus = workStatus_df[(hid, pid)]
            schoolStatus = schoolStatus_df[(hid, pid)]
            childDependency = childDependency_df[(hid, pid)]
            personObject.add_status_dependency(workStatus, schoolStatus,
                                               childDependency)
            householdObject.add_person(personObject)

        if specification.terminalEpisodesAllocation:
            householdObject.allocate_terminal_dependent_activities(seed)
        elif specification.childDepProcessingType == 'Allocation':
            householdObject.allocate_dependent_activities(seed)
        elif specification.childDepProcessingType == 'Resolution':
            householdObject.lineup_activities(seed)
        elif specification.childDepProcessingType == 'Fix Trip Purpose':
            householdObject.fix_trippurpose(seed)
        elif specification.childDepProcessingType == 'Extract Tour Attributes':
            householdObject.extract_tripattributes(seed)

        reconciledSchedules = householdObject._collate_results()
        actList += reconciledSchedules
    print "Time taken to loop through all schedules - %.4f" % (time.time() - t)
    return actList
def process_dependency(args):
    data = args[0]
    seed = args[1]
    activityAttribs = args[2]
    dailyStatusAttribs = args[3]
    dependencyAttribs = args[4]
    specification = args[5]    

    t = time.time()
    data["actobjects"] = data.apply(lambda x: return_act(x,  activityAttribs),  axis=1)
    
    hschedulesGrouped = data.groupby(level=0, sort=False)
    pschedulesGrouped = data.groupby(level=[0,1], sort=False)
    
    workStatus_df = pschedulesGrouped[dailyStatusAttribs.workStatusName].min()
    schoolStatus_df = pschedulesGrouped[dailyStatusAttribs.schoolStatusName].min()
    childDependency_df = pschedulesGrouped[dependencyAttribs.childDependencyName].min()
    
    #print workStatus_df.shape
    #print workStatus_df
    print "Size is %d and time taken to run the df apply - %.4f" %(data.shape[0], time.time()-t)

    t = time.time()
    actList = []
    for hid,  hidSchedules in hschedulesGrouped:
        householdObject = Household(hid)
        for pid,  pidSchedules in hidSchedules.groupby(level=1, axis=0):
            personObject = Person(hid, pid)                

            activityList = list(pidSchedules["actobjects"].values)
            personObject.add_episodes(activityList)
            
            workStatus = workStatus_df[(hid, pid)]
            schoolStatus = schoolStatus_df[(hid, pid)]
            childDependency = childDependency_df[(hid, pid)]
            personObject.add_status_dependency(workStatus, schoolStatus,
                                                    childDependency)
            householdObject.add_person(personObject)

        if specification.terminalEpisodesAllocation:
            householdObject.allocate_terminal_dependent_activities(seed)
        elif specification.childDepProcessingType == 'Allocation':
            householdObject.allocate_dependent_activities(seed)
        elif specification.childDepProcessingType == 'Resolution':
            householdObject.lineup_activities(seed)
        elif specification.childDepProcessingType == 'Fix Trip Purpose':
            householdObject.fix_trippurpose(seed)
        elif specification.childDepProcessingType == 'Extract Tour Attributes':
            householdObject.extract_tripattributes(seed)            

        reconciledSchedules = householdObject._collate_results()
        actList += reconciledSchedules
    print "Time taken to loop through all schedules - %.4f" %(time.time()-t)
    return actList
コード例 #5
0
    def resolve_consistency(self, data, seed):

        actList = []
        actListJoint = []

        data.sort([self.activityAttribs.hidName,
                   self.activityAttribs.pidName,
                   self.activityAttribs.scheduleidName])

        # Create Index Matrix
        self.create_indices(data)
        self.create_col_numbers(data._colnames)

        for hhldIndex in self.hhldIndicesOfPersons:
            firstPersonRec = hhldIndex[1]
            lastPersonRec = hhldIndex[2]

            firstPersonFirstAct = self.personIndicesOfActs[firstPersonRec, 2]
            lastPersonLastAct = self.personIndicesOfActs[lastPersonRec - 1, 3]

            schedulesForHhld = DataArray(data.data[firstPersonFirstAct:
                                                   lastPersonLastAct, :], data.varnames)
            print 'hID - ', hhldIndex[0]
            # print schedulesForHhld.data.astype(int)
            # print data.varnames

            persIndicesForActsForHhld = self.personIndicesOfActs[firstPersonRec:
                                                                 lastPersonRec,
                                                                 :]

            # if hhldIndex[0] not in [8, 1839, 6006, 13139, 15080, 22501, 25779, 32174,
            #                       34664, 35751, 40563, 71887,
            #                       49815, 57273, 94554, 95335, 96768, 130599, 1353601, 149978]:
            # continue
            #   pass

            householdObject = Household(hhldIndex[0])

            for perIndex in persIndicesForActsForHhld:
                personObject = Person(perIndex[0], perIndex[1])
                schedulesForPerson = DataArray(
                    data.data[perIndex[2]:perIndex[3], :], data.varnames)
                activityList = self.return_activity_list_for_person(
                    schedulesForPerson)
                personObject.add_episodes(activityList)
                workStatus, schoolStatus, childDependency = self.return_status_dependency(
                    schedulesForPerson)
                personObject.add_status_dependency(workStatus, schoolStatus,
                                                   childDependency)
                householdObject.add_person(personObject)

            if self.specification.terminalEpisodesAllocation:
                householdObject.allocate_terminal_dependent_activities(seed)
            else:
                householdObject.allocate_dependent_activities(seed)

                # householdObject.lineup_subsequent_ih_dropoffs(seed)

            reconciledSchedules = householdObject._collate_results()
            reconciledSchedulesJoint = householdObject._collate_results_without_dependentActs()

            actList += reconciledSchedules
            actListJoint += reconciledSchedulesJoint

            # if (hhldIndex[0] == 8 or hhldIndex[0] == 6006 or hhldIndex[0] == 13139
            #   or hhldIndex[0] == 15080 or hhldIndex[0] == 35751
            #   or hhldIndex[0] == 95335 or hhldIndex[0] == 57273
            #   or hhldIndex[0] == 94554 or hhldIndex[0] == 96768
            #   or hhldIndex[0] == 1353601 or hhldIndex[0] == 149978 or hhldIndex[0] == 155946):
            #   householdObject.persons[1].print_activity_list()
            # raw_input()
            pass

        # return DataArray(actList, self.colNames), DataArray(actListJoint,
        # self.colNames)
        return DataArray(actList, self.colNames), DataArray(actList, self.colNames)