Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | ce2a03d | 2017-08-03 19:21:03 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 15 | */ |
tom | e348941 | 2014-08-29 02:30:38 -0700 | [diff] [blame] | 16 | package org.onlab.graph; |
| 17 | |
| 18 | import java.util.Map; |
| 19 | import java.util.Set; |
| 20 | |
| 21 | /** |
| 22 | * Representation of a graph path search algorithm. |
| 23 | * |
| 24 | * @param <V> vertex type |
| 25 | * @param <E> edge type |
| 26 | */ |
| 27 | public interface GraphPathSearch<V extends Vertex, E extends Edge<V>> { |
| 28 | |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 29 | static int ALL_PATHS = -1; |
Thomas Vachuska | c31d9f1 | 2015-01-22 12:33:27 -0800 | [diff] [blame] | 30 | |
tom | e348941 | 2014-08-29 02:30:38 -0700 | [diff] [blame] | 31 | /** |
| 32 | * Abstraction of a path search result. |
| 33 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 34 | interface Result<V extends Vertex, E extends Edge<V>> { |
tom | e348941 | 2014-08-29 02:30:38 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * Returns the search source. |
| 38 | * |
| 39 | * @return search source |
| 40 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 41 | V src(); |
tom | e348941 | 2014-08-29 02:30:38 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * Returns the search destination, if was was given. |
| 45 | * |
| 46 | * @return optional search destination |
| 47 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 48 | V dst(); |
tom | e348941 | 2014-08-29 02:30:38 -0700 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * Returns the set of paths produced as a result of the graph search. |
| 52 | * |
| 53 | * @return set of paths |
| 54 | */ |
| 55 | Set<Path<V, E>> paths(); |
| 56 | |
| 57 | /** |
| 58 | * Returns bindings of each vertex to its parent edges in the path. |
| 59 | * |
| 60 | * @return map of vertex to its parent edge bindings |
| 61 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 62 | Map<V, Set<E>> parents(); |
tom | e348941 | 2014-08-29 02:30:38 -0700 | [diff] [blame] | 63 | |
| 64 | /** |
| 65 | * Return a bindings of each vertex to its cost in the path. |
| 66 | * |
| 67 | * @return map of vertex to path cost bindings |
| 68 | */ |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 69 | Map<V, Weight> costs(); |
tom | e348941 | 2014-08-29 02:30:38 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /** |
Thomas Vachuska | c31d9f1 | 2015-01-22 12:33:27 -0800 | [diff] [blame] | 73 | * Searches the specified graph for paths between vertices. |
tom | e348941 | 2014-08-29 02:30:38 -0700 | [diff] [blame] | 74 | * |
Thomas Vachuska | c31d9f1 | 2015-01-22 12:33:27 -0800 | [diff] [blame] | 75 | * @param graph graph to be searched |
| 76 | * @param src optional source vertex |
| 77 | * @param dst optional destination vertex; if null paths to all vertex |
| 78 | * destinations will be searched |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 79 | * @param weigher optional edge-weigher; if null, {@link DefaultEdgeWeigher} |
| 80 | * will be used (assigns equal weights to all links) |
Thomas Vachuska | c31d9f1 | 2015-01-22 12:33:27 -0800 | [diff] [blame] | 81 | * @param maxPaths limit on number of paths; {@link GraphPathSearch#ALL_PATHS} if no limit |
tom | e348941 | 2014-08-29 02:30:38 -0700 | [diff] [blame] | 82 | * @return search results |
| 83 | */ |
Thomas Vachuska | c31d9f1 | 2015-01-22 12:33:27 -0800 | [diff] [blame] | 84 | Result<V, E> search(Graph<V, E> graph, V src, V dst, |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 85 | EdgeWeigher<V, E> weigher, int maxPaths); |
tom | e348941 | 2014-08-29 02:30:38 -0700 | [diff] [blame] | 86 | |
| 87 | } |