コード例 #1
0
ファイル: Graph.hpp プロジェクト: Tahuoszu/Hensei
string Graph<E>::getString()
{
    string graph_type = "digraph ";
    string graph_name = "G";
    string rankdir    = "rankdir = ";
    string dir        = "TB"; // "LR"
    string node_lab   = "node[label = \"";
    string shape      = "\", shape = ";
    string shapename  = "record"; // "circle"
    string fontname   = ", fontname = ";
    string font       = "Helvetica";
    string fontsize   = "\", fontsize = ";
    string size       = "10";

    std::stringstream os;
    os << graph_type << graph_name << " {\n";
    os << rankdir << dir <<  "\n";
    os << node_lab << shape << "]\n";

    typename set<E>::iterator node;
    for (node = getNodes().begin(); node != getNodes().end(); ++node) {
        os << node_lab << node->getLabel();
        os << fontname << font << fontsize << size << "];\n";
    }

    typename multimap<E, E>::iterator edge;
    for (edge = getEdges().begin(); edge != getEdges().end(); ++edge)
        os << edge->first  << " -> " << edge->second << ";\n";

    os << "}\n";

    return os.str();
}
コード例 #2
0
ファイル: MatrixGraph.cpp プロジェクト: iceslab/PEA_PROJEKT
uint MatrixGraph::greedyAlg(vector<uint> &bestRoute)
{
	priority_queue<Edge> beginBH;
	priority_queue<Edge> currBH;

	uint bestWeight = numeric_limits<unsigned int>::max();
	vector<uint> currRoute(vertexNumber + 1);
	bestRoute.reserve(vertexNumber + 1);
	vector<bool> visited(vertexNumber);

	// Petla sprawdzajaca wyjscie z kazdego wierzcholka
	// Zmieniono na < 1, bo ma sprawdzać tylko 1 cykl
	for (uint towns = 0; towns < 1; ++towns)
	{
		uint nextTown = towns;
		uint currWeight = 0;
		fill(visited.begin(), visited.end(), false);
		vector<Edge> tmpEdges;
		// Petla znajdowania cyklu
		for (uint i = 0; i < vertexNumber - 1; ++i)
		{
			tmpEdges = getEdges(nextTown);
			beginBH = priority_queue<Edge>(tmpEdges.begin(), tmpEdges.end());
			if (i < vertexNumber)
				visited[nextTown] = true;
			// Dodawanie ścieżki
			currRoute[i] = nextTown;

			while (visited[beginBH.top().end])
			{
				beginBH.pop();
			}

			currWeight += beginBH.top().weight;
			nextTown = beginBH.top().end;
		}

		currRoute[vertexNumber - 1] = nextTown;

		// Powrót do miasta startowego, pobranie krawędzi ostatniego miasta
		tmpEdges = getEdges(currRoute[vertexNumber - 1]);
		for (uint i = 0; i < tmpEdges.size(); ++i)
		{
			if (tmpEdges[i].end == towns)
			{
				currWeight += tmpEdges[i].weight;
				currRoute[vertexNumber] = towns;
			}
		}

		if (currWeight < bestWeight)
		{
			bestWeight = currWeight;
			bestRoute = currRoute;
		}
	}

	return bestWeight;
}
コード例 #3
0
/*
 * Assumes that _this_ is the smaller graph and computes the maximal
 * common edge set between _this_ and graph.
 */
std::vector<int> Graph::maximal_common_edge_set(const Graph *graph)
{
	unsigned int bestarcsleft = 0;
	std::vector<int> common(vertexs.size(), -1);
	std::vector<int> solution(vertexs.size(), -1);
	std::vector<bool> marcs(getEdges().size() * graph->getEdges().size(), true);
	std::vector<bool> used_val(graph->vertexs.size(), false);

	max_common_edge_set_bkt(0, marcs, used_val,
			vertexs, graph->getVertexs(),
			getEdges(), graph->getEdges(),
			common, solution, bestarcsleft);
	return solution;
}
コード例 #4
0
Iterator<unsigned int> *ParallelCoordinatesGraphProxy::getDataIterator() {
  if (getDataLocation() == NODE) {
    return new ParallelCoordinatesDataIterator<node>(getNodes());
  } else {
    return new ParallelCoordinatesDataIterator<edge>(getEdges());
  }
}
コード例 #5
0
ファイル: RayAngorythm.cpp プロジェクト: Andrey-Dubas/Graph
void rayAlhorythm(ElementContainer objects, int width, int height, EdgeInfo** validateEdges, int& count, int dWidth, int dHeight){
	ElementContainer::iterator it;
	EdgeInfo** edges = new EdgeInfo*[height];
	for(int i=0; i<height; ++i){
		edges[i] = new EdgeInfo[width];
	}
	int elemsAmount = objects.size();
	point* centers = new point[elemsAmount];
	int* radiuses = new int[elemsAmount];


	CordContainer* cords;
	it = objects.begin();
	for(int i=0; i<elemsAmount; ++i){
		cords = (*it)->convertedPos;
		getContainedCircle(cords->Cords, cords->rows, cords->cols, centers[i], radiuses[i]);
		defineVisibleEdges(edges, width, height, *cords, centers[i], radiuses[i], dWidth, dHeight);
		it++;
	}

	getEdges(edges, width, height, validateEdges, count, dWidth, dHeight);


	delete[] centers;
	delete[] radiuses;
	for(int i=0; i<height; ++i){
		delete [] edges[i];
	}
	delete [] edges;

}
コード例 #6
0
ファイル: formsegmentator.cpp プロジェクト: AlexeyKor/tools
void FormSegmentator::analyze(QList<Component> &objects, QList<Component> &edges)
{
	uniteComponents();
	objects = getObjects();
	edges = getEdges();
	return;
}
コード例 #7
0
istream& BipartiteGraph<VT>::get(istream& in)
{
    this->clear();
    getVertexes(in);
    getEdges(in);
    return in;
}
コード例 #8
0
void Matrix::readFromFile(std::string name)
{
	//otworz plik
	std::ifstream fin;
	fin.open(name.c_str());
	if (!fin.is_open()) {
		throw "Brak pliku z danymi";
	}
	fin >> verticles;
	std::cout << verticles;
	edges = ((getVerticles() * (getVerticles() - 1)) / 2);

	M = new int*[getVerticles()];
	for (int i = 0; i < getVerticles(); i++)
		M[i] = new int[getVerticles()];

	cleanMatrix();

	int start, end, weight;
	for (int i = 0; i < getEdges()	; i++) {
		fin >> start;
		fin >> end;
		fin >> weight;

		M[start][end] = weight;
		M[end][start] = weight;
	}
	fin.close();

	printMatrix();
}
コード例 #9
0
ファイル: kruskal.cpp プロジェクト: ashwath/heuristics2012
void kruskal(string dataFile, string outFile, int nverts,int nedges, map<int,int> local_to_global)
{
    int edgesAccepted = 0;
    DisjSets ds(nverts);
    vector<edge> edges = getEdges(dataFile, nedges);
    priority_queue<edge,vector<edge>,compareEdges> pq(edges.begin(), edges.end());
    edge e;

    ofstream out(outFile.c_str());
    while (edgesAccepted < nverts - 1) {
        e = pq.top();
        pq.pop();

        int uset = ds.find(e.v1);
        int vset = ds.find(e.v2);
        if (uset != vset) {
            out << local_to_global.find(e.v1)->second << " " << local_to_global.find(e.v2)->second << " " << e.weight << endl;
            //out << e.v1 << " " << e.v2 << " " << e.weight << endl;
            edgesAccepted++;
            ds.unionSets(uset, vset);
        }
    }
    out.close();

    /*
    	if (verifyMst(outFile, nverts, nedges) == false) {
    		exit(1);
    	}
    */
}
コード例 #10
0
ファイル: KBF2.hpp プロジェクト: lynxoid/kbf
 // constructor 1:
 // takes in kmer sets - kmers and potential edges (read edges)
 KBF2(const int k, unordered_set<kmer_t> & kmer_set, unordered_set<kmer_t> & edge_set, const unsigned extend_len = 1, const size_t size_factor = 10) : BaseBloomFilter(k, kmer_set.size(), size_factor), extend_len(extend_len){
   populate(kmer_set);
   getEdges(edge_set);
   cerr << "Edges: " << edge_kmers.size() << endl;
   extended_check = 0;
   edge_check = 0;
   edge_pass = 0;
 }
