Пример #1
0
void Node::AddMutualNeighborIfInRange(Node &n) {
	double dist = DistanceToNode(n);
	if(dist <= SquaredRange)
		AddNeighbor(n.Name, dist);
	if(dist <= n.SquaredRange)
		n.AddNeighbor(Name, dist);
}
Пример #2
0
void Graph::storeEdge(NodeID fromID, NodeID toID){
    Node *nd;
    if(IDtoNodeMap.count(fromID)>0){ //node from already in the map
        nd=IDtoNodeMap[fromID];
        nd->AddNeighbor(toID);
    } else {
        nd = new Node(fromID);
        nd->AddNeighbor(toID);
        IDtoNodeMap[fromID] = nd;
    }
    //for undirected graph if edges are listed only once we have to insert both nodes
    unsigned int swapt;
    swapt = fromID;
    fromID=toID;
    toID=swapt;
    if(IDtoNodeMap.count(fromID)>0){ //node from already in the map
        nd=IDtoNodeMap[fromID];
        nd->AddNeighbor(toID);
    } else {
        nd = new Node(fromID);
        nd->AddNeighbor(toID);
        IDtoNodeMap[fromID] = nd;
    }
}