Skip to content

Commit

Permalink
Update M
Browse files Browse the repository at this point in the history
  • Loading branch information
LuuO committed Jul 25, 2023
1 parent 617935b commit a13bb2e
Showing 1 changed file with 55 additions and 57 deletions.
112 changes: 55 additions & 57 deletions cmd/lp-push-relabel/explore/m/push-relabel-m.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ var (
SourceSupply = int64(0)
)

func updateHeight(v *Vertex, height int64) {
v.Property.Height = height
v.Property.HeightChanged = true
}

func updateFlow(v *Vertex, nbr *Neighbour, amount int64) {
nbr.ResCapOut -= amount
nbr.ResCapIn += amount
v.Property.Excess -= amount
}

func (VertexProp) New() (new VertexProp) {
new.NbrMap = make(map[uint32]int32)
return new
Expand Down Expand Up @@ -200,39 +211,6 @@ func (pr *PushRelabel) OnUpdateVertex(g *Graph, v *Vertex, n graph.Notification[
return
}

func (pr *PushRelabel) dischargeOnce(g *Graph, v *Vertex, myId uint32) (sent uint64, nextHeight int64, nextPush int32) {
nextHeight = int64(MaxHeight)
nextPush = -1
for i := range v.Property.Nbrs {
nbr := &v.Property.Nbrs[i]
if nbr.ResCapOut > 0 {
if !(v.Property.Height > nbr.Height) {
if nbr.Height+1 < nextHeight {
nextHeight = nbr.Height + 1
nextPush = int32(i)
}
} else {
amount := utils.Min(v.Property.Excess, nbr.ResCapOut)
v.Property.Excess -= amount
nbr.ResCapOut -= amount
nbr.ResCapIn += amount
Assert(amount > 0, "")

mailbox, tidx := g.NodeVertexMailbox(nbr.Didx)
sent += g.EnsureSend(g.ActiveNotification(myId, graph.Notification[Note]{
Target: nbr.Didx,
Note: Note{Height: v.Property.Height, Flow: amount, SrcPos: nbr.Pos},
}, mailbox, tidx))

if v.Property.Excess == 0 {
return
}
}
}
}
return sent, nextHeight, nextPush
}

func (pr *PushRelabel) processMessage(g *Graph, v *Vertex, n graph.Notification[Note]) (sent uint64) {
if n.Note.PosType == EmptyValue {
return
Expand Down Expand Up @@ -279,7 +257,7 @@ func (pr *PushRelabel) processMessage(g *Graph, v *Vertex, n graph.Notification[
v.Property.UnknownPosCount--
}

case 0b11: // other special message type
case TypePosMask: // other special message type
switch n.Note.PosType {

case UpdateInCapPos:
Expand All @@ -298,8 +276,7 @@ func (pr *PushRelabel) processMessage(g *Graph, v *Vertex, n graph.Notification[

case NewMaxVertexCount:
Assert(v.Property.Type == Source, "Non-source received NewMaxVertexCount")
v.Property.Height = VertexCountHelper.GetMaxVertexCount()
v.Property.HeightChanged = true
updateHeight(v, VertexCountHelper.GetMaxVertexCount())
return

case NewHeightEpoch:
Expand Down Expand Up @@ -329,9 +306,7 @@ func (pr *PushRelabel) processMessage(g *Graph, v *Vertex, n graph.Notification[
// retract request
amount := utils.Max(n.Note.Flow, -nbr.ResCapOut)
if amount < 0 {
nbr.ResCapOut -= -amount
nbr.ResCapIn += -amount
v.Property.Excess -= -amount
updateFlow(v, nbr, -amount)

mailbox, tidx := g.NodeVertexMailbox(nbr.Didx)
sent += g.EnsureSend(g.ActiveNotification(n.Target, graph.Notification[Note]{
Expand All @@ -341,9 +316,7 @@ func (pr *PushRelabel) processMessage(g *Graph, v *Vertex, n graph.Notification[
}
} else if n.Note.Flow > 0 {
// additional flow
nbr.ResCapOut += n.Note.Flow
nbr.ResCapIn -= n.Note.Flow
v.Property.Excess += n.Note.Flow
updateFlow(v, nbr, -n.Note.Flow)
}
}

Expand All @@ -353,11 +326,11 @@ func (pr *PushRelabel) processMessage(g *Graph, v *Vertex, n graph.Notification[
restoreSent := pr.restoreHeightInvariant(g, v, nbr, n.Target)
sent += restoreSent
if restoreSent > 0 {
sendHeight = false
sendHeight = false // already told the neighbour our height
}
}

if sendHeight && !v.Property.HeightChanged {
if sendHeight && !v.Property.HeightChanged { // Tell the neighbour our height
mailbox, tidx := g.NodeVertexMailbox(nbr.Didx)
sent += g.EnsureSend(g.ActiveNotification(n.Target, graph.Notification[Note]{
Target: nbr.Didx,
Expand All @@ -371,11 +344,9 @@ func (pr *PushRelabel) restoreHeightInvariant(g *Graph, v *Vertex, nbr *Neighbou
if nbr.ResCapOut > 0 && v.Property.Height > nbr.Height+1 {
canPush := SkipPush.Load()
if canPush && v.Property.Excess > 0 {
// Push
amount := utils.Min(v.Property.Excess, nbr.ResCapOut)
v.Property.Excess -= amount
nbr.ResCapOut -= amount
nbr.ResCapIn += amount

updateFlow(v, nbr, amount)
mailbox, tidx := g.NodeVertexMailbox(nbr.Didx)
sent += g.EnsureSend(g.ActiveNotification(myId, graph.Notification[Note]{
Target: nbr.Didx,
Expand All @@ -384,10 +355,10 @@ func (pr *PushRelabel) restoreHeightInvariant(g *Graph, v *Vertex, nbr *Neighbou
}
if nbr.ResCapOut > 0 {
if v.Property.Type == Source {
// Source has sufficient flow to saturate all outgoing edges
Assert(!canPush, "")
} else {
v.Property.Height = nbr.Height + 1
v.Property.HeightChanged = true
updateHeight(v, nbr.Height+1)
}
}
}
Expand All @@ -409,16 +380,13 @@ func (pr *PushRelabel) discharge(g *Graph, v *Vertex, myId uint32) (sent uint64)
if nextHeight >= MaxHeight {
break
}
v.Property.Height = nextHeight
v.Property.HeightChanged = true
updateHeight(v, nextHeight)
lifted = true

// push
nbr := &v.Property.Nbrs[nextPush]
amount := utils.Min(v.Property.Excess, nbr.ResCapOut)
v.Property.Excess -= amount
nbr.ResCapOut -= amount
nbr.ResCapIn += amount
updateFlow(v, nbr, amount)
Assert(amount > 0, "")
mailbox, tidx := g.NodeVertexMailbox(nbr.Didx)
sent += g.EnsureSend(g.ActiveNotification(myId, graph.Notification[Note]{
Expand All @@ -444,12 +412,42 @@ func (pr *PushRelabel) discharge(g *Graph, v *Vertex, myId uint32) (sent uint64)
}
} else if v.Property.Excess < 0 && v.Property.Type == Normal && v.Property.Height > 0 {
Assert(false, "Excess shouldn't be <0 if there's no deletes. Integer overflow?")
v.Property.Height = -VertexCountHelper.GetMaxVertexCount()
v.Property.HeightChanged = true
updateHeight(v, -VertexCountHelper.GetMaxVertexCount())
}
return
}

func (pr *PushRelabel) dischargeOnce(g *Graph, v *Vertex, myId uint32) (sent uint64, nextHeight int64, nextPush int32) {
nextHeight = int64(MaxHeight)
nextPush = -1
for i := range v.Property.Nbrs {
nbr := &v.Property.Nbrs[i]
if nbr.ResCapOut > 0 {
if !(v.Property.Height > nbr.Height) {
if nbr.Height+1 < nextHeight {
nextHeight = nbr.Height + 1
nextPush = int32(i)
}
} else {
amount := utils.Min(v.Property.Excess, nbr.ResCapOut)
updateFlow(v, nbr, amount)
Assert(amount > 0, "")

mailbox, tidx := g.NodeVertexMailbox(nbr.Didx)
sent += g.EnsureSend(g.ActiveNotification(myId, graph.Notification[Note]{
Target: nbr.Didx,
Note: Note{Height: v.Property.Height, Flow: amount, SrcPos: nbr.Pos},
}, mailbox, tidx))

if v.Property.Excess == 0 {
return
}
}
}
}
return sent, nextHeight, nextPush
}

func (pr *PushRelabel) finalizeVertexState(g *Graph, v *Vertex, myId uint32) (sent uint64) {
// discharge
if !SkipPush.Load() {
Expand Down

0 comments on commit a13bb2e

Please sign in to comment.