Exemplo n.º 1
0
/**
 * Gets the edge label of an edge between vertices u and v.
 * @param u - one vertex the edge is connected to
 * @param v - the other vertex the edge is connected to
 * @return the edge label between u and v
 */
string Graph::getEdgeLabel(Vertex u, Vertex v) const
{
    assertExists(u, __func__);
    assertExists(v, __func__);
    assertConnected(u, v, __func__);
    return graph.at(u).at(v).label;
}
Exemplo n.º 2
0
/**
 * Gets an edge between two vertices.
 * @param u - one vertex the edge is connected to
 * @param v - the other vertex the edge is connected to
 * @return the edge between u and v
 */
Edge Graph::getEdge(Vertex u, Vertex v) const
{
    assertExists(u, __func__);
    assertExists(v, __func__);
    assertConnected(u, v, __func__);
    return graph.at(u).at(v);
}
Exemplo n.º 3
0
/**
 * Sets the weight of an edge between two vertices.
 * @param u - one vertex the edge is connected to
 * @param v - the other vertex the edge is connected to
 * @param weight - the weight to set the edge
 */
void Graph::setEdgeWeight(Vertex u, Vertex v, int weight)
{
    assertExists(u, __func__);
    assertExists(v, __func__);
    assertConnected(u, v, __func__);
    graph[u][v].weight = weight;
    graph[v][u].weight = weight;
}
Exemplo n.º 4
0
/**
 * Removes an edge between two vertices.
 * @param u - one vertex the edge is connected to
 * @param v - the other vertex the edge is connected to
 */
void Graph::removeEdge(Vertex u, Vertex v)
{
    assertExists(u, __func__);
    assertExists(v, __func__);
    assertConnected(u, v, __func__);
    graph[u].erase(graph[u].find(v));
    graph[v].erase(graph[v].find(u));
}
Exemplo n.º 5
0
/**
 * Sets the edge label of an edge between vertices u and v.
 * @param u - one vertex the edge is connected to
 * @param v - the other vertex the edge is connected to
 */
void Graph::setEdgeLabel(Vertex u, Vertex v, string label)
{
    assertExists(u, __func__);
    assertExists(v, __func__);
    assertConnected(u, v, __func__);
    graph[u][v].label = label;
    graph[v][u].label = label;
}
Exemplo n.º 6
0
/**
 * Gets the weight of an edge between two vertices.
 * @param u - one vertex the edge is connected to
 * @param v - the other vertex the edge is connected to
 * @return the weight of the edge
 */
int Graph::getEdgeWeight(Vertex u, Vertex v) const
{
    if (!weighted)
        error("can't get edge weights on non-weighted graphs!");

    assertExists(u, __func__);
    assertExists(v, __func__);
    assertConnected(u, v, __func__);
    return graph.at(u).at(v).weight;
}
Exemplo n.º 7
0
void copyFiles(const string & sourceFolder, const string & destFolder, const vector<string> & files)
{
	assertExists(destFolder);
	for (size_t i = 0; i < files.size(); i++)
	{
		string sourceFile = sourceFolder + files[i];
		assertExists(sourceFile);
		copyFile(sourceFile, destFolder);
	}
}
Exemplo n.º 8
0
/**
 * Inserts an edge between two vertices.
 * A boolean is returned for use with the random graph generation.
 * Hence, an error is not thrown when it fails to insert an edge.
 * @param u - one vertex the edge is connected to
 * @param v - the other vertex the edge is connected to
 * @return whether inserting the edge was successful
 */
bool Graph::insertEdge(Vertex u, Vertex v)
{
    assertExists(u, __func__);
    assertExists(v, __func__);

    EdgeMap uEdges = graph[u];

    // "fail" silently for random graph generation
    if (uEdges.find(v) != uEdges.end())
        return false;

    Edge uEdge(u, v, -1, "");
    graph[u].insert(make_pair(v, uEdge));

    Edge vEdge(v, u, -1, "");
    graph[v].insert(make_pair(u, vEdge));

    return true;
}
Exemplo n.º 9
0
/**
 * Gets all adjacent vertices to the parameter vertex.
 * @param v - the vertex to get neighbors from
 * @return a vector of vertices
 */
