示例#1
0
/**
 * Saves the graph as a PNG image.
 * @param title - the filename of the PNG image
 */
void Graph::savePNG(string title) const
{
    std::ofstream neatoFile;
    string filename = "images/" + title + ".dot";
    neatoFile.open(filename.c_str());

    if (!neatoFile.good())
        error("couldn't create " + filename + ".dot");

    neatoFile
        << "strict graph G {\n"
        << "\toverlap=\"false\";\n"
        << "\tdpi=\"160\";\n"
        << "\tsep=\"1.5\";\n"
        << "\tnode [fixedsize=\"true\", shape=\"circle\", fontsize=\"6.0\"];\n"
        << "\tedge [penwidth=\"1.5\", fontsize=\"6.0\"];\n";

    VertexMap::const_iterator it;
    for (it = graph.begin(); it != graph.end(); ++it) {
        EdgeMap::const_iterator git;
        for (git = it->second.begin(); git != it->second.end(); ++git) {
            string vertex1Text = getVertexName(it->first);
            string vertex2Text = getVertexName(git->first);

            neatoFile << "\t\"" << it->first;
            neatoFile << vertex1Text;
            neatoFile << "\" -- \"" << git->first;
            neatoFile << vertex2Text;
            neatoFile << "\"";

            string edgeLabel = git->second.label;
            if (edgeLabel == "MST" || edgeLabel == "MIN"
                || edgeLabel == "MINPATH")
                neatoFile << "[color=\"blue\"]";
            else if (edgeLabel == "CROSS")
                neatoFile << "[color=\"red\"]";
            else if (edgeLabel == "DISCOVERY")
                neatoFile << "[color=\"green\"]";
            else if (edgeLabel == "VISITED")
                neatoFile << "[color=\"grey\"]";
            if (weighted && git->second.weight != -1)
                neatoFile << "[label=\"" << git->second.weight << "\"]";
            neatoFile << ";\n";
        }
    }

    neatoFile << "}";
    neatoFile.close();
    string command = "neato -Tpng " + filename + " -o " + "images/" + title
                     + ".png 2> /dev/null";
    system(command.c_str());
    string rmCommand = "rm -f " + filename + " 2> /dev/null";
    system(rmCommand.c_str());
}
示例#2
0
/**
 * Prints the graph to stdout.
 */
void Graph::print() const
{
    VertexMap::const_iterator it;
    for (it = graph.begin(); it != graph.end(); ++it) {
        cout << it->first << getVertexName(it->first) << endl;
        EdgeMap::const_iterator git;
        for (git = it->second.begin(); git != it->second.end(); ++git) {
            std::stringstream ss;
            ss << git->second.dest;
            string vertexColumn = "    => " + ss.str();
            vertexColumn += " " + getVertexName(git->first);
            cout << std::left << std::setw(26) << vertexColumn;
            string edgeColumn = "edge label = \"" + git->second.label + "\"";
            cout << std::left << std::setw(26) << edgeColumn;
            if (weighted)
                cout << "weight = " << git->second.weight;
            cout << endl;
        }
        cout << endl;
    }
}
std::string MultipleNetwork::getGlobalVertexName(std::string local_vertex_name, std::string network_name) {
	network_id net = getNetworkId(network_name);
	vertex_id local_id = getNetwork(net)->getVertexId(local_vertex_name);
	global_vertex_id global_id = getGlobalVertexId(local_id, net);
	return getVertexName(global_id);
}