Class GraphGenerator

java.lang.Object
org.graph4j.generators.GraphGenerator

public class GraphGenerator extends Object
Static methods for generating various standard graphs. Most of the methods are shortcuts to a corresponding class responsible with the actual creation of the graph.
Author:
Cristian Frăsinaru
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Graph
    complete(int numVertices)
    Generates a complete graph.
    static Graph
    completeBipartite(int n1, int n2)
    Generates a complete bipartite graph.
    static Graph
    completeMultipartite(int... numVertices)
    Generates a complete multipartite graph.
    static Graph
    completeTree(int numLevels, int degree)
    Generates a complete tree.
    static Graph
    cycle(int numVertices)
    Generates a random cycle graph.
    static Graph
    empty(int numVertices)
    Creates a graph with a specified number of vertices and no edges.
    static Graph
    fan(int m, int n)
    Generates a fan graph (a join between an empty graph and a path).
    static Graph
    grid(int rows, int cols)
    Generates a grid graph.
    static Graph
    mycielski(int chromaticNumber)
    Generates a Mycielski graph with the specified chromatic number.
    static Graph
    path(int numVertices)
    Generates a random path graph.
    static Digraph
    randomArborescence(int numVertices)
    Generates a random arborescence.
    static Graph
    randomChordalGraph(int numVertices)
    Generates a random chordal graph.
    static Digraph
    randomDAG(int numVertices, double edgeProbability)
    Generates a random directed acyclic graph (DAG).
    static Graph
    randomForest(int numVertices)
    Generates a random forest.
    static Graph
    randomGnm(int numVertices, int numEdges)
    Generates a random G(n,m) graph.
    static Graph
    randomGnmBipartite(int n1, int n2, int m)
    Generates a random Gnm bipartite graph.
    static Graph
    randomGnp(int numVertices, double edgeProbability)
    Generates a random G(n,p) graph.
    static Graph
    randomGnpBipartite(int n1, int n2, double edgeProbability)
    Generates a random G(n,p) bipartite graph.
    static Digraph
    randomTournament(int numVertices)
    Generates a random tournament graph.
    static Graph
    randomTree(int numVertices)
    Generates a random tree.
    static Graph
    regular(int numVertices, int degree)
    Generates a regular graph.
    static Graph
    star(int numVertices)
    Generates a random star graph.
    static Graph
    trivial(int vertexNumber)
    Creates a graph with a single vertex having the specified number.
    static Graph
    wheel(int numVertices)
    Generates a random wheel graph.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GraphGenerator

      public GraphGenerator()
  • Method Details

    • empty

      public static Graph empty(int numVertices)
      Creates a graph with a specified number of vertices and no edges.
      Parameters:
      numVertices - the number of vertices
      Returns:
      a graph with n vertices and no edges.
      See Also:
    • trivial

      public static Graph trivial(int vertexNumber)
      Creates a graph with a single vertex having the specified number.
      Parameters:
      vertexNumber - the number of the vertex.
      Returns:
      a graph with a single vertex and no edges.
      See Also:
    • complete

      public static Graph complete(int numVertices)
      Generates a complete graph.
      Parameters:
      numVertices - the number of vertices.
      Returns:
      a complete graph with n vertices.
      See Also:
    • randomGnp

      public static Graph randomGnp(int numVertices, double edgeProbability)
      Generates a random G(n,p) graph.
      Parameters:
      numVertices - the number of vertices.
      edgeProbability - the probability that an edge belongs to the graph.
      Returns:
      a random graph.
      See Also:
    • randomGnm

      public static Graph randomGnm(int numVertices, int numEdges)
      Generates a random G(n,m) graph.
      Parameters:
      numVertices - the number of vertices.
      numEdges - the number of edges.
      Returns:
      a random graph.
      See Also:
    • completeBipartite

      public static Graph completeBipartite(int n1, int n2)
      Generates a complete bipartite graph.
      Parameters:
      n1 - the number of vertices in the first partition set.
      n2 - the number of vertices in the second partition set.
      Returns:
      a complete bipartite graph.
      See Also:
    • completeMultipartite

      public static Graph completeMultipartite(int... numVertices)
      Generates a complete multipartite graph.
      Parameters:
      numVertices - the number of vertices in each partition set.
      Returns:
      a complete multipartite graph.
      See Also:
    • randomGnpBipartite

      public static Graph randomGnpBipartite(int n1, int n2, double edgeProbability)
      Generates a random G(n,p) bipartite graph.
      Parameters:
      n1 - the number of vertices in the first partition set.
      n2 - the number of vertices in the second partition set.
      edgeProbability - the probability that an edge belongs to the graph.
      Returns:
      a random bipartite graph.
      See Also:
    • randomGnmBipartite

      public static Graph randomGnmBipartite(int n1, int n2, int m)
      Generates a random Gnm bipartite graph.
      Parameters:
      n1 - the number of vertices in the first partition set.
      n2 - the number of vertices in the second partition set.
      m - the number of edges.
      Returns:
      a random bipartite graph.
      See Also:
    • randomTree

      public static Graph randomTree(int numVertices)
      Generates a random tree.
      Parameters:
      numVertices - the number of vertices.
      Returns:
      a random tree.
      See Also:
    • randomArborescence

      public static Digraph randomArborescence(int numVertices)
      Generates a random arborescence. The root of the arborescence can be found using the method GraphMeasures.minIndegreeVertex(org.graph4j.Digraph).
      Parameters:
      numVertices - the number of vertices.
      Returns:
      a random arborescence.
      See Also:
    • randomForest

      public static Graph randomForest(int numVertices)
      Generates a random forest.
      Parameters:
      numVertices - the number of vertices.
      Returns:
      a random forest.
      See Also:
    • randomChordalGraph

      public static Graph randomChordalGraph(int numVertices)
      Generates a random chordal graph.
      Parameters:
      numVertices - the number of vertices.
      Returns:
      a random chordal graph.
      See Also:
    • path

      public static Graph path(int numVertices)
      Generates a random path graph.
      Parameters:
      numVertices - the number of vertices.
      Returns:
      a path graph.
      See Also:
    • cycle

      public static Graph cycle(int numVertices)
      Generates a random cycle graph.
      Parameters:
      numVertices - the number of vertices.
      Returns:
      a cycle graph.
      See Also:
    • wheel

      public static Graph wheel(int numVertices)
      Generates a random wheel graph.
      Parameters:
      numVertices - the number of vertices.
      Returns:
      a wheel graph.
      See Also:
    • star

      public static Graph star(int numVertices)
      Generates a random star graph.
      Parameters:
      numVertices - the number of vertices
      Returns:
      a star graph.
      See Also:
    • completeTree

      public static Graph completeTree(int numLevels, int degree)
      Generates a complete tree.
      Parameters:
      numLevels - the number of levels of the tree.
      degree - the degree of the internal nodes.
      Returns:
      a complete tree.
      See Also:
    • regular

      public static Graph regular(int numVertices, int degree)
      Generates a regular graph.
      Parameters:
      numVertices - the number of vertices.
      degree - the degree of all vertices.
      Returns:
      a regular graph.
      See Also:
    • grid

      public static Graph grid(int rows, int cols)
      Generates a grid graph.
      Parameters:
      rows - number of rows.
      cols - number of columns.
      Returns:
      a grid graph.
      See Also:
    • randomDAG

      public static Digraph randomDAG(int numVertices, double edgeProbability)
      Generates a random directed acyclic graph (DAG).
      Parameters:
      numVertices - number of vertices.
      edgeProbability - the probability that an edge belongs to the graph.
      Returns:
      a random DAG.
      See Also:
    • randomTournament

      public static Digraph randomTournament(int numVertices)
      Generates a random tournament graph.
      Parameters:
      numVertices - the number of vertices.
      Returns:
      a randomly generated tournament.
      See Also:
    • fan

      public static Graph fan(int m, int n)
      Generates a fan graph (a join between an empty graph and a path).
      Parameters:
      m - the number of vertices in the empty graph.
      n - the number of vertices in the path graph.
      Returns:
      a fan graph.
      See Also:
    • mycielski

      public static Graph mycielski(int chromaticNumber)
      Generates a Mycielski graph with the specified chromatic number.
      Parameters:
      chromaticNumber - the number of vertices in the empty graph.
      Returns:
      a Mycielski graph having the specified chromatic number.
      See Also: