package networksimplex
type Adapter [N comparable , E comparable ] struct {
Nodes []N
Outgoing func (N ) []E
Source func (E ) N
Target func (E ) N
Weight func (E ) float64
MinLength func (E ) int
}
type Options struct {
Balance bool
PreviousLayeringNodeCounts []int
IterationLimit int
}
func Layer [N comparable , E comparable ](adapter Adapter [N , E ], options Options ) map [N ]int {
graph := NewGraph ()
nodeIDs := make (map [N ]NodeID , len (adapter .Nodes ))
for _ , original := range adapter .Nodes {
id := graph .AddNode ()
graph .Node (id ).Origin = original
nodeIDs [original ] = id
}
for _ , originalNode := range adapter .Nodes {
for _ , originalEdge := range adapter .Outgoing (originalNode ) {
edge := graph .AddEdge (
nodeIDs [adapter .Source (originalEdge )],
nodeIDs [adapter .Target (originalEdge )],
adapter .Weight (originalEdge ),
adapter .MinLength (originalEdge ),
)
graph .Edge (edge ).Origin = originalEdge
}
}
simplex := ForGraph (graph ).WithBalancing (options .Balance )
if options .PreviousLayeringNodeCounts != nil {
simplex .WithPreviousLayering (options .PreviousLayeringNodeCounts )
}
if options .IterationLimit != 0 {
simplex .WithIterationLimit (options .IterationLimit )
}
simplex .Execute ()
result := make (map [N ]int , len (adapter .Nodes ))
for _ , original := range adapter .Nodes {
result [original ] = graph .Node (nodeIDs [original ]).Layer
}
return result
}
The pages are generated with Golds v0.8.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .