def resolve_consistency(self, data, seed):

        actList = []
        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]

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

            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)
            reconciledSchedules = householdObject.clean_schedules_for_in_home_episodes(seed)
            
            actList += reconciledSchedules

        return DataArray(actList, self.colNames)
    def resolve_consistency(self, data, seed):

        verts = []
        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)
            persIndicesForActsForHhld = self.personIndicesOfActs[
                firstPersonRec:lastPersonRec, :]

            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)

                householdObject.add_person(personObject)

            hhldVerts = householdObject.retrieve_fixed_activity_vertices(seed)
            #for i in hhldVerts:
            #   print i
            #raw_input()

            verts += hhldVerts

        return DataArray(verts, self.colNames)
    def resolve_consistency(self, data, seed):

        verts = []
        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)
            persIndicesForActsForHhld = self.personIndicesOfActs[firstPersonRec:
                                                                     lastPersonRec,
                                                                 :]

            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)

                householdObject.add_person(personObject)

            hhldVerts = householdObject.retrieve_fixed_activity_vertices(seed)
            #for i in hhldVerts:
            #   print i
            #raw_input()

            verts += hhldVerts


        return DataArray(verts, self.colNames)
    def resolve_consistency(self, data, seed):

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

        # Create Index Matrix
        ti = time.time()
        self.create_indices(data)
        print 'indices created in %.4f' % (time.time() - ti)
        self.create_col_numbers(data._colnames)

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

            #print 'hID - ', hhldIndex[0]
            persIndicesForActsForHhld = self.personIndicesOfActs[
                firstPersonRec:lastPersonRec, :]
            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 personObject.print_activity_list()

            reconciledSchedules = householdObject.clean_schedules(seed)

            actList += reconciledSchedules

        return DataArray(actList, self.colNames)
