@Test public void testSetWeight() { System.out.println("setWeight"); g4.setWeight(1, 4, 5.7); assertEquals(5.7, g4.getWeight(1, 4), 1E-10); assertEquals(1.0, g4.getWeight(4, 1), 1E-10); g8.setWeight(1, 4, 5.7); assertEquals(5.7, g8.getWeight(1, 4), 1E-10); assertEquals(5.7, g8.getWeight(4, 1), 1E-10); }
@Override public AdjacencyList setWeight(int source, int target, double weight) { if (digraph) { for (Edge edge : graph[source]) { if (edge.v2 == target) { edge.weight = weight; return this; } } } else { for (Edge edge : graph[source]) { if ((edge.v1 == source && edge.v2 == target) || (edge.v2 == source && edge.v1 == target)) { edge.weight = weight; return this; } } } addEdge(source, target, weight); return this; }
AdjacencyList implements Graph { @Override public AdjacencyList setWeight(int source, int target, double weight) { if (digraph) { for (Edge edge : graph[source]) { if (edge.v2 == target) { edge.weight = weight; return this; } } } else { for (Edge edge : graph[source]) { if ((edge.v1 == source && edge.v2 == target) || (edge.v2 == source && edge.v1 == target)) { edge.weight = weight; return this; } } } addEdge(source, target, weight); return this; } }
AdjacencyList implements Graph { @Override public AdjacencyList setWeight(int source, int target, double weight) { if (digraph) { for (Edge edge : graph[source]) { if (edge.v2 == target) { edge.weight = weight; return this; } } } else { for (Edge edge : graph[source]) { if ((edge.v1 == source && edge.v2 == target) || (edge.v2 == source && edge.v1 == target)) { edge.weight = weight; return this; } } } addEdge(source, target, weight); return this; } AdjacencyList(int n); @SuppressWarnings("unchecked")  AdjacencyList(int n, boolean digraph); }
AdjacencyList implements Graph { @Override public AdjacencyList setWeight(int source, int target, double weight) { if (digraph) { for (Edge edge : graph[source]) { if (edge.v2 == target) { edge.weight = weight; return this; } } } else { for (Edge edge : graph[source]) { if ((edge.v1 == source && edge.v2 == target) || (edge.v2 == source && edge.v1 == target)) { edge.weight = weight; return this; } } } addEdge(source, target, weight); return this; } AdjacencyList(int n); @SuppressWarnings("unchecked")  AdjacencyList(int n, boolean digraph); @Override int getNumVertices(); @Override boolean hasEdge(int source, int target); @Override double getWeight(int source, int target); @Override AdjacencyList setWeight(int source, int target, double weight); @Override Collection<Edge> getEdges(); @Override Collection<Edge> getEdges(int vertex); @Override Collection<Edge> getEdges(int source, int target); @Override Edge getEdge(int source, int target); @Override void addEdge(int source, int target); @Override void addEdge(int source, int target, double weight); @Override void removeEdges(Collection<Edge> edges); @Override void removeEdge(int source, int target); @Override void removeEdge(Edge edge); @Override int getDegree(int vertex); @Override int getIndegree(int vertex); @Override int getOutdegree(int vertex); @Override int[] sortdfs(); @Override int[][] dfs(); @Override void dfs(Visitor visitor); @Override int[] sortbfs(); @Override int[][] bfs(); @Override void bfs(Visitor visitor); @Override double[] dijkstra(int s); @Override AdjacencyList subgraph(int[] vertices); @Override SparseMatrix toMatrix(); static AdjacencyList of(SparseMatrix matrix); }
AdjacencyList implements Graph { @Override public AdjacencyList setWeight(int source, int target, double weight) { if (digraph) { for (Edge edge : graph[source]) { if (edge.v2 == target) { edge.weight = weight; return this; } } } else { for (Edge edge : graph[source]) { if ((edge.v1 == source && edge.v2 == target) || (edge.v2 == source && edge.v1 == target)) { edge.weight = weight; return this; } } } addEdge(source, target, weight); return this; } AdjacencyList(int n); @SuppressWarnings("unchecked")  AdjacencyList(int n, boolean digraph); @Override int getNumVertices(); @Override boolean hasEdge(int source, int target); @Override double getWeight(int source, int target); @Override AdjacencyList setWeight(int source, int target, double weight); @Override Collection<Edge> getEdges(); @Override Collection<Edge> getEdges(int vertex); @Override Collection<Edge> getEdges(int source, int target); @Override Edge getEdge(int source, int target); @Override void addEdge(int source, int target); @Override void addEdge(int source, int target, double weight); @Override void removeEdges(Collection<Edge> edges); @Override void removeEdge(int source, int target); @Override void removeEdge(Edge edge); @Override int getDegree(int vertex); @Override int getIndegree(int vertex); @Override int getOutdegree(int vertex); @Override int[] sortdfs(); @Override int[][] dfs(); @Override void dfs(Visitor visitor); @Override int[] sortbfs(); @Override int[][] bfs(); @Override void bfs(Visitor visitor); @Override double[] dijkstra(int s); @Override AdjacencyList subgraph(int[] vertices); @Override SparseMatrix toMatrix(); static AdjacencyList of(SparseMatrix matrix);  }