Ejemplo n.º 1
0
Archivo: Demand.py Proyecto: rcads/dta
    def applyTimeOfDayFactors(self, factorsInAList):
        """
        Apply the given time of day factors to the existing 
        demand object and return a new demand object with as many 
        time slices as the number of factors. Each time slice is 
        the result of the original table multiplied by a factor 
        in the list. 
        """
        #raise Exception("This is not the correct implementation. Change it")
        if self.getNumSlices() != 1:
            raise DtaError(
                "Time of day factors can be applied only to a demand that has only"
                " one time slice")
        for i in range(0, len(factorsInAList)):
            factorsInAList[i] = float(factorsInAList[i])

        if abs(sum(factorsInAList) - 1.) > 0.0000001:
            raise DtaError(
                "The input time of day factors should sum up to 1.0.  Factors are %s"
                % factorsInAList)

        newTimeStepInMin = self.timeStep.getMinutes() / len(factorsInAList)
        newTimeStep = Time.fromMinutes(newTimeStepInMin)

        newDemand = Demand(self._net, self.vehClassName, self.startTime,
                           self.endTime, newTimeStep)
        #timeSpan = (newDemand.endTime - newDemand.startTime).getMinutes()/60.0
        oldDemand = 0
        sliceDemand = []
        for k, timeSlice in enumerate(newDemand._timePeriods):
            sliceDemand.append(0)
        for origin in self._centroidIds:
            for destination in self._centroidIds:
                tripsOD_Old = self.getValue(self.endTime, origin,
                                            destination) * len(factorsInAList)
                for k, timeSlice in enumerate(newDemand._timePeriods):
                    tripsOD = factorsInAList[k] * tripsOD_Old
                    newDemand.setValue(timeSlice, origin, destination, tripsOD)

        return newDemand
Ejemplo n.º 2
0
        if not (link.hasCountInfo() or link.hasMovementCountInfo()):
            continue

        # writes once every specified interval minutes interval, aggregating  to specified min intervals
        for sTime in range(simStartTime, simEndTime - 1, simTimeStep):
            if sTime + reportingTimeStep >= simEndTime:
                continue

            # first try writing any link counts
            if link.hasObsCount(sTime, sTime + reportingTimeStep):
                outputStream.write("%d," % link.getId())
                outputStream.write("%s," % link.getLabel())
                outputStream.write("%d," % link.getFacilityType())
                outputStream.write("%d," % link.getFreeFlowSpeedInMPH())
                outputStream.write("%d," % link.getNumLanes())
                outputStream.write("%s," % Time.fromMinutes(sTime))
                outputStream.write("%s," %
                                   Time.fromMinutes(sTime + reportingTimeStep))
                outputStream.write(
                    "%d," % link.getObsCount(sTime, sTime + reportingTimeStep))
                outputStream.write(
                    "%d\n" %
                    link.getSimOutVolume(sTime, sTime + reportingTimeStep))
            # then try summing the movement counts
            elif link.hasAllMovementCounts(sTime, sTime + reportingTimeStep):
                outputStream.write("%d," % link.getId())
                outputStream.write("%s," % link.getLabel())
                outputStream.write("%d," % link.getFacilityType())
                outputStream.write("%d," % link.getFreeFlowSpeedInMPH())
                outputStream.write("%d," % link.getNumLanes())
                outputStream.write("%s," % Time.fromMinutes(sTime))