Refactoring

* package refactoring
* new matrix implementation (todo)
* new adj list implemetation (todo)
* fixed tests
This commit is contained in:
2019-06-15 15:15:13 +02:00
parent a8596331e7
commit 0de35fd4a1
35 changed files with 772 additions and 118 deletions

View File

@@ -1,4 +1,4 @@
package berack96.sim.util.graph;
package berack96.lib.graph;
/**
* Class used for retrieving the edges of the graph.

View File

@@ -1,4 +1,4 @@
package berack96.sim.util.graph;
package berack96.lib.graph;
import java.io.File;
import java.io.FileReader;
@@ -12,9 +12,9 @@ import java.util.function.Consumer;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import berack96.sim.util.graph.models.GraphSaveStructure;
import berack96.sim.util.graph.visit.VisitInfo;
import berack96.sim.util.graph.visit.VisitStrategy;
import berack96.lib.graph.models.GraphSaveStructure;
import berack96.lib.graph.visit.VisitStrategy;
import berack96.lib.graph.visit.impl.VisitInfo;
/**
* An interface for the graphs.<br>
@@ -96,8 +96,9 @@ public interface Graph<V, W extends Number> extends Iterable<V> {
*
* @param vertex the vertex to remove
* @throws NullPointerException if the vertex is null
* @throws IllegalArgumentException if the vertex is not contained
*/
void removeVertex(V vertex) throws IllegalArgumentException;
void removeVertex(V vertex) throws NullPointerException, IllegalArgumentException;
/**
* Remove all the vertex contained in the graph.<br>

View File

@@ -1,12 +1,12 @@
package berack96.sim.util.graph;
import berack96.sim.util.graph.visit.VisitInfo;
import berack96.sim.util.graph.visit.VisitStrategy;
package berack96.lib.graph;
import java.util.Collection;
import java.util.HashSet;
import java.util.function.Consumer;
import berack96.lib.graph.visit.VisitStrategy;
import berack96.lib.graph.visit.impl.VisitInfo;
/**
* Class used for represent a vertex of the graph.<br>
* The vertex contained is linked with the graph, so if any changes are made to

View File

@@ -0,0 +1,313 @@
package berack96.lib.graph.impl;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import berack96.lib.graph.Edge;
import berack96.lib.graph.Graph;
import berack96.lib.graph.Vertex;
import berack96.lib.graph.visit.VisitStrategy;
import berack96.lib.graph.visit.impl.VisitInfo;
public class AdjGraph<V, W extends Number> implements Graph<V, W> {
@Override
public Iterator<V> iterator() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean isCyclic() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isDAG() {
// TODO Auto-generated method stub
return false;
}
@Override
public Vertex<V> getVertex(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public void addVertex(V vertex) throws NullPointerException {
// TODO Auto-generated method stub
}
@Override
public boolean addVertexIfAbsent(V vertex) throws NullPointerException {
// TODO Auto-generated method stub
return false;
}
@Override
public void addAllVertices(Collection<V> vertices) throws NullPointerException {
// TODO Auto-generated method stub
}
@Override
public void removeVertex(V vertex) throws IllegalArgumentException {
// TODO Auto-generated method stub
}
@Override
public void removeAllVertex() {
// TODO Auto-generated method stub
}
@Override
public boolean contains(V vertex) throws NullPointerException {
// TODO Auto-generated method stub
return false;
}
@Override
public void mark(V vertex, Object mark) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
}
@Override
public void unMark(V vertex, Object mark) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
}
@Override
public void unMark(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
}
@Override
public Collection<V> getMarkedWith(Object mark) throws NullPointerException {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<Object> getMarks(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public void unMarkAll(Object mark) throws NullPointerException {
// TODO Auto-generated method stub
}
@Override
public void unMarkAll() {
// TODO Auto-generated method stub
}
@Override
public W addEdge(V vertex1, V vertex2, W weight) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public W addEdge(Edge<V, W> edge) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public W addEdgeAndVertices(V vertex1, V vertex2, W weight) throws NullPointerException {
// TODO Auto-generated method stub
return null;
}
@Override
public W addEdgeAndVertices(Edge<V, W> edge) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public void addAllEdges(Collection<Edge<V, W>> edges) throws NullPointerException {
// TODO Auto-generated method stub
}
@Override
public W getWeight(V vertex1, V vertex2) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public void removeEdge(V vertex1, V vertex2) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
}
@Override
public void removeAllInEdge(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
}
@Override
public void removeAllOutEdge(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
}
@Override
public void removeAllEdge(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
}
@Override
public void removeAllEdge() {
// TODO Auto-generated method stub
}
@Override
public boolean containsEdge(V vertex1, V vertex2) throws NullPointerException {
// TODO Auto-generated method stub
return false;
}
@Override
public Collection<V> vertices() {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<Edge<V, W>> edges() {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<Edge<V, W>> edgesOf(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<Edge<V, W>> getEdgesIn(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<Edge<V, W>> getEdgesOut(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<V> getChildren(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<V> getAncestors(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public int degreeIn(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return 0;
}
@Override
public int degreeOut(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return 0;
}
@Override
public int degree(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return 0;
}
@Override
public int numberOfVertices() {
// TODO Auto-generated method stub
return 0;
}
@Override
public int numberOfEdges() {
// TODO Auto-generated method stub
return 0;
}
@Override
public VisitInfo<V> visit(V source, VisitStrategy<V, W> strategy, Consumer<V> visit)
throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public Graph<V, W> transpose() {
// TODO Auto-generated method stub
return null;
}
@Override
public List<V> topologicalSort() throws UnsupportedOperationException {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<Collection<V>> stronglyConnectedComponents() {
// TODO Auto-generated method stub
return null;
}
@Override
public Graph<V, W> subGraph(V source, int depth) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public Graph<V, W> subGraph(Object... marker) {
// TODO Auto-generated method stub
return null;
}
@Override
public List<Edge<V, W>> distance(V source, V destination)
throws NullPointerException, IllegalArgumentException, UnsupportedOperationException {
// TODO Auto-generated method stub
return null;
}
@Override
public Map<V, List<Edge<V, W>>> distance(V source) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
}

View File

@@ -1,14 +1,17 @@
package berack96.sim.util.graph;
import berack96.sim.util.graph.visit.Dijkstra;
import berack96.sim.util.graph.visit.Tarjan;
import berack96.sim.util.graph.visit.VisitInfo;
import berack96.sim.util.graph.visit.VisitStrategy;
package berack96.lib.graph.impl;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import berack96.lib.graph.Edge;
import berack96.lib.graph.Graph;
import berack96.lib.graph.Vertex;
import berack96.lib.graph.visit.VisitStrategy;
import berack96.lib.graph.visit.impl.Dijkstra;
import berack96.lib.graph.visit.impl.Tarjan;
import berack96.lib.graph.visit.impl.VisitInfo;
/**
* Graph that uses HashMap for vertices and edges<br>
* More specifically it utilizes a Map containing all the vertices mapped to all their edges<br>

View File

@@ -0,0 +1,313 @@
package berack96.lib.graph.impl;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import berack96.lib.graph.Edge;
import berack96.lib.graph.Graph;
import berack96.lib.graph.Vertex;
import berack96.lib.graph.visit.VisitStrategy;
import berack96.lib.graph.visit.impl.VisitInfo;
public class MatrixGraph<V, W extends Number> implements Graph<V, W> {
@Override
public Iterator<V> iterator() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean isCyclic() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isDAG() {
// TODO Auto-generated method stub
return false;
}
@Override
public Vertex<V> getVertex(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public void addVertex(V vertex) throws NullPointerException {
// TODO Auto-generated method stub
}
@Override
public boolean addVertexIfAbsent(V vertex) throws NullPointerException {
// TODO Auto-generated method stub
return false;
}
@Override
public void addAllVertices(Collection<V> vertices) throws NullPointerException {
// TODO Auto-generated method stub
}
@Override
public void removeVertex(V vertex) throws IllegalArgumentException {
// TODO Auto-generated method stub
}
@Override
public void removeAllVertex() {
// TODO Auto-generated method stub
}
@Override
public boolean contains(V vertex) throws NullPointerException {
// TODO Auto-generated method stub
return false;
}
@Override
public void mark(V vertex, Object mark) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
}
@Override
public void unMark(V vertex, Object mark) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
}
@Override
public void unMark(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
}
@Override
public Collection<V> getMarkedWith(Object mark) throws NullPointerException {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<Object> getMarks(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public void unMarkAll(Object mark) throws NullPointerException {
// TODO Auto-generated method stub
}
@Override
public void unMarkAll() {
// TODO Auto-generated method stub
}
@Override
public W addEdge(V vertex1, V vertex2, W weight) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public W addEdge(Edge<V, W> edge) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public W addEdgeAndVertices(V vertex1, V vertex2, W weight) throws NullPointerException {
// TODO Auto-generated method stub
return null;
}
@Override
public W addEdgeAndVertices(Edge<V, W> edge) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public void addAllEdges(Collection<Edge<V, W>> edges) throws NullPointerException {
// TODO Auto-generated method stub
}
@Override
public W getWeight(V vertex1, V vertex2) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public void removeEdge(V vertex1, V vertex2) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
}
@Override
public void removeAllInEdge(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
}
@Override
public void removeAllOutEdge(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
}
@Override
public void removeAllEdge(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
}
@Override
public void removeAllEdge() {
// TODO Auto-generated method stub
}
@Override
public boolean containsEdge(V vertex1, V vertex2) throws NullPointerException {
// TODO Auto-generated method stub
return false;
}
@Override
public Collection<V> vertices() {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<Edge<V, W>> edges() {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<Edge<V, W>> edgesOf(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<Edge<V, W>> getEdgesIn(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<Edge<V, W>> getEdgesOut(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<V> getChildren(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<V> getAncestors(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public int degreeIn(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return 0;
}
@Override
public int degreeOut(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return 0;
}
@Override
public int degree(V vertex) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return 0;
}
@Override
public int numberOfVertices() {
// TODO Auto-generated method stub
return 0;
}
@Override
public int numberOfEdges() {
// TODO Auto-generated method stub
return 0;
}
@Override
public VisitInfo<V> visit(V source, VisitStrategy<V, W> strategy, Consumer<V> visit)
throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public Graph<V, W> transpose() {
// TODO Auto-generated method stub
return null;
}
@Override
public List<V> topologicalSort() throws UnsupportedOperationException {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<Collection<V>> stronglyConnectedComponents() {
// TODO Auto-generated method stub
return null;
}
@Override
public Graph<V, W> subGraph(V source, int depth) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public Graph<V, W> subGraph(Object... marker) {
// TODO Auto-generated method stub
return null;
}
@Override
public List<Edge<V, W>> distance(V source, V destination)
throws NullPointerException, IllegalArgumentException, UnsupportedOperationException {
// TODO Auto-generated method stub
return null;
}
@Override
public Map<V, List<Edge<V, W>>> distance(V source) throws NullPointerException, IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
}

View File

@@ -1,4 +1,4 @@
package berack96.sim.util.graph.models;
package berack96.lib.graph.models;
/**
* Support class used for saving a Graph in a file.

View File

@@ -1,7 +1,7 @@
package berack96.sim.util.graph.models;
package berack96.lib.graph.models;
import berack96.sim.util.graph.Edge;
import berack96.sim.util.graph.Graph;
import berack96.lib.graph.Edge;
import berack96.lib.graph.Graph;
/**
* Support class used for saving a Graph in a file.

View File

@@ -1,4 +1,4 @@
package berack96.sim.util.graph.models;
package berack96.lib.graph.models;
/**
* Support class used for saving a Graph in a file.

View File

@@ -1,4 +1,4 @@
package berack96.sim.util.graph.view;
package berack96.lib.graph.view;
import java.awt.Color;
import java.awt.Component;
@@ -20,10 +20,10 @@ import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.BevelBorder;
import berack96.sim.util.graph.Graph;
import berack96.sim.util.graph.view.edge.EdgeListener;
import berack96.sim.util.graph.view.vertex.VertexListener;
import berack96.sim.util.graph.visit.VisitStrategy;
import berack96.lib.graph.Graph;
import berack96.lib.graph.view.edge.EdgeListener;
import berack96.lib.graph.view.vertex.VertexListener;
import berack96.lib.graph.visit.VisitStrategy;
public class GraphInfo<V, W extends Number> extends JPanel {

View File

@@ -1,4 +1,4 @@
package berack96.sim.util.graph.view;
package berack96.lib.graph.view;
import java.awt.event.KeyListener;
import java.awt.event.MouseListener;

View File

@@ -1,4 +1,4 @@
package berack96.sim.util.graph.view;
package berack96.lib.graph.view;
import java.awt.Component;
import java.awt.Container;
@@ -18,12 +18,12 @@ import java.util.List;
import java.util.Observer;
import java.util.Set;
import berack96.sim.util.graph.Edge;
import berack96.sim.util.graph.Graph;
import berack96.sim.util.graph.MapGraph;
import berack96.sim.util.graph.Vertex;
import berack96.sim.util.graph.view.edge.EdgeComponent;
import berack96.sim.util.graph.view.vertex.VertexComponent;
import berack96.lib.graph.Edge;
import berack96.lib.graph.Graph;
import berack96.lib.graph.Vertex;
import berack96.lib.graph.impl.MapGraph;
import berack96.lib.graph.view.edge.EdgeComponent;
import berack96.lib.graph.view.vertex.VertexComponent;
@SuppressWarnings({"unchecked", "deprecation"})
public class GraphPanel<V, W extends Number> extends Component {

View File

@@ -1,12 +1,16 @@
package berack96.sim.util.graph.view;
package berack96.lib.graph.view;
import berack96.sim.util.graph.view.edge.EdgeIntListener;
import berack96.sim.util.graph.view.edge.EdgeListener;
import berack96.sim.util.graph.view.edge.EdgeView;
import berack96.sim.util.graph.view.vertex.VertexIntListener;
import berack96.sim.util.graph.view.vertex.VertexListener;
import berack96.sim.util.graph.view.vertex.VertexView;
import berack96.sim.util.graph.visit.*;
import berack96.lib.graph.view.edge.EdgeIntListener;
import berack96.lib.graph.view.edge.EdgeListener;
import berack96.lib.graph.view.edge.EdgeView;
import berack96.lib.graph.view.vertex.VertexIntListener;
import berack96.lib.graph.view.vertex.VertexListener;
import berack96.lib.graph.view.vertex.VertexView;
import berack96.lib.graph.visit.*;
import berack96.lib.graph.visit.impl.BFS;
import berack96.lib.graph.visit.impl.DFS;
import berack96.lib.graph.visit.impl.Dijkstra;
import berack96.lib.graph.visit.impl.Tarjan;
import javax.swing.*;
import java.awt.*;

View File

@@ -1,4 +1,4 @@
package berack96.sim.util.graph.view;
package berack96.lib.graph.view;
import java.awt.*;

View File

@@ -1,9 +1,9 @@
package berack96.sim.util.graph.view;
package berack96.lib.graph.view;
import berack96.sim.util.graph.Graph;
import berack96.sim.util.graph.view.vertex.VertexComponent;
import berack96.sim.util.graph.visit.VisitInfo;
import berack96.sim.util.graph.visit.VisitStrategy;
import berack96.lib.graph.Graph;
import berack96.lib.graph.view.vertex.VertexComponent;
import berack96.lib.graph.visit.VisitStrategy;
import berack96.lib.graph.visit.impl.VisitInfo;
import javax.swing.*;
import java.awt.event.KeyEvent;

View File

@@ -1,7 +1,7 @@
package berack96.sim.util.graph.view.edge;
package berack96.lib.graph.view.edge;
import berack96.sim.util.graph.Edge;
import berack96.sim.util.graph.view.vertex.VertexComponent;
import berack96.lib.graph.Edge;
import berack96.lib.graph.view.vertex.VertexComponent;
import java.awt.*;

View File

@@ -1,7 +1,7 @@
package berack96.sim.util.graph.view.edge;
package berack96.lib.graph.view.edge;
import berack96.sim.util.graph.Vertex;
import berack96.sim.util.graph.view.GraphPanel;
import berack96.lib.graph.Vertex;
import berack96.lib.graph.view.GraphPanel;
public class EdgeIntListener<V> extends EdgeListener<V, Integer> {

View File

@@ -1,9 +1,9 @@
package berack96.sim.util.graph.view.edge;
package berack96.lib.graph.view.edge;
import berack96.sim.util.graph.Vertex;
import berack96.sim.util.graph.view.GraphListener;
import berack96.sim.util.graph.view.GraphPanel;
import berack96.sim.util.graph.view.vertex.VertexComponent;
import berack96.lib.graph.Vertex;
import berack96.lib.graph.view.GraphListener;
import berack96.lib.graph.view.GraphPanel;
import berack96.lib.graph.view.vertex.VertexComponent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;

View File

@@ -1,12 +1,12 @@
package berack96.sim.util.graph.view.edge;
import berack96.sim.util.graph.view.GraphicalView;
import berack96.sim.util.graph.view.stuff.Arrow;
package berack96.lib.graph.view.edge;
import java.awt.*;
import java.awt.geom.Point2D;
import java.util.Collection;
import berack96.lib.graph.view.GraphicalView;
import berack96.lib.graph.view.stuff.Arrow;
public class EdgeView<V, W extends Number> implements GraphicalView<EdgeComponent<V, W>> {
private static final Font FONT = new Font("Papyrus", Font.BOLD, 14);

View File

@@ -1,4 +1,4 @@
package berack96.sim.util.graph.view.stuff;
package berack96.lib.graph.view.stuff;
import java.awt.*;

View File

@@ -1,9 +1,9 @@
package berack96.sim.util.graph.view.vertex;
import berack96.sim.util.graph.Vertex;
package berack96.lib.graph.view.vertex;
import java.awt.*;
import berack96.lib.graph.Vertex;
public class VertexComponent<V> extends Component {
private static final long serialVersionUID = 1L;

View File

@@ -1,9 +1,9 @@
package berack96.sim.util.graph.view.vertex;
package berack96.lib.graph.view.vertex;
import java.util.Arrays;
import berack96.sim.util.graph.Graph;
import berack96.sim.util.graph.view.GraphPanel;
import berack96.lib.graph.Graph;
import berack96.lib.graph.view.GraphPanel;
public class VertexIntListener extends VertexListener<Integer> {

View File

@@ -1,8 +1,8 @@
package berack96.sim.util.graph.view.vertex;
package berack96.lib.graph.view.vertex;
import berack96.sim.util.graph.Graph;
import berack96.sim.util.graph.view.GraphListener;
import berack96.sim.util.graph.view.GraphPanel;
import berack96.lib.graph.Graph;
import berack96.lib.graph.view.GraphListener;
import berack96.lib.graph.view.GraphPanel;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;

View File

@@ -1,9 +1,9 @@
package berack96.sim.util.graph.view.vertex;
import berack96.sim.util.graph.view.GraphicalView;
package berack96.lib.graph.view.vertex;
import java.awt.*;
import berack96.lib.graph.view.GraphicalView;
public class VertexView<V> implements GraphicalView<VertexComponent<V>> {
private static final Font FONT = new Font("Comic Sans MS", Font.BOLD, 17);

View File

@@ -1,10 +1,10 @@
package berack96.sim.util.graph.visit;
import berack96.sim.util.graph.Edge;
import berack96.sim.util.graph.Graph;
package berack96.lib.graph.visit;
import java.util.List;
import berack96.lib.graph.Edge;
import berack96.lib.graph.Graph;
/**
* Interface that is helpful for implements visit that needs to retrieve the distance between a vertex to all the others
*

View File

@@ -1,10 +1,10 @@
package berack96.sim.util.graph.visit;
import berack96.sim.util.graph.Edge;
package berack96.lib.graph.visit;
import java.util.List;
import java.util.Map;
import berack96.lib.graph.Edge;
/**
* Interface that is helpful for implements visit that needs to retrieve the distance between a vertex to all the others
*

View File

@@ -1,4 +1,4 @@
package berack96.sim.util.graph.visit;
package berack96.lib.graph.visit;
import java.util.Collection;

View File

@@ -1,9 +1,10 @@
package berack96.sim.util.graph.visit;
import berack96.sim.util.graph.Graph;
package berack96.lib.graph.visit;
import java.util.function.Consumer;
import berack96.lib.graph.Graph;
import berack96.lib.graph.visit.impl.VisitInfo;
/**
* This class is used for define some strategy for the visit of a graph.
*

View File

@@ -1,4 +1,4 @@
package berack96.sim.util.graph.visit;
package berack96.lib.graph.visit;
import java.util.List;

View File

@@ -1,10 +1,11 @@
package berack96.sim.util.graph.visit;
import berack96.sim.util.graph.Graph;
package berack96.lib.graph.visit.impl;
import java.util.LinkedList;
import java.util.function.Consumer;
import berack96.lib.graph.Graph;
import berack96.lib.graph.visit.VisitStrategy;
/**
* Breadth-first search<br>
* The algorithm starts at the root node and explores all of the neighbor nodes at the present depth prior to moving on to the nodes at the next depth level.

View File

@@ -1,11 +1,12 @@
package berack96.sim.util.graph.visit;
import berack96.sim.util.graph.Graph;
package berack96.lib.graph.visit.impl;
import java.util.Iterator;
import java.util.Stack;
import java.util.function.Consumer;
import berack96.lib.graph.Graph;
import berack96.lib.graph.visit.VisitStrategy;
/**
* Depth-first search<br>
* The algorithm starts at the root node and explores as far as possible along each branch before backtracking.

View File

@@ -1,11 +1,12 @@
package berack96.sim.util.graph.visit;
import berack96.sim.util.graph.Edge;
import berack96.sim.util.graph.Graph;
package berack96.lib.graph.visit.impl;
import java.util.*;
import java.util.function.Consumer;
import berack96.lib.graph.Edge;
import berack96.lib.graph.Graph;
import berack96.lib.graph.visit.VisitDistance;
/**
* Class that implements the Dijkstra algorithm and uses it for getting all the distance from a source
*

View File

@@ -1,10 +1,12 @@
package berack96.sim.util.graph.visit;
import berack96.sim.util.graph.Graph;
package berack96.lib.graph.visit.impl;
import java.util.*;
import java.util.function.Consumer;
import berack96.lib.graph.Graph;
import berack96.lib.graph.visit.VisitSCC;
import berack96.lib.graph.visit.VisitTopological;
/**
* Class that implements the Tarjan algorithm and uses it for getting the SCC and the topological sort
*

View File

@@ -1,8 +1,10 @@
package berack96.sim.util.graph.visit;
package berack96.lib.graph.visit.impl;
import java.util.*;
import java.util.function.Consumer;
import berack96.lib.graph.visit.VisitStrategy;
/**
* The class used for getting the info of the visit.<br>
* It could be used with the algorithm of the visit for set some useful data.

View File

@@ -1,4 +1,4 @@
package berack96.test.sim;
package berack96.test.lib;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -27,17 +27,20 @@ import org.junit.Test;
import com.google.gson.JsonSyntaxException;
import berack96.sim.util.graph.Edge;
import berack96.sim.util.graph.Graph;
import berack96.sim.util.graph.MapGraph;
import berack96.sim.util.graph.Vertex;
import berack96.sim.util.graph.visit.BFS;
import berack96.sim.util.graph.visit.DFS;
import berack96.sim.util.graph.visit.VisitInfo;
import berack96.lib.graph.Edge;
import berack96.lib.graph.Graph;
import berack96.lib.graph.Vertex;
import berack96.lib.graph.impl.AdjGraph;
import berack96.lib.graph.impl.MapGraph;
import berack96.lib.graph.impl.MatrixGraph;
import berack96.lib.graph.visit.impl.BFS;
import berack96.lib.graph.visit.impl.DFS;
import berack96.lib.graph.visit.impl.VisitInfo;
@SuppressWarnings("deprecation")
public class TestGraph {
/* We only try this for sake of simplicity */
private Graph<String, Integer> graph;
private final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
@@ -52,6 +55,8 @@ public class TestGraph {
public void before() {
// Change here the instance for changing all the test for that particular class
graph = new MapGraph<>();
// graph = new MatrixGraph<>();
// graph = new AdjGraph<>();
PrintStream p = null;
try {
@@ -557,6 +562,14 @@ public class TestGraph {
graph.addEdge("8", "7", 8);
Set<String> vertices = new HashSet<>();
Iterator<String> iter = graph.iterator();
assertTrue("This should not be null!", iter != null);
while (iter.hasNext())
vertices.add(iter.next());
shouldContain(vertices, "1", "2", "3", "4", "5", "6", "7", "8");
vertices.clear();
for (String vertex : graph)
vertices.add(vertex);
shouldContain(vertices, "1", "2", "3", "4", "5", "6", "7", "8");
@@ -564,13 +577,6 @@ public class TestGraph {
vertices.clear();
graph.forEach(vertices::add);
shouldContain(vertices, "1", "2", "3", "4", "5", "6", "7", "8");
vertices.clear();
Iterator<String> iter = graph.iterator();
while (iter.hasNext())
vertices.add(iter.next());
shouldContain(vertices, "1", "2", "3", "4", "5", "6", "7", "8");
}
@Test
@@ -746,6 +752,7 @@ public class TestGraph {
graph.addEdge("7", "8", 8);
Graph<String, Integer> transposed = graph.transpose();
assertTrue("This should not be null!", transposed != null);
DFS<String, Integer> dfs = new DFS<>();
VisitInfo<String> visitDFS = transposed.visit("6", dfs, null);
@@ -838,6 +845,7 @@ public class TestGraph {
graph.addEdge("7", "8", 8);
List<Edge<String, Integer>> distance = graph.distance("1", "6");
assertTrue("This should not be null!", distance != null);
int sum = distance.stream().mapToInt(Edge::getWeight).sum();
assertEquals(13, sum);
shouldContainInOrder(distance,
@@ -897,6 +905,7 @@ public class TestGraph {
graph.addEdge("7", "8", 8);
Map<String, List<Edge<String, Integer>>> distance = graph.distance("1");
assertTrue("This should not be null!", distance != null);
assertNull(distance.get("1"));
shouldContainInOrder(distance.get("2"),
new Edge<>("1", "2", 1));
@@ -1112,6 +1121,7 @@ public class TestGraph {
graph.mark("4", "z");
Graph<String, Integer> sub = graph.subGraph("1", -541);
assertTrue("This should not be null!", sub != null);
shouldContain(sub.vertices(), "1");
shouldContain(sub.edges());
@@ -1425,6 +1435,7 @@ public class TestGraph {
private void shouldContain(Collection<?> actual, Object... expected) {
assertTrue("You should pass me a collection!", actual != null);
assertEquals("They have not the same number of elements\nActual: " + actual, expected.length, actual.size());
for (Object obj : expected)
@@ -1432,6 +1443,7 @@ public class TestGraph {
}
private void shouldContainInOrder(List<?> actual, Object... expected) {
assertTrue("You should pass me a list!", actual != null);
assertEquals("They have not the same number of elements\nActual: " + actual, expected.length, actual.size());
for (int i = 0; i < actual.size(); i++)