Skip to content

Commit 05628d2

Browse files
author
Navjinder Virdee
committed
Added few more comments.
1 parent 7cc628d commit 05628d2

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

Contraction Hierarchies/DistPreprocessSmall.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//Program to implement Contraction Hierarchies Algorithm
1+
//Program to implement Contraction Hierarchies Algorithm.
22

33
import java.util.Scanner;
44
import java.util.ArrayList;
@@ -38,7 +38,7 @@ public Distance(){
3838
}
3939
}
4040

41-
//in this ids are made for the same reason, to not have to reinitialize processed variable. for every query in bidirectional dijkstra.
41+
//in this ids are made for the same reason, to not have to reinitialize processed variable for every query in bidirectional dijkstra.
4242
static class Processed{
4343
boolean forwProcessed; //is processed in forward search.
4444
boolean revProcessed; //is processed in backward search.
@@ -51,7 +51,7 @@ public Processed(){
5151
}
5252
}
5353

54-
//class for Vertex
54+
//class for Vertex of a graph.
5555
static class Vertex{
5656
int vertexNum;//id of the vertex.
5757
ArrayList<Integer> inEdges; //list of incoming edges to this vertex.
@@ -66,10 +66,10 @@ static class Vertex{
6666
Distance distance;
6767
Processed processed;
6868

69-
//parameters for computing importance.
70-
int edgeDiff; //egdediff = sE - inE - outE.
71-
long delNeighbors; // number of contracted neighbors.
72-
int shortcutCover; // number of shotcuts to be introduces if this vertex is contracted.
69+
//parameters for computing importance according to which we will contract the vertices. Vertex wih least importance wil be contracted first.
70+
int edgeDiff; //egdediff = sE - inE - outE. (sE=inE*outE , i.e number of shortcuts that we may have to add.)
71+
long delNeighbors; //number of contracted neighbors.
72+
int shortcutCover; //number of shortcuts to be introduced if this vertex is contracted.
7373

7474
long importance; //total importance = edgediff + shortcutcover + delneighbors.
7575

@@ -155,8 +155,9 @@ private void computeImportance(Vertex [] graph, Vertex vertex){
155155

156156
while(PQImp.size()!=0){
157157
Vertex vertex = (Vertex)PQImp.poll();
158-
computeImportance(graph,vertex);//recompute importance before contractingthe vertex.
158+
computeImportance(graph,vertex);//recompute importance before contracting the vertex.
159159

160+
//if the vertex's recomputed importance is still minimum then contract it.
160161
if(PQImp.size()!=0 && vertex.importance > PQImp.peek().importance){
161162
PQImp.add(vertex);
162163
continue;
@@ -166,13 +167,14 @@ private void computeImportance(Vertex [] graph, Vertex vertex){
166167
vertex.orderPos = extractNum;
167168
extractNum = extractNum + 1;
168169

169-
contractNode(graph,vertex,extractNum-1);//contraction part.
170+
//contraction part.
171+
contractNode(graph,vertex,extractNum-1);
170172
}
171173
return nodeOrdering;
172174
}
173175

174176

175-
//update the neighbors of the contracted vertex that this this vertex is contracted.
177+
//update the neighbors of the contracted vertex that this vertex is contracted.
176178
private void calNeighbors(Vertex [] graph,ArrayList<Integer> inEdges, ArrayList<Integer> outEdges){
177179
for(int i=0;i<inEdges.size();i++){
178180
int temp =inEdges.get(i);
@@ -218,7 +220,7 @@ private void contractNode(Vertex [] graph, Vertex vertex, int contractId){
218220
}
219221
}
220222

221-
long max = inMax+outMax; //total max distance.
223+
long max = inMax+outMax; //total max distance.
222224

223225
for(int i=0;i<inEdges.size();i++){
224226
int inVertex = inEdges.get(i);
@@ -300,7 +302,7 @@ private boolean checkId(Vertex [] graph,int source,int target){
300302

301303
//main function of this class.
302304
public int [] processing(Vertex [] graph){
303-
computeImportance(graph);//find initial importance by traversing all vertices.
305+
computeImportance(graph);//find initial importance by traversing all vertices.
304306
int [] nodeOrdering = preProcess(graph);
305307
return nodeOrdering;
306308
}
@@ -491,4 +493,4 @@ public static void main(String args[]) {
491493
System.out.println(bd.computeDist(graph,u,v,i,nodeOrdering));
492494
}
493495
}
494-
}
496+
}

0 commit comments

Comments
 (0)