Beispiel #1
0
MyGraph MyGraph::graph_union(const MyGraph& g2) const {
    MyGraph output = copyGraph();
    graph_hashmap::const_iterator g2_it = g2.thegraph.begin();
    while(g2_it != this->thegraph.end()){
        if ( output.thegraph.find(g2_it->first) == output.thegraph.end())
            output.insertVertex(g2_it->first);
        //cycle through all the edges contained in the node hashmap
        node_hashmap::const_iterator node_iter = g2_it->second.begin();
        while (node_iter != g2_it->second.end() ){
            if (!output.areAdjacent(g2_it->first,node_iter->first))
                output.insertEdge(g2_it->first,node_iter->first);
            *node_iter++;
            }
        *g2_it++;
        }
    return output;
    }
Beispiel #2
0
MyGraph MyGraph::graph_complement() const{
    MyGraph output = copyGraph();
    graph_hashmap::const_iterator g_iter = thegraph.begin();
    my_set::const_iterator g2_iter;
    while (g_iter != thegraph.end()){
        g2_iter = set_of_vertices.begin();
        while ( g2_iter != set_of_vertices.end()){
            if (strcmp(g_iter->first.c_str(),(*g2_iter).c_str()) ){ //avoid self-loops
                if( areAdjacent(g_iter->first, *g2_iter) )
                    output.removeEdge(g_iter->first, *g2_iter);
                else
                    if (!output.areAdjacent(g_iter->first, *g2_iter))
                        output.insertEdge(g_iter->first, *g2_iter);
                }
            *g2_iter++;
            }
        *g_iter++;
        }
    return output;
}
Beispiel #3
0
MyGraph MyGraph::graph_intersection(const MyGraph& g2) const {
    MyGraph output;
    graph_hashmap::const_iterator g1_it = this->thegraph.begin();
    while(g1_it != this->thegraph.end()){
        //If the vertex in g1 does not exist in g2, then skip it.
        if( g2.set_of_vertices.find(g1_it->first) != g2.set_of_vertices.end()) {
            output.thegraph[g1_it->first]= node_hashmap();
            //cycle through all the edges contained in the node hashmap
            node_hashmap::const_iterator node_iter = g1_it->second.begin();
            while (node_iter != g1_it->second.end() ){
                if( this->thegraph.at(g1_it->first).find(node_iter->first) != thegraph.at(g1_it->first).end() &&
                        g2.thegraph.at(g1_it->first).find(node_iter->first) != g2.thegraph.at(g1_it->first).end()){

                    output.insertEdge(g1_it->first,node_iter->first);
                      }
                *node_iter++;
                }
            }
        *g1_it++;
        }
    return output;
    }