maxflow

package
v0.0.0-...-fe23fab Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2018 License: BSD-2-Clause-Views Imports: 0 Imported by: 1

Documentation

Overview

Maxflow package implements the max-flow(min-cuts, graph-cuts) algorithm that is used to solve the labeling problem in computer vision or graphics area.

The algorithm is described in

An Experimental Comparison of Min-Cut/Max-Flow Algorithms for Energy Minimization in Computer Vision.
Yuri Boykov and Vladimir Kolmogorov.
In IEEE Transactions on Pattern Analysis and Machine Intelligence, September 2004.

Reference the document of Graph struct for usage information.

Index

Constants

View Source
const INFINITE_D int = 1000000000

Variables

This section is empty.

Functions

This section is empty.

Types

type CapType

type CapType int

type Graph

type Graph struct {
	// contains filtered or unexported fields
}

Graph is a data structure representing a graph for maxflow algorithm.

Usage:

g := NewGraph()

nodes := make([]*Node, 2)

for i := range(nodes) {
    nodes[i] = g.AddNode()
} // for i

g.SetTweights(nodes[0], 1, 5)
g.SetTweights(nodes[1], 2, 6)
g.AddEdge(nodes[0], nodes[1], 3, 4)

g.Run();

flow := g.Flow()

if g.IsSource(nodes[0]) {
    fmt.Println("nodes 0 is SOURCE")
} else {
    fmt.Println("nodes 0 is SINK")
} // else

func NewGraph

func NewGraph() *Graph

NewGraph creates an initialzed Graph instance.

func (*Graph) AddEdge

func (g *Graph) AddEdge(from, to *Node, cap, revCap CapType)

AddEdge adds edges between two nodes.

cap and revCap are two directions

func (*Graph) AddNode

func (g *Graph) AddNode() *Node

AddNode creates a node in the graph and returns a pointer to the node.

Fields of the Node struct is not(and need not be) accessible.

func (*Graph) Flow

func (g *Graph) Flow() CapType

Flow returns the calculated maxflow.

Call this method after calling to Run

func (*Graph) IsSource

func (g *Graph) IsSource(i *Node) bool

IsSource checks whether a node is a source in the minimum cuts.

Call this method after calling to Run

func (*Graph) Run

func (g *Graph) Run()

Run executes the maxflow algorithm to find the maxflow of the current graph.

func (*Graph) SetTweights

func (g *Graph) SetTweights(i *Node, capSource, capSink CapType)

SetTweights sets the capacities of a node to the souce and sink node

Do not call this method twice for a node

type Node

type Node struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL