// dsaII_17_15_skeleton.java // traj dsaII_17_15_skeleton [ n [ e [ seed [ distance ]]]] /** * 15. Write an algorithm that finds and returns the "near" vertices of a * given vertex v in graph G. To a near vertex, there is a path of cost at * most k (as the sum of weights of the edges of the path) from vertex v. * Parameters are thus a graph, starting vertex, and maximum path cost. Return * value is a set of vertices. Use depth or breadth first search and limit the * depth of search by the cost of the path. **/ import fi.joensuu.cs.tra.*; import java.lang.RuntimeException; import java.util.Random; public class dsaII_17_15_skeleton { public static void main(String[] args) { // defaults int vertices = 6; int edges = 13; int maxDistance = 10; if (args.length > 0) vertices = Integer.valueOf(args[0]); if (args.length > 1) edges = Integer.valueOf(args[1]); // random seed int rseed = vertices+edges; if (args.length > 2) rseed = Integer.valueOf(args[2]); // maxDistance if (args.length > 3) maxDistance = Integer.valueOf(args[3]); dsaII_17_15_skeleton y = new dsaII_17_15_skeleton(); DiGraph graph = GraphMaker.createDiGraph(vertices, edges, rseed); GraphMaker.setWeights(graph, 10, (float)0.1, rseed); if (vertices < 20) System.out.println(GraphMaker.toString(graph, 1)); // search near from every vertex System.out.println("\nNear vertices (max " + maxDistance + ")"); for (Vertex v : graph.vertices()) { System.out.println("From " + v + " : " + y.nearVertices(graph, v, maxDistance)); } } // main() // returns vertices at most distance x from v Set nearVertices(DiGraph g, Vertex v, float x) { // TODO Set S = new Set(); return S; } }