コード例 #1
0
ファイル: vehicle.py プロジェクト: naronald/SUMOoD
    def getCurrentPos(self):
        """ return current position """

        if self.currentStatus != VehicleStatus.PARKED:
            currentLink = network.getVehicleCurrentEdge(self.name)
            currentPos = network.getVehicleCurrentPosition(self.name)
        else:
            currentLink = self.lastLink
            currentPos = self.lastPos

        currentStop = Stop(-1, currentLink, currentPos, StopType.CURRENT)
        return currentStop  # Stop
コード例 #2
0
ファイル: vehicle.py プロジェクト: qisimple/SUMOoD
    def getCurrentPos(self):     
        """ return current position """

        if self.currentStatus != VehicleStatus.PARKED:
            currentLink = network.getVehicleCurrentEdge(self.name)
            currentPos = network.getVehicleCurrentPosition(self.name)
        else:
            currentLink = self.lastLink
            currentPos = self.lastPos

        currentStop = Stop(-1, currentLink, currentPos, StopType.CURRENT)
        return currentStop # Stop
コード例 #3
0
ファイル: vehicle.py プロジェクト: qisimple/SUMOoD
    def addPerson(self, person, puPosition, doPosition, penalty):
        """ add a person to a vehicle's plan, insert stops at specified places
        (Person, int, int, float)"""

        # extract details from person
        personID = person.personID
        link1 = person.getOrigin().link
        pos1 = person.getOrigin().pos
        request = person.getOrigin().serviceTime
        link2 = person.getDestination().link
        pos2 = person.getDestination().pos

        # add stops to plan 
        self.plan.insert(puPosition, Stop(personID, link1, pos1,
                                          StopType.PICKUP, request))
        self.plan.insert(doPosition, Stop(personID, link2, pos2,
                                          StopType.DROPOFF))
        print "Person " + str(personID) + " now waiting at " + link1 + "," + \
              str(pos1) + " going to " + link2 + "," + str(pos2) + \
              " waiting for " + self.name

        print self.name, "plan:"
        for i in range(0, len(self.plan)):
            self.plan[i].printLn()

        # set person to allocated
        person.allocated()

        # reroute vehicle as plan is updated
        self.currentLink = network.getVehicleCurrentEdge(self.name)
        self.currentPos = network.getVehicleCurrentPosition(self.name)
        if self.currentStatus == VehicleStatus.PARKED:
            self.currentStatus = VehicleStatus.BOOKED
            if self.operatingState != VehicleState.vsRunning:
                # raise from parking position at depot
                print self.parkedLink, self.parkedPos
                traci.vehicle.setStop(self.name, self.parkedLink,
                                      self.parkedPos, 0, 0)
            else:
                # raise from parking position
                traci.vehicle.setStop(self.name, self.parkedLink,
                                      self.parkedPos, 0, 0) 
        myNextStop = self.plan[0]
        traci.vehicle.changeTarget(self.name, myNextStop.link)
        traci.vehicle.setStop(self.name, myNextStop.link, myNextStop.pos, 0,
                              DWELLTIME)
        print self.name, " heading for ", myNextStop.personID, " at", \
              myNextStop.link, myNextStop.pos

        self.operatingState = VehicleState.vsRunning
コード例 #4
0
ファイル: vehicle.py プロジェクト: naronald/SUMOoD
    def addPerson(self, person, puPosition, doPosition, penalty):
        """ add a person to a vehicle's plan, insert stops at specified places
        (Person, int, int, float)"""

        # extract details from person
        personID = person.personID
        link1 = person.getOrigin().link
        pos1 = person.getOrigin().pos
        request = person.getOrigin().serviceTime
        link2 = person.getDestination().link
        pos2 = person.getDestination().pos

        # add stops to plan
        self.plan.insert(puPosition, Stop(personID, link1, pos1, StopType.PICKUP, request))
        self.plan.insert(doPosition, Stop(personID, link2, pos2, StopType.DROPOFF))
        print "Person " + str(personID) + " now waiting at " + link1 + "," + str(
            pos1
        ) + " going to " + link2 + "," + str(pos2) + " waiting for " + self.name

        print self.name, "plan:"
        for i in range(0, len(self.plan)):
            self.plan[i].printLn()

        # set person to allocated
        person.allocated()

        # reroute vehicle as plan is updated
        self.currentLink = network.getVehicleCurrentEdge(self.name)
        self.currentPos = network.getVehicleCurrentPosition(self.name)
        if self.currentStatus == VehicleStatus.PARKED:
            self.currentStatus = VehicleStatus.BOOKED
            if self.operatingState != VehicleState.vsRunning:
                # raise from parking position at depot
                print self.parkedLink, self.parkedPos
                traci.vehicle.setStop(self.name, self.parkedLink, self.parkedPos, 0, 0)
            else:
                # raise from parking position
                traci.vehicle.setStop(self.name, self.parkedLink, self.parkedPos, 0, 0)
        myNextStop = self.plan[0]
        traci.vehicle.changeTarget(self.name, myNextStop.link)
        traci.vehicle.setStop(self.name, myNextStop.link, myNextStop.pos, 0, DWELLTIME)
        print self.name, " heading for ", myNextStop.personID, " at", myNextStop.link, myNextStop.pos

        self.operatingState = VehicleState.vsRunning
コード例 #5
0
ファイル: vehicle.py プロジェクト: naronald/SUMOoD
    def update(self, step):
        """ update plan at a time step 
        (int)"""
        global peopleCollection

        # determine current position
        self.currentLink = network.getVehicleCurrentEdge(self.name)
        self.currentPos = network.getVehicleCurrentPosition(self.name)

        # distance travelled
        if self.lastLink != None:  # has started moving
            # if has moved since last update, ignore if vehicle parked
            if (
                not (self.lastLink == self.currentLink and self.lastPos == self.currentPos)
                or self.currentStatus != VehicleStatus.PARKED
            ):
                distMoved = network.getDistanceLong(self.lastLink, self.lastPos, self.currentLink, self.currentPos)
                if distMoved < LARGEDIST:  # ignore large numbers
                    self.totalDistance += distMoved
                    # update passengers
                    for p in self.currentPassengers:
                        peopleCollection.incrementPersonDistance(p, distMoved)
                    # update shared/deadheading
                    if self.countPassengers >= 2:
                        self.shared += distMoved
                    if self.countPassengers == 0:
                        self.deadheading += distMoved

        nextUpdate = self.getNextStop()
        # if at target and not depot; "at target" considered to be within
        # STOP_OFFSET of actual target, otherwise bus crowding delays passengers
        # unnecessarily
        while (
            nextUpdate != None
            and nextUpdate.stopType != StopType.DEPOT
            and nextUpdate.link == self.currentLink
            and nextUpdate.pos - self.currentPos < STOP_OFFSET
        ):
            print step, self.name, nextUpdate.link, nextUpdate.pos, nextUpdate.stopType, self.currentLink, self.currentPos, nextUpdate.serviceTime
            # if target is a pickup
            if nextUpdate.stopType == StopType.PICKUP:
                peopleCollection.updatePersonPickup(nextUpdate.personID, step)
                self.countPassengers += 1
                self.currentStatus = VehicleStatus.BOOKED
                self.currentPassengers.append(nextUpdate.personID)
                print self.name, self.countPassengers, " on board"
                nextUpdate = self.getNextStop(True)
            # else if target is a dropoff
            elif nextUpdate.stopType == StopType.DROPOFF:
                self.countPassengers -= 1
                peopleCollection.updatePersonDropoff(nextUpdate.personID, step)
                self.totalPassengers += 1
                self.currentPassengers.remove(nextUpdate.personID)
                self.occupancyTime += peopleCollection.getTravelTime(nextUpdate.personID)
                print self.name, self.countPassengers, " on board"
                nextUpdate = self.getNextStop(True)

        # update route
        if nextUpdate != None:
            if nextUpdate.stopType == StopType.DEPOT:
                # no future requests at this stage
                if self.operatingState == VehicleState.vsRunning:
                    assert self.countPassengers == 0
                    currentStop = self.getCurrentPos()
                    goHomeTime = self.end - network.getTime(currentStop, nextUpdate)
                    if step < goHomeTime:  # not time to go home yet
                        if self.currentStatus != VehicleStatus.PARKED:
                            self.currentStatus = VehicleStatus.PARKED
                            print self.name, "waiting", goHomeTime
                            self.parkedLink = self.currentLink
                            self.parkedPos = self.currentPos + PARK_OFFSET
                            # !! was 60+5*self.i
                            # if many vehicles and few set stops, then parking
                            # somewhere else reduces delay to other vehicles
                            traci.vehicle.setStop(
                                self.name, self.parkedLink, self.parkedPos, 0, (goHomeTime - step) * MILLISECONDS
                            )
                    else:
                        # raise from parking position and go home
                        traci.vehicle.setStop(self.name, self.parkedLink, self.parkedPos, 0, 0)
                        self.operatingState = VehicleState.vsGoingHome
                        traci.vehicle.changeTarget(self.name, nextUpdate.link)
                        self.currentStatus = VehicleStatus.BOOKED
                        print self.name, "moving to depot"
                # elif self.operatingState == VehicleState.vsNotStarted:
                # waiting at start
            else:  # update route for next pickup/dropoff
                traci.vehicle.changeTarget(self.name, nextUpdate.link)
                traci.vehicle.setStop(self.name, nextUpdate.link, nextUpdate.pos, 0, DWELLTIME)
                if self.currentStatus == VehicleStatus.PARKED:
                    # raise from parking position if parked
                    traci.vehicle.setStop(self.name, self.parkedLink, self.parkedPos, 0, 0)
                self.currentStatus = VehicleStatus.BOOKED

        # store last known link
        self.lastLink = self.currentLink
        self.lastPos = self.currentPos
コード例 #6
0
ファイル: vehicle.py プロジェクト: qisimple/SUMOoD
    def update(self, step):
        """ update plan at a time step 
        (int)"""
        global peopleCollection

        # determine current position
        self.currentLink = network.getVehicleCurrentEdge(self.name)
        self.currentPos = network.getVehicleCurrentPosition(self.name)

        # distance travelled
        if self.lastLink != None: # has started moving
            # if has moved since last update, ignore if vehicle parked
            if not(self.lastLink == self.currentLink and \
                   self.lastPos == self.currentPos) or \
                   self.currentStatus != VehicleStatus.PARKED: 
                distMoved = network.getDistanceLong(self.lastLink, self.lastPos,
                                                    self.currentLink,
                                                    self.currentPos)
                if distMoved < LARGEDIST: # ignore large numbers
                    self.totalDistance += distMoved
                    # update passengers
                    for p in self.currentPassengers:
                        peopleCollection.incrementPersonDistance(p, distMoved)
                    # update shared/deadheading
                    if self.countPassengers >= 2:
                        self.shared += distMoved
                    if self.countPassengers == 0:
                        self.deadheading += distMoved
                        
        nextUpdate = self.getNextStop()
        # if at target and not depot; "at target" considered to be within
        # STOP_OFFSET of actual target, otherwise bus crowding delays passengers
        # unnecessarily
        while nextUpdate != None and nextUpdate.stopType != StopType.DEPOT and \
            nextUpdate.link == self.currentLink and \
            nextUpdate.pos - self.currentPos < STOP_OFFSET:
            print step, self.name, nextUpdate.link, nextUpdate.pos, \
                  nextUpdate.stopType, self.currentLink, self.currentPos, \
                  nextUpdate.serviceTime
            # if target is a pickup
            if nextUpdate.stopType == StopType.PICKUP:
                peopleCollection.updatePersonPickup(nextUpdate.personID, step)
                self.countPassengers += 1
                self.currentStatus = VehicleStatus.BOOKED
                self.currentPassengers.append(nextUpdate.personID)
                print self.name, self.countPassengers, " on board"
                nextUpdate = self.getNextStop(True)
            # else if target is a dropoff
            elif nextUpdate.stopType == StopType.DROPOFF:
                self.countPassengers -= 1
                peopleCollection.updatePersonDropoff(nextUpdate.personID, step)
                self.totalPassengers += 1
                self.currentPassengers.remove(nextUpdate.personID)
                self.occupancyTime += \
                    peopleCollection.getTravelTime(nextUpdate.personID)
                print self.name, self.countPassengers, " on board"
                nextUpdate = self.getNextStop(True)
            

        # update route
        if nextUpdate != None:
            if nextUpdate.stopType == StopType.DEPOT:
                # no future requests at this stage
                if self.operatingState == VehicleState.vsRunning:
                    assert self.countPassengers == 0
                    currentStop = self.getCurrentPos()
                    goHomeTime = self.end - network.getTime(currentStop,
                                                            nextUpdate)
                    if step < goHomeTime: # not time to go home yet
                        if self.currentStatus != VehicleStatus.PARKED:
                            self.currentStatus = VehicleStatus.PARKED
                            print self.name, "waiting", goHomeTime
                            self.parkedLink = self.currentLink
                            self.parkedPos = self.currentPos + PARK_OFFSET
                            # !! was 60+5*self.i
                            # if many vehicles and few set stops, then parking
                            # somewhere else reduces delay to other vehicles
                            traci.vehicle.setStop(self.name, self.parkedLink,
                                                  self.parkedPos, 0,
                                                  (goHomeTime - step)*MILLISECONDS)
                    else:
                        # raise from parking position and go home
                        traci.vehicle.setStop(self.name, self.parkedLink,
                                              self.parkedPos, 0, 0) 
                        self.operatingState = VehicleState.vsGoingHome
                        traci.vehicle.changeTarget(self.name, nextUpdate.link)
                        self.currentStatus = VehicleStatus.BOOKED
                        print self.name, "moving to depot"
                #elif self.operatingState == VehicleState.vsNotStarted:
                    # waiting at start
            else: # update route for next pickup/dropoff
                traci.vehicle.changeTarget(self.name, nextUpdate.link)
                traci.vehicle.setStop(self.name, nextUpdate.link,
                                      nextUpdate.pos, 0, DWELLTIME)
                if self.currentStatus == VehicleStatus.PARKED:
                    # raise from parking position if parked
                    traci.vehicle.setStop(self.name, self.parkedLink,
                                          self.parkedPos, 0, 0) 
                self.currentStatus = VehicleStatus.BOOKED
            

        # store last known link
        self.lastLink = self.currentLink
        self.lastPos = self.currentPos