コード例 #1
0
TEST_F(GraphToolsGTest, testRestoreGraph) {
	Graph G(10,false,true);
	G.removeNode(0);
	G.removeNode(2);
	G.removeNode(4);
	G.removeNode(6);
	G.removeNode(8);
	G.addEdge(1,3);
	G.addEdge(5,3);
	G.addEdge(7,5);
	G.addEdge(7,9);
	G.addEdge(1,9);
	auto nodeMap = GraphTools::getContinuousNodeIds(G);
	auto invertedNodeMap = GraphTools::invertContinuousNodeIds(nodeMap,G);
	std::vector<node> reference = {1,3,5,7,9,10};


	EXPECT_EQ(6,invertedNodeMap.size());
	EXPECT_EQ(reference,invertedNodeMap);

	auto Gcompact = GraphTools::getCompactedGraph(G,nodeMap);
	Graph Goriginal = GraphTools::restoreGraph(invertedNodeMap,Gcompact);

	EXPECT_EQ(Goriginal.totalEdgeWeight(),Gcompact.totalEdgeWeight());
	EXPECT_NE(Goriginal.upperNodeIdBound(),Gcompact.upperNodeIdBound());
	EXPECT_EQ(Goriginal.numberOfNodes(),Gcompact.numberOfNodes());
	EXPECT_EQ(Goriginal.numberOfEdges(),Gcompact.numberOfEdges());
	EXPECT_EQ(Goriginal.isDirected(),Gcompact.isDirected());
	EXPECT_EQ(Goriginal.isWeighted(),Gcompact.isWeighted());
}
コード例 #2
0
ファイル: ErdosRenyi_opt.cpp プロジェクト: CxAalto/lcelib
int main(int argc, char* argv[]) { 
  
  if ( argc < 4 )
    {
      std::cerr << "\nPlease specify arguments: \n\tN, p, randseed\n\n"; exit(1);
    }

  size_t netSize = atoi(argv[1]);
  float p = atof(argv[2]);
  size_t randseed = atoi(argv[3]);
  
  RandNumGen<> generator(randseed); 
  NetType net(netSize); 

  // Generate the network
  ErdosRenyi2(net, p, generator);

  std::auto_ptr<NetType> netPointer2(findLargestComponent<NetType>(net)); 
  NetType& net2 = *netPointer2;  // Create a reference for easier handling of net.

  // Calculate average clustering coefficient
  double avg_clust = 0;
  for (size_t i = 0; i < net.size(); i++)
      avg_clust += clusteringCoefficient(net, i);

  size_t edges = numberOfEdges(net2);
  std::cout << net2.size() << " " << (double)2*edges/net2.size() << " " << avg_clust/net2.size() << " " << pearsonCoeff(net2) << "\n";
}
コード例 #3
0
TEST_F(GraphToolsGTest, testGetCompactedGraphUndirectedWeighted1) {
	Graph G(10,true,false);
	G.removeNode(0);
	G.removeNode(2);
	G.removeNode(4);
	G.removeNode(6);
	G.removeNode(8);
	G.addEdge(1,3,0.2);
	G.addEdge(5,3,2132.351);
	G.addEdge(7,5,3.14);
	G.addEdge(7,9,2.7);
	G.addEdge(1,9,0.12345);

	auto nodeMap = GraphTools::getContinuousNodeIds(G);
	auto Gcompact = GraphTools::getCompactedGraph(G,nodeMap);
	
	EXPECT_EQ(G.totalEdgeWeight(),Gcompact.totalEdgeWeight());
	EXPECT_NE(G.upperNodeIdBound(),Gcompact.upperNodeIdBound());
	EXPECT_EQ(G.numberOfNodes(),Gcompact.numberOfNodes());
	EXPECT_EQ(G.numberOfEdges(),Gcompact.numberOfEdges());
	EXPECT_EQ(G.isDirected(),Gcompact.isDirected());
	EXPECT_EQ(G.isWeighted(),Gcompact.isWeighted());
	// TODOish: find a deeper test to check if the structure of the graphs are the same, 
	// probably compare results of some algorithms or compare each edge with a reference node id map.
}
コード例 #4
0
ファイル: Marsili_opt.cpp プロジェクト: CxAalto/lcelib
int main(int argc, char* argv[]) { 
  
  struct MarsiliArgs args;
  readMarsiliArgs(args, argc, argv);
  
  RandNumGen<> generator(args.randseed); 
  _NetType net(args.netSize); 

  //time_t starttime = time(NULL);

  // Generate the network
  Marsili(net, args, generator);

  //time_t endtime = time(NULL);
  //std::cerr << "Time taken by generation: " << difftime(endtime, starttime) << " s\n";

  std::auto_ptr<_NetType> netPointer2(findLargestComponent<_NetType>(net)); 
  _NetType& net2 = *netPointer2;  // Create a reference for easier handling of net.

  double avg_clust = 0;
  for (size_t i = 0; i < net2.size(); i++)
      avg_clust += clusteringCoefficient(net2, i);

  size_t edges = numberOfEdges(net2);
  std::cout << net2.size() << " " << (double)2*edges/net2.size() << " " << avg_clust/net2.size() << " " << pearsonCoeff2(net2) << "\n";
}
コード例 #5
0
unsigned int ParallelCoordinatesGraphProxy::getDataCount() const {
  if (getDataLocation() == NODE) {
    return numberOfNodes();
  } else {
    return numberOfEdges();
  }
}
コード例 #6
0
ファイル: FloatPolygon.cpp プロジェクト: Wrichik1999/webkit
bool FloatPolygon::containsEvenOdd(const FloatPoint& point) const
{
    unsigned crossingCount = 0;
    for (unsigned i = 0; i < numberOfEdges(); ++i) {
        const FloatPoint& vertex1 = edgeAt(i).vertex1();
        const FloatPoint& vertex2 = edgeAt(i).vertex2();
        if (isPointOnLineSegment(vertex1, vertex2, point))
            return true;
        if ((vertex1.y() <= point.y() && vertex2.y() > point.y()) || (vertex1.y() > point.y() && vertex2.y() <= point.y())) {
            float vt = (point.y()  - vertex1.y()) / (vertex2.y() - vertex1.y());
            if (point.x() < vertex1.x() + vt * (vertex2.x() - vertex1.x()))
                ++crossingCount;
        }
    }
    return crossingCount & 1;
}
コード例 #7
0
ファイル: FloatPolygon.cpp プロジェクト: Wrichik1999/webkit
bool FloatPolygon::containsNonZero(const FloatPoint& point) const
{
    int windingNumber = 0;
    for (unsigned i = 0; i < numberOfEdges(); ++i) {
        const FloatPoint& vertex1 = edgeAt(i).vertex1();
        const FloatPoint& vertex2 = edgeAt(i).vertex2();
        if (isPointOnLineSegment(vertex1, vertex2, point))
            return true;
        if (vertex2.y() < point.y()) {
            if ((vertex1.y() > point.y()) && (leftSide(vertex1, vertex2, point) > 0))
                ++windingNumber;
        } else if (vertex2.y() > point.y()) {
            if ((vertex1.y() <= point.y()) && (leftSide(vertex1, vertex2, point) < 0))
                --windingNumber;
        }
    }
    return windingNumber;
}
コード例 #8
0
ファイル: basic_analysis.cpp プロジェクト: CxAalto/lcelib
int main(int argc, char* argv[])
{

  /* Read network from stdin. Using a pointer to a network, since we
     don't know how many nodes and edges we will read */
  std::auto_ptr<NetType> netPointer(readNet<EdgeData>());
  NetType& net = *netPointer;  // Create a reference for easier handling of net.

  
  // Go through all nodes and calculate their degree and clustering coeff
  std::cerr << "Node_ID Degree Clustering_coeff\n";
  float degree = 0, avg_degree = 0;
  float clust = 0, avg_clust = 0;
  double neighbour_degree = 0;
  for (size_t i = 0; i < net.size(); i++)
    {
      // Degree
      degree = net(i).size();
      avg_degree += degree;

      // Clustering coefficient
      clust = clusteringCoefficient(net, i);
      avg_clust += clust;

      // Calculate average neighbour degree
      neighbour_degree = 0;
      for (NetType::edge_iterator j = net[i].begin();
	   !j.finished();
	   ++j)
	{
	  neighbour_degree += net(*j).size();
	}
      neighbour_degree /= net(i).size();
 
      std::cout << i << ' ' << degree << ' ' << neighbour_degree << ' ' << clust << '\n';
    }

  avg_degree /= net.size();
  avg_clust /= net.size();

  std::cout << net.size() << ' ' << numberOfEdges(net) << ' ' << avg_degree << " " << avg_clust << '\n';
}
コード例 #9
0
ファイル: Davidsen_opt.cpp プロジェクト: CxAalto/lcelib
int main(int argc, char* argv[]) { 
  
  struct DavidsenArgs args;
  readDavidsenArgs(args, argc, argv);
  
  RandNumGen<> generator(args.randseed); 
  NetType net(args.netSize); 

  /* Generate the network and do something with it */
  Davidsen(net, args, generator);

  // Analyse only the largest component.
  std::auto_ptr<NetType> netPointer2(findLargestComponent<NetType>(net)); 
  NetType& net2 = *netPointer2;  // Create a reference for easier handling of net.

  double avg_clust = 0;
  for (size_t i = 0; i < net2.size(); i++)
      avg_clust += clusteringCoefficient(net2, i);

  size_t edges = numberOfEdges(net2);
  std::cout << net2.size() << " " << (double)2*edges/net2.size() << " " << avg_clust/net2.size() << " " << pearsonCoeff2(net2) << "\n";
}
コード例 #10
0
TEST_F(GraphToolsGTest, testGetCompactedGraphUndirectedUnweighted1) {
	Graph G(10,false,false);
	G.addEdge(0,1);
	G.addEdge(2,1);
	G.addEdge(0,3);
	G.addEdge(2,4);
	G.addEdge(3,6);
	G.addEdge(4,8);
	G.addEdge(5,9);
	G.addEdge(3,7);
	G.addEdge(5,7);

	auto nodeMap = GraphTools::getContinuousNodeIds(G);
	auto Gcompact = GraphTools::getCompactedGraph(G,nodeMap);
	
	EXPECT_EQ(G.numberOfNodes(),Gcompact.numberOfNodes());
	EXPECT_EQ(G.numberOfEdges(),Gcompact.numberOfEdges());
	EXPECT_EQ(G.isDirected(),Gcompact.isDirected());
	EXPECT_EQ(G.isWeighted(),Gcompact.isWeighted());
	// TODOish: find a deeper test to check if the structure of the graphs are the same, 
	// probably compare results of some algorithms or compare each edge with a reference node id map.
}
コード例 #11
0
ファイル: Wong_opt.cpp プロジェクト: CxAalto/lcelib
int main(int argc, char* argv[]) { 
  
  struct WongArgs args;
  readWongArgs(args, argc, argv);
  
  RandNumGen<> generator(args.randseed); 
  NetType net(args.netSize); 

  // Generate the network
  Wong(net, args, generator);

  std::auto_ptr<NetType> netPointer2(findLargestComponent<NetType>(net)); 
  NetType& net2 = *netPointer2;  // Create a reference for easier handling of net.
  
  // Calculate average clustering coefficient
  double avg_clust = 0;
  for (size_t i = 0; i < net2.size(); i++)
      avg_clust += clusteringCoefficient(net2, i);

  size_t edges = numberOfEdges(net2);
  std::cout << net2.size() << " " << (double)2*edges/net2.size() << " " << avg_clust/net2.size() << " " << pearsonCoeff2(net2) << "\n";
}
コード例 #12
0
WXSmoothEdge *WXFaceLayer::BuildSmoothEdge()
{
	// if the smooth edge has already been built: exit
	if (_pSmoothEdge)
		return _pSmoothEdge;
	real ta, tb;
	WOEdge *woea(0), *woeb(0);
	bool ok = false;
	vector<int> cuspEdgesIndices;
	int indexStart, indexEnd;
	unsigned nedges = _pWXFace->numberOfEdges();
	if (_nNullDotP == nedges) {
		_pSmoothEdge = NULL;
		return _pSmoothEdge;
	}
	if ((_nPosDotP != 0) && (_nPosDotP != _DotP.size()) && (_nNullDotP == 0)) {
		// that means that we have a smooth edge that starts from an edge and ends at an edge
		//-----------------------------
		// We retrieve the 2 edges for which we have opposite signs for each extremity
		RetrieveCuspEdgesIndices(cuspEdgesIndices);
		if (cuspEdgesIndices.size() != 2) // we necessarly have 2 cusp edges
			return 0;

		// let us determine which cusp edge corresponds to the starting:
		// We can do that because we defined that a silhouette edge had the back facing part on its right.
		// So if the WOEdge woea is such that woea[0].dotp > 0 and woea[1].dotp < 0, it is the starting edge.
		//-------------------------------------------

		if (_DotP[cuspEdgesIndices[0]] > 0) {
			woea = _pWXFace->GetOEdge(cuspEdgesIndices[0]);
			woeb = _pWXFace->GetOEdge(cuspEdgesIndices[1]);
			indexStart = cuspEdgesIndices[0];
			indexEnd = cuspEdgesIndices[1];
		}
		else {
			woea = _pWXFace->GetOEdge(cuspEdgesIndices[1]);
			woeb = _pWXFace->GetOEdge(cuspEdgesIndices[0]);
			indexStart = cuspEdgesIndices[1];
			indexEnd = cuspEdgesIndices[0];
		}

		// Compute the interpolation:
		ta = _DotP[indexStart] / (_DotP[indexStart] - _DotP[(indexStart + 1) % nedges]);
		tb = _DotP[indexEnd] / (_DotP[indexEnd] - _DotP[(indexEnd + 1) % nedges]);
		ok = true;
	}
	else if (_nNullDotP == 1) {
		// that means that we have exactly one of the 2 extremities of our silhouette edge is a vertex of the mesh
		if ((_nPosDotP == 2) || (_nPosDotP == 0)) {
			_pSmoothEdge = NULL;
			return _pSmoothEdge;
		}
		RetrieveCuspEdgesIndices(cuspEdgesIndices);
		// We should have only one EdgeCusp:
		if (cuspEdgesIndices.size() != 1) {
			if (G.debug & G_DEBUG_FREESTYLE) {
				cout << "Warning in BuildSmoothEdge: weird WXFace configuration" << endl;
			}
			_pSmoothEdge = NULL;
			return NULL;
		}
		unsigned index0 = Get0VertexIndex(); // retrieve the 0 vertex index
		unsigned nedges = _pWXFace->numberOfEdges();
		if (_DotP[cuspEdgesIndices[0]] > 0) {
			woea = _pWXFace->GetOEdge(cuspEdgesIndices[0]);
			woeb = _pWXFace->GetOEdge(index0);
			indexStart = cuspEdgesIndices[0];
			ta = _DotP[indexStart] / (_DotP[indexStart] - _DotP[(indexStart + 1) % nedges]);
			tb = 0.0;
		}
		else {
			woea = _pWXFace->GetOEdge(index0);
			woeb = _pWXFace->GetOEdge(cuspEdgesIndices[0]);
			indexEnd = cuspEdgesIndices[0];
			ta = 0.0;
			tb = _DotP[indexEnd] / (_DotP[indexEnd] - _DotP[(indexEnd + 1) % nedges]);
		}
		ok = true;
	}
	else if (_nNullDotP == 2) {
		// that means that the silhouette edge is an edge of the mesh
		int index = GetSmoothEdgeIndex();
		if (!_pWXFace->front()) {  // is it in the right order ?
			// the order of the WOEdge index is wrong
			woea = _pWXFace->GetOEdge((index + 1) % nedges);
			woeb = _pWXFace->GetOEdge((index - 1) % nedges);
			ta = 0;
			tb = 1;
			ok = true;
		}
		else {
			// here it's not good, our edge is a single point -> skip that face
			ok = false;
#if 0
			// the order of the WOEdge index is good
			woea = _pWXFace->GetOEdge((index - 1) % nedges);
			woeb = _pWXFace->GetOEdge((index + 1) % nedges);
			ta = 1;
			tb = 0;
#endif
		}
	}
	if (ok) {
		_pSmoothEdge = new WXSmoothEdge;
		_pSmoothEdge->setWOeA(woea);
		_pSmoothEdge->setWOeB(woeb);
		_pSmoothEdge->setTa(ta);
		_pSmoothEdge->setTb(tb);
		if (_Nature & Nature::SILHOUETTE) {
			if (_nNullDotP != 2) {
				if (_DotP[_ClosestPointIndex] + 0.01 > 0)
					_pSmoothEdge->setFront(true);
				else
					_pSmoothEdge->setFront(false);
			}
		}
	}

#if 0
	// check bording edges to see if they have different dotp values in bording faces.
	for (int i = 0; i < numberOfEdges(); i++) {
		WSFace *bface = (WSFace *)GetBordingFace(i);
		if (bface) {
			if ((front()) ^ (bface->front())) { // fA->front XOR fB->front (true if one is 0 and the other is 1)
				// that means that the edge i of the face is a silhouette edge
				// CHECK FIRST WHETHER THE EXACTSILHOUETTEEDGE HAS NOT YET BEEN BUILT ON THE OTHER FACE (1 is enough).
				if (((WSExactFace *)bface)->exactSilhouetteEdge()) {
					// that means that this silhouette edge has already been built
					return ((WSExactFace *)bface)->exactSilhouetteEdge();
				}
				// Else we must build it
				WOEdge *woea, *woeb;
				real ta, tb;
				if (!front()) { // is it in the right order ?
					// the order of the WOEdge index is wrong
					woea = _OEdgeList[(i + 1) % numberOfEdges()];
					if (0 == i)
						woeb = _OEdgeList[numberOfEdges() - 1];
					else
						woeb = _OEdgeList[(i - 1)];
					ta = 0;
					tb = 1;
				}
				else {
					// the order of the WOEdge index is good
					if (0 == i)
						woea = _OEdgeList[numberOfEdges() - 1];
					else
						woea = _OEdgeList[(i - 1)];
					woeb = _OEdgeList[(i + 1) % numberOfEdges()];
					ta = 1;
					tb = 0;
				}

				_pSmoothEdge = new ExactSilhouetteEdge(ExactSilhouetteEdge::VERTEX_VERTEX);
				_pSmoothEdge->setWOeA(woea);
				_pSmoothEdge->setWOeA(woeb);
				_pSmoothEdge->setTa(ta);
				_pSmoothEdge->setTb(tb);

				return _pSmoothEdge;
			}
		}
	}
#endif
	return _pSmoothEdge;
}
コード例 #13
0
ファイル: PlanRepInc.cpp プロジェクト: lncosie/ogdf
int PlanRepInc::genusLayout(Layout &drawing) const
{
	Graph testGraph;
	GraphAttributes AG(testGraph, GraphAttributes::nodeGraphics |
		GraphAttributes::edgeGraphics |
		GraphAttributes::nodeStyle |
		GraphAttributes::edgeStyle
		);
	Layout xy;
	NodeArray<node> tcopy(*this, 0);
	EdgeArray<bool> finished(*this, false);
	EdgeArray<edge> eOrig(testGraph, 0);
	Color invalid(0,0,0,0);
	EdgeArray<Color> eCol(*this, invalid);

	if (numberOfNodes() == 0) return 0;

	int nIsolated = 0;
	for(node v : nodes)
		if (v->degree() == 0) ++nIsolated;

	NodeArray<int> component(*this);
	int nCC = connectedComponents(*this,component);

	AdjEntryArray<bool> visited(*this,false);
	int nFaceCycles = 0;

	int colBase = 3;
	int colBase2 = 250;
	for(node v : nodes)
	{
		Color col =Color(colBase,colBase2,colBase);
		colBase = (colBase*3) % 233;
		colBase2 = (colBase*2) % 233;

		if (tcopy[v] == 0)
		{
			node u = testGraph.newNode();
			tcopy[v] = u;
			AG.x(u) = drawing.x(v);
			AG.y(u) = drawing.y(v);
			AG.fillColor(u) = col;
			AG.strokeColor(u) = Color::Red;
			AG.strokeWidth(u) = 8;
		}//if

		for(adjEntry adj1 : v->adjEdges) {
			bool handled = visited[adj1];
			adjEntry adj = adj1;

			do {
				node z = adj->theNode();
				if (tcopy[z] == 0)
				{
					node u1 = testGraph.newNode();
					tcopy[z] = u1;
					AG.x(u1) = drawing.x(z);
					AG.y(u1) = drawing.y(z);
					AG.fillColor(u1) = col;
				}//if not yet inserted in the copy
				if (!finished[adj->theEdge()])
				{
					node w = adj->theEdge()->opposite(z);
					if (tcopy[w] != 0)
					{
						edge e;
						if (w == adj->theEdge()->source())
							e = testGraph.newEdge(tcopy[w], tcopy[z]);
						else e = testGraph.newEdge(tcopy[z], tcopy[w]);
						eOrig[e] = adj->theEdge();
						if (eCol[adj->theEdge()] == invalid)
							AG.strokeColor(e) = eCol[adj->theEdge()];
						else
						{
							eCol[adj->theEdge()] = col;
							AG.strokeColor(e) = col;
						}
						finished[adj->theEdge()] = true;
					}
					/*
					else
					{
						eCol[adj->theEdge()] = col;
					}*/

				}
				visited[adj] = true;
				adj = adj->faceCycleSucc();
			} while (adj != adj1);

			if (handled) continue;

			++nFaceCycles;
		}
	}
	//insert the current embedding order by setting bends
	//for(node v : testGraph.nodes)
	//{
	//	adjEntry ad1 = v->firstAdj();
	//}

	int genus = (numberOfEdges() - numberOfNodes() - nIsolated - nFaceCycles + 2*nCC) / 2;
	//if (genus != 0)
	{
		GraphIO::writeGML(AG, "GenusErrorLayout.gml");
	}
	return genus;
}