Documentation
¶
Index ¶
- func Range(start int, end int) []int
- type Components
- type ContractionHybridSampling
- type ContractionInclusiveRandomNodeNeighbourSampling
- type ContractionPageRankNodeSampling
- type ContractionRandomDegreeNodeSampling
- type ContractionRandomEdgeSampling
- type ContractionRandomNodeEdgeSampling
- type ContractionRandomNodeNeighbourSampling
- type ContractionRandomNodeSampling
- type ContractionRandomWalkSampling
- type ContractionRandomWalkWithJumpSampling
- type ContractionRandomWalkWithRestartSampling
- type DeletionHybridSampling
- type DeletionInclusiveRandomNodeNeighbourSampling
- type DeletionRandomDegreeNodeSampling
- type DeletionRandomEdgeSampling
- type DeletionRandomNodeEdgeSampling
- type DeletionRandomNodeNeighbourSampling
- type DeletionRandomNodeSampling
- type DeletionRandomWalkSampling
- type DeletionRandomWalkWithJumpSampling
- type DeletionRandomWalkWithRestartSampling
- type DeletionSamplingStrategy
- type Edge
- type Graph
- type IDeletionSamplingStrategy
- type ISamplingStrategy
- type Node
- type PreservationHybridSampling
- type PreservationInclusiveRandomNodeNeighbourSampling
- type PreservationNodeSamplingWithContraction
- type PreservationRandomDegreeNodeSampling
- type PreservationRandomEdgeSampling
- type PreservationRandomNodeEdgeSampling
- type PreservationRandomNodeNeighbourSampling
- type PreservationRandomNodeSampling
- type PreservationRandomWalkSampling
- type PreservationRandomWalkWithJumpSampling
- type PreservationRandomWalkWithRestartSampling
- type PreservationTopKEdgeSampling
- type RandomPageRankNodeSampling
- type SamplingStrategy
- type UndirectedGraph
- func BarabasiAlbertRandomGraph(numberOfNodes int, numberOfEdges int) (g *UndirectedGraph)
- func CirculantGraph(numberOfNodes int, offset int) *UndirectedGraph
- func CircularLadderGraph(nodesInSinglePath int) (*UndirectedGraph, error)
- func CompleteGraph(numberOfNodes int) *UndirectedGraph
- func CycleGraph(numberOfNodes int) *UndirectedGraph
- func DenseGNMRandomGraph(numberOfNodes int, numberOfEdges int) (g *UndirectedGraph)
- func FastGNPRandomGraph(numberOfNodes int, probabilityForEdgeCreation float64) (g UndirectedGraph)
- func LadderGraph(nodesInSinglePath int) *UndirectedGraph
- func LollipopGraph(completeGraphSize int, pathGraphSize int) *UndirectedGraph
- func NullGraph() *UndirectedGraph
- func PathGraph(numberOfNodes int) *UndirectedGraph
- func StarGraph(numberOfNodes int) *UndirectedGraph
- func TadpoleGraph(cycleSize int, pathSize int) (*UndirectedGraph, error)
- func TrivialGraph() *UndirectedGraph
- func TuranGraph(numberOfNodes int, numberOfPartitions int) *UndirectedGraph
- func WattsStrogatzRandomGraph(numberOfNodes int, nearestNeighboursCount int, edgeRewiringProbability float32) (g *UndirectedGraph)
- func WheelGraph(numberOfNodes int) *UndirectedGraph
- func (g *UndirectedGraph) AddEdge(edge Edge)
- func (g *UndirectedGraph) AddEdgesFromIntEdgeList(sourceNode Node, edges []Node)
- func (g *UndirectedGraph) AddEdgesFromIntTupleList(edges [][2]int)
- func (g *UndirectedGraph) AddNode(node Node)
- func (g *UndirectedGraph) AddNodes(nodes []Node)
- func (g *UndirectedGraph) ContractEdge(edge Edge)
- func (g *UndirectedGraph) ContractNode(node Node)
- func (g *UndirectedGraph) DFS(startNode Node) *UndirectedGraph
- func (g *UndirectedGraph) Equals(other *UndirectedGraph) bool
- func (g *UndirectedGraph) GetEdgeTuples() []Edge
- func (g *UndirectedGraph) HasNode(node Node) bool
- func (g *UndirectedGraph) NodeDegree(node Node) int
- func (g *UndirectedGraph) NumberOfEdges() int
- func (g *UndirectedGraph) RemoveEdge(edge Edge)
- func (g *UndirectedGraph) RemoveNode(node Node)
- func (g *UndirectedGraph) Sample(sampler ISamplingStrategy, ratioNodesToDelete float32) (*UndirectedGraph, error)
- func (g *UndirectedGraph) String() string
- type WeightedElement
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Components ¶
type Components struct { ComponentsArray []*UndirectedGraph BiggestComponentIdx int // contains filtered or unexported fields }
func ConnectedComponents ¶
func ConnectedComponents(g *UndirectedGraph) (components Components)
ConnectedComponents finds the connected components in an undirected graph. It takes an undirected graph (g) as input and returns a Components struct. The Components struct contains an array of UndirectedGraphs, each representing a connected component in the input graph.
Parameters:
- g: Pointer to an UndirectedGraph representing the input graph.
Returns:
- components: Components struct containing an array of UndirectedGraphs, each representing a connected component in the input graph. The biggest connected component's index is stored in BiggestComponentIdx field of the Components struct.
The function iterates through each node in the input graph and performs DFS traversal from each unvisited node to identify connected components. It stores each connected component as an UndirectedGraph in the Components struct.
Example usage:
graph := UndirectedGraph{ Nodes: make(map[Node]bool), Edges: make(map[Node][]Node), } edges := []Edge{ {Node1: 1, Node2: 2}, {Node1: 3, Node2: 4}, {Node1: 5, Node2: 6}, } for _, edge := range edges { graph.AddEdge(edge) } components := ConnectedComponents(&graph) // Access each connected component for _, component := range components.ComponentsArray { fmt.Println("Connected component:") for node := range component.Nodes { fmt.Println(node) } }
func (*Components) AddComponent ¶
func (c *Components) AddComponent(component *UndirectedGraph)
func (*Components) GetBiggestComponent ¶
func (c *Components) GetBiggestComponent() *UndirectedGraph
type ContractionHybridSampling ¶
type ContractionHybridSampling struct{ ISamplingStrategy }
func (*ContractionHybridSampling) Sample ¶
func (strategy *ContractionHybridSampling) Sample(graph UndirectedGraph, sampledGraphSizeRatio float32) (UndirectedGraph, error)
type ContractionInclusiveRandomNodeNeighbourSampling ¶
type ContractionInclusiveRandomNodeNeighbourSampling struct{ ISamplingStrategy }
func (*ContractionInclusiveRandomNodeNeighbourSampling) Sample ¶
func (strategy *ContractionInclusiveRandomNodeNeighbourSampling) Sample(graph UndirectedGraph, sampledGraphSizeRatio float32) (UndirectedGraph, error)
type ContractionPageRankNodeSampling ¶
type ContractionPageRankNodeSampling struct{ ISamplingStrategy }
type ContractionRandomDegreeNodeSampling ¶
type ContractionRandomDegreeNodeSampling struct{ ISamplingStrategy }
func (*ContractionRandomDegreeNodeSampling) Sample ¶
func (strategy *ContractionRandomDegreeNodeSampling) Sample(graph UndirectedGraph, sampledGraphSizeRatio float32) (UndirectedGraph, error)
type ContractionRandomEdgeSampling ¶
type ContractionRandomEdgeSampling struct{ ISamplingStrategy }
func (*ContractionRandomEdgeSampling) Sample ¶
func (strategy *ContractionRandomEdgeSampling) Sample(graph UndirectedGraph, sampledGraphSizeRatio float32) (UndirectedGraph, error)
type ContractionRandomNodeEdgeSampling ¶
type ContractionRandomNodeEdgeSampling struct{ ISamplingStrategy }
func (*ContractionRandomNodeEdgeSampling) Sample ¶
func (strategy *ContractionRandomNodeEdgeSampling) Sample(graph UndirectedGraph, sampledGraphSizeRatio float32) (UndirectedGraph, error)
type ContractionRandomNodeNeighbourSampling ¶
type ContractionRandomNodeNeighbourSampling struct{ ISamplingStrategy }
func (*ContractionRandomNodeNeighbourSampling) Sample ¶
func (strategy *ContractionRandomNodeNeighbourSampling) Sample(graph UndirectedGraph, sampledGraphSizeRatio float32) (UndirectedGraph, error)
type ContractionRandomNodeSampling ¶
type ContractionRandomNodeSampling struct{ ISamplingStrategy }
func (*ContractionRandomNodeSampling) Sample ¶
func (strategy *ContractionRandomNodeSampling) Sample(graph UndirectedGraph, sampledGraphSizeRatio float32) (UndirectedGraph, error)
type ContractionRandomWalkSampling ¶
type ContractionRandomWalkSampling struct{ ISamplingStrategy }
func (*ContractionRandomWalkSampling) Sample ¶
func (strategy *ContractionRandomWalkSampling) Sample(graph UndirectedGraph, sampledGraphSizeRatio float32) (UndirectedGraph, error)
type ContractionRandomWalkWithJumpSampling ¶
type ContractionRandomWalkWithJumpSampling struct{ ISamplingStrategy }
func (*ContractionRandomWalkWithJumpSampling) Sample ¶
func (strategy *ContractionRandomWalkWithJumpSampling) Sample(graph UndirectedGraph, sampledGraphSizeRatio float32) (UndirectedGraph, error)
type ContractionRandomWalkWithRestartSampling ¶
type ContractionRandomWalkWithRestartSampling struct{ ISamplingStrategy }
func (*ContractionRandomWalkWithRestartSampling) Sample ¶
func (strategy *ContractionRandomWalkWithRestartSampling) Sample(graph UndirectedGraph, sampledGraphSizeRatio float32) (UndirectedGraph, error)
type DeletionHybridSampling ¶
type DeletionHybridSampling struct{ IDeletionSamplingStrategy }
func (*DeletionHybridSampling) SamplingStage ¶
func (strategy *DeletionHybridSampling) SamplingStage(g *UndirectedGraph, howManyToDelete int) error
type DeletionInclusiveRandomNodeNeighbourSampling ¶
type DeletionInclusiveRandomNodeNeighbourSampling struct{ IDeletionSamplingStrategy }
func (*DeletionInclusiveRandomNodeNeighbourSampling) SamplingStage ¶
func (strategy *DeletionInclusiveRandomNodeNeighbourSampling) SamplingStage(g *UndirectedGraph, howManyToDelete int) error
type DeletionRandomDegreeNodeSampling ¶
type DeletionRandomDegreeNodeSampling struct{ IDeletionSamplingStrategy }
func (*DeletionRandomDegreeNodeSampling) SamplingStage ¶
func (strategy *DeletionRandomDegreeNodeSampling) SamplingStage(g *UndirectedGraph, howManyToDelete int) error
type DeletionRandomEdgeSampling ¶
type DeletionRandomEdgeSampling struct{ IDeletionSamplingStrategy }
func (*DeletionRandomEdgeSampling) SamplingStage ¶
func (strategy *DeletionRandomEdgeSampling) SamplingStage(g *UndirectedGraph, howManyToDelete int) error
type DeletionRandomNodeEdgeSampling ¶
type DeletionRandomNodeEdgeSampling struct{ IDeletionSamplingStrategy }
func (*DeletionRandomNodeEdgeSampling) SamplingStage ¶
func (strategy *DeletionRandomNodeEdgeSampling) SamplingStage(g *UndirectedGraph, howManyToDelete int) error
type DeletionRandomNodeNeighbourSampling ¶
type DeletionRandomNodeNeighbourSampling struct{ IDeletionSamplingStrategy }
func (*DeletionRandomNodeNeighbourSampling) SamplingStage ¶
func (strategy *DeletionRandomNodeNeighbourSampling) SamplingStage(g *UndirectedGraph, howManyToDelete int) error
type DeletionRandomNodeSampling ¶
type DeletionRandomNodeSampling struct{ IDeletionSamplingStrategy }
DELETION GRAPH SAMPLING METHODS
func (*DeletionRandomNodeSampling) SamplingStage ¶
func (strategy *DeletionRandomNodeSampling) SamplingStage(g *UndirectedGraph, howMany int) error
type DeletionRandomWalkSampling ¶
type DeletionRandomWalkSampling struct{ IDeletionSamplingStrategy }
func (*DeletionRandomWalkSampling) SamplingStage ¶
func (strategy *DeletionRandomWalkSampling) SamplingStage(g *UndirectedGraph, howManyToDelete int) error
type DeletionRandomWalkWithJumpSampling ¶
type DeletionRandomWalkWithJumpSampling struct{ IDeletionSamplingStrategy }
func (*DeletionRandomWalkWithJumpSampling) SamplingStage ¶
func (strategy *DeletionRandomWalkWithJumpSampling) SamplingStage(g *UndirectedGraph, howManyToDelete int) error
type DeletionRandomWalkWithRestartSampling ¶
type DeletionRandomWalkWithRestartSampling struct{ IDeletionSamplingStrategy }
func (*DeletionRandomWalkWithRestartSampling) SamplingStage ¶
func (strategy *DeletionRandomWalkWithRestartSampling) SamplingStage(g *UndirectedGraph, howManyToDelete int) error
type DeletionSamplingStrategy ¶
type DeletionSamplingStrategy struct {
IDeletionSamplingStrategy IDeletionSamplingStrategy
}
func (*DeletionSamplingStrategy) Sample ¶
func (strategy *DeletionSamplingStrategy) Sample(graph *UndirectedGraph, sampledGraphSizeRatio float32) (*UndirectedGraph, error)
type Edge ¶
func Pairwise ¶
Pairwise generates a list of edges connecting consecutive nodes in the given list of node IDs. It takes a slice of node IDs and returns a slice of edges, where each edge connects a node with the next node in the input slice. For example, if nodeIds is [1, 2, 3, 4], Pairwise will return [{1, 2}, {2, 3}, {3, 4}].
type IDeletionSamplingStrategy ¶
type IDeletionSamplingStrategy interface { SamplingStage(graph *UndirectedGraph, howManyToDelete int) error Sample(graph *UndirectedGraph, sampledGraphSizeRatio float32) (*UndirectedGraph, error) }
type ISamplingStrategy ¶
type ISamplingStrategy interface {
Sample(graph *UndirectedGraph, sampledGraphSizeRatio float32) (*UndirectedGraph, error)
}
type PreservationHybridSampling ¶
type PreservationHybridSampling struct{ ISamplingStrategy }
func (*PreservationHybridSampling) Sample ¶
func (strategy *PreservationHybridSampling) Sample(graph *UndirectedGraph, sampledGraphSizeRatio float32) (*UndirectedGraph, error)
type PreservationInclusiveRandomNodeNeighbourSampling ¶
type PreservationInclusiveRandomNodeNeighbourSampling struct{ ISamplingStrategy }
func (*PreservationInclusiveRandomNodeNeighbourSampling) Sample ¶
func (strategy *PreservationInclusiveRandomNodeNeighbourSampling) Sample(graph UndirectedGraph, sampledGraphSizeRatio float32) (UndirectedGraph, error)
type PreservationNodeSamplingWithContraction ¶
type PreservationNodeSamplingWithContraction struct{ ISamplingStrategy }
type PreservationRandomDegreeNodeSampling ¶
type PreservationRandomDegreeNodeSampling struct{ ISamplingStrategy }
func (*PreservationRandomDegreeNodeSampling) Sample ¶
func (strategy *PreservationRandomDegreeNodeSampling) Sample(g UndirectedGraph, sampledGraphSizeRatio float32) (UndirectedGraph, error)
type PreservationRandomEdgeSampling ¶
type PreservationRandomEdgeSampling struct{ ISamplingStrategy }
func (*PreservationRandomEdgeSampling) Sample ¶
func (strategy *PreservationRandomEdgeSampling) Sample(g UndirectedGraph, sampledGraphSizeRatio float32) (UndirectedGraph, error)
type PreservationRandomNodeEdgeSampling ¶
type PreservationRandomNodeEdgeSampling struct{ ISamplingStrategy }
func (*PreservationRandomNodeEdgeSampling) Sample ¶
func (strategy *PreservationRandomNodeEdgeSampling) Sample(g UndirectedGraph, sampledGraphSizeRatio float32) (UndirectedGraph, error)
type PreservationRandomNodeNeighbourSampling ¶
type PreservationRandomNodeNeighbourSampling struct{ ISamplingStrategy }
func (*PreservationRandomNodeNeighbourSampling) Sample ¶
func (strategy *PreservationRandomNodeNeighbourSampling) Sample(graph UndirectedGraph, sampledGraphSizeRatio float32) (UndirectedGraph, error)
type PreservationRandomNodeSampling ¶
type PreservationRandomNodeSampling struct{ ISamplingStrategy }
func (*PreservationRandomNodeSampling) Sample ¶
func (strategy *PreservationRandomNodeSampling) Sample(g UndirectedGraph, sampledGraphSizeRatio float32) (UndirectedGraph, error)
type PreservationRandomWalkSampling ¶
type PreservationRandomWalkSampling struct{ ISamplingStrategy }
func (*PreservationRandomWalkSampling) Sample ¶
func (strategy *PreservationRandomWalkSampling) Sample(graph UndirectedGraph, sampledGraphSizeRatio float32) (UndirectedGraph, error)
type PreservationRandomWalkWithJumpSampling ¶
type PreservationRandomWalkWithJumpSampling struct{ ISamplingStrategy }
func (*PreservationRandomWalkWithJumpSampling) Sample ¶
func (strategy *PreservationRandomWalkWithJumpSampling) Sample(graph UndirectedGraph, sampledGraphSizeRatio float32) (UndirectedGraph, error)
type PreservationRandomWalkWithRestartSampling ¶
type PreservationRandomWalkWithRestartSampling struct{ ISamplingStrategy }
func (*PreservationRandomWalkWithRestartSampling) Sample ¶
func (strategy *PreservationRandomWalkWithRestartSampling) Sample(graph UndirectedGraph, sampledGraphSizeRatio float32) (UndirectedGraph, error)
type PreservationTopKEdgeSampling ¶
type PreservationTopKEdgeSampling struct{ ISamplingStrategy }
func (*PreservationTopKEdgeSampling) Sample ¶
func (strategy *PreservationTopKEdgeSampling) Sample(g UndirectedGraph, sampledGraphSizeRatio float32) (UndirectedGraph, error)
type RandomPageRankNodeSampling ¶
type RandomPageRankNodeSampling struct{ ISamplingStrategy }
type SamplingStrategy ¶
type SamplingStrategy struct {
ISamplingStrategy ISamplingStrategy
}
type UndirectedGraph ¶
func BarabasiAlbertRandomGraph ¶
func BarabasiAlbertRandomGraph(numberOfNodes int, numberOfEdges int) (g *UndirectedGraph)
func CirculantGraph ¶
func CirculantGraph(numberOfNodes int, offset int) *UndirectedGraph
CirculantGraph returns a circulant graph of n nodes and .
func CircularLadderGraph ¶
func CircularLadderGraph(nodesInSinglePath int) (*UndirectedGraph, error)
CircularLadderGraph returns the circular ladder graph CL_n of length n
func CompleteGraph ¶
func CompleteGraph(numberOfNodes int) *UndirectedGraph
CompleteGraph generates a complete graph with the specified number of nodes. A complete graph is a simple undirected graph where each pair of distinct nodes is connected by a unique edge. The graph is represented by an UndirectedGraph object.
Parameters:
numberOfNodes: The number of nodes in the complete graph.
Returns:
An UndirectedGraph representing the complete graph with the specified number of nodes.
Example:
// Generate a complete graph with 4 nodes graph := CompleteGraph(4)
func CycleGraph ¶
func CycleGraph(numberOfNodes int) *UndirectedGraph
CycleGraph returns a cyrcle graph.
func DenseGNMRandomGraph ¶
func DenseGNMRandomGraph(numberOfNodes int, numberOfEdges int) (g *UndirectedGraph)
In the $G_{n,m}$ model, a graph is chosen uniformly at random from the set of all graphs with $n$ nodes and $m$ edges. Algorithm by Keith M. Briggs Mar 31, 2006. Inspired by Knuth's Algorithm S (Selection sampling technique), in section 3.4.2 of [1] References: [1] Donald E. Knuth, The Art of Computer Programming, Volume 2/Seminumerical algorithms, Third Edition, Addison-Wesley, 1997.
func FastGNPRandomGraph ¶
func FastGNPRandomGraph(numberOfNodes int, probabilityForEdgeCreation float64) (g UndirectedGraph)
FastGNPRandomGraph generates a random undirected graph using the G(n,p) model, where n is the number of nodes and p is the probability of edge creation between nodes. The algorithm efficiently constructs the graph by avoiding unnecessary calculations and improving overall performance.
Parameters:
- numberOfNodes: The total number of nodes in the graph.
- probabilityForEdgeCreation: The probability of creating an edge between any two nodes, ranging from 0.0 (no edges) to 1.0 (fully connected graph).
Returns:
An UndirectedGraph generated using the G(n,p) model, with edges connecting nodes based on the specified probability.
Note:
The graph's nodes are labeled from 0 to n-1, and the edge creation follows a fast non-uniform random process. This implementation is efficient for large graphs with sparse connections.
Returns a $G_{n,p}$ random graph, also known as an Erdős-Rényi graph or a binomial graph. References: [1] Vladimir Batagelj and Ulrik Brandes, "Efficient generation of large random networks", Phys. Rev. E, 71, 036113, 2005.
func LadderGraph ¶
func LadderGraph(nodesInSinglePath int) *UndirectedGraph
LadderGraph returns the Ladder graph of length n and 2n nodes
func LollipopGraph ¶
func LollipopGraph(completeGraphSize int, pathGraphSize int) *UndirectedGraph
LollipopGraph returns a path graph.
func NullGraph ¶
func NullGraph() *UndirectedGraph
NullGraph returns a graph without nodes and edges
func TadpoleGraph ¶
func TadpoleGraph(cycleSize int, pathSize int) (*UndirectedGraph, error)
TadpoleGraph returns a Tadpole graph consisting of a cycle graph on cycleSize (at least 3) vertices and a path graph of pathSize vertices, connected with a bridge.
func TrivialGraph ¶
func TrivialGraph() *UndirectedGraph
TrivialGraph returns a graph with one node (with label 0) and no edges
func TuranGraph ¶
func TuranGraph(numberOfNodes int, numberOfPartitions int) *UndirectedGraph
TuranGraph returns the Turán graph
func WattsStrogatzRandomGraph ¶
func WattsStrogatzRandomGraph(numberOfNodes int, nearestNeighboursCount int, edgeRewiringProbability float32) (g *UndirectedGraph)
func WheelGraph ¶
func WheelGraph(numberOfNodes int) *UndirectedGraph
WheelGraph returns the wheel graph
func (*UndirectedGraph) AddEdge ¶
func (g *UndirectedGraph) AddEdge(edge Edge)
AddEdge adds an undirected edge to the UndirectedGraph.
Parameters: - edge: An Edge struct representing the edge to be added, with Node1 and Node2 as the connected nodes.
Description: The function ensures the existence of the Edges map in the UndirectedGraph and adds the specified edge. It also adds both connected nodes to the graph if they do not already exist.
Example:
undirectedGraph := UndirectedGraph{ Nodes: make(map[Node]bool), Edges: make(map[Node][]Node), } edge := Edge{Node1: 1, Node2: 2} undirectedGraph.AddEdge(edge) fmt.Println(undirectedGraph.Edges) // Output: map[1:[2] 2:[1]]
func (*UndirectedGraph) AddEdgesFromIntEdgeList ¶
func (g *UndirectedGraph) AddEdgesFromIntEdgeList(sourceNode Node, edges []Node)
func (*UndirectedGraph) AddEdgesFromIntTupleList ¶
func (g *UndirectedGraph) AddEdgesFromIntTupleList(edges [][2]int)
func (*UndirectedGraph) AddNode ¶
func (g *UndirectedGraph) AddNode(node Node)
AddNode adds a node to the UndirectedGraph.
Parameters: - node: A Node representing the node to be added to the graph.
Description: The function ensures the existence of the Nodes map in the UndirectedGraph and adds the specified node if it does not already exist.
Example:
undirectedGraph := UndirectedGraph{ Nodes: make(map[Node]bool), Edges: make(map[Node][]Node), } undirectedGraph.AddNode(1) undirectedGraph.AddNode(2) fmt.Println(undirectedGraph.Nodes) // Output: map[1:true 2:true]
func (*UndirectedGraph) AddNodes ¶
func (g *UndirectedGraph) AddNodes(nodes []Node)
AddNodes adds multiple nodes to the UndirectedGraph.
Parameters: - nodes: A slice of Node representing the nodes to be added to the graph.
Description: The function iterates over the provided slice of nodes and adds each node to the graph using the AddNode method.
Example:
undirectedGraph := UndirectedGraph{ Nodes: make(map[Node]bool), Edges: make(map[Node][]Node), } nodeSlice := []Node{1, 2, 3} undirectedGraph.AddNodes(nodeSlice) fmt.Println(undirectedGraph.Nodes) // Output: map[1:true 2:true 3:true]
func (*UndirectedGraph) ContractEdge ¶
func (g *UndirectedGraph) ContractEdge(edge Edge)
func (*UndirectedGraph) ContractNode ¶
func (g *UndirectedGraph) ContractNode(node Node)
func (*UndirectedGraph) DFS ¶
func (g *UndirectedGraph) DFS(startNode Node) *UndirectedGraph
func (*UndirectedGraph) Equals ¶
func (g *UndirectedGraph) Equals(other *UndirectedGraph) bool
func (*UndirectedGraph) GetEdgeTuples ¶
func (g *UndirectedGraph) GetEdgeTuples() []Edge
GetEdgeTuples returns a slice of Edge representing all the edges in the UndirectedGraph.
Description: The function iterates through the graph's Edges map, creating an Edge tuple for each pair of connected nodes. The resulting slice provides a comprehensive list of all edges in the undirected graph.
Returns: - edges: A slice of Edge, where each Edge is a tuple representing a connection between two nodes in the graph.
Example:
undirectedGraph := UndirectedGraph{ Nodes: make(map[Node]bool), Edges: map[Node][]Node{ 1: {2, 3}, 2: {1, 3}, 3: {1, 2}, }, } edgeTuples := undirectedGraph.GetEdgeTuples() fmt.Println(edgeTuples) // Output: [{1 2} {1 3} {2 1} {2 3} {3 1} {3 2}]
func (*UndirectedGraph) HasNode ¶
func (g *UndirectedGraph) HasNode(node Node) bool
HasNode checks if the UndirectedGraph contains a specific node.
Parameters: - node: A Node representing the node to check for existence in the graph.
Returns: - bool: True if the node exists in the graph, otherwise false.
Description: The function returns true if the specified node is present in the Nodes map of the UndirectedGraph, indicating its existence in the graph. Otherwise, it returns false.
Example:
undirectedGraph := UndirectedGraph{ Nodes: map[Node]bool{ 1: true, 2: true, 3: true, }, Edges: map[Node][]Node{ 1: {2, 3}, 2: {1, 3}, 3: {1, 2}, }, } result1 := undirectedGraph.HasNode(2) // true result2 := undirectedGraph.HasNode(4) // false
func (*UndirectedGraph) NodeDegree ¶
func (g *UndirectedGraph) NodeDegree(node Node) int
NodeDegree returns the degree (number of incident edges) of the specified node in the graph.
func (*UndirectedGraph) NumberOfEdges ¶
func (g *UndirectedGraph) NumberOfEdges() int
NumberOfEdges returns the total number of edges in the undirected graph.
func (*UndirectedGraph) RemoveEdge ¶
func (g *UndirectedGraph) RemoveEdge(edge Edge)
RemoveEdge removes an undirected edge from the UndirectedGraph.
Parameters: - edge: An Edge struct representing the edge to be removed, with Node1 and Node2 as the connected nodes.
Description: The function removes the specified edge from the Edges map of the UndirectedGraph, effectively disconnecting the two nodes associated with the edge.
Example:
undirectedGraph := UndirectedGraph{ Nodes: map[Node]bool{ 1: true, 2: true, 3: true, }, Edges: map[Node][]Node{ 1: {2, 3}, 2: {1, 3}, 3: {1, 2}, }, } edgeToRemove := Edge{Node1: 1, Node2: 2} undirectedGraph.RemoveEdge(edgeToRemove) // After removal, Edges map becomes: map[1:[3] 2:[3] 3:[1 2]]
func (*UndirectedGraph) RemoveNode ¶
func (g *UndirectedGraph) RemoveNode(node Node)
RemoveNode removes a node from the UndirectedGraph and all associated edges.
Parameters: - node: A Node representing the node to be removed from the graph.
Description: The function removes the specified node from the Nodes map of the UndirectedGraph, as well as all edges connected to the node in the Edges map. This operation effectively disconnects the node and eliminates all edges involving that node.
Example:
undirectedGraph := UndirectedGraph{ Nodes: map[Node]bool{ 1: true, 2: true, 3: true, }, Edges: map[Node][]Node{ 1: {2, 3}, 2: {1, 3}, 3: {1, 2}, }, } nodeToRemove := Node(2) undirectedGraph.RemoveNode(nodeToRemove) // After removal, Nodes map becomes: map[1:true 3:true] // After removal, Edges map becomes: map[1:[3] 3:[1]]
func (*UndirectedGraph) Sample ¶
func (g *UndirectedGraph) Sample(sampler ISamplingStrategy, ratioNodesToDelete float32) (*UndirectedGraph, error)
func (*UndirectedGraph) String ¶
func (g *UndirectedGraph) String() string