Esempio n. 1
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));
            }
        }
    }
};
Esempio n. 2
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);
};
Esempio n. 3
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()]);
        }
    };
};
Esempio n. 4
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);
};
Esempio n. 5
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
    }
};
Esempio n. 6
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;
};