Beispiel #1
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);
};
Beispiel #2
0
ConnectPathTree::ConnectPathTree(Location::PtrConst _root,
        Location::PtrConst _end, Conn * _owner) :
        PathTree(_root, _owner), end_(_end)
{
    FWK_DEBUG("Conn::ConnectPathTree::ConnectPathTree() with root: " <<
            _root->name());
    while(!queue_.empty()){
        FWK_DEBUG("Conn::ConnectPathTree::ConnectPathTree() queue size: " <<
                queue_.size());
        processQueueFront();
        queue_.pop();
    }
    PathIterator it = pathIter();
    unsigned int i = 0;
    unsigned int n =paths();
    while (i < n){
        PathIterator curIt = path_.end();
        if ((*it)->lastPathItem().loc->name() != end_->name()) {
            curIt = it;
        }
        ++it; ++i;
        if (curIt != path_.end())
            path_.erase(curIt);
    }
};
Beispiel #3
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);
};
Beispiel #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()]);
        }
    };
};
Beispiel #5
0
PathTree::PathTree(Location::PtrConst _root, Conn * _owner) : owner_(_owner)
{
    FWK_DEBUG("Conn::PathTree::PathTree() with root: " << _root->name());
    PathItem pI;
    pI.loc = _root;
    Path::Ptr p = new Path();
    p->nextPathItemIs(pI);
    path_.push_back(p);
    queue_.push(path_.back());
};
Beispiel #6
0
ExplorePathTree::ExplorePathTree(ExploreData _ed, 
    Location::PtrConst _root, Conn * _owner) : 
PathTree(_root, _owner) , exploreData_(_ed)   
{
    FWK_DEBUG("Conn::ExplorePathTree::ExplorePathTree() with root: " << _root->name());
    while(!queue_.empty()){
        FWK_DEBUG("Conn::ExplorePathTree::ExplorePathTree() queue size: " << queue_.size());
        processQueueFront();
        queue_.pop();
    }
    if (path_.front()->pathItems() == 1) path_.clear(); //if only starter root
};
Beispiel #7
0
void Stats::onLocationDel(Location::PtrConst _p) {
    FWK_DEBUG("Stats::onLocationDel(" << _p->name() << ")");
    if (_p->type()  == Location::customer()) {
        customerCount_--;
    } else if (_p->type()  == Location::port()) {
        portCount_--;
    } else if (_p->type()  == Location::truckTerminal()) {
        truckTerminalCount_--;
    } else if (_p->type()  == Location::boatTerminal()) {
        boatTerminalCount_--;
    } else if (_p->type()  == Location::planeTerminal()) {
        planeTerminalCount_--;
    }
}
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;
};
Beispiel #9
0
void Conn::onLocationUpdate(Location::PtrConst loc){
    FWK_DEBUG("Conn::onLocationUpdate() with name: " << loc->name());
    removeGraphLocation(loc);
};