Skip to content

Commit

Permalink
redudant pointer to incident edges
Browse files Browse the repository at this point in the history
  • Loading branch information
LdDl committed Dec 16, 2022
1 parent dcb59c8 commit 5238e91
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ debug-new.txt
debug-old.txt
new_m_n.txt
old_m_n.txt
new_no_ptr.txt
old_ptr.txt
/cmd
2 changes: 1 addition & 1 deletion bidirectional_ch_n_to_n.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (graph *Graph) directionalSearchManyToMany(d direction, endpointIndex int,
// if vertex.dist <= *estimate { // TODO: move to another place
localProcessed[vertex.id] = true
// Edge relaxation in a forward propagation
var vertexList []*incidentEdge
var vertexList []incidentEdge
if d == forward {
vertexList = graph.Vertices[vertex.id].outIncidentEdges
} else {
Expand Down
8 changes: 3 additions & 5 deletions contraction.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (graph *Graph) Preprocess(pqImportance *importanceHeap) {
// inEdges Incoming edges from vertex
// outEdges Outcoming edges from vertex
//
func (graph *Graph) markNeighbors(inEdges, outEdges []*incidentEdge) {
func (graph *Graph) markNeighbors(inEdges, outEdges []incidentEdge) {
for i := range inEdges {
temp := inEdges[i]
graph.Vertices[temp.vertexID].delNeighbors++
Expand Down Expand Up @@ -107,17 +107,15 @@ func (graph *Graph) processIncidentEdges(vertex *Vertex, pmax float64) {
batchShortcuts := make([]*ShortcutPath, 0, len(incomingEdges)*len(outcomingEdges))

previousOrderPos := int64(vertex.orderPos - 1)
for i := range incomingEdges {
u := incomingEdges[i]
for _, u := range incomingEdges {
inVertex := u.vertexID
// Do not consider any vertex has been excluded earlier
if graph.Vertices[inVertex].contracted {
continue
}
inCost := u.weight
graph.shortestPathsWithMaxCost(inVertex, pmax, previousOrderPos) // Finds the shortest distances from the inVertex to all outVertices.
for j := range outcomingEdges {
w := outcomingEdges[j]
for _, w := range outcomingEdges {
outVertex := w.vertexID
outVertexPtr := graph.Vertices[outVertex]
// Do not consider any vertex has been excluded earlier
Expand Down
2 changes: 1 addition & 1 deletion dijkstra_bidirectional.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (graph *Graph) directionalSearch(d direction, q *vertexDistHeap, localProce
if vertex.dist <= *estimate {
localProcessed[vertex.id] = true
// Edge relaxation in a forward propagation
var vertexList []*incidentEdge
var vertexList []incidentEdge
if d == forward {
vertexList = graph.Vertices[vertex.id].outIncidentEdges
} else {
Expand Down
4 changes: 2 additions & 2 deletions graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func (graph *Graph) AddEdge(from, to int64, weight float64) error {
}

func (graph *Graph) addEdge(from, to int64, weight float64) {
graph.Vertices[from].outIncidentEdges = append(graph.Vertices[from].outIncidentEdges, &incidentEdge{vertexID: to, weight: weight})
graph.Vertices[to].inIncidentEdges = append(graph.Vertices[to].inIncidentEdges, &incidentEdge{vertexID: from, weight: weight})
graph.Vertices[from].outIncidentEdges = append(graph.Vertices[from].outIncidentEdges, incidentEdge{vertexID: to, weight: weight})
graph.Vertices[to].inIncidentEdges = append(graph.Vertices[to].inIncidentEdges, incidentEdge{vertexID: from, weight: weight})
}

// AddShortcut Adds new shortcut between two vertices
Expand Down
4 changes: 2 additions & 2 deletions incident_edge.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ type incidentEdge struct {
// incomingVertexID - Library defined ID of vertex
// weight - Travel cost of incoming edge
func (vertex *Vertex) addInIncidentEdge(incomingVertexID int64, weight float64) {
vertex.inIncidentEdges = append(vertex.inIncidentEdges, &incidentEdge{incomingVertexID, weight})
vertex.inIncidentEdges = append(vertex.inIncidentEdges, incidentEdge{incomingVertexID, weight})
}

// addOutIncidentEdge Adds incident edge's to pool of "outcoming" edges of given vertex.
// Just an alias to append() function
// outcomingVertexID - Library defined ID of vertex
// weight - Travel cost of outcoming edge
func (vertex *Vertex) addOutIncidentEdge(outcomingVertexID int64, weight float64) {
vertex.outIncidentEdges = append(vertex.outIncidentEdges, &incidentEdge{outcomingVertexID, weight})
vertex.outIncidentEdges = append(vertex.outIncidentEdges, incidentEdge{outcomingVertexID, weight})
}

// findInIncidentEdge Returns index of incoming incident edge by vertex ID
Expand Down
4 changes: 2 additions & 2 deletions vertex.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package ch
// Vertex All information about vertex
type Vertex struct {
distance *Distance
inIncidentEdges []*incidentEdge
outIncidentEdges []*incidentEdge
inIncidentEdges []incidentEdge
outIncidentEdges []incidentEdge

vertexNum int64
Label int64
Expand Down

0 comments on commit 5238e91

Please sign in to comment.