1 | |
---|
2 | package GraphType; |
---|
3 | |
---|
4 | import clustering.MyPair; |
---|
5 | import edu.uci.ics.jung.graph.AbstractTypedGraph; |
---|
6 | import edu.uci.ics.jung.graph.DirectedGraph; |
---|
7 | import edu.uci.ics.jung.graph.util.EdgeType; |
---|
8 | import edu.uci.ics.jung.graph.util.Pair; |
---|
9 | import java.util.ArrayList; |
---|
10 | import java.util.Arrays; |
---|
11 | import java.util.Collection; |
---|
12 | import java.util.HashMap; |
---|
13 | import java.util.List; |
---|
14 | import java.util.Map; |
---|
15 | |
---|
16 | public class DirectedDenseGraph<V,E> extends AbstractTypedGraph<V, E> implements DirectedGraph<V, E> { |
---|
17 | |
---|
18 | protected Map<V,List<MyPair<V,E>>> adjacency_list; |
---|
19 | |
---|
20 | public DirectedDenseGraph() { |
---|
21 | super(EdgeType.DIRECTED); |
---|
22 | adjacency_list = new HashMap<V, List<MyPair<V,E>>>(); |
---|
23 | |
---|
24 | } |
---|
25 | |
---|
26 | public Collection<E> getInEdges(V v) { |
---|
27 | List<E> edges = new ArrayList<E>(); |
---|
28 | for(V key : adjacency_list.keySet()){ |
---|
29 | List<MyPair<V,E>> edges_to_check = adjacency_list.get(key); |
---|
30 | for(MyPair<V,E> edge : edges_to_check){ |
---|
31 | if(edge.getFirst().equals(v)) |
---|
32 | edges.add(edge.getSecond()); |
---|
33 | } |
---|
34 | } |
---|
35 | return edges; |
---|
36 | } |
---|
37 | |
---|
38 | public Collection<E> getOutEdges(V v) { |
---|
39 | List<E> edges = new ArrayList<E>(); |
---|
40 | if(adjacency_list.containsKey(v)){ |
---|
41 | for(MyPair<V,E> edge : adjacency_list.get(v)){ |
---|
42 | edges.add(edge.getSecond()); |
---|
43 | } |
---|
44 | } |
---|
45 | return edges; |
---|
46 | } |
---|
47 | |
---|
48 | public Collection<V> getPredecessors(V v) { |
---|
49 | throw new UnsupportedOperationException("Not supported yet."); |
---|
50 | } |
---|
51 | |
---|
52 | public Collection<V> getSuccessors(V v) { |
---|
53 | throw new UnsupportedOperationException("Not supported yet."); |
---|
54 | } |
---|
55 | |
---|
56 | @Override |
---|
57 | public int inDegree(V v) { |
---|
58 | throw new UnsupportedOperationException("Not supported yet."); |
---|
59 | } |
---|
60 | |
---|
61 | @Override |
---|
62 | public int outDegree(V v) { |
---|
63 | if(adjacency_list.containsKey(v)){ |
---|
64 | return adjacency_list.get(v).size(); |
---|
65 | } |
---|
66 | else |
---|
67 | return 0; |
---|
68 | } |
---|
69 | |
---|
70 | public boolean isPredecessor(V v, V v1) { |
---|
71 | throw new UnsupportedOperationException("Not supported yet."); |
---|
72 | } |
---|
73 | |
---|
74 | public boolean isSuccessor(V v, V v1) { |
---|
75 | throw new UnsupportedOperationException("Not supported yet."); |
---|
76 | } |
---|
77 | |
---|
78 | public int getPredecessorCount(V v) { |
---|
79 | throw new UnsupportedOperationException("Not supported yet."); |
---|
80 | } |
---|
81 | |
---|
82 | public int getSuccessorCount(V v) { |
---|
83 | throw new UnsupportedOperationException("Not supported yet."); |
---|
84 | } |
---|
85 | |
---|
86 | public V getSource(E e) { |
---|
87 | throw new UnsupportedOperationException("Not supported yet."); |
---|
88 | } |
---|
89 | |
---|
90 | public V getDest(E e) { |
---|
91 | throw new UnsupportedOperationException("Not supported yet."); |
---|
92 | } |
---|
93 | |
---|
94 | public boolean isSource(V v, E e) { |
---|
95 | throw new UnsupportedOperationException("Not supported yet."); |
---|
96 | } |
---|
97 | |
---|
98 | public boolean isDest(V v, E e) { |
---|
99 | throw new UnsupportedOperationException("Not supported yet."); |
---|
100 | } |
---|
101 | |
---|
102 | @Override |
---|
103 | public boolean addEdge(E e, V v, V v1) { |
---|
104 | List<MyPair<V,E>> edge_list; |
---|
105 | if(adjacency_list.containsKey(v)){ |
---|
106 | edge_list = adjacency_list.get(v); |
---|
107 | } |
---|
108 | else{ |
---|
109 | edge_list = new ArrayList<MyPair<V,E>>(); |
---|
110 | } |
---|
111 | edge_list.add(new MyPair(v1,e)); |
---|
112 | adjacency_list.put(v, edge_list); |
---|
113 | |
---|
114 | if(!adjacency_list.containsKey(v1)) |
---|
115 | adjacency_list.put(v1, new ArrayList<MyPair<V,E>>()); |
---|
116 | |
---|
117 | return true; |
---|
118 | } |
---|
119 | |
---|
120 | public boolean addEdge(E e, V v, V v1, EdgeType et) { |
---|
121 | throw new UnsupportedOperationException("Not supported yet."); |
---|
122 | } |
---|
123 | |
---|
124 | public Pair<V> getEndpoints(E e) { |
---|
125 | throw new UnsupportedOperationException("Not supported yet."); |
---|
126 | } |
---|
127 | |
---|
128 | public V getOpposite(V v, E e) { |
---|
129 | throw new UnsupportedOperationException("Not supported yet."); |
---|
130 | } |
---|
131 | |
---|
132 | public Collection<E> getEdges() { |
---|
133 | throw new UnsupportedOperationException("Not supported yet."); |
---|
134 | } |
---|
135 | |
---|
136 | public Collection<V> getVertices() { |
---|
137 | return adjacency_list.keySet(); |
---|
138 | } |
---|
139 | |
---|
140 | public boolean containsVertex(V v) { |
---|
141 | throw new UnsupportedOperationException("Not supported yet."); |
---|
142 | } |
---|
143 | |
---|
144 | public boolean containsEdge(E e) { |
---|
145 | throw new UnsupportedOperationException("Not supported yet."); |
---|
146 | } |
---|
147 | |
---|
148 | public int getEdgeCount() { |
---|
149 | int edge_count = 0; |
---|
150 | for(V key : adjacency_list.keySet()){ |
---|
151 | edge_count+=adjacency_list.get(key).size(); |
---|
152 | } |
---|
153 | return edge_count; |
---|
154 | } |
---|
155 | |
---|
156 | public int getVertexCount() { |
---|
157 | return adjacency_list.keySet().size(); |
---|
158 | } |
---|
159 | |
---|
160 | public Collection<V> getNeighbors(V v) { |
---|
161 | throw new UnsupportedOperationException("Not supported yet."); |
---|
162 | } |
---|
163 | |
---|
164 | public Collection<E> getIncidentEdges(V v) { |
---|
165 | throw new UnsupportedOperationException("Not supported yet."); |
---|
166 | } |
---|
167 | |
---|
168 | @Override |
---|
169 | public Collection<V> getIncidentVertices(E e) { |
---|
170 | List<V> incident_vertices = new ArrayList<V>(); |
---|
171 | for(V key : adjacency_list.keySet()){ |
---|
172 | for(MyPair<V,E> edge : adjacency_list.get(key)){ |
---|
173 | if (edge.getSecond().equals(e)){ |
---|
174 | incident_vertices.add(edge.getFirst()); |
---|
175 | } |
---|
176 | } |
---|
177 | } |
---|
178 | return incident_vertices; |
---|
179 | } |
---|
180 | |
---|
181 | public E findEdge(V v, V v1) { |
---|
182 | throw new UnsupportedOperationException("Not supported yet."); |
---|
183 | } |
---|
184 | |
---|
185 | public Collection<E> findEdgeSet(V v, V v1) { |
---|
186 | throw new UnsupportedOperationException("Not supported yet."); |
---|
187 | } |
---|
188 | |
---|
189 | public boolean addVertex(V v) { |
---|
190 | throw new UnsupportedOperationException("Not supported yet."); |
---|
191 | } |
---|
192 | |
---|
193 | public boolean addEdge(E e, Collection<? extends V> clctn) { |
---|
194 | throw new UnsupportedOperationException("Not supported yet."); |
---|
195 | } |
---|
196 | |
---|
197 | public boolean addEdge(E e, Collection<? extends V> clctn, EdgeType et) { |
---|
198 | throw new UnsupportedOperationException("Not supported yet."); |
---|
199 | } |
---|
200 | |
---|
201 | public boolean removeVertex(V v) { |
---|
202 | throw new UnsupportedOperationException("Not supported yet."); |
---|
203 | } |
---|
204 | |
---|
205 | public boolean removeEdge(E e) { |
---|
206 | throw new UnsupportedOperationException("Not supported yet."); |
---|
207 | } |
---|
208 | |
---|
209 | public boolean isNeighbor(V v, V v1) { |
---|
210 | throw new UnsupportedOperationException("Not supported yet."); |
---|
211 | } |
---|
212 | |
---|
213 | public boolean isIncident(V v, E e) { |
---|
214 | throw new UnsupportedOperationException("Not supported yet."); |
---|
215 | } |
---|
216 | |
---|
217 | public int degree(V v) { |
---|
218 | throw new UnsupportedOperationException("Not supported yet."); |
---|
219 | } |
---|
220 | |
---|
221 | public int getNeighborCount(V v) { |
---|
222 | throw new UnsupportedOperationException("Not supported yet."); |
---|
223 | } |
---|
224 | |
---|
225 | @Override |
---|
226 | public int getIncidentCount(E e) { |
---|
227 | return 1; |
---|
228 | } |
---|
229 | |
---|
230 | public EdgeType getEdgeType(E e) { |
---|
231 | throw new UnsupportedOperationException("Not supported yet."); |
---|
232 | } |
---|
233 | |
---|
234 | public EdgeType getDefaultEdgeType() { |
---|
235 | throw new UnsupportedOperationException("Not supported yet."); |
---|
236 | } |
---|
237 | |
---|
238 | public Collection<E> getEdges(EdgeType et) { |
---|
239 | throw new UnsupportedOperationException("Not supported yet."); |
---|
240 | } |
---|
241 | |
---|
242 | public int getEdgeCount(EdgeType et) { |
---|
243 | throw new UnsupportedOperationException("Not supported yet."); |
---|
244 | } |
---|
245 | |
---|
246 | @Override |
---|
247 | public boolean addEdge(E e, Pair<? extends V> pair, EdgeType et) { |
---|
248 | throw new UnsupportedOperationException("Not supported yet."); |
---|
249 | } |
---|
250 | |
---|
251 | |
---|
252 | |
---|
253 | } |
---|