SUMOReal
NIVissimDistrictConnection::getMeanSpeed(/*NBDistribution &dc*/) const {
    //assert(myAssignedVehicles.size()!=0);
    if (myAssignedVehicles.size() == 0) {
        WRITE_WARNING("No streams assigned at district'" + toString(myID) + "'.\n Using default speed 200km/h");
        return (SUMOReal) 200 / (SUMOReal) 3.6;
    }
    SUMOReal speed = 0;
    std::vector<std::pair<int, int> >::const_iterator i;
    for (i = myAssignedVehicles.begin(); i != myAssignedVehicles.end(); i++) {
        speed += getRealSpeed(/*dc, */(*i).second);
    }
    return speed / (SUMOReal) myAssignedVehicles.size();
}
示例#2
0
void Character::moveTo(const Position &pos) {
    int moveTime = 1000/getRealSpeed();

    // Timer speed
    _speedTimer.mark();
    if(_speedTimer.timemsec()<moveTime) {
        return;
    } else {
        _speedTimer.start();

        // Move
        Position distance(pos.x()-this->getPosition().x(), pos.y()-this->getPosition().y());
        int dirX = distance.x()==0? 0 : distance.x()/abs(distance.x());
        int dirY = distance.y()==0? 0 : distance.y()/abs(distance.y());
        Position direction(dirX, dirY);

        Position newPosition(getPosition().x()+direction.x(), getPosition().y()+direction.y());
        this->setPosition(newPosition);
    }
}
示例#3
0
void
NIVissimEdge::propagateSpeed(/* NBDistribution &dc */ SUMOReal speed, std::vector<int> forLanes) {
    // if no lane is given, all set be set
    if (forLanes.size() == 0) {
        for (size_t i = 0; i < myNoLanes; i++) {
            forLanes.push_back((int) i);
        }
    }
    // for the case of a first call
    // go through the lanes
    for (std::vector<int>::const_iterator i = forLanes.begin(); i < forLanes.end(); i++) {
        // check whether a speed was set before
        if (myLaneSpeeds[*i] != -1) {
            // do not reset it from incoming
            continue;
        }
        // check whether the lane has a new speed to set
        if ((int) myPatchedSpeeds.size() > *i && myPatchedSpeeds[*i] != -1) {
            // use it
            speed = getRealSpeed(/*dc, */myPatchedSpeeds[*i]);
        }
        // check whether a speed is given
        if (speed == -1) {
            // do nothing if not
            continue;
        }
        // set the lane's speed to the given
        myLaneSpeeds[*i] = speed;
        // propagate the speed further
        // get the list of connected edges
        std::vector<NIVissimConnection*> connected = getOutgoingConnected(*i);
        // go throught the list
        for (std::vector<NIVissimConnection*>::iterator j = connected.begin(); j != connected.end(); j++) {
            NIVissimConnection* c = *j;
            NIVissimEdge* e = NIVissimEdge::dictionary(c->getToEdgeID());
            // propagate
            e->propagateSpeed(/*dc, */speed, c->getToLanes());
        }
    }
}