Projects Inventory

Simulation of Routing Algorithms Gaming Project in C++

Explanation

  1. Graph Class:
    • Attributes:
      • adj: Adjacency list representation of the graph. Each vertex has a list of pairs representing adjacent vertices and edge weights.
      • Advertisement
    • Methods:
      • addEdge(int u, int v, int w): Adds an undirected edge between vertices u and v with weight w.
      • dijkstra(int src): Computes the shortest paths from source vertex src
        Advertisement
        using Dijkstra’s algorithm.
  2. Dijkstra’s Algorithm:
    • Purpose: Finds the shortest path from the source vertex to all other vertices in the graph.
    • Data Structures:
      • Priority Queue: Stores vertices to be processed, ordered by their current shortest distance.
      • Distance Vector: Maintains the shortest distance from the source to each vertex.
      • Visited Vector: Keeps track of vertices that have been processed.
    • Algorithm:
      • Initialize distances to all vertices as infinity, except the source vertex.
      • Use a priority queue to explore vertices with the smallest known distance.
      • Update distances based on the weights of the edges and the shortest paths found.
  3. Main Function:
    • Graph Creation: Initializes a graph with a specified number of vertices and adds edges.
    • Advertisement
    • Distance Calculation: Calls dijkstra to compute shortest paths from the source vertex.
    • Result Display: Prints the shortest distance from the source vertex to each vertex.

Usage

Exit mobile version