aboutsummaryrefslogtreecommitdiff
path: root/Practical1/src/nl/camilstaps/cs/graphs/Node.java
diff options
context:
space:
mode:
authorCamil Staps2015-10-22 17:56:45 +0200
committerCamil Staps2015-10-22 17:56:45 +0200
commit21c80bcf9c0541dff03783bc76ef75fe3b4f3d00 (patch)
tree2ffeec58028b88b7cff47425e3224614c8426dd5 /Practical1/src/nl/camilstaps/cs/graphs/Node.java
parentPractical 1 Tester (diff)
Robson's algorithm; added test outputs; more test cases; tester bugfix
Diffstat (limited to 'Practical1/src/nl/camilstaps/cs/graphs/Node.java')
-rw-r--r--Practical1/src/nl/camilstaps/cs/graphs/Node.java54
1 files changed, 45 insertions, 9 deletions
diff --git a/Practical1/src/nl/camilstaps/cs/graphs/Node.java b/Practical1/src/nl/camilstaps/cs/graphs/Node.java
index 87471e8..4edc666 100644
--- a/Practical1/src/nl/camilstaps/cs/graphs/Node.java
+++ b/Practical1/src/nl/camilstaps/cs/graphs/Node.java
@@ -9,7 +9,7 @@ import java.util.List;
*
* @author Camil Staps
*/
-public class Node {
+public class Node implements Comparable<Node> {
private final int content;
private final List<Node> neighbours = new ArrayList<>();
@@ -17,19 +17,50 @@ public class Node {
this.content = content;
}
- /**
- * Create a copy of another Node
- * @param copy
- */
- public Node(Node copy) {
- this.content = copy.content;
- this.neighbours.addAll(copy.neighbours);
+ public int getDegree() {
+ return neighbours.size();
}
- public List<Node> getNeighbours() {
+ public List<Node> getNeighbourhood() {
return neighbours;
}
+ public List<Node> getInclusiveNeighbourhood() {
+ List<Node> nb = new ArrayList<>();
+ nb.add(this);
+ nb.addAll(neighbours);
+ return nb;
+ }
+
+ public List<Node> getSecondNeighbourhood() {
+ List<Node> nb = new ArrayList<>();
+ for (Node n : getNeighbourhood())
+ for (Node n2 : n.getNeighbourhood())
+ if (!nb.contains(n2))
+ nb.add(n2);
+ nb.remove(this);
+ return nb;
+ }
+
+ public boolean dominates(Node b) {
+ for (Node nb : getInclusiveNeighbourhood())
+ if (!b.getInclusiveNeighbourhood().contains(nb))
+ return false;
+ return true;
+ }
+
+ public boolean neighbourhoodsDisjoint(Node b) {
+ return neighbourhoodIntersection(b).isEmpty();
+ }
+
+ public List<Node> neighbourhoodIntersection(Node b) {
+ List<Node> intersection = new ArrayList<>();
+ for (Node n : neighbours)
+ if (b.getNeighbourhood().contains(n))
+ intersection.add(n);
+ return intersection;
+ }
+
public String toString() {
return "<" + content + ">";
}
@@ -43,4 +74,9 @@ public class Node {
return !(another == null || another.getClass() != this.getClass()) &&
content == (((Node) another).content);
}
+
+ @Override
+ public int compareTo(Node node) {
+ return node == null ? 1 : Integer.compare(neighbours.size(), node.neighbours.size());
+ }
}