From 21c80bcf9c0541dff03783bc76ef75fe3b4f3d00 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Thu, 22 Oct 2015 17:56:45 +0200 Subject: Robson's algorithm; added test outputs; more test cases; tester bugfix --- Practical1/src/nl/camilstaps/cs/graphs/Node.java | 54 ++++++++++++++++++++---- 1 file changed, 45 insertions(+), 9 deletions(-) (limited to 'Practical1/src/nl/camilstaps/cs/graphs/Node.java') 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 { private final int content; private final List 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 getNeighbours() { + public List getNeighbourhood() { return neighbours; } + public List getInclusiveNeighbourhood() { + List nb = new ArrayList<>(); + nb.add(this); + nb.addAll(neighbours); + return nb; + } + + public List getSecondNeighbourhood() { + List 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 neighbourhoodIntersection(Node b) { + List 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()); + } } -- cgit v1.2.3