Пример #1
0
string LocationRep::attribute(const string& attributeName) {

    FWK_DEBUG("LocationRep::attribute " << attributeName);

    Location::PtrConst locPtr = engineManager_->entityManager()->location(name());

    if (locPtr == NULL) {
        cerr << name() << " not a valid location (maybe deleted), returning empty string for " << attributeName << endl;
        return "";
    }

    if (attributeName.substr(0,7) != "segment" ) {
        cerr << "LocationRep::attribute: " << attributeName << " is not a valid attribute name" << endl;
        return "";
    }

    unsigned int segNr = LocationRep::segmentNumber(attributeName)-1;

    FWK_DEBUG("segNr " << segNr << ", outSegments(): " << locPtr->outSegments() );
    if (segNr >= locPtr->outSegments() ) {
        cerr << "Segment number " << segNr+1 << " does not exist. Returning empty string.\n";
        return "";
    }

    Location::OutSegmentIteratorConst it = 
        engineManager_->entityManager()->location(name())->outSegmenterIterConst(segNr);
    string attr = locPtr->outSegment(it)->name();

    return attr;
};
Пример #2
0
void ConnectPathTree::processQueueFront() {
    Path::Ptr frontPath = queue_.front();
    if (frontPath->lastPathItem().loc->name() == end_->name()) return;
    FWK_DEBUG("Conn::ExplorePathTree::processQueueFront() with path: " << frontPath->lastPathItem().loc->name() );
    unsigned int children = 0;
    Location::PtrConst curLoc = frontPath->lastPathItem().loc;
    Location::OutSegmentIteratorConst it = curLoc->outSegmenterIterConst();
    Path::Ptr curPath = frontPath->cloneIs();
    for (unsigned int i = 0; i < curLoc->outSegments(); ++it, ++i){
        if (!segExists((*it)->name())) continue; 
        PathItem pI = pathItem(*it);
        if (isAddable(frontPath, pI) == addable_) {
            ++children;
            Path::Ptr newPath = addChildren(children, curPath, frontPath, pI);
            if (queue_.back()->lastPathItem().seg->expediteSupport() == Segment::noExpediteSupport() &&
                queue_.back()->expediteSupport() == Segment::fullExpediteSupport()) {
                queue_.back()->expediteSupportIs( Segment::noExpediteSupport());
            } 
            
            if (queue_.back()->expediteSupport() == Segment::fullExpediteSupport() &&
                queue_.back()->lastPathItem().loc->name() == end_->name()) {
                ++children;
                addChildren(children, curPath, frontPath, pI);
                queue_.back()->expediteSupportIs( Segment::noExpediteSupport());
                queue_.back()->costIs(Dollars(queue_.back()->cost().value() * (2.0/3.0)));
                queue_.back()->timeIs(Hours(queue_.back()->time().value()  * 1.3));
            }
        }
    }
};
Пример #3
0
void Conn::removeGraphLocation(Location::PtrConst loc) {
    FWK_DEBUG("Conn::removeGraphLocation() with name: " << loc->name());
    Location::OutSegmentIteratorConst it = loc->outSegmenterIterConst();
    for (unsigned int i = 0; i < loc->outSegments(); ++i, it++){
        if ( graphSegment_.find((*it)->name()) != graphSegment_.end()) return;
    };
    graphLocation_.erase(loc->name());
    routeTable_->statusIs(RouteTable::needsUpdate);
};
Пример #4
0
void Conn::onLocationDel(Location::PtrConst loc) {
    FWK_DEBUG("Conn::removeGraphLocation() with name: " << loc->name());
    Location::OutSegmentIteratorConst it = loc->outSegmenterIterConst();
    for (unsigned int i = 0; i < loc->outSegments(); ++i, it++){
        if ( graphSegment_.find((*it)->name()) != graphSegment_.end()){ 
            removeGraphSegment(*it);
            removeGraphSegment(graphSegment_[(*it)->returnSegment()]);
        }
    };
};
Пример #5
0
void Conn::onLocationShipmentNew(Location::PtrConst _cur,
    Shipment::Ptr _shipment) {
        FWK_DEBUG("Conn::onLocationShipmentNew() with name: " << _cur->name());

        Location::PtrConst next =
            routeTable_->nextLocation(_cur, _shipment->destination());
        Segment::Ptr out;
        Location::OutSegmentIteratorConst it = _cur->outSegmenterIterConst();
        for (int i =0; i < _cur->outSegments(); ++i, ++it) {
            Segment::PtrConst r = graphSegment_.at((*it)->returnSegment());
            if (r->source() == next->name()){
                out = *it;
                break;
            }
        }
        //Segment * s = const_cast<Segment *> (out.ptr());
        Location::Ptr p =  const_cast<Location *>(next.ptr());
        out->shipmentEnq(_shipment,p);
};
Пример #6
0
void ExplorePathTree::processQueueFront() {
    Path::Ptr frontPath = queue_.front();
    FWK_DEBUG("Conn::ExplorePathTree::processQueueFront() with path: " << frontPath->lastPathItem().loc->name() );
    unsigned int children = 0;
    Location::PtrConst curLoc = frontPath->lastPathItem().loc;
    Location::OutSegmentIteratorConst it = curLoc->outSegmenterIterConst();
    Path::Ptr curPath = frontPath->cloneIs();
    for (unsigned int i = 0; i < curLoc->outSegments(); ++it, ++i){
        if (!segExists((*it)->name())) continue; 
        PathItem pI = pathItem(*it);
        if (isAddable(frontPath, pI) == addable_) {
            ++children;
            addChildren(children, curPath, frontPath, pI);
        }
    }
    if (children != 0 && curPath->pathItems() > 1){
        path_.push_back(curPath->cloneIs());//add current
    }
};
Пример #7
0
ShortestDistance::Ptr DjikstrasAlgorithm::shortestDistance(
        const std::string & source){
    ShortestDistance::Ptr s = new ShortestDistance();
     if (!s) {
        std::cerr << "DjikstrasAlgorithm new() failed" << std::endl;
        throw(Fwk::MemoryException("DjikstrasAlgorithm::shortestDistance"));
    }
    const unsigned int size = graphLocation_->size();

    //Djikstras!

    Miles * dist = new Miles[size];
    std::map<std::string, Location::PtrConst > prev;
    std::string * intToName = new std::string[size];
    std::map<std::string, unsigned int> nameToInt;
    std::map<std::string, Location::PtrConst >::const_iterator it =
            graphLocation_->begin();
    std::set<unsigned int> Q;
    for (unsigned int i = 0; i < size; ++i, ++it) {
        Q.insert(i);
        intToName[i] = it->second->name();
        nameToInt[it->second->name()] = i;
        prev[it->second->name()] = NULL;
        if (it->second->name() == source)
            dist[i] = 0;
        else
            dist[i] = Miles::max();
    }

    while (!Q.empty()) {
        Miles minDist = Miles::max();
        unsigned int u;
        for (std::set<unsigned int>::iterator it = 
            Q.begin(); it != Q.end(); ++it) {
            if (dist[*it] < minDist) {
                u = *it;
                minDist = dist[u];
            }
        }
        if (minDist == Miles::max()) break;
        Q.erase(u);
        Location::PtrConst loc = graphLocation_->operator [](intToName[u]);
        Location::OutSegmentIteratorConst it = loc->outSegmenterIterConst();
        unsigned int outSegs = loc->outSegments();
        for (unsigned int i = 0; i < outSegs; ++i, ++it) {
            std::string returnStr = (*it)->returnSegment();
            std::string neighborLocStr =
                    graphSegment_->operator [](returnStr)->source();
            if (graphLocation_->find(neighborLocStr) !=graphLocation_->end() ) {
                Miles alt = dist[u].value() + (*it)->length().value();
               unsigned int v = nameToInt[neighborLocStr];
                if (alt < dist[v]){
                    dist[v] = alt;
                    prev[neighborLocStr] = loc;
                }
            }
        }
    }

    for (unsigned int i = 0; i < size; ++i) {
        if (dist[i] == Miles::max() || dist[i] == 0) continue;
        std::string name = intToName[i];

        Location::PtrConst p = prev[name];
        Location::PtrConst old = graphLocation_->operator [](name);
        while (p->name() != source) {
            old = p;
            p = prev[p->name()];
        }
        s->next[name] = old;
        FWK_DEBUG("SOURCE: " << source << " DEST: " << name << " NEXT: " <<
            old->name() << " DIST : " << dist[i].value());
    }

    return s;
};