Beispiel #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));
            }
        }
    }
};
Beispiel #2
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;
};
Beispiel #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);
};
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
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 #6
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 #7
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
    }
};
Beispiel #8
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 #9
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_--;
    }
}
Beispiel #10
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);
};
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 #12
0
void Conn::onLocationUpdate(Location::PtrConst loc){
    FWK_DEBUG("Conn::onLocationUpdate() with name: " << loc->name());
    removeGraphLocation(loc);
};