Advertisement
Sidsh

Dijkstra rough

Feb 4th, 2022
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Dijkstra2 ();
  2.  
  3. reg [11:0] cost [0:49][0:49];
  4.  
  5. reg [0:5] key;
  6.  
  7. input clk;
  8.  
  9. parameter inf = 999;
  10.  
  11.      always @(posedge clk)
  12.      begin
  13.      function automatic [0:49] getMin;
  14.      input [0:6] key;
  15.      input [0:6] i;
  16.      input [0:5] dist;
  17.      input [0:1] visited;
  18.         begin
  19.             for(i=0; i<n; i=i+1)
  20.                 if(!visited[i] && dist [i] < min)
  21.                 min <= dist[i];
  22.                 key <= i;
  23.  
  24.            end 
  25.        end     
  26.      endfunction
  27.      end
  28.      end
  29.  
  30.  
  31.  
  32. always @(posedge clk)
  33.    begin
  34.      
  35.      function dijkstra;
  36.         input [0:49] par;
  37.         input [0:49] dist;
  38.         input [0:49] visited = 0;
  39.         input [0:49] g;
  40.         input [0:9] k=0;
  41.         input [0:9] v=0;
  42.         dist[src] = 0;
  43.         par[src] = 1;
  44.         begin
  45.             for (k=0; k <=n-1; k=k+1)
  46.                 assign u = getMin(dist,visited);
  47.                  for    (v 0; v < n; v v+1)
  48.                     if(!visited[v] && (dist[u] + cost[u][v] < dist[v] && cost[u][v]! = 999 )
  49.                     begin
  50.                     par[v] = u;
  51.                     dist[v] = dist[u] + cost[u][v];
  52.                     end
  53.                    end
  54.                  end
  55.                 end
  56.             end
  57.         end
  58.      endfunction     
  59. par[src] = -1;
  60.       for(g=0; g<n-1; g=g+1)
  61.             if(!visited[v] && (dist[u] + cost[u][v] < dist[v] && cost[u][v]! = 999 )
  62.                 begin
  63.             par[v] = u;
  64.             dist[v] = dist[u] + cost[u][v];
  65.             end
  66.                 end
  67.  
  68.     end
  69. end
  70.  
  71. endmodule
  72.    
  73.  
  74.  
  75.  
  76.  
  77.        
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement