-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweighted_graph_algorithms.java
75 lines (72 loc) · 2.29 KB
/
weighted_graph_algorithms.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package ex1.src;
import java.util.List;
/**
* This interface represents an Undirected (positive) Weighted Graph Theory algorithms including:
* 0. clone(); (copy)
* 1. init(graph);
* 2. isConnected();
* 3. double shortestPathDist(int src, int dest);
* 4. List<node_data> shortestPath(int src, int dest);
* 5. Save(file);
* 6. Load(file);
*
* @author boaz.benmoshe
*
*/
public interface weighted_graph_algorithms {
/**
* Init the graph on which this set of algorithms operates on.
* @param g
*/
public void init(weighted_graph g);
/**
* Return the underlying graph of which this class works.
* @return
*/
public weighted_graph getGraph();
/**
* Compute a deep copy of this weighted graph.
* @return
*/
public weighted_graph copy();
/**
* Returns true if and only if (iff) there is a valid path from EVREY node to each
* other node. NOTE: assume ubdirectional graph.
* @return
*/
public boolean isConnected();
/**
* returns the length of the shortest path between src to dest
* Note: if no such path --> returns -1
* @param src - start node
* @param dest - end (target) node
* @return
*/
public double shortestPathDist(int src, int dest);
/**
* returns the the shortest path between src to dest - as an ordered List of nodes:
* src--> n1-->n2-->...dest
* see: https://en.wikipedia.org/wiki/Shortest_path_problem
* Note if no such path --> returns null;
* @param src - start node
* @param dest - end (target) node
* @return
*/
public List<node_info> shortestPath(int src, int dest);
/**
* Saves this weighted (undirected) graph to the given
* file name
* @param file - the file name (may include a relative path).
* @return true - iff the file was successfully saved
*/
public boolean save(String file);
/**
* This method load a graph to this graph algorithm.
* if the file was successfully loaded - the underlying graph
* of this class will be changed (to the loaded one), in case the
* graph was not loaded the original graph should remain "as is".
* @param file - file name
* @return true - iff the graph was successfully loaded.
*/
public boolean load(String file);
}