Ejemplo n.º 1
0
SUMOReal
ROEdge::getDistanceTo(const ROEdge* other) const {
    if (getToNode() != 0 && other->getFromNode() != 0) {
        return getToNode()->getPosition().distanceTo2D(other->getFromNode()->getPosition());
    } else {
        return 0; // optimism is just right for astar
    }

}
Ejemplo n.º 2
0
/**
* Returns the directed edge that starts at this directed edge's end point, or null
* if there are zero or multiple directed edges starting there.  
* @return
*/
LineMergeDirectedEdge* LineMergeDirectedEdge::getNext() {
	if (getToNode()->getDegree()!=2) {
		return NULL;
	}
	if ((*(getToNode()->getOutEdges()->getEdges()))[0]==getSym()) {
		return (LineMergeDirectedEdge*) (*(getToNode()->getOutEdges()->getEdges()))[1];
	}
	Assert::isTrue((*(getToNode()->getOutEdges()->getEdges()))[1]==getSym());
	return (LineMergeDirectedEdge*) (*(getToNode()->getOutEdges()->getEdges()))[0];
}
Ejemplo n.º 3
0
/**
 * Returns the directed edge that starts at this directed edge's end point,
 * or null if there are zero or multiple directed edges starting there.  
 * @return
 */
LineMergeDirectedEdge*
LineMergeDirectedEdge::getNext()
{
	if (getToNode()->getDegree()!=2) {
		return NULL;
	}
	if (getToNode()->getOutEdges()->getEdges()[0]==getSym()) {
		return (LineMergeDirectedEdge*) getToNode()->getOutEdges()->getEdges()[1];
	}
	assert(getToNode()->getOutEdges()->getEdges()[1]==getSym());

	LineMergeDirectedEdge* nextedge = dynamic_cast<LineMergeDirectedEdge*>(getToNode()->getOutEdges()->getEdges()[0]);
	assert(nextedge);

	return nextedge;
}
Ejemplo n.º 4
0
const DirectedEdge& DirectedEdge::startRootElement(XML::DocumentBuilder& xmlDocument,
												   util::PointerToID& ptrToID) const
{
	XML::AttributeMap attributes;
	attributes["directed"] = "true";
	attributes["from"] = util::toString(ptrToID[getFromNode()]);
	attributes["to"] = util::toString(ptrToID[getToNode()]);
	if (!getLabel().empty()) {
		attributes["label"] = getLabel();
	}
	xmlDocument.beginElement(getTypeName(), attributes);
	return *this;
}
Ejemplo n.º 5
0
void
NIVissimEdge::buildNBEdge(NBDistrictCont& dc, NBNodeCont& nc, NBEdgeCont& ec,
                          SUMOReal sameNodesOffset) {
    // build the edge
    std::pair<NIVissimConnectionCluster*, NBNode*> fromInf, toInf;
    NBNode* fromNode, *toNode;
    fromNode = toNode = 0;
    sort(myConnectionClusters.begin(), myConnectionClusters.end(), connection_cluster_position_sorter(myID));
    sort(myDistrictConnections.begin(), myDistrictConnections.end());
    ConnectionClusters tmpClusters = myConnectionClusters;
    if (tmpClusters.size() != 0) {
        sort(tmpClusters.begin(), tmpClusters.end(), connection_cluster_position_sorter(myID));
        // get or build the from-node
        //  A node may have to be build when the edge starts or ends at
        //  a parking place or something like this
        fromInf = getFromNode(nc, tmpClusters);
        fromNode = fromInf.second;
        // get or build the to-node
        //if(tmpClusters.size()>0) {
        toInf = getToNode(nc, tmpClusters);
        toNode = toInf.second;
        if (fromInf.first != 0 && toNode != 0 && fromInf.first->around(toNode->getPosition())) {
            WRITE_WARNING("Will not build edge '" + toString(myID) + "'.");
            myAmWithinJunction = true;
            return;
        }
        //}
        // if both nodes are the same, resolve the problem otherwise
        if (fromNode == toNode) {
            std::pair<NBNode*, NBNode*> tmp = resolveSameNode(nc, sameNodesOffset, fromNode, toNode);
            if (fromNode != tmp.first) {
                fromInf.first = 0;
            }
            if (toNode != tmp.second) {
                toInf.first = 0;
            }
            fromNode = tmp.first;
            toNode = tmp.second;
        }
    }

    //
    if (fromNode == 0) {
        fromInf.first = 0;
        Position pos = myGeom[0];
        fromNode = new NBNode(toString<int>(myID) + "-SourceNode", pos, NODETYPE_NOJUNCTION);
        if (!nc.insert(fromNode)) {
            throw ProcessError("Could not insert node '" + fromNode->getID() + "' to nodes container.");
        }
    }
    if (toNode == 0) {
        toInf.first = 0;
        Position pos = myGeom[-1];
        toNode = new NBNode(toString<int>(myID) + "-DestinationNode", pos, NODETYPE_NOJUNCTION);
        if (!nc.insert(toNode)) {
            throw ProcessError("Could not insert node '" + toNode->getID() + "' to nodes container.");
        }
    }

    // build the edge
    SUMOReal avgSpeed = 0;
    int i;
    for (i = 0; i < (int) myNoLanes; i++) {
        if (myLaneSpeeds.size() <= (size_t) i || myLaneSpeeds[i] == -1) {
            myLanesWithMissingSpeeds.push_back(toString(myID) + "_" + toString(i));
            avgSpeed += OptionsCont::getOptions().getFloat("vissim.default-speed");
        } else {
            avgSpeed += myLaneSpeeds[i];
        }
    }
    avgSpeed /= (SUMOReal) myLaneSpeeds.size();
    avgSpeed *= OptionsCont::getOptions().getFloat("vissim.speed-norm");

    if (fromNode == toNode) {
        WRITE_WARNING("Could not build edge '" + toString(myID) + "'; would connect same node.");
        return;
    }

    NBEdge* buildEdge = new NBEdge(toString<int>(myID), fromNode, toNode, myType,
                                   avgSpeed / (SUMOReal) 3.6, myNoLanes, -1,
                                   NBEdge::UNSPECIFIED_WIDTH, NBEdge::UNSPECIFIED_OFFSET,
                                   myGeom, myName, LANESPREAD_CENTER, true);
    for (i = 0; i < (int) myNoLanes; i++) {
        if ((int) myLaneSpeeds.size() <= i || myLaneSpeeds[i] == -1) {
            buildEdge->setSpeed(i, OptionsCont::getOptions().getFloat("vissim.default-speed") / (SUMOReal) 3.6);
        } else {
            buildEdge->setSpeed(i, myLaneSpeeds[i] / (SUMOReal) 3.6);
        }
    }
    ec.insert(buildEdge);
    // check whether the edge contains any other clusters
    if (tmpClusters.size() > 0) {
        bool cont = true;
        for (ConnectionClusters::iterator j = tmpClusters.begin(); cont && j != tmpClusters.end(); ++j) {
            // split the edge at the previously build node
            std::string nextID = buildEdge->getID() + "[1]";
            cont = ec.splitAt(dc, buildEdge, (*j)->getNBNode());
            // !!! what to do if the edge could not be split?
            buildEdge = ec.retrieve(nextID);
        }
    }
}