コード例 #11
0
ファイル: model.c プロジェクト: AaronPerl/OpenHand
void checkBoundaries(model m, long *size, vec3d **badEdges)
{
	vec3d *edges;
	long edgec;
	short *counts;
	int i;
	int k;
	long badCount=0;
	getEdges(m,&edgec,&edges);
	counts = (short*) malloc(sizeof(short)*edgec);
	for (i=0;i<edgec;i++)
	{
		counts[i] = 0;
	}
	for (i=0;i<m.objectc;i++)
	{
		object *obj = m.objects[i];
		vec3d *vertices = obj->vertices;
		int j;
		for (j=0;j<obj->facec;j++)
		{
			triangle face = obj->faces[j];
			vec3d fa = vertices[face.a];
			vec3d fb = vertices[face.b];
			vec3d fc = vertices[face.c];
			int k;
			for (k=0;k<edgec;k++)
			{
				vec3d a = edges[k*2];
				vec3d b = edges[k*2+1];
				if (equalsEdge(fa,fb,a,b))
					counts[k]++;
				if (equalsEdge(fa,fc,a,b))
					counts[k]++;
				if (equalsEdge(fb,fc,a,b))
					counts[k]++;
			}
		}
	}
	for (k=0;k<edgec;k++)
	{
		if (counts[k]<2)
		{
			if (badCount==0)
				*badEdges = (vec3d*)malloc(sizeof(vec3d)*2*(badCount+1));
			else
				*badEdges = (vec3d*)realloc(*badEdges,sizeof(vec3d)*2*(badCount+1));
			(*badEdges)[badCount*2+0]=edges[k*2+0];
			(*badEdges)[badCount*2+1]=edges[k*2+1];
			badCount++;
			printf("Bad edge : %d\n",k);
		}
	}
	*size = badCount;
	free(edges);
	free(counts);
}
コード例 #12
0
VOID CEdgeContainer::accept(CVisitor &visitor) const
{
	CIterator& iter = getEdges();
	while (!iter.isDone()) {
		CEdge& e = (CEdge&)iter.currentItem();
		visitor.visit(e);
	}
	delete &iter;
}
コード例 #13
0
ファイル: KBFSparseRelaxed.hpp プロジェクト: pombredanne/kbf
 // constructor actions
 void constructKBF(unordered_set<kmer_t> & kmer_set, unordered_set<kmer_t> & edge_set){
   populate(kmer_set);
   getEdges(edge_set);
   cerr << "Edges: " << edge_kmers.size() << endl;
   sparse_check = 0;
   extended_check = 0;
   edge_check = 0;
   edge_pass = 0;
 }
コード例 #14
0
ファイル: Graph.cpp プロジェクト: parrottsquawk/School
std::string Graph::getGraph(){
    std::string temp;
    temp += str_gdef;
    temp += getKeys();
    temp += str_head;
    temp += getNodes();
    temp += getEdges();
    temp += str_foot;
    return temp;
}
コード例 #15
0
RBox RImageData::getBoundingBox(bool ignoreEmpty) const {
    Q_UNUSED(ignoreEmpty)

    RBox ret;
    QList<RLine> edges = getEdges();
    for (int i=0; i<edges.size(); i++) {
        ret.growToInclude(edges.at(i).getBoundingBox());
    }
    return ret;
}
コード例 #16
0
ファイル: GridTile.cpp プロジェクト: Serinox/HexPlanet
FVector GridTile::getPosition(const float& radius) const
{
	FVector myPosition = FVector::ZeroVector;
	GridEdgePtrList edges = getEdges();
	for (const GridEdgePtr& edge : edges)
	{
		myPosition += edge->getPosition(radius);
	}
	return myPosition/edges.Num();
}
コード例 #17
0
/*
 * Computes the complement of _this_ graph and the nodes from the
 * vertex_subset where vertex_subset[i] = x means that node i in _this_
 * graph correspondes to node x in the other graph.
 */
Graph* Graph::subgraph_complement(std::vector<int> &vertex_subset)
{
	Graph* result = new Graph();
	std::vector< std::pair<Vertex*, Vertex*> > graph_edges = getEdges();
	for(unsigned int i = 0; i < vertex_subset.size(); i++)
		if(vertex_subset[i] == VERTEX_NONE)
			result->add_vertex(new Vertex(*vertexs[i]));

	result->generate_edges();
	return result;
}
コード例 #18
0
ファイル: GridTile.cpp プロジェクト: Serinox/HexPlanet
GridNodePtrList GridTile::getNodes() const
{
	GridEdgePtrList edges = getEdges();
	GridNodePtrList myNodes;
	for (const GridEdgePtr& edge : edges)
	{
		myNodes.AddUnique(edge->getStartPoint());
		myNodes.AddUnique(edge->getEndPoint());
	}
	return myNodes;
}
コード例 #19
0
ファイル: EdgeGeom.cpp プロジェクト: BlueQuartzSoftware/SIMPL
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
IGeometry::Pointer EdgeGeom::deepCopy()
{
  EdgeGeom::Pointer edgeCopy = EdgeGeom::CreateGeometry(getEdges(), getVertices(), getName());

  edgeCopy->setElementsContainingVert(getElementsContainingVert());
  edgeCopy->setElementNeighbors(getElementNeighbors());
  edgeCopy->setElementCentroids(getElementCentroids());
  edgeCopy->setSpatialDimensionality(getSpatialDimensionality());

  return edgeCopy;
}
コード例 #20
0
ファイル: InternalGraph.hpp プロジェクト: EfestoLab/TuttleOFX
	bool hasEdge( const vertex_descriptor& out, const vertex_descriptor& in, const std::string& inAttr ) const
	{
		const out_edge_range_t edges = getEdges( out, in );
		BOOST_FOREACH( const edge_descriptor ed, edges )
		{
			if( instance(ed).getInAttrName() == inAttr )
			{
				return true;
			}
		}
		return false;
	}
