Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
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 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 69 | Map<V, Double> 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 |
| 79 | * @param weight optional edge-weight; if null cost of each edge will be |
| 80 | * assumed to be 1.0 |
| 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, |
| 85 | EdgeWeight<V, E> weight, int maxPaths); |
tom | e348941 | 2014-08-29 02:30:38 -0700 | [diff] [blame] | 86 | |
| 87 | } |