public class Graph extends java.util.Observable implements SimpleGraph
Modifier and Type | Field and Description |
---|---|
static int |
CLOSE_DISTANCE |
static char |
DIRECTED |
static int |
HORIZONTAL |
static int |
NORMAL_DISTANCE |
static char |
UNDIRECTED |
static int |
VERTICAL |
Constructor and Description |
---|
Graph() |
Graph(Graph graph)
Deep copy constructor
|
Graph(Graph newGraph)
This constructor creates a new Graph object from a database.Graph object
|
Modifier and Type | Method and Description |
---|---|
void |
addDoppelgangerVertex(int indexOfVertex,
boolean connectDoppelToGanger)
Add a new vertex (the doppel) in the graph that is connected to all of the vertices that the indexOfVertex-th
vertex (the ganger) is connected to.
|
void |
addDoppelgangerVertex(int indexOfVertex,
int numberOfDoppels,
boolean connectDoppelsToGanger)
Add a set of doppelganger vertices to a vertex in the graph.
|
boolean |
addEdge(Vertex v1,
Vertex v2)
Adds an edge between two given vertices
|
java.util.ArrayList<Edge> |
addEdges(java.util.List<Edge> edges)
Adds edges to this graph from a given list
|
Vertex |
addNewVertex(java.awt.Point p)
Adds new vertex to the graph with coordinates given by the passed in Point
|
void |
addSubGraph(java.awt.Point offset,
Graph subgraph)
Add subgraph to this graph, offset by the given point.
|
void |
addVertex(Vertex v)
Adds a vertex to this graph.
|
java.util.ArrayList<Edge> |
addVertexAndLink(Vertex toPaste,
java.util.ArrayList<Vertex> toLink) |
void |
addVertices(java.util.List<Vertex> verts)
Adds all of the vertices in the list to this graph
|
boolean |
areThereMissingEdges()
A method to make sure an undirected graph was created properly.
|
java.util.ArrayList<Edge> |
connectAll(java.util.ArrayList<Vertex> verts)
This method creates edges between all the vertices that are passed in
|
boolean |
containsInducedSubgraph(Graph other)
Returns true if other other is a subgraph of this where other matches exactly within the subgraph of this.
|
boolean |
containsSubgraph(Graph other)
Returns true if other other is a subgraph of this
|
Edge |
convertEdge(SimpleEdge simpleEdge)
Convert the SimpleEdge to an Edge, whether or not it is actually in the graph.
|
java.util.ArrayList<Edge> |
convertEdges(java.util.ArrayList<SimpleEdge> simpleEdges)
Return an ArrayList of Edges equivalent to the SimpleEdges passed in.
|
Graph |
copyOfOriginalGraph()
Makes a copy from the state of the graph when it was initialized (including from copy constructors) or when
makeCurrentStateInitialState() was called
|
java.util.ArrayList<Vertex> |
copySubgraph(java.util.ArrayList<Vertex> verts)
Creates a corresponding vertex for each given vertex and adds corresponding edges between them
|
java.util.ArrayList<Edge> |
disconnectAll(java.util.ArrayList<Vertex> verts)
This method removes edges between all the vertices that are passed in
|
void |
ensureAdjacencyConsistency()
For each edge in this graph make sure that the corresponding edge obtained by flipping the source and the
destination vertices exists.
|
void |
fromAdjMatrix(int[][] adjMatrix,
boolean isDirectedGraph)
Generates a graph from an already created int matrix.
|
void |
fromAdjMatrixString(java.lang.String adjMatrix,
boolean isDirectedGraph) |
void |
fromString(java.lang.String adjList)
This method sets the adjacency list of all the vertices in the graph based on a string that is passed in.
|
int |
getDegree(int index)
The degree will be defined as the sum of the weights of the edges, including negative weights.
|
DegreeSequence |
getDegreeSequence() |
int |
getDiam() |
java.util.ArrayList<Edge> |
getEdges() |
java.util.ArrayList<Edge> |
getExistingEdges(java.util.ArrayList<Vertex> verts)
Create a list of edges that exist between the vertices that were passed in and makes those edges either directed
or undirected depending on the boolean flag's value
|
int |
getGraphID()
This method returns the graph ID.
|
java.lang.String |
getGraphName() |
static int |
getGridsize() |
java.lang.String |
getInitialVertexCoords()
Returns a String that represents the initial coordinates of all of the vertices in this graph in the format 'x,y
x2,y2' etc.
|
int |
getMaximumXCoordinate()
This method finds the vertex with the greatest x-value and then returns that value.
|
int |
getMaximumYCoordinate()
This method finds the vertex with the greatest y-value and then returns that value.
|
int |
getMinimumXCoordinate()
This method finds the vertex with the smallest x-value and then returns that value.
|
int |
getMinimumYCoordinate()
This method finds the vertex with the smallest y-value and then returns that value.
|
java.util.ArrayList<Edge> |
getMissingEdges()
Returns the edges that are not in the graph but the reverse edge is in the graph
|
java.util.ArrayList<Edge> |
getNonExistingEdges(java.util.ArrayList<Vertex> verts)
Given a list of vertices, finds all vertex pairs that do not have an edge between them
|
int |
getNumberOfEdges()
This method returns the number of edges in this graph between pairs of vertices.
|
int |
getNumberOfVertices() |
int |
getRadius() |
java.awt.Point |
getSubGraphLowerRightPoint(java.util.ArrayList<Vertex> list)
Find the smallest x and y values of this subgraph based on the vertices in the graph
|
int[] |
getSubgraphPermutation(Graph other)
Determine if the other graph is a subgraph of this graph.
|
java.awt.Point |
getSubGraphUpperLeftPoint(java.util.ArrayList<Vertex> list)
Find the smallest x and y values of this subgraph based on the vertices in the graph
|
int |
getUserID() |
Vertex |
getVertexAtIndex(int n)
This method returns the vertex at a specific index.
|
java.lang.String |
getVertexCoords()
This method gets the coordinates of all the vertices in this graph parsed into a string so that it can be stored
in the database.
|
java.util.ArrayList<Vertex> |
getVertices()
This method returns a list of all the vertices in the current graph.
|
int[] |
getVerticesDistanceDiamApart()
Returns DistanceMatrix.getVerticesDistanceDiamApart
|
void |
grow()
Spreads out the entire graph.
|
void |
grow(java.util.ArrayList<Vertex> verticesToGrow)
Spreads out the passed in vertices
|
void |
horizontalFlip()
Translates the vertices in this graph by flipping them across the x axis
|
void |
horizontalFlip(java.util.ArrayList<Vertex> verts)
Translates the group of vertices that are passed in by flipping them across a line on the x axis
|
int |
indexOf(Vertex vertex)
This method checks to see what the numerical location of a specific vertex is.
|
boolean |
isAcyclic() |
boolean |
isAdjacent(Vertex v1,
Vertex v2)
Given two vertices, checks whether or not there is an edge between them
|
boolean |
isCompleteGraph()
Checks whether or not this graph is a complete graph (each vertex is adjacent to all other vertices in the
graph).
|
boolean |
isConnectedGraph()
Checks whether or not this graph is connected (any vertex can be reached from a source vertex traveling by edges
in the graph)
|
boolean |
isDirectedGraph() |
boolean |
isEditable() |
boolean |
isSnapToGrid() |
void |
makeCurrentStateInitialState()
Makes the graph act as if the current data it has was the initial data it was given.
|
int |
nextTimestamp() |
java.util.ArrayList<Edge> |
pasteSubgraph(java.util.ArrayList<Vertex> verts,
int translateX,
int translateY)
This method adds the list of vertices that are passed in to the graph and creates the necessary edges between
them.
|
java.util.ArrayList<Edge> |
pasteSubgraphAndLink(java.util.ArrayList<Vertex> toPaste,
java.util.ArrayList<Vertex> toLink,
int translateX,
int translateY) |
boolean |
removeEdge(Vertex from,
Vertex to)
Removes an edge from this graph if the given vertices are adjacent
|
java.util.ArrayList<Edge> |
removeEdges(java.util.List<Edge> edges)
Removes edges contained in the given list from this graph
|
java.util.ArrayList<Edge> |
removeSubgraph(java.util.List<Vertex> verts)
Remove all of these vertices and the associated edges between them and to other vertices that are still in the
graph.
|
java.util.ArrayList<java.awt.Point> |
resetToInitialLocations(boolean notifyListeners)
This method forces all the vertices in this graph to return to their intial starting locations.
|
void |
setEditable(boolean editable) |
void |
setGraphID(int graphID)
This method sets the graph ID of this graph.
|
void |
setGraphName(java.lang.String graphName) |
void |
setSnapToGrid(boolean snapToGrid) |
void |
setUserID(int userID) |
void |
setVertexCoords(java.lang.String graphConfig,
boolean theseAreInitialCoords)
This method sets the coordinates of all the vertices in the list of vertices based on a string that is passed in
from the database.
|
void |
shrink()
Puts all the vertices in this graph closer together.
|
void |
shrink(java.util.ArrayList<Vertex> verticesToShrink)
Puts all the vertices in the passed in list closer together
|
void |
snapToGrid(Vertex vert)
Normalizes the locations of the passed in vertex For example, if the grid size is 10, then it will round to the
10s place: (53, 36) would be rounded to (50, 40)
|
java.lang.String |
toAdjacencyMatrixString()
Get the adjacency matrix in its string representation.
|
java.lang.String |
toString()
This method returns a string that contains all the vertices in the graphs's adjacency lists.
|
void |
translateGraph(java.awt.Point change)
This method translates all the vertices in this graph by point passed in.
|
void |
translateGraphCloseToHome() |
java.awt.Point |
translateGraphToHome() |
boolean |
translateVertex(Vertex vert,
java.awt.Point change)
This method takes a vertex that passed in an *shifts* (not translates) the vertex by the x and y coordinates that
are in the point that is passed in.
|
void |
translateVertices(java.util.ArrayList<Vertex> verts,
java.util.ArrayList<java.awt.Point> changes)
Adds the offset in 'changes' to the corresponding (same index) vertex's location (in 'verts').
|
void |
translateVertices(java.util.ArrayList<Vertex> toTranslate,
java.awt.Point change)
This method translates all the vertices in this graph by the two amounts that are passed in.
|
void |
unResetToInitialLocations(java.util.ArrayList<java.awt.Point> oldLocations)
This method sets all the vertices in this graph to the passed in locations.
|
Vertex |
vertexAt(java.awt.Point p,
int widthRad,
int heightRad)
Returns a vertex which is "near" p--within a small threshold.
|
boolean |
vertexCoordsChanged()
Returns true if at least one of the vertices in this graph have been moved from their initial coordinates
|
void |
verticalFlip()
Translates the vertices in this graph by flipping them across the y axis
|
void |
verticalFlip(java.util.ArrayList<Vertex> verts)
Translates the group of vertices that are passed in by flipping them across a line on the y axis
|
void |
xyFlip()
Translates the vertices in this graph by flipping them across the line y=x
|
void |
xyFlip(java.util.ArrayList<Vertex> verts)
Translates the group of vertices that are passed in by flipping them across the line y=x
|
public static final int HORIZONTAL
public static final int VERTICAL
public static final int CLOSE_DISTANCE
public static final int NORMAL_DISTANCE
public static final char UNDIRECTED
public static final char DIRECTED
public Graph()
public Graph(Graph graph)
graph
- The Graph to make the deep copy frompublic Graph(Graph newGraph)
newGraph
- The database.Graph object to be passed inpublic Graph copyOfOriginalGraph()
public void makeCurrentStateInitialState()
public void fromString(java.lang.String adjList)
adjList
- The adjacency list from the databasepublic void fromAdjMatrix(int[][] adjMatrix, boolean isDirectedGraph)
public void fromAdjMatrixString(java.lang.String adjMatrix, boolean isDirectedGraph)
public java.lang.String toString()
toString
in class java.lang.Object
public int nextTimestamp()
public java.lang.String getGraphName()
public Vertex addNewVertex(java.awt.Point p)
p
- 2-Dimensional coordinates representing where the new vertex is addedpublic void addVertex(Vertex v)
v
- The vertex to be added to this graphpublic void addVertices(java.util.List<Vertex> verts)
verts
- The list of vertices to add to the graphpublic boolean addEdge(Vertex v1, Vertex v2)
v1
- The source vertex of the edgev2
- The destination vertex of the edgepublic boolean removeEdge(Vertex from, Vertex to)
from
- The source vertex of the edgeto
- The destination vertex of the edgepublic java.util.ArrayList<Edge> addEdges(java.util.List<Edge> edges)
edges
- A list of edges to be added to this graphpublic java.util.ArrayList<Edge> removeEdges(java.util.List<Edge> edges)
edges
- The edges to removepublic void addSubGraph(java.awt.Point offset, Graph subgraph)
offset
- The values that are added to the coordinates of the vertices of the subgraph before they are added
to this graph. For example, if a vertex is at (4,5) in the original subgraph and the offset is (2,3),
then the corresponding vertex added to this graph will be at the point (6,8).subgraph
- A graph whose vertices and edges are added to this graphpublic java.util.ArrayList<Edge> removeSubgraph(java.util.List<Vertex> verts)
verts
- A list of the vertices of the subgraph to removepublic java.util.ArrayList<Edge> getEdges()
public java.util.ArrayList<Edge> connectAll(java.util.ArrayList<Vertex> verts)
verts
- The vertices that need to have edges created between thempublic java.util.ArrayList<Edge> disconnectAll(java.util.ArrayList<Vertex> verts)
verts
- The vertices that need to have edges removed between thempublic void horizontalFlip()
public void verticalFlip()
public void xyFlip()
public void horizontalFlip(java.util.ArrayList<Vertex> verts)
verts
- The list of vertices to be translatedpublic void verticalFlip(java.util.ArrayList<Vertex> verts)
verts
- The list of vertices to be translatedpublic void xyFlip(java.util.ArrayList<Vertex> verts)
verts
- The list of vertices to be translatedpublic java.util.ArrayList<Vertex> copySubgraph(java.util.ArrayList<Vertex> verts)
verts
- The list of vertices to be copiedpublic java.util.ArrayList<Edge> pasteSubgraph(java.util.ArrayList<Vertex> verts, int translateX, int translateY)
verts
- The list of vertices to be added to the graphpublic java.util.ArrayList<Edge> addVertexAndLink(Vertex toPaste, java.util.ArrayList<Vertex> toLink)
public java.util.ArrayList<Edge> pasteSubgraphAndLink(java.util.ArrayList<Vertex> toPaste, java.util.ArrayList<Vertex> toLink, int translateX, int translateY)
public java.util.ArrayList<Edge> getExistingEdges(java.util.ArrayList<Vertex> verts)
verts
- The vertices that will be used to generate the list of edgesedgeExists
- If true this method will return the edges that exist. False, the edges that could, but don'tisDirected
- Determines whether or not the edges will be directed or undirectedpublic java.util.ArrayList<Edge> getNonExistingEdges(java.util.ArrayList<Vertex> verts)
verts
- The list of vertices that will be used to determine what the possible edges that will be returned
arepublic boolean isAdjacent(Vertex v1, Vertex v2)
v1
- The source vertexv2
- The destination vertexpublic int indexOf(Vertex vertex)
vertex
- The vertex to checkpublic Vertex getVertexAtIndex(int n)
n
- The index at which the vertex is expected to be foundpublic java.util.ArrayList<Vertex> getVertices()
public int getNumberOfVertices()
getNumberOfVertices
in interface SimpleGraph
public int getNumberOfEdges()
getNumberOfEdges
in interface SimpleGraph
public boolean isCompleteGraph()
public boolean isConnectedGraph()
public void ensureAdjacencyConsistency()
public int getUserID()
public void setUserID(int userID)
userID
- the userID to setpublic void translateVertices(java.util.ArrayList<Vertex> verts, java.util.ArrayList<java.awt.Point> changes)
verts
- A list of vertices to be shiftedchanges
- A list of points. Their x and y values are added to the corresponding vertex's coordinatespublic boolean translateVertex(Vertex vert, java.awt.Point change)
vert
- The vertex to movechange
- The Point that holds the amount to shift this vertex bypublic void translateVertices(java.util.ArrayList<Vertex> toTranslate, java.awt.Point change)
edges
- The list of vertices to translatexAmount
- The amount to move them horizontallyyAmount
- The amount to move them verticallypublic void translateGraph(java.awt.Point change)
public java.awt.Point translateGraphToHome()
public void translateGraphCloseToHome()
public void grow()
public void grow(java.util.ArrayList<Vertex> verticesToGrow)
verticesToGrow
- The vertices to spread outpublic void shrink()
public void shrink(java.util.ArrayList<Vertex> verticesToShrink)
verticesToShrink
- The vertices to be put closer together.public boolean isDirectedGraph()
public int getGraphID()
public void setGraphID(int graphID)
graphID
- The int value that will be set as the graph IDpublic void setGraphName(java.lang.String graphName)
public void setVertexCoords(java.lang.String graphConfig, boolean theseAreInitialCoords)
graphConfig
- The string that contains all the coordinate informationpublic boolean vertexCoordsChanged()
public java.lang.String getVertexCoords()
public java.lang.String getInitialVertexCoords()
public Vertex vertexAt(java.awt.Point p, int widthRad, int heightRad)
p
- The center of the area that is searched for a vertexwidthRad
- Distance from the center that the x value of a vertex is allowed to differ and still be selectedheightRad
- Distance from the center that the y value of a vertex is allowed to differ and still be selectedpublic static int getGridsize()
public boolean isSnapToGrid()
public void setSnapToGrid(boolean snapToGrid)
snapToGrid
- the snapToGrid to setpublic void snapToGrid(Vertex vert)
vert
- public boolean isEditable()
public void setEditable(boolean editable)
public java.util.ArrayList<java.awt.Point> resetToInitialLocations(boolean notifyListeners)
notifyListeners
- TODOpublic void unResetToInitialLocations(java.util.ArrayList<java.awt.Point> oldLocations)
oldLocations
- The locations that the points are moved topublic int getMinimumYCoordinate()
public int getMaximumYCoordinate()
public int getMinimumXCoordinate()
public int getMaximumXCoordinate()
public java.awt.Point getSubGraphUpperLeftPoint(java.util.ArrayList<Vertex> list)
list
- The subgraph to checkpublic java.awt.Point getSubGraphLowerRightPoint(java.util.ArrayList<Vertex> list)
list
- The subgraph to checkpublic boolean areThereMissingEdges()
public java.util.ArrayList<Edge> getMissingEdges()
public int getDegree(int index)
getDegree
in interface SimpleGraph
index
- Index of the vertex whose degree we want to checkpublic int[] getSubgraphPermutation(Graph other)
other
- the potential subgraphpublic boolean containsSubgraph(Graph other)
public boolean containsInducedSubgraph(Graph other)
public int getDiam()
public int[] getVerticesDistanceDiamApart()
public int getRadius()
public boolean isAcyclic()
public DegreeSequence getDegreeSequence()
getDegreeSequence
in interface SimpleGraph
public java.util.ArrayList<Edge> convertEdges(java.util.ArrayList<SimpleEdge> simpleEdges)
simpleEdges
- A list of Simple Edges to be convertedpublic Edge convertEdge(SimpleEdge simpleEdge)
public java.lang.String toAdjacencyMatrixString()
public void addDoppelgangerVertex(int indexOfVertex, boolean connectDoppelToGanger)
indexOfVertex
- connectDoppelToGanger
- public void addDoppelgangerVertex(int indexOfVertex, int numberOfDoppels, boolean connectDoppelsToGanger)
indexOfVertex
- numberOfDoppels
- connectDoppelsToGanger
-