コード例 #21
0
std::vector<TopoFace*> TopoFace::getNeighbours() {
    std::vector<TopoFace*> neigh;

    for(auto edge : getEdges())
        neigh.insert(neigh.end(),edge->getFaces().begin(),edge->getFaces().end());

    std::sort(neigh.begin(),neigh.end());
    neigh.erase(std::unique(neigh.begin(),neigh.end()),neigh.end());
    auto pos = std::find(neigh.begin(),neigh.end(),this);
    if(pos!=neigh.end())
        neigh.erase(pos);
    return neigh;
}
コード例 #22
0
Edge< Node<T> >* selectEdgeWithLargestWeight(const std::vector<Node<T>*>& graph)
{
  std::map<Edge< Node<T> >*, bool> edges = getEdges(graph);
  Edge< Node<T> >* largest = NULL;
  for(typename std::map<Edge< Node<T> >*, bool>::const_iterator EI = edges.begin(); EI != edges.end(); ++EI)
  {
    if( getPositionedWeight(EI->first) > getPositionedWeight(largest) )
    {
      largest = EI->first;
    }
  }
  return largest;
}
コード例 #23
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
IGeometry::Pointer TriangleGeom::deepCopy()
{
  TriangleGeom::Pointer triCopy = TriangleGeom::CreateGeometry(getTriangles(), getVertices(), getName());

  triCopy->setEdges(getEdges());
  triCopy->setUnsharedEdges(getUnsharedEdges());
  triCopy->setElementsContainingVert(getElementsContainingVert());
  triCopy->setElementNeighbors(getElementNeighbors());
  triCopy->setElementCentroids(getElementCentroids());
  triCopy->setSpatialDimensionality(getSpatialDimensionality());

  return triCopy;
}
コード例 #24
0
void Bipartite::printGraph()  const{
	// Print X Y.
	printf("%d %d\n", xSize_, ySize_);
	// Print the number of edges.
	printf("%d\n", edges_);
	
	// Print edges (x,y).
	for(unsigned i = 0; i < xSize_; i++){
		std::list<unsigned> edges = getEdges(i);
		for(auto j = edges.begin() ; j != edges.end(); j++){
			printf("%d %d\n", i + 1, (*j) + 1 + xSize_);
		}
	}

	// Print edges (y,x).
	for(unsigned i = xSize_; i < xSize_ + ySize_; i++){
		std::list<unsigned> edges = getEdges(i);
		for(auto j = edges.begin() ; j != edges.end(); j++){
			printf("%d %d\n", i + 1, (*j) + 1);
		}
	}
}
コード例 #25
0
ファイル: QuadGeom.cpp プロジェクト: ravishivaraman/DREAM3D
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
IGeometry::Pointer QuadGeom::deepCopy()
{
  QuadGeom::Pointer quadCopy = QuadGeom::CreateGeometry(getQuads(), getVertices(), getName());

  quadCopy->setEdges(getEdges());
  quadCopy->setUnsharedEdges(getUnsharedEdges());
  quadCopy->setElementsContainingVert(getElementsContainingVert());
  quadCopy->setElementNeighbors(getElementNeighbors());
  quadCopy->setElementCentroids(getElementCentroids());
  quadCopy->setSpatialDimensionality(getSpatialDimensionality());

  return quadCopy;
}
コード例 #26
0
ファイル: InternalGraph.hpp プロジェクト: EfestoLab/TuttleOFX
	edge_descriptor getEdge( const VertexKey& out, const VertexKey& in, const std::string& inAttr ) const
	{
		const out_edge_range_t edges = getEdges( getVertexDescriptor(out), getVertexDescriptor(in) );
		BOOST_FOREACH( const edge_descriptor ed, edges )
		{
			if( instance(ed).getInAttrName() == inAttr )
			{
				return ed;
			}
		}
		BOOST_THROW_EXCEPTION( exception::Logic()
			<< exception::user() + "No connection in the graph from \"" + getVertex(out) + "\" to \"" + getVertex(in) + "/" + inAttr + "\"" );
	}
