GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Overhaul model and graph class - create abstract graph and abstract m… · RepGraph/RepGraph@6e713bb

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • OLDCODE
      • Graph.java
    • main/java/com/RepGraph
      • AbstractGraph.java
      • AbstractModel.java
      • DMRSGraph.java
      • DMRSModel.java
      • Edge.java
      • Node.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/main/java/com/RepGraph/Graph.java‎ ‎src/OLDCODE/Graph.java‎src/main/java/com/RepGraph/Graph.java renamed to src/OLDCODE/Graph.java

Copy file name to clipboard
File renamed without changes.
Collapse file

‎src/main/java/com/RepGraph/AbstractGraph.java‎

Copy file name to clipboardExpand all lines: src/main/java/com/RepGraph/AbstractGraph.java
+92-4Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ abstract class AbstractGraph {
3232
* A HashMap of the Graph nodes with the Node's ID as the key - used for quicker,easier and safer algorithmic use of Node data
3333
*/
3434
@JsonIgnore
35-
protected HashMap<Integer, Node> nodes;
35+
protected HashMap<String, Node> nodes;
3636

3737

3838
/**
@@ -69,7 +69,7 @@ public AbstractGraph() {
6969
* @param input The Graph's input/sentence.
7070
* @param edges An array list of the Graph's edges.
7171
*/
72-
public AbstractGraph(String id, String source, String input, HashMap<Integer, Node> nodes, ArrayList<Edge> edges, String top) {
72+
public AbstractGraph(String id, String source, String input, HashMap<String, Node> nodes, ArrayList<Edge> edges, String top) {
7373
this.id = id;
7474
this.source = source;
7575
this.input = input;
@@ -96,7 +96,7 @@ public AbstractGraph(String id, String source, String input, ArrayList<Node> nod
9696
this.source = source;
9797
this.input = input;
9898
this.nodelist = nodelist;
99-
this.nodes = new HashMap<Integer, Node>();
99+
this.nodes = new HashMap<String, Node>();
100100
for (Node n : nodelist) {
101101
this.nodes.put(n.getId(), n);
102102
}
@@ -217,13 +217,101 @@ public void setTops(String top) {
217217
this.top = top;
218218
}
219219

220+
/**
221+
* Getter method for the Graph's nodes HashMap.
222+
*
223+
* @return HashMap<Integer, Node> The Graph's nodes HashMap.
224+
*/
225+
public HashMap<String, Node> getNodes() {
226+
return nodes;
227+
}
228+
229+
/**
230+
* Setter method for the Graph's nodes HashMap. This setter also resets and populates the linear list of nodes "nodeslist"
231+
*
232+
* @param nodes The Graph's nodes HashMap.
233+
*/
234+
public void setNodes(HashMap<String, Node> nodes) {
235+
this.nodelist.clear();
236+
this.nodes = nodes;
237+
for (Node n : nodes.values()) {
238+
this.nodelist.add(n);
239+
}
240+
}
241+
242+
/**
243+
* This method checks to see if a Graph has a dangling Edge i.e an Edge that doesnt connect to any Node
244+
*
245+
* @return boolean returns true if the Graph has a dangling Edge otherwise returns false.
246+
*/
247+
public boolean hasDanglingEdge() {
248+
for (Edge e : edges) {
249+
if (!nodes.containsKey(e.getTarget()) || !nodes.containsKey(e.getSource())) {
250+
return true;
251+
}
252+
}
253+
return false;
254+
}
255+
256+
/**
257+
* Assigns all the nodes in the Graph their directed and undirected neighbouring nodes, which will be used for analysis.
258+
*/
259+
public void setNodeNeighbours() {
260+
String source;
261+
String target;
262+
263+
if (edges.size() == 0) {
264+
//Graph has no edges
265+
return;
266+
} else {
267+
268+
source = edges.get(0).getSource();
269+
270+
if (!nodes.containsKey(source) || nodes.get(source).getDirectedNeighbours().size() != 0) {
271+
//Node neighbours have already been set
272+
return;
273+
}
274+
}
275+
276+
//Iterate through each Edge and set the corresponding Node's thier neighbours.
277+
for (int i = 0; i < edges.size(); i++) {
278+
Edge currentEdge = edges.get(i);
279+
280+
source = currentEdge.getSource();
281+
target = currentEdge.getTarget();
282+
283+
Node sourceNode = nodes.get(source);
284+
sourceNode.addDirectedNeighbour(nodes.get(target));
285+
nodes.get(target).addUndirectedNeighbour(sourceNode);
286+
287+
sourceNode.addDirectedEdgeNeighbour(currentEdge);
288+
nodes.get(target).addUndirectedEdgeNeighbour(currentEdge);
289+
290+
}
291+
292+
}
293+
294+
/**
295+
* Combines the directed and undirected Node neighbours of a given Node.
296+
*
297+
* @param nodeID The ID of the Node.
298+
* @return ArrayList<Node> List of the Node's directed and undirected neighbours.
299+
*/
300+
public ArrayList<Node> combineNeighbours(String nodeID) {
301+
ArrayList<Node> allNeighbours = new ArrayList<>(nodes.get(nodeID).getDirectedNeighbours());
302+
ArrayList<Node> undirectedNeighbours = new ArrayList<>(nodes.get(nodeID).getUndirectedNeighbours());
303+
//Adds all a Node's undirected neighbours and its directed neighbours together.
304+
allNeighbours.addAll(undirectedNeighbours);
305+
return allNeighbours;
306+
}
307+
220308
/**
221309
* Analysis Tool for finding the longest paths in the Graph.
222310
*
223311
* @param directed This is the boolean to decide if the longest path found is directed or undirected.
224312
* @return ArrayList<ArrayList < Integer>> The a list of longest paths in the Graph.
225313
*/
226-
public abstract ArrayList<ArrayList<Integer>> findLongest(boolean directed);
314+
public abstract ArrayList<ArrayList<String>> findLongest(boolean directed);
227315

228316

229317
/**
Collapse file

‎src/main/java/com/RepGraph/AbstractModel.java‎

Copy file name to clipboard
+115Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package com.RepGraph;
2+
3+
import java.util.*;
4+
5+
/**
6+
* The RepGraphModel class is used to store all the system's graphs and run analysis functions on graphs.
7+
*/
8+
abstract class AbstractModel {
9+
10+
/**
11+
* A hashmap of the model's graphs that maps Graph IDs to their Graph objects.
12+
*/
13+
protected HashMap<String, AbstractGraph> graphs;
14+
15+
/**
16+
* Default constructor for the model class.
17+
*/
18+
public AbstractModel() {
19+
graphs = new HashMap<String, AbstractGraph>();
20+
}
21+
22+
/**
23+
* Getter method for a Graph given the Graph's ID.
24+
*
25+
* @param graphID A Graph's ID.
26+
* @return Graph The requested Graph.
27+
*/
28+
public AbstractGraph getGraph(String graphID) {
29+
return graphs.get(graphID);
30+
}
31+
32+
public HashMap<String, AbstractGraph> getAllGraphs() {
33+
return graphs;
34+
}
35+
36+
/**
37+
* Adds Graph to hashmap.
38+
*
39+
* @param value This is the Graph object that is added to the graphs hashmap
40+
*/
41+
public void addGraph(AbstractGraph value) {
42+
graphs.put(value.getId(), value);
43+
}
44+
45+
/**
46+
* Checks to see if hashmap of graphs contains a certain ID
47+
*
48+
* @param graphID This is the key value to be checked
49+
* @return boolean This is true if the hashmap of graphs contains the graphID
50+
*/
51+
public boolean containsKey(String graphID) {
52+
return graphs.containsKey(graphID);
53+
}
54+
55+
/**
56+
* Clears all graphs in the hashmap of graphs
57+
*/
58+
public void clearGraphs() {
59+
graphs.clear();
60+
}
61+
62+
63+
public abstract HashMap<String, Object> DisplaySubset(String graphId, String headNodeID, String SubsetType, int format);
64+
65+
66+
public abstract AbstractGraph CreateSubsetAdjacent(String graphID, String headNodeID);
67+
68+
69+
public abstract AbstractGraph CreateSubsetDescendent(String graphID, String headNodeID) ;
70+
71+
72+
public abstract HashMap<String, Object> searchSubgraphPattern(String graphID, String[] NodeId, int[] EdgeIndices);
73+
74+
75+
public abstract HashMap<String, Object> searchSubgraphPattern(AbstractGraph subgraph);
76+
77+
78+
public abstract HashMap<String, Object> searchSubgraphNodeSet(ArrayList<String> labels);
79+
80+
/**
81+
* Checks if all values in boolean array are true
82+
*
83+
* @param array an array of boolean values
84+
* @return boolean True if all values are true and false if there is at least one false value
85+
*/
86+
public boolean areAllTrue(boolean[] array) {
87+
for (boolean b : array) {
88+
if (!b) return false;
89+
}
90+
91+
return true;
92+
}
93+
94+
95+
public abstract HashMap<String, Object> compareTwoGraphs(String graphID1, String graphID2);
96+
97+
98+
public abstract HashMap<String, Object> runFormalTests(String graphID, boolean planar, boolean longestPathDirected, boolean longestPathUndirected, boolean connected);
99+
100+
101+
public abstract HashMap<String, Object> Visualise(String graphID, int format);
102+
103+
104+
public abstract HashMap<String, Object> VisualisePlanar(AbstractGraph graph);
105+
106+
107+
public abstract HashMap<String, Object> VisualiseFlat(AbstractGraph graph);
108+
109+
110+
public abstract HashMap<String, Object> VisualiseTree(AbstractGraph graph);
111+
112+
113+
public abstract HashMap<String, Object> VisualiseHierarchy(AbstractGraph graph);
114+
115+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.