Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial GJF format #99

Merged
merged 1 commit into from
Aug 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, The JUNG Authors
* Copyright (c) 2003, The JUNG Authors
*
* All rights reserved.
*
Expand All @@ -12,124 +12,110 @@
*/
package edu.uci.ics.jung.algorithms.blockmodel;

import com.google.common.graph.Graph;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import com.google.common.graph.Graph;

/**
* Maintains information about a vertex partition of a graph.
* This can be built from a map from vertices to vertex sets
* or from a collection of (disjoint) vertex sets,
* such as those created by various clustering methods.
* Maintains information about a vertex partition of a graph. This can be built from a map from
* vertices to vertex sets or from a collection of (disjoint) vertex sets, such as those created by
* various clustering methods.
*/
public class VertexPartition<V>
{
private Map<V,Set<V>> vertex_partition_map;
private Collection<Set<V>> vertex_sets;
private Graph<V> graph;

/**
* Creates an instance based on the specified graph and mapping from vertices
* to vertex sets, and generates a set of partitions based on this mapping.
* @param g the graph over which the vertex partition is defined
* @param partition_map the mapping from vertices to vertex sets (partitions)
*/
public VertexPartition(Graph<V> g, Map<V, Set<V>> partition_map)
{
this.vertex_partition_map = Collections.unmodifiableMap(partition_map);
this.graph = g;
}
public class VertexPartition<V> {
private Map<V, Set<V>> vertex_partition_map;
private Collection<Set<V>> vertex_sets;
private Graph<V> graph;

/**
* Creates an instance based on the specified graph and mapping from vertices to vertex sets, and
* generates a set of partitions based on this mapping.
*
* @param g the graph over which the vertex partition is defined
* @param partition_map the mapping from vertices to vertex sets (partitions)
*/
public VertexPartition(Graph<V> g, Map<V, Set<V>> partition_map) {
this.vertex_partition_map = Collections.unmodifiableMap(partition_map);
this.graph = g;
}

/**
* Creates an instance based on the specified graph, vertex-set mapping, and set of disjoint
* vertex sets. The vertex-set mapping and vertex partitions must be consistent; that is, the
* mapping must reflect the division of vertices into partitions, and each vertex must appear in
* exactly one partition.
*
* @param g the graph over which the vertex partition is defined
* @param partition_map the mapping from vertices to vertex sets (partitions)
* @param vertex_sets the set of disjoint vertex sets
*/
public VertexPartition(Graph<V> g, Map<V, Set<V>> partition_map, Collection<Set<V>> vertex_sets) {
this.vertex_partition_map = Collections.unmodifiableMap(partition_map);
this.vertex_sets = vertex_sets;
this.graph = g;
}

/**
* Creates an instance based on the specified graph and set of disjoint vertex sets, and generates
* a vertex-to-partition map based on these sets.
*
* @param g the graph over which the vertex partition is defined
* @param vertex_sets the set of disjoint vertex sets
*/
public VertexPartition(Graph<V> g, Collection<Set<V>> vertex_sets) {
this.vertex_sets = vertex_sets;
this.graph = g;
}

/**
* Returns the graph on which the partition is defined.
*
* @return the graph on which the partition is defined
*/
public Graph<V> getGraph() {
return graph;
}

/**
* Creates an instance based on the specified graph, vertex-set mapping,
* and set of disjoint vertex sets. The vertex-set mapping and vertex
* partitions must be consistent; that is, the mapping must reflect the
* division of vertices into partitions, and each vertex must appear in
* exactly one partition.
* @param g the graph over which the vertex partition is defined
* @param partition_map the mapping from vertices to vertex sets (partitions)
* @param vertex_sets the set of disjoint vertex sets
*/
public VertexPartition(Graph<V> g, Map<V, Set<V>> partition_map,
Collection<Set<V>> vertex_sets)
{
this.vertex_partition_map = Collections.unmodifiableMap(partition_map);
this.vertex_sets = vertex_sets;
this.graph = g;
/**
* Returns a map from each vertex in the input graph to its partition. This map is generated if it
* does not already exist.
*
* @return a map from each vertex in the input graph to a vertex set
*/
public Map<V, Set<V>> getVertexToPartitionMap() {
if (vertex_partition_map == null) {
this.vertex_partition_map = new HashMap<V, Set<V>>();
for (Set<V> set : this.vertex_sets) for (V v : set) this.vertex_partition_map.put(v, set);
}
return vertex_partition_map;
}

/**
* Creates an instance based on the specified graph and set of disjoint vertex sets,
* and generates a vertex-to-partition map based on these sets.
* @param g the graph over which the vertex partition is defined
* @param vertex_sets the set of disjoint vertex sets
*/
public VertexPartition(Graph<V> g, Collection<Set<V>> vertex_sets)
{
this.vertex_sets = vertex_sets;
this.graph = g;
/**
* Returns a collection of vertex sets, where each vertex in the input graph is in exactly one
* set. This collection is generated based on the vertex-to-partition map if it does not already
* exist.
*
* @return a collection of vertex sets such that each vertex in the instance's graph is in exactly
* one set
*/
public Collection<Set<V>> getVertexPartitions() {
if (vertex_sets == null) {
this.vertex_sets = new HashSet<Set<V>>();
this.vertex_sets.addAll(vertex_partition_map.values());
}

/**
* Returns the graph on which the partition is defined.
* @return the graph on which the partition is defined
*/
public Graph<V> getGraph()
{
return graph;
}
return vertex_sets;
}

/**
* Returns a map from each vertex in the input graph to its partition.
* This map is generated if it does not already exist.
* @return a map from each vertex in the input graph to a vertex set
*/
public Map<V,Set<V>> getVertexToPartitionMap()
{
if (vertex_partition_map == null)
{
this.vertex_partition_map = new HashMap<V, Set<V>>();
for (Set<V> set : this.vertex_sets)
for (V v : set)
this.vertex_partition_map.put(v, set);
}
return vertex_partition_map;
}

/**
* Returns a collection of vertex sets, where each vertex in the
* input graph is in exactly one set.
* This collection is generated based on the vertex-to-partition map
* if it does not already exist.
* @return a collection of vertex sets such that each vertex in the
* instance's graph is in exactly one set
*/
public Collection<Set<V>> getVertexPartitions()
{
if (vertex_sets == null)
{
this.vertex_sets = new HashSet<Set<V>>();
this.vertex_sets.addAll(vertex_partition_map.values());
}
return vertex_sets;
}
/** @return the number of partitions. */
public int numPartitions() {
return vertex_sets.size();
}

/**
* @return the number of partitions.
*/
public int numPartitions()
{
return vertex_sets.size();
}

@Override
public String toString()
{
return "Partitions: " + vertex_partition_map;
}
@Override
public String toString() {
return "Partitions: " + vertex_partition_map;
}
}
Loading