예제 #1
0
void Network::setStringEdgeAttribute(vertex_id vid1, vertex_id vid2, const std::string& attribute_name, const std::string& val) {
	if (!containsVertex(vid1)) throw ElementNotFoundException("Vertex " + std::to_string(vid1));
	if (!containsVertex(vid2)) throw ElementNotFoundException("Vertex " + std::to_string(vid2));
	if (!containsEdge(vid1, vid2)) throw ElementNotFoundException("Edge (" + std::to_string(vid2) + ", " + std::to_string(vid2) + ")");
	if (edge_string_attribute.count(attribute_name)==0) throw ElementNotFoundException("Attribute " + attribute_name);
	edge_id eid(vid1, vid2, isDirected());
	edge_string_attribute.at(attribute_name)[eid] = val;
}
예제 #2
0
edge_id Network::addEdge(const std::string& vertex_name1, const std::string& vertex_name2) {
	if (!isNamed()) throw OperationNotSupportedException("Cannot reference a named vertex in an unnamed network");
	if (!containsVertex(vertex_name1)) throw ElementNotFoundException("Vertex " + vertex_name1);
	if (!containsVertex(vertex_name2)) throw ElementNotFoundException("Vertex " + vertex_name2);
	//std::cout << "Edge: " << vertex_name1 << " " << vertex_name_to_id[vertex_name1]
	//<< " " << vertex_name2 << " " << vertex_name_to_id[vertex_name2] << std::endl;
	return addEdge(vertex_name_to_id[vertex_name1],vertex_name_to_id[vertex_name2]);
}
예제 #3
0
std::string Network::getStringEdgeAttribute(vertex_id vid1, vertex_id vid2, const std::string& attribute_name) const {
	if (!containsVertex(vid1)) throw ElementNotFoundException("Vertex " + std::to_string(vid1));
	if (!containsVertex(vid2)) throw ElementNotFoundException("Vertex " + std::to_string(vid2));
	if (!containsEdge(vid1, vid2)) throw ElementNotFoundException("Edge (" + std::to_string(vid1) + ", " + std::to_string(vid2) + ")");
	if (edge_string_attribute.count(attribute_name)==0) throw ElementNotFoundException("Attribute " + attribute_name);
	edge_id eid(vid1, vid2, isDirected());
	if (edge_string_attribute.at(attribute_name).count(eid)==0)  throw ElementNotFoundException("No attribute value for attribute " + attribute_name + " on edge (" + std::to_string(vid1) + "," +  std::to_string(vid2) + ")");
	return edge_string_attribute.at(attribute_name).at(eid);
}
예제 #4
0
edge_id Network::addEdge(vertex_id vid1, vertex_id vid2) {
	if (!containsVertex(vid1)) throw ElementNotFoundException("Vertex " + std::to_string(vid1));
	if (!containsVertex(vid2)) throw ElementNotFoundException("Vertex " + std::to_string(vid2));
	if (out_edges[vid1].count(vid2)>0) throw DuplicateElementException("Edge (" + std::to_string(vid1) + "," + std::to_string(vid2) +  ") already exists");
	//max_edge_id++;
	out_edges[vid1].insert(vid2);
	in_edges[vid2].insert(vid1);
	if (!isDirected() && vid1!=vid2) {
		out_edges[vid2].insert(vid1);
		in_edges[vid1].insert(vid2);
	}
	if (isWeighted()) setNumericEdgeAttribute(vid1,vid2,"weight",MULTIPLENETWORK_DEFAULT_WEIGHT); // this value will be replaced if this method has been called inside addEdge(vertex_id, vertex_id, double)
	num_edges++;
	return edge_id(vid1, vid2, isDirected());
}
예제 #5
0
bool Network::deleteVertex(vertex_id vid) {
	if (!containsVertex(vid)) return false;
	std::set<vertex_id> in = getInNeighbors(vid);
	std::set<vertex_id> out = getOutNeighbors(vid);

	// removing adjacent edges
	for (std::set<vertex_id>::iterator it=in.begin(); it!=in.end(); it++)
		deleteEdge(*it,vid);
	for (std::set<vertex_id>::iterator it=out.begin(); it!=out.end(); it++)
		deleteEdge(vid,*it);

	// removing the vertex
	vertexes.erase(vid);
	if (isNamed()) {
		// some more structures to empty
		const std::string& vertex_name=vertex_id_to_name[vid];
		vertex_id_to_name.erase(vid);
		vertex_name_to_id.erase(vertex_name);
	}
	// remove attribute values
	for (std::map<std::string,std::map<vertex_id,std::string> >::iterator it=vertex_string_attribute.begin(); it!=vertex_string_attribute.end(); it++)
		vertex_string_attribute[it->first].erase(vid);
	for (std::map<std::string,std::map<vertex_id,double> >::iterator it=vertex_numeric_attribute.begin(); it!=vertex_numeric_attribute.end(); it++)
		vertex_numeric_attribute[it->first].erase(vid);
	return true;
}
예제 #6
0
bool Triangle2::isDegeneratedAfterCollapseToTriangle()
{
    if (containsVertex(NULL))
        return true;
    
    if (containsVertexEdge(NULL))
        return true;
    
    for (unsigned int i = 0; i < count() - 1; i++)
    {
        for (unsigned int j = i + 1; j < count(); j++)
        {
            if (vertex(i) == vertex(j))
            {
                if (_isQuad)
                {
                    if (i < 3 && j < 3)
                        swap(node(i), node(3));
                    
                    node(3) = PackedNode();
                    _isQuad = false;
                    
                    return isDegeneratedAfterCollapseToTriangle();
                }
                return true;
            }
        }
    }
    	
	return false;
}
bool MultipleNetwork::containsVertex(global_vertex_id gvid, network_id nid) {
	// check if global vertex exists
	if (!containsVertex(gvid)) return false;
	// now check if it has an associated local vertex on network nid
	// (if nid does not exist, this condition will always be true)
	if (global_to_local_id[gvid].count(nid)==0) return false;
	else return true;
}
void MultipleNetwork::map(global_vertex_id gvid, vertex_id lvid, int nid) {
	if (!containsVertex(gvid)) throw ElementNotFoundException("global vertex " + std::to_string(gvid));
	if (!containsNetwork(nid)) throw ElementNotFoundException("network " + std::to_string(nid));
	if (!getNetwork(nid)->containsVertex(lvid)) throw ElementNotFoundException("local vertex " + std::to_string(lvid));
	if (global_to_local_id[gvid].count(nid)>0) throw DuplicateElementException("global vertex " + std::to_string(gvid) + " in network " + std::to_string(nid));
	// We update the references between global and local identifiers
	global_to_local_id[gvid][nid] = lvid;
	local_to_global_id[nid][lvid] = gvid;
}
예제 #9
0
std::set<vertex_id> Network::getInNeighbors(vertex_id vid) const  {
	std::set<vertex_id> neighbors;
	if (!containsVertex(vid)) throw ElementNotFoundException("Vertex " + std::to_string(vid));
	std::set<vertex_id>::const_iterator it;
	if (in_edges.count(vid)!=0)
		for (it=in_edges.at(vid).begin(); it!=in_edges.at(vid).end(); it++)
			neighbors.insert(*it);
	return neighbors;
}
예제 #10
0
std::set<std::string> Network::getInNeighbors(const std::string& vertex_name) const  {
	if (!isNamed()) throw OperationNotSupportedException("Cannot reference a named vertex in an unnamed network");
	if (!containsVertex(vertex_name)) throw ElementNotFoundException("Vertex " + vertex_name);
	std::set<std::string> neighbors;
	std::set<vertex_id> tmp_id_result = getInNeighbors(vertex_name_to_id.at(vertex_name));
	for (std::set<vertex_id>::iterator it=tmp_id_result.begin(); it!=tmp_id_result.end(); it++)
		neighbors.insert(vertex_id_to_name.at(*it));
	return neighbors;
}
예제 #11
0
bool tarch::plotter::griddata::regular::CartesianGridArrayWriter::containsVertex(
  const tarch::la::Vector<2,double>& x
) const {
  tarch::la::Vector<3,double> x3D;
  x3D(0) = x(0);
  x3D(1) = x(1);
  x3D(2) = 0.0;
  return containsVertex(x3D);
}
예제 #12
0
vertex_id Network::addVertex(const std::string& vertex_name) {
	if (containsVertex(vertex_name)) throw DuplicateElementException("Vertex " + vertex_name + " already exists");
	if (!isNamed()) throw OperationNotSupportedException("Cannot add a named vertex to an unnamed network");
	max_vertex_id++;
	vertex_id new_vertex_id = max_vertex_id;
	vertexes.insert(new_vertex_id);
	vertex_id_to_name[new_vertex_id] = vertex_name;
	vertex_name_to_id[vertex_name] = new_vertex_id;
	return new_vertex_id;
}
예제 #13
0
vertex_id MultiplexNetwork::getVertexId(global_identity gvid, network_id nid) const {
	if (!containsVertex(gvid,nid)) throw ElementNotFoundException("global identity " + std::to_string(gvid) + " in network " + std::to_string(nid));
	return global_to_local_id.at(gvid).at(nid);
}
vertex_id MultipleNetwork::getLocalVertexId(global_vertex_id gvid, network_id nid) {
	if (!containsVertex(gvid,nid)) throw ElementNotFoundException("global vertex " + std::to_string(gvid) + " in network " + std::to_string(nid));
	return global_to_local_id[gvid][nid];
}
예제 #15
0
void Network::setStringEdgeAttribute(const std::string& vertex_name1, const std::string& vertex_name2, const std::string& attribute_name, const std::string& val) {
	if (!isNamed()) throw OperationNotSupportedException("Cannot reference a named vertex in an unnamed network");
	if (!containsVertex(vertex_name1)) throw ElementNotFoundException("Vertex " + vertex_name1);
	if (!containsVertex(vertex_name2)) throw ElementNotFoundException("Vertex " + vertex_name2);
	setStringEdgeAttribute(vertex_name_to_id.at(vertex_name1), vertex_name_to_id.at(vertex_name2), attribute_name, val);
}
void MultipleNetwork::map(std::string global_vertex_name, std::string local_vertex_name, std::string network_name) {
	if (!containsVertex(global_vertex_name)) throw ElementNotFoundException("global vertex name " + global_vertex_name);
	if (!getNetwork(network_name)->containsVertex(local_vertex_name)) throw ElementNotFoundException("local vertex name " + local_vertex_name);
	if (!containsNetwork(network_name)) throw ElementNotFoundException("network " + network_name);
	map(getVertexId(global_vertex_name),getNetwork(network_name)->getVertexId(local_vertex_name),getNetworkId(network_name));
}
std::string MultipleNetwork::getVertexName(global_vertex_id gvid) {
	if (!containsVertex(gvid)) throw ElementNotFoundException("global vertex id " + std::to_string(gvid));
	return vertex_id_to_name[gvid];
}
예제 #18
0
double Network::getNumericEdgeAttribute(const std::string& vertex_name1, const std::string& vertex_name2, const std::string& attribute_name) const {
	if (!isNamed()) throw OperationNotSupportedException("Cannot reference a named vertex in an unnamed network");
	if (!containsVertex(vertex_name1)) throw ElementNotFoundException("Vertex " + vertex_name1);
	if (!containsVertex(vertex_name2)) throw ElementNotFoundException("Vertex " + vertex_name2);
	return getNumericEdgeAttribute(vertex_name_to_id.at(vertex_name1), vertex_name_to_id.at(vertex_name2), attribute_name);
}
bool MultipleNetwork::containsVertex(std::string global_vertex_name, std::string network_name) {
	global_vertex_id global_id = getVertexId(global_vertex_name);
	network_id net = getNetworkId(network_name);
	return containsVertex(global_id,net);
}
예제 #20
0
edge_id Network::addEdge(const std::string& vertex_name1, const std::string& vertex_name2, double weight) {
	if (!isNamed()) throw OperationNotSupportedException("Cannot reference a named vertex in an unnamed network");
	if (!containsVertex(vertex_name1)) throw ElementNotFoundException("Vertex " + vertex_name1);
	if (!containsVertex(vertex_name2)) throw ElementNotFoundException("Vertex " + vertex_name2);
	return addEdge(vertex_name_to_id[vertex_name1],vertex_name_to_id[vertex_name2], weight);
}
예제 #21
0
bool MultiplexNetwork::containsVertex(const std::string& global_identity_name, const std::string& network_name) const {
	global_identity global_id = getGlobalIdentity(global_identity_name);
	network_id net = getNetworkId(network_name);
	return containsVertex(global_id,net);
}
예제 #22
0
std::string Network::getVertexName(vertex_id vid) const  {
	if (!isNamed()) throw OperationNotSupportedException("Cannot reference a named vertex in an unnamed network");
	if (!containsVertex(vid)) throw ElementNotFoundException("Vertex " + std::to_string(vid));
	return vertex_id_to_name.at(vid);
}
예제 #23
0
bool Network::containsEdge(const std::string& vertex_name1, const std::string& vertex_name2) const {
	if (!isNamed()) throw OperationNotSupportedException("Cannot reference a named edge in an unnamed network");
	if (!containsVertex(vertex_name1)) return false;
	if (!containsVertex(vertex_name2)) return false;
	return containsEdge(vertex_name_to_id.at(vertex_name1),vertex_name_to_id.at(vertex_name2));
}
예제 #24
0
bool Network::deleteVertex(const std::string& vertex_name) {
	if (!isNamed()) throw OperationNotSupportedException("Cannot reference a named vertex in an unnamed network");
	if (!containsVertex(vertex_name)) return false;
	deleteVertex(vertex_name_to_id[vertex_name]);
	return true;
}
예제 #25
0
vertex_id Network::getVertexId(const std::string& vertex_name) const  {
	if (!isNamed()) throw OperationNotSupportedException("Cannot reference a named vertex in an unnamed network");
	if (!containsVertex(vertex_name)) throw ElementNotFoundException("Vertex " + vertex_name);
	return vertex_name_to_id.at(vertex_name);
}
global_vertex_id MultipleNetwork::getVertexId(std::string global_vertex_name) {
	if (!containsVertex(global_vertex_name)) throw ElementNotFoundException("global vertex name " + global_vertex_name);
	return vertex_name_to_id[global_vertex_name];
}
예제 #27
0
bool Polygon::intersects(const Polygon& other) const {
    return containsVertex(other) || other.containsVertex(*this);
}
예제 #28
0
long Network::getInDegree(vertex_id vid) const  {
	if (!containsVertex(vid)) throw ElementNotFoundException("Vertex " + std::to_string(vid));
	if (in_edges.count(vid)==0) return 0;
	return in_edges.at(vid).size();
}