Beispiel #1
0
AdjacencyMatrix DijkstraFinder::find( const QgsPoint& frontPoint, const QgsPoint& backPoint )
{
  std::map< QgsPoint , DijkstraFinder::DijkstraIterator, QgsPointCompare> r = find( frontPoint );
  std::map< QgsPoint , DijkstraFinder::DijkstraIterator, QgsPointCompare>::iterator it;
  if ( r.find( backPoint ) == r.end() )
  {
    return AdjacencyMatrix();
  }

  AdjacencyMatrix m;
  m[ frontPoint ];
  QgsPoint nextPoint = backPoint;
  QgsPoint firstPoint = backPoint;
  while ( true )
  {
    if ( firstPoint != nextPoint )
      m[ nextPoint ][ firstPoint ] = mAdjacencyMatrix.find( nextPoint )->second.find( firstPoint )->second;

    if ( r[ nextPoint ].mFrontPoint == r[ nextPoint ].mBackPoint )
      break;
    firstPoint = nextPoint;
    nextPoint = r[ nextPoint ].mFrontPoint;
  }
  return m;
} // DijkstraFinder::find( const QgsPoint& frontPoint, const QgsPoint& backPoint )
int main()
{
    int a[100][100],n;
    printf("enter the number of vertices\n");
    scanf("%d",&n);
    AdjacencyMatrix(a,n);
    kruskal(a,n);
    return 0;
}
int main()
{
	int a[100][100],n,*q;
	printf("Enter the number of vertices\n");
	scanf("%d",&n);
	q = (int *)malloc(sizeof(int)*n);
	AdjacencyMatrix(a,n);
	printdfs(a,n,q);
	return 0;
}
TEST(AdjacencyMatrixGTest, testSmallAdjacencyMatrix) {
	Graph graph(6);
	graph.addEdge(0,0);
	graph.addEdge(0,1);
	graph.addEdge(0,4);
	graph.addEdge(1,2);
	graph.addEdge(1,4);
	graph.addEdge(2,3);
	graph.addEdge(3,4);
	graph.addEdge(3,5);

	AdjacencyMatrix mat(graph);

	// first row
	EXPECT_EQ(1, mat(0,0));
	EXPECT_EQ(1, mat(0,1));
	EXPECT_EQ(0, mat(0,2));
	EXPECT_EQ(0, mat(0,3));
	EXPECT_EQ(1, mat(0,4));
	EXPECT_EQ(0, mat(0,5));

	// third row
	EXPECT_EQ(0, mat(2,0));
	EXPECT_EQ(1, mat(2,1));
	EXPECT_EQ(0, mat(2,2));
	EXPECT_EQ(1, mat(2,3));
	EXPECT_EQ(0, mat(2,4));
	EXPECT_EQ(0, mat(2,5));

	// fifth row
	EXPECT_EQ(1, mat(4,0));
	EXPECT_EQ(1, mat(4,1));
	EXPECT_EQ(0, mat(4,2));
	EXPECT_EQ(1, mat(4,3));
	EXPECT_EQ(0, mat(4,4));
	EXPECT_EQ(0, mat(4,5));


	// directed, weighted graph
	Graph dGraph(4, true, true);
	dGraph.addEdge(0,1,2);
	dGraph.addEdge(0,0, 42);
	dGraph.addEdge(2,3,-3);
	dGraph.addEdge(3,2,5);

	mat = AdjacencyMatrix(dGraph);
	ASSERT_EQ(dGraph.numberOfNodes(), mat.numberOfRows());
	ASSERT_EQ(dGraph.numberOfNodes(), mat.numberOfColumns());

	EXPECT_EQ(2, mat(0,1));
	EXPECT_EQ(0, mat(1,0));
	EXPECT_EQ(42, mat(0,0));
	EXPECT_EQ(-3, mat(2,3));
	EXPECT_EQ(5, mat(3,2));
}
Beispiel #5
0
void Graph::setWayPointList(const QList<WayPoint>* const wpl)
{
    QVector<WayPoint> wayPoints;

    // completely useless, i believe
    numVertices = wpl->size();
    wayPoints.reserve(numVertices);

    for(int i=0;i<wpl->size();i++)
        wayPoints.push_back(wpl->at(i));

    // build the adjacency "matrix" (really just a vector)
    this->adjMat = AdjacencyMatrix(wayPoints);
}