diff options
author | Camil Staps | 2015-10-22 17:56:45 +0200 |
---|---|---|
committer | Camil Staps | 2015-10-22 17:56:45 +0200 |
commit | 21c80bcf9c0541dff03783bc76ef75fe3b4f3d00 (patch) | |
tree | 2ffeec58028b88b7cff47425e3224614c8426dd5 /Practical1/src/nl/camilstaps/cs/graphs/Node.java | |
parent | Practical 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.java | 54 |
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()); + } } |