Removed graph package

pull/35/head
James Ball 2020-02-11 22:12:02 +00:00
rodzic dd35221625
commit 10e0418ef4
2 zmienionych plików z 0 dodań i 87 usunięć

Wyświetl plik

@ -1,34 +0,0 @@
package graphs;
import shapes.Line;
import shapes.Vector2;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
// TODO: Implement Chinese postman solving.
public class Graph {
private Map<Vector2, Node> nodes;
public Graph(List<Line> lines) {
this.nodes = new HashMap<>();
for (Line line : lines) {
if (!nodes.containsKey(line.getA())) {
nodes.put(line.getA(), new Node(line.getA()));
}
if (!nodes.containsKey(line.getB())) {
nodes.put(line.getB(), new Node(line.getB()));
}
Node nodeA = nodes.get(line.getA());
Node nodeB = nodes.get(line.getB());
nodeA.addAdjacent(nodeB, line.getLength());
nodeB.addAdjacent(nodeA, line.getLength());
}
}
}

Wyświetl plik

@ -1,53 +0,0 @@
package graphs;
import shapes.Vector2;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class Node {
private Vector2 location;
private List<Node> adjacentNodes;
private List<Double> adjacentWeights;
public Node(Vector2 location) {
this.location = location;
this.adjacentNodes = new ArrayList<>();
this.adjacentWeights = new ArrayList<>();
}
public Vector2 getLocation() {
return location;
}
public void addAdjacent(Node node, double weight) {
adjacentNodes.add(node);
adjacentWeights.add(weight);
}
public Node getAdjacentNode(int index) {
return adjacentNodes.get(index);
}
public double getAdjacentWeight(int index) {
return adjacentWeights.get(index);
}
public int degree() {
return adjacentNodes.size();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Node node = (Node) o;
return location.equals(node.location);
}
@Override
public int hashCode() {
return Objects.hash(location);
}
}