コード例 #27
0
ファイル: GridTile.cpp プロジェクト: Serinox/HexPlanet
float GridTile::getEnclosedVolume(const float& radius) const
{
	float volume = 0.0;
	FVector myPosition = getPosition(radius);
	GridEdgePtrList edges = getEdges();
	for (const GridEdgePtr& edge : edges)
	{
		FVector vec1 = edge->getStartPoint()->getPosition(radius) - myPosition;
		FVector vec2 = edge->getEndPoint()->getPosition(radius) - myPosition;
		FVector v1xv2 = FVector::CrossProduct(vec1, vec2);
		volume += FMath::Abs(FVector::DotProduct(v1xv2, myPosition)/6);
	}
	return volume;
}
コード例 #28
0
ファイル: Polygon2D.cpp プロジェクト: Jornason/ofxToxiclibs
bool toxi::geom::Polygon2D::intersectsPolygon( Polygon2D & p )
{
	for (Line2D ea : getEdges()) 
	{
		for (Line2D eb : p.getEdges()) 
		{
			toxi::geom::LineIntersection::Type isec = ea.intersectLine(eb).getType();
			if (isec == toxi::geom::LineIntersection::Type::INTERSECTING || isec == toxi::geom::LineIntersection::Type::COINCIDENT) 
			{
				return true;
			}
		}
	}
	return false;
}
コード例 #29
0
ファイル: Polygon2D.cpp プロジェクト: Jornason/ofxToxiclibs
toxi::geom::Vec2D toxi::geom::Polygon2D::getClosestPointTo( Vec2D & p )
{
	float minD = FLT_MAX;
	Vec2D q = Vec2D();
	for (Line2D l : getEdges()) 
	{
		Vec2D c = l.closestPointTo(p);
		float d = static_cast< float > ( c.distanceToSquared( p ) );
		if (d < minD) 
		{
			q = c;
			minD = d;
		}
	}
	return q;
}
コード例 #30
0
ファイル: Segmenter.cpp プロジェクト: gwichern/sirens
	void Segmenter::viterbi(int frame) {
		int edges = getEdges();
		
		// Compute costs for all possible next states.
		for (int new_index = 0; new_index < edges; new_index++) {
			for (int old_index = 0; old_index < edges; old_index++) {
				double cost_temp = 0;
				
				for (int feature_index = 0; feature_index < features.size(); feature_index++) {
					SegmentationParameters* parameters = features[feature_index]->getSegmentationParameters();
					
					newDistributions[feature_index][new_index][old_index].cost = KalmanLPF(
						y[feature_index],
						newDistributions[feature_index][new_index][old_index].covariance,
						newDistributions[feature_index][new_index][old_index].mean,
						parameters->getR(),
						parameters->q[modeMatrix[feature_index + 1][old_index] - 1][modeMatrix[feature_index + 1][new_index] - 1],
						parameters->getAlpha()
					);
					
					cost_temp += newDistributions[feature_index][new_index][old_index].cost;
				}
				
				costs[new_index][old_index] = oldCosts[old_index] + cost_temp - probabilityMatrix[new_index][old_index];
			}
		}
		
		// Find the next element with least cost along each path.
		for (int i = 0; i < costs.size(); i++) {
			vector<double>::iterator minimum_iterator = min_element(costs[i].begin(), costs[i].end());
			psi[frame][i] = distance(costs[i].begin(), minimum_iterator);
			oldCosts[i] = *minimum_iterator;
		}
		
		// Copy best filtered states and covariances.
		for (int i = 0; i < edges; i++) {
			for (int feature_index = 0; feature_index < features.size(); feature_index++) {
				for (int row = 0; row < 2; row++) {
					maxDistributions[feature_index][i].mean[row] = newDistributions[feature_index][i][psi[frame][i]].mean[row];
					
					for (int column = 0; column < 2; column++)
						maxDistributions[feature_index][i].covariance[row][column] = newDistributions[feature_index][i][psi[frame][i]].covariance[row][column];
				}
			}
		}
	}