Example #5
0
    def resolve_consistency(self, data, seed):
        actList = []
        data.sort([
            self.activityAttribs.hidName, self.activityAttribs.pidName,
            self.activityAttribs.scheduleidName
        ])
        ti = time.time()
        # Create Index Matrix
        self.create_indices(data)
        self.create_col_numbers(data._colnames)

        #print data._colnames, data.varnames

        print 'Indices created in %.4f' % (time.time() - ti)

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

            persIndicesForActsForHhld = self.personIndicesOfActs[
                firstPersonRec:lastPersonRec, :]
            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)

                if self.schedAdjType == "Arrival Adjustment":
                    actualArrival, expectedArrival, tripDependentPerson = self.return_arrival_info(
                        schedulesForPerson)
                    personObject.add_arrival_status(actualArrival,
                                                    expectedArrival,
                                                    tripDependentPerson)

                elif self.schedAdjType == "Occupancy Adjustment":
                    tripInd, tripStTime = self.return_trip_occupancy_info(
                        schedulesForPerson)
                    #print 'trip indicator, trip start time -- ', tripInd, tripStTime
                    personObject.add_occupancy_status(tripInd, tripStTime)
                    householdObject.wait_push_subsequent_activities(
                        personObject)
                else:
                    raise Exception, 'Invalid adjustment type ... '

            if self.schedAdjType == "Arrival Adjustment":
                householdObject.adjust_schedules_given_arrival_info(seed)
            elif self.schedAdjType == "Occupancy Adjustment":

                #raw_input()
                pass
            #raw_input()
            reconciledSchedules = householdObject._collate_results()

            if not personObject._check_for_conflicts():
                personObject.print_activity_list()
                print "THE SCHEDULES ARE STILL MESSED UP"
                raise Exception, "THE SCHEDULES ARE STILL MESSED UP"

            actList += reconciledSchedules

        print 'Finished running the component including index creation in %.4f' % (
            time.time() - ti)
        return DataArray(actList, self.colNames)
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 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)
    def resolve_consistency(self, data, seed):

        hhldAgentList = []
        personAgentList = []
        data.sort([self.idSpec.hidName,
                   self.idSpec.pidName])

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

	highestHid = amax(self.hhldIndicesOfPersons[:,0])

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

	    print 'HID - ', hhldIndex[0]
	
	    personRecs = DataArray(data.data[firstPersonRec:lastPersonRec, :], data.varnames)
	    print '\tPerson records - \n', personRecs.data.astype(int)



            householdObject = Household(hhldIndex[0])
	   
            householdObject.set_household_attributes(

						     personRecs.data[0][self.bldgszCol],
						     personRecs.data[0][self.hhtCol],
						     personRecs.data[0][self.hincCol],
						     personRecs.data[0][self.nocCol],
						     personRecs.data[0][self.personsCol],
						     personRecs.data[0][self.unittypeCol],
						     personRecs.data[0][self.vehiclCol],
						     personRecs.data[0][self.wifCol],
						     personRecs.data[0][self.yrMovedCol])
		
            for personRec in personRecs.data:
		personObject = Person(personRec[self.hidCol], personRec[self.pidCol])
		
		personObject.set_person_attributes(personRec[self.ageCol],
						   personRec[self.clwkrCol],
						   personRec[self.educCol],
						   personRec[self.enrollCol],
						   personRec[self.esrCol],
						   personRec[self.indnaicsCol],
						   personRec[self.occcen5Col],
						   personRec[self.race1Col],
						   personRec[self.relateCol],
						   personRec[self.sexCol],
						   personRec[self.marstatCol],
						   personRec[self.hoursCol],
						   personRec[self.gradeCol],
						   personRec[self.hispanCol])

		personObject.set_evolution_attributes(personRec[self.morality_fCol],
						      personRec[self.birth_fCol],
						      personRec[self.age_fCol],
						      personRec[self.enrollment_fCol],
						      personRec[self.grade_fCol],
						      personRec[self.educ_fCol],
						      personRec[self.educInYears_fCol],
						      personRec[self.residenceType_fCol],
						      personRec[self.laborParticipation_fCol],
						      personRec[self.occupation_fCol],
						      personRec[self.income_fCol],
						      personRec[self.marriageDecision_fCol],
						      personRec[self.divorceDecision_fCol])


	    	householdObject.add_person(personObject)
	    additionalHouseholdObject, highestHid = householdObject.evolve_population(highestHid)
		


	    if householdObject.personsSize == 0:
		#raw_input('the household has a size of 0? and hid - %s' %hhldIndex[0])
		continue
	    hhldAgentList.append([householdObject.hid,
				  householdObject.bldgsz,
				  householdObject.hht,
				  householdObject.hinc,
				  householdObject.noc,
				  householdObject.personsSize,
				  householdObject.unittype,
				  householdObject.vehicl,
				  householdObject.wif,
			          householdObject.yrMoved,
				  householdObject.oldHid])

	    if additionalHouseholdObject is not None:
	    	hhldAgentList.append([additionalHouseholdObject.hid,
					  additionalHouseholdObject.bldgsz,
					  additionalHouseholdObject.hht,
					  additionalHouseholdObject.hinc,
					  additionalHouseholdObject.noc,
					  additionalHouseholdObject.personsSize,
					  additionalHouseholdObject.unittype,
					  additionalHouseholdObject.vehicl,
					  additionalHouseholdObject.wif,
				          additionalHouseholdObject.yrMoved,
					  additionalHouseholdObject.oldHid])



	    personAgentList += householdObject.return_person_list()
	    if additionalHouseholdObject is not None:
		personAgentList += additionalHouseholdObject.return_person_list()
		    #print additionalHouseholdObject.return_person_list()
		    #raw_input()

	print self.personColNames
	print array(personAgentList).shape
	print self.hhldColNames
	print array(hhldAgentList).shape

        return DataArray(personAgentList, self.personColNames), DataArray(hhldAgentList, self.hhldColNames)
    def resolve_consistency(self, data, seed):
        actList = []
        data.sort([self.activityAttribs.hidName,
                   self.activityAttribs.pidName,
                   self.activityAttribs.scheduleidName])
        ti = time.time()
        # Create Index Matrix
        self.create_indices(data)
        self.create_col_numbers(data._colnames)

        # print data._colnames, data.varnames

        print 'Indices created in %.4f' % (time.time() - ti)

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

            persIndicesForActsForHhld = self.personIndicesOfActs[firstPersonRec:
                                                                 lastPersonRec,
                                                                 :]
            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)

                if self.schedAdjType == "Arrival Adjustment":
                    actualArrival, expectedArrival, tripDependentPerson = self.return_arrival_info(
                        schedulesForPerson)
                    personObject.add_arrival_status(
                        actualArrival, expectedArrival, tripDependentPerson)

                elif self.schedAdjType == "Occupancy Adjustment":
                    tripInd, tripStTime = self.return_trip_occupancy_info(
                        schedulesForPerson)
                    # print 'trip indicator, trip start time -- ', tripInd,
                    # tripStTime
                    personObject.add_occupancy_status(tripInd, tripStTime)
                    householdObject.wait_push_subsequent_activities(
                        personObject)
                else:
                    raise Exception, 'Invalid adjustment type ... '

            if self.schedAdjType == "Arrival Adjustment":
                householdObject.adjust_schedules_given_arrival_info(seed)
            elif self.schedAdjType == "Occupancy Adjustment":

                # raw_input()
                pass
            # raw_input()
            reconciledSchedules = householdObject._collate_results()

            if not personObject._check_for_conflicts():
                personObject.print_activity_list()
                print "THE SCHEDULES ARE STILL MESSED UP"
                raise Exception, "THE SCHEDULES ARE STILL MESSED UP"

            actList += reconciledSchedules

        print 'Finished running the component including index creation in %.4f' % (time.time() - ti)
        return DataArray(actList, self.colNames)
