Documentation ¶
Overview ¶
Package lib provides various functions, data structures and methods to aid in the design of algorithms to compute structural decomposition methods.
Index ¶
- Variables
- func Diff(a, b []int) []int
- func GetGraph(s string) (Graph, ParseGraph)
- func GetPercentagesSlice(cs []*CombinationIterator) (int, int)
- func IntHash(vertices []int) uint32
- func Inter(as, bs []int) []int
- func PrintVertices(vertices []int) string
- func RemoveDuplicates(elements []int) []int
- func Subset(as []int, bs []int) bool
- func TransparentEncoding()
- func WriteDecomp(input Decomp) []byte
- type AlgorithmH
- type BalancedCheck
- type Cache
- func (c *Cache) AddNegative(sep Edges, comp Graph)
- func (c *Cache) AddPositive(sep Edges, comp Graph)
- func (c *Cache) CheckNegative(sep Edges, comps []Graph) bool
- func (c *Cache) CheckPositive(sep Edges, comps []Graph) bool
- func (c *Cache) CopyRef(other *Cache)
- func (c *Cache) Init()
- func (c *Cache) Len() int
- func (c *Cache) Reset()
- type CombinationIterator
- type Cover
- type DSD
- type Decomp
- type DecompJson
- type Edge
- type Edges
- func CutEdges(edges Edges, vertices []int) Edges
- func FilterVertices(edges Edges, vertices []int) Edges
- func FilterVerticesStrict(edges Edges, vertices []int) Edges
- func GetDegreeOrder(edges Edges) Edges
- func GetEdgeDegreeOrder(edges Edges) Edges
- func GetMSCOrder(edges Edges) Edges
- func GetMaxSepOrder(edges Edges) Edges
- func GetSubset(edges Edges, s []int) Edges
- func NewEdges(slice []Edge) Edges
- func (e *Edges) Diff(other Edges) Edges
- func (e Edges) FullString() string
- func (e *Edges) GobDecode(b []byte) error
- func (e Edges) GobEncode() ([]byte, error)
- func (e *Edges) Hash() uint64
- func (e Edges) Len() int
- func (e Edges) Less(i, j int) bool
- func (e *Edges) RemoveDuplicates()
- func (e Edges) Slice() []Edge
- func (e Edges) String() string
- func (e Edges) Swap(i, j int)
- func (e *Edges) Vertices() []int
- type EdgesCostMap
- type GYÖReduct
- type Generator
- type Graph
- func (g Graph) ComputeSubEdges(K int) Graph
- func (g Graph) GYÖReduct() (Graph, []GYÖReduct)
- func (g Graph) GetBIP() int
- func (g Graph) GetComponents(sep Edges, vertices map[int]*disjoint.Element) ([]Graph, map[int]int, []Edge)
- func (g Graph) GetSubset(s []int) Edges
- func (g *Graph) Hash() uint64
- func (g Graph) Len() int
- func (g *Graph) MakeEdgesDistinct() []int
- func (g Graph) String() string
- func (g Graph) ToHyberBenchFormat() string
- func (g Graph) ToPACE() string
- func (g Graph) TypeCollapse() (Graph, map[int][]int, int)
- func (g *Graph) Vertices() []int
- type Hingetree
- type JoinHeap
- type Node
- func (n *Node) CombineNodes(subtree Node, connecting Edges) *Node
- func (n Node) IntoJson() NodeJson
- func (n *Node) RemoveVertices(vertices []int)
- func (n Node) Reroot(child Node) Node
- func (n Node) RerootEdge(edge []int) Node
- func (n Node) RestoreGYÖ(reducts []GYÖReduct) (Node, bool)
- func (n Node) RestoreTypes(restoreMap map[int][]int) (Node, bool)
- func (n Node) String() string
- func (n *Node) Vertices() []int
- type NodeJson
- type ParallelSearch
- type ParallelSearchGen
- type ParseGraph
- type Predicate
- type Search
- type SearchGenerator
- type SepSub
- type Separator
Constants ¶
This section is empty.
Variables ¶
var Empty struct{}
Empty used for maps of type struct{}
Functions ¶
func GetGraph ¶
func GetGraph(s string) (Graph, ParseGraph)
GetGraph parses a string in HyperBench format into a graph
func GetPercentagesSlice ¶ added in v1.6.1
func GetPercentagesSlice(cs []*CombinationIterator) (int, int)
GetPercentagesSlice calculates a total percentage from a slice of CombinationIterators
func PrintVertices ¶
PrintVertices will pretty print an int slice using the encodings in the m map
func RemoveDuplicates ¶
RemoveDuplicates is using an algorithm from "SliceTricks" https://github.com/golang/go/wiki/SliceTricks
func TransparentEncoding ¶ added in v1.7.2
func TransparentEncoding()
TransparentEncoding will overwrite the encoding map in order to print out the exact underlying integer encoding. Needs to be called after GetGraph to be effective.
func WriteDecomp ¶ added in v1.7.0
Types ¶
type AlgorithmH ¶
type AlgorithmH interface { Name() string FindDecomp() Decomp FindDecompGraph(G Graph) Decomp SetWidth(K int) }
AlgorithmH is strict generalisation on the Algorithm interface.
type BalancedCheck ¶
type BalancedCheck struct{}
BalancedCheck looks for Balanced Separators
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache implements a caching mechanism for generic hypergraph decomposition algorithms
func (*Cache) AddNegative ¶
AddNegative adds a separator sep and subgraph comp as a known failure case
func (*Cache) AddPositive ¶
AddPositive adds a separator sep and subgraph comp as a known successor case TODO: not really used and tested
func (*Cache) CheckNegative ¶
CheckNegative checks for a separator sep and a subgraph whether it is a known failure case
func (*Cache) CheckPositive ¶
CheckPositive checks for a separator sep and a subgraph whether it is a known successor case TODO: not really used and tested
type CombinationIterator ¶
type CombinationIterator struct { N int K int OldK int // needed to compute current progress Combination []int Empty bool StepSize int Extended bool Confirmed bool BalSep bool // cache the result of balSep check }
A CombinationIterator generates combinations iteratively.
func (*CombinationIterator) CheckFound ¶ added in v1.6.6
func (c *CombinationIterator) CheckFound() bool
CheckFound returns the current value of the cached result
func (*CombinationIterator) Confirm ¶ added in v1.6.6
func (c *CombinationIterator) Confirm()
Confirm is used to double check the last element has been used. Useful only for concurrent searching
func (*CombinationIterator) Found ¶ added in v1.6.6
func (c *CombinationIterator) Found()
Found is used by the search to cache the previous check result
func (*CombinationIterator) GetNext ¶ added in v1.6.6
func (c *CombinationIterator) GetNext() []int
GetNext returns the currently selected combination
func (CombinationIterator) GetPercentage ¶
func (c CombinationIterator) GetPercentage() float32
GetPercentage returns the current progress as a percentage, with 100% representing that all combinations have been visited
func (*CombinationIterator) HasNext ¶ added in v1.6.6
func (c *CombinationIterator) HasNext() bool
HasNext checks if the iterator still has new elements and advances the iterator if so
type Cover ¶
type Cover struct { InComp []bool //indicates for each Edge if its in comp. or not Subset []int //The current selection HasNext bool // contains filtered or unexported fields }
Cover is used to quickly iterate over all valid hypergraph covers for a subset of vertices
func (*Cover) NextSubset ¶
NextSubset returns number of selected edges, or -1 if no alternative possible
type DSD ¶ added in v1.6.11
type DSD struct { Graph *Graph SepVertices map[int]bool //cached vertices of the seperator Vertices map[int]*disjoint.Element Comps map[*disjoint.Element][]Edge CompsSp map[*disjoint.Element][]Edges }
A DSD (short for Disjoint-Set-Datastructure) collects the information on the connected components of a graph
relative to seperator
func (*DSD) AddSepVertices ¶ added in v1.6.12
AddSepVertices adds new map bindings to SepVertices
type Decomp ¶
A Decomp (short for Decomposition) consists of a labelled tree which subdivides a graph in a certain way
func GetDecompGML ¶
GetDecompGML can parse an input string in GML format to produce a decomp
func (Decomp) CheckWidth ¶
CheckWidth returns the size of the largest bag of any node in a decomp
func (Decomp) Correct ¶
Correct checks if a decomp full fills the properties of a GHD when given a hypergraph g as input. It also checks for the special condition of HDs, though it merely prints a warning if it is not satisfied, the output is not affected by this additional check.
func (Decomp) IntoJson ¶ added in v1.7.0
func (d Decomp) IntoJson() DecompJson
func (*Decomp) RestoreSubedges ¶
func (d *Decomp) RestoreSubedges()
RestoreSubedges replaces any ad-hoc subedge with actual edges occurring in the graph
type DecompJson ¶ added in v1.7.0
type DecompJson struct {
Root NodeJson
}
func (DecompJson) IntoDecomp ¶ added in v1.7.0
func (d DecompJson) IntoDecomp(graph Graph, encoding map[string]int) Decomp
type Edge ¶
An Edge (used here for hyperedge) consists of a collection of vertices and a name
func (Edge) FullString ¶
FullString always prints the list of vertices of an edge, even if the edge is named
func (Edge) FullStringInt ¶ added in v1.5.7
FullStringInt always prints the list of vertices of an edge, even if the edge is named
type Edges ¶
type Edges struct {
// contains filtered or unexported fields
}
Edges struct is a slice of Edge, defined for the use of the sort interface, as well as various other optimisations which are only possible on the slice level
func CutEdges ¶
CutEdges filters an Edges slice for a given set of vertices. Edges are transformed to their intersection against the vertex set, producing the induced subgraph
func FilterVertices ¶
FilterVertices filters an Edges slice for a given set of vertices. Edges are only removed, if they have an empty intersection with the vertex set.
func FilterVerticesStrict ¶
FilterVerticesStrict filters an Edges slice for a given set of vertices. Edges are removed if they are not full subsets of the vertex set
func GetDegreeOrder ¶
GetDegreeOrder orders the edges based on the sum of the vertex degrees
func GetEdgeDegreeOrder ¶
GetEdgeDegreeOrder orders the edges based on the sum of the edge degrees
func GetMSCOrder ¶
GetMSCOrder produces the Maximal Cardinality Search Ordering. Implementation is based det-k-decomp of Samer and Gottlob '09
func GetMaxSepOrder ¶
GetMaxSepOrder orders the edges by how much they increase shortest paths within the hypergraph, using basic Floyd-Warschall (using the primal graph)
func GetSubset ¶
GetSubset produces a selection of edges from slice of integers s used as indices. This is used to select new potential separators. Note that special edges are ignored here, since they should never be considered when choosing a separator
func (Edges) FullString ¶
FullString always prints the list of vertices of an edge, even if named
func (*Edges) Hash ¶
Hash computes a (non-cryptographic) hash. This hash is the same for all permutations of edges
func (*Edges) RemoveDuplicates ¶
func (e *Edges) RemoveDuplicates()
RemoveDuplicates removes duplicate edges from an Edges struct
type EdgesCostMap ¶ added in v1.6.15
type EdgesCostMap struct {
// contains filtered or unexported fields
}
An EdgesCostMap associates costs to combinations of edges
func (*EdgesCostMap) Cost ¶ added in v1.6.15
func (m *EdgesCostMap) Cost(edgeComb []int) float64
Cost of an edge combination
func (*EdgesCostMap) Init ¶ added in v1.6.15
func (m *EdgesCostMap) Init()
Init an EdgeCostMap with the edges on which it will work
func (*EdgesCostMap) Put ¶ added in v1.6.15
func (m *EdgesCostMap) Put(edgeComb []int, c float64)
Put the cost of an edge combination into the map
func (EdgesCostMap) Records ¶ added in v1.6.15
func (m EdgesCostMap) Records() ([]uint64, []float64)
Records in this EdgesCostMap
type GYÖReduct ¶
type GYÖReduct interface {
// contains filtered or unexported methods
}
A GYÖReduct (that's short for GYÖ (Graham - Yu - Özsoyoğlu) Reduction ) consists of a list of operations that simplify a graph by 1) removing isolated vertices or 2) removing edges fully contained in other edges (and applying these two operations iteratively, until convergence)
type Generator ¶ added in v1.6.6
type Generator interface { HasNext() bool // check if generator still has new elements GetNext() []int // the slice of int represents some choice of edges, with an underlying order Confirm() // confirm that the current selection has been checked *and* sent to central goroutine Found() // used to cache the check result CheckFound() bool // used by search to see if previous run already performed the check }
A Generator is black-box view for any kind of generation of items to look at in linear order, and it provides some helpful methods for the search
type Graph ¶
A Graph is a collection of (special) edges
func GetGraphPACE ¶
GetGraphPACE parses a string in PACE 2019 format into a graph
func (Graph) ComputeSubEdges ¶
ComputeSubEdges computes all relevant subedges to produce a GHD of width K
func (Graph) GetComponents ¶
func (g Graph) GetComponents(sep Edges, vertices map[int]*disjoint.Element) ([]Graph, map[int]int, []Edge)
GetComponents uses Disjoint Set data structure to compute connected components
func (Graph) GetSubset ¶
GetSubset is as above, but the first parameter is omitted when used as the method call of a graph
func (*Graph) Hash ¶
Hash computes a (non-cryptographic) hash. This hash is the same for all permutations of edges
func (*Graph) MakeEdgesDistinct ¶ added in v1.6.12
func (Graph) ToHyberBenchFormat ¶ added in v1.5.7
ToHyberBenchFormat transforms the graph structure to a string in HyperBench Format. This is only relevant for generated instances with no existing string representation. Using this with a parsed graph is not the target use case, only used for internal testing
func (Graph) TypeCollapse ¶
TypeCollapse performs type collapse on the graph, the mapping that's also output can be used to restore the original hypergraph.
Possible optimization: When computing the distances, use the matrix to speed up type detection
type Hingetree ¶
type Hingetree struct {
// contains filtered or unexported fields
}
A Hingetree is a tree with each node representing a subgraph and its respective decomposition and connected by exactly one edge, which is the sole intersection between the two graphs of its connecting nodes
func GetHingeTree ¶
GetHingeTree produces a hingetree for a given graph
func (Hingetree) DecompHinge ¶
func (h Hingetree) DecompHinge(alg AlgorithmH, g Graph) Decomp
DecompHinge computes a decomposition of the original input graph, using the hingetree to speed up the computation
func (Hingetree) GetLargestGraph ¶
GetLargestGraph returns the largest graph within the hinge tree
type Node ¶
type Node struct { Bag []int Cover Edges Cost float64 Children []Node // contains filtered or unexported fields }
A Node is the root of a labelled tree, where the labels are the bag and the (edge) cover
func (*Node) CombineNodes ¶
CombineNodes attaches subtree to n, via the connecting special edge
func (*Node) RemoveVertices ¶ added in v1.6.12
func (Node) RerootEdge ¶
RerootEdge reroots G at node covering edge, producing an isomorphic graph
func (Node) RestoreGYÖ ¶
RestoreGYÖ can restore any performed reductions on the graph, given a slice of reducts
func (Node) RestoreTypes ¶
RestoreTypes can restore any performed Type reductions given a mapping of the reductions
type ParallelSearch ¶ added in v1.6.6
type ParallelSearch struct { H *Graph Edges *Edges BalFactor int Result []int Generators []Generator ExhaustedSearch bool }
func (*ParallelSearch) FindNext ¶ added in v1.6.6
func (s *ParallelSearch) FindNext(pred Predicate)
FindNext starts the search and stops if some separator which satisfies the predicate is found, or if the entire search space has been exhausted
func (*ParallelSearch) GetResult ¶ added in v1.6.6
func (s *ParallelSearch) GetResult() []int
GetResult returns the last found result
func (*ParallelSearch) SearchEnded ¶ added in v1.6.6
func (s *ParallelSearch) SearchEnded() bool
SearchEnded returns true if search is completed
type ParallelSearchGen ¶ added in v1.6.6
type ParallelSearchGen struct{}
type ParseGraph ¶
ParseGraph contains data used to parse a graph, potentially useful for testing
func (*ParseGraph) GetEdge ¶
func (p *ParseGraph) GetEdge(input string) Edge
GetEdge can be used parse additional hyperedges. Useful for testing purposes
type Predicate ¶
type Predicate interface {
Check(H *Graph, sep *Edges, balancedFactor int, Vertices map[int]*disjoint.Element) bool
}
A Predicate checks if for some subgraph and a separator, some condition holds
type Search ¶
type Search interface { FindNext(pred Predicate) SearchEnded() bool // return true if every element has been returned once GetResult() []int // get the last found result }
A Search implements a parallel search for separators fulfilling some given predicate
type SearchGenerator ¶ added in v1.6.6
type SearchGenerator interface {
GetSearch(H *Graph, Edges *Edges, BalFactor int, Generators []Generator) Search
}
A SearchGenerator sets up a Search interface