Class SocialNetwork

java.lang.Object
org.episteme.social.sociology.SocialNetwork
All Implemented Interfaces:
Serializable, Graph<Person>, WeightedGraph<Person,Real>, Commented, ComprehensiveIdentification, Identified<Identification>, Named

public class SocialNetwork extends Object implements ComprehensiveIdentification, WeightedGraph<Person,Real>
Represents a social network graph where persons are nodes and relationships are edges. Provides basic graph algorithms for social network analysis, such as degrees of separation. Modernized to implement ComprehensiveIdentification and support edge weights. * @version 1.2
Since:
1.0
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
See Also:
  • Constructor Details

    • SocialNetwork

      public SocialNetwork(String name)
  • Method Details

    • getId

      public Identification getId()
      Description copied from interface: Identified
      Returns the unique identifier of this entity.
      Specified by:
      getId in interface Identified<Identification>
      Returns:
      the identifier
    • getTraits

      public Map<String,Object> getTraits()
      Description copied from interface: ComprehensiveIdentification
      Returns the traits map for this entity.
      Specified by:
      getTraits in interface Commented
      Specified by:
      getTraits in interface ComprehensiveIdentification
      Returns:
      the traits map
    • vertices

      public Set<Person> vertices()
      Description copied from interface: Graph
      Returns all vertices in this graph.
      Specified by:
      vertices in interface Graph<Person>
      Returns:
      unmodifiable set of vertices
    • edges

      public Set<Graph.Edge<Person>> edges()
      Description copied from interface: Graph
      Returns all edges in this graph.
      Specified by:
      edges in interface Graph<Person>
      Returns:
      unmodifiable set of edges
    • addVertex

      public boolean addVertex(Person vertex)
      Description copied from interface: Graph
      Adds a vertex to the graph.
      Specified by:
      addVertex in interface Graph<Person>
      Parameters:
      vertex - the vertex to add
      Returns:
      true if vertex was added, false if already present
    • addEdge

      public boolean addEdge(Person source, Person target, Real weight)
      Description copied from interface: WeightedGraph
      Adds a weighted edge to the graph.

      Vertices are automatically added if not already present.

      Specified by:
      addEdge in interface WeightedGraph<Person,Real>
      Parameters:
      source - the source vertex
      target - the target vertex
      weight - the edge weight
      Returns:
      true if the edge was added
    • neighbors

      public Set<Person> neighbors(Person vertex)
      Description copied from interface: Graph
      Returns neighbors of a vertex.
      Specified by:
      neighbors in interface Graph<Person>
      Parameters:
      vertex - the vertex
      Returns:
      set of adjacent vertices
    • degree

      public int degree(Person vertex)
      Description copied from interface: Graph
      Returns the degree (number of edges) of a vertex.
      Specified by:
      degree in interface Graph<Person>
      Parameters:
      vertex - the vertex
      Returns:
      degree of vertex
    • isDirected

      public boolean isDirected()
      Description copied from interface: Graph
      Checks if this graph is directed.
      Specified by:
      isDirected in interface Graph<Person>
      Returns:
      true if directed, false if undirected
    • vertexCount

      public int vertexCount()
      Description copied from interface: Graph
      Returns the number of vertices in the graph.
      Specified by:
      vertexCount in interface Graph<Person>
      Returns:
      the number of vertices
    • getWeight

      public Real getWeight(Person p1, Person p2)
      Description copied from interface: WeightedGraph
      Returns the weight of an edge.
      Specified by:
      getWeight in interface WeightedGraph<Person,Real>
      Parameters:
      p1 - the source vertex
      p2 - the target vertex
      Returns:
      the edge weight, or null if no such edge exists
    • getWeightedEdges

      public Set<WeightedEdge<Person,Real>> getWeightedEdges()
      Description copied from interface: WeightedGraph
      Returns all weighted edges in the graph.
      Specified by:
      getWeightedEdges in interface WeightedGraph<Person,Real>
      Returns:
      unmodifiable set of weighted edges
    • getWeightedEdgesFrom

      public Set<WeightedEdge<Person,Real>> getWeightedEdgesFrom(Person vertex)
      Description copied from interface: WeightedGraph
      Returns weighted edges originating from a vertex.
      Specified by:
      getWeightedEdgesFrom in interface WeightedGraph<Person,Real>
      Parameters:
      vertex - the source vertex
      Returns:
      set of weighted edges from vertex
    • getDefaultWeight

      public Real getDefaultWeight()
      Description copied from interface: WeightedGraph
      Returns the default weight for unweighted edge additions.

      Used when addEdge(V, V) is called without a weight. Subclasses should override to provide appropriate default.

      Specified by:
      getDefaultWeight in interface WeightedGraph<Person,Real>
      Returns:
      the default weight (e.g., 1.0, Real.ONE)
    • addPerson

      public void addPerson(Person p)
      Adds a person to the network as a node.
      Parameters:
      p - the person to add
    • addConnection

      public void addConnection(Person p1, Person p2)
      Adds a bidirectional connection (relationship) between two people. Automatically adds the persons to the network if they are not already present.
      Parameters:
      p1 - first person
      p2 - second person
    • addConnection

      public void addConnection(Person p1, Person p2, Real weight)
      Adds a bidirectional weighted connection.
      Parameters:
      p1 - first person
      p2 - second person
      weight - relationship strength
    • addConnection

      public void addConnection(Person p1, Person p2, double weight)
    • areConnected

      public boolean areConnected(Person p1, Person p2)
      Checks if two people are directly connected.
      Parameters:
      p1 - first person
      p2 - second person
      Returns:
      true if a direct connection exists
    • getDegreesOfSeparation

      public int getDegreesOfSeparation(Person start, Person end)
      Finds the shortest path (degrees of separation) between two people using Breadth-First Search (BFS).
      Parameters:
      start - the starting person
      end - the target person
      Returns:
      the number of hops (degrees), or 0 if same person, or -1 if no path exists
    • getDegreeCentrality

      public Real getDegreeCentrality(Person p)
      Calculates the degree centrality of a person.
      Parameters:
      p - the person
      Returns:
      normalized degree centrality (0.0 to 1.0)
    • getClosenessCentrality

      public Real getClosenessCentrality(Person p)
      Calculates the closeness centrality of a person.
      Parameters:
      p - the person
      Returns:
      closeness centrality
    • getClusteringCoefficient

      public Real getClusteringCoefficient(Person p)
      Calculates the local clustering coefficient of a person.
      Parameters:
      p - the person
      Returns:
      clustering coefficient (0.0 to 1.0)
    • getNeighbors

      public Set<Person> getNeighbors(Person p)
    • getPersons

      public Set<Person> getPersons()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object