bool
NBTrafficLightLogicCont::computeSingleLogic(OptionsCont& oc, NBTrafficLightDefinition* def) {
    const std::string& id = def->getID();
    const std::string& programID = def->getProgramID();
    // build program
    NBTrafficLightLogic* built = def->compute(oc);
    if (built == 0) {
        WRITE_WARNING("Could not build program '" + programID + "' for traffic light '" + id + "'");
        return false;
    }
    // compute offset
    SUMOTime T = built->getDuration();
    if (myHalfOffsetTLS.count(id)) {
        built->setOffset((SUMOTime)(T / 2.));
    }
    if (myQuarterOffsetTLS.count(id)) {
        built->setOffset((SUMOTime)(T / 4.));
    }
    // and insert the result after computation
    // make sure we don't leak memory if computeSingleLogic is called externally
    if (myComputed[id][programID] != 0) {
        delete myComputed[id][programID];
    }
    myComputed[id][programID] = built;
    return true;
}
Exemplo n.º 2
0
void
NBTrafficLightLogicCont::computeLogics(NBEdgeCont &ec, OptionsCont &oc) throw() {
    unsigned int no = 0;
    for (DefinitionContType::iterator i=myDefinitions.begin(); i!=myDefinitions.end(); i++) {
        std::string id = (*i).first;
        if (myComputed.find(id)!=myComputed.end()) {
            WRITE_WARNING("Traffic light '" + id + "' was already built.");
            continue;
        }
        // build program
        NBTrafficLightDefinition *def = (*i).second;
        NBTrafficLightLogic *built = def->compute(ec, oc);
        if (built==0) {
            WRITE_WARNING("Could not build traffic lights '" + id + "'");
            continue;
        }
        // compute offset
        SUMOTime T = built->getDuration();
        if (find(myHalfOffsetTLS.begin(), myHalfOffsetTLS.end(), id)!=myHalfOffsetTLS.end()) {
            built->setOffset((SUMOTime)(T/2.));
        }
        if (find(myQuarterOffsetTLS.begin(), myQuarterOffsetTLS.end(), id)!=myQuarterOffsetTLS.end()) {
            built->setOffset((SUMOTime)(T/4.));
        }
        // and insert the result after computation
        myComputed[(*i).first] = built;
        no++;
    }
    WRITE_MESSAGE(toString<int>(no) + " traffic light(s) computed.");
}