Example #11
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)
Example #12
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 resolve_consistency(self, data, seed):

        hhldAgentList = []
        personAgentList = []
        data.sort([self.idSpec.hidName,
                   self.idSpec.pidName])

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

        highestHid = amax(self.hhldIndicesOfPersons[:,0])

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

            print 'HID - ', hhldIndex[0]

            personRecs = DataArray(data.data[firstPersonRec:lastPersonRec, :], data.varnames)
            print '\tPerson records - \n', personRecs.data.astype(int)



            householdObject = Household(hhldIndex[0])

            householdObject.set_household_attributes(

                                                     personRecs.data[0][self.bldgszCol],
                                                     personRecs.data[0][self.hhtCol],
                                                     personRecs.data[0][self.hincCol],
                                                     personRecs.data[0][self.nocCol],
                                                     personRecs.data[0][self.personsCol],
                                                     personRecs.data[0][self.unittypeCol],
                                                     personRecs.data[0][self.vehiclCol],
                                                     personRecs.data[0][self.wifCol],
                                                     personRecs.data[0][self.yrMovedCol])

            for personRec in personRecs.data:
                personObject = Person(personRec[self.hidCol], personRec[self.pidCol])

                personObject.set_person_attributes(personRec[self.ageCol],
                                                   personRec[self.clwkrCol],
                                                   personRec[self.educCol],
                                                   personRec[self.enrollCol],
                                                   personRec[self.esrCol],
                                                   personRec[self.indnaicsCol],
                                                   personRec[self.occcen5Col],
                                                   personRec[self.race1Col],
                                                   personRec[self.relateCol],
                                                   personRec[self.sexCol],
                                                   personRec[self.marstatCol],
                                                   personRec[self.hoursCol],
                                                   personRec[self.gradeCol],
                                                   personRec[self.hispanCol])

                personObject.set_evolution_attributes(personRec[self.morality_fCol],
                                                      personRec[self.birth_fCol],
                                                      personRec[self.age_fCol],
                                                      personRec[self.enrollment_fCol],
                                                      personRec[self.grade_fCol],
                                                      personRec[self.educ_fCol],
                                                      personRec[self.educInYears_fCol],
                                                      personRec[self.residenceType_fCol],
                                                      personRec[self.laborParticipation_fCol],
                                                      personRec[self.occupation_fCol],
                                                      personRec[self.income_fCol],
                                                      personRec[self.marriageDecision_fCol],
                                                      personRec[self.divorceDecision_fCol])


                householdObject.add_person(personObject)
            additionalHouseholdObject, highestHid = householdObject.evolve_population(highestHid)



            if householdObject.personsSize == 0:
                #raw_input('the household has a size of 0? and hid - %s' %hhldIndex[0])
                continue
            hhldAgentList.append([householdObject.hid,
                                  householdObject.bldgsz,
                                  householdObject.hht,
                                  householdObject.hinc,
                                  householdObject.noc,
                                  householdObject.personsSize,
                                  householdObject.unittype,
                                  householdObject.vehicl,
                                  householdObject.wif,
                                  householdObject.yrMoved,
                                  householdObject.oldHid])

            if additionalHouseholdObject is not None:
                hhldAgentList.append([additionalHouseholdObject.hid,
                                          additionalHouseholdObject.bldgsz,
                                          additionalHouseholdObject.hht,
                                          additionalHouseholdObject.hinc,
                                          additionalHouseholdObject.noc,
                                          additionalHouseholdObject.personsSize,
                                          additionalHouseholdObject.unittype,
                                          additionalHouseholdObject.vehicl,
                                          additionalHouseholdObject.wif,
                                          additionalHouseholdObject.yrMoved,
                                          additionalHouseholdObject.oldHid])



            personAgentList += householdObject.return_person_list()
            if additionalHouseholdObject is not None:
                personAgentList += additionalHouseholdObject.return_person_list()
                    #print additionalHouseholdObject.return_person_list()
                    #raw_input()

        print self.personColNames
        print array(personAgentList).shape
        print self.hhldColNames
        print array(hhldAgentList).shape

        return DataArray(personAgentList, self.personColNames), DataArray(hhldAgentList, self.hhldColNames)