vector<Vertex> Graph::getAdjacent(Vertex v) const
{
    assertExists(v, "getAdjacent");

    vector<Vertex> ret;
    EdgeMap edges = graph.at(v);
    EdgeMap::iterator it;
    for (it = edges.begin(); it != edges.end(); ++it)
        ret.push_back(it->second.dest);

    return ret;
}
Exemplo n.º 10
0
void copyFile(const string & source, const string & dest)
{
	assertExists(source);
	vector<string> folders = tokenize(dest, '/');
	string currdir = "";
	for (size_t i = 0; i < folders.size() - 1; i++)
	{
		currdir += folders[i] + '/';
		if (!exists(currdir))
			exec("mkdir", currdir.c_str());
	}
	exec("cp", source.c_str(), dest.c_str());
}
Exemplo n.º 11
0
void rename_main(const string & file, const string & newname)
{
	if (newname[0] != '_')
	{
		cerr << "INTERNAL ERROR: " __FILE__ << ":" << __LINE__
		     << "newname argument to rename_main must begin with an underscore to ensure replacement safety" << endl;
		exit(-2);
	}
	assertExists(file);
	exec( "sed", "-i",
	      ( "s/int[\\r\\n \\t][\\r\\n \\t]*main(.*)/int " + newname +
		    "(int argc, char ** argv)/" ).c_str(),
	      file.c_str() );
}
Exemplo n.º 12
0
void linkDirs(const string & sourceFolder, const string & destFolder, const vector<string> & dirs)
{
	assertExists(destFolder);
	for (size_t i = 0; i < dirs.size(); i++)
	{
		string source = sourceFolder + dirs[i];
		string target = destFolder   + dirs[i];

		// Check for redundant monad/ directory
		// This allows the monad/ dir to be safely renamed
		if (replaceFirst(source, "/../monad/","/"))
			replaceFirst(target, "/monad/","/");

		assertExists(destFolder + source + '/');

		if (symlink(source.c_str(), target.c_str()) != 0)
		{
			cerr << "symlink failed: " << target << ": ";
			perror(NULL);
			exit(-1);
		}
	}
}
Exemplo n.º 13
0
/**
 * Removes a given vertex from the graph.
 * @param v - the vertex to remove
 */
void Graph::removeVertex(Vertex v)
{
    assertExists(v, __func__);

    // first, remove all references to the vertex in every other edge list
    // luckily, we can call getAdjacent and work backwards
    //  instead of traversing the whole hash table
    vector<Vertex> adjacent = getAdjacent(v);
    vector<Vertex>::iterator it;
    for (it = adjacent.begin(); it != adjacent.end(); ++it)
        removeEdge(*it, v);

    // now that all references are gone, we can delete the vertex
    graph.erase(v);
    vertexLabels.erase(v);
}
Exemplo n.º 14
0
void protectFiles(const string & folder, const vector<string> & files)
{
#if 0 // (debug)
	for (size_t i = 0; i < files.size(); i++)
	{
		string file = folder + files[i];
		assertExists(file);

		if (chmod(file.c_str(), S_IRUSR) != 0)
		{
			perror("chmod failed");
			exit(-1);
		}
	}
#endif
}
Exemplo n.º 15
0
/**
 * Gets the label of a vertex.
 * @param v - vertex to get label from
 * @return the vertex label
 */
string Graph::getVertexLabel(Vertex v) const
{
    assertExists(v, __func__);
    return vertexLabels.at(v);
}
Exemplo n.º 16
0
/**
 * Labels a vertex with a string.
 * This is a method.
 * @param v - the vertex to label
 * @param label - label of the vertex to change
 */
void Graph::setVertexLabel(Vertex v, string label)
{
    assertExists(v, __func__);
    vertexLabels[v] = label;
}