import java.util.HashMap; import java.util.Map; import java.util.Random; /** * Simple topology generator. It produces a graph with a given * number of nodes, and connects each node to the 3 nearest ones. * * @author Andras */ public class Nearest3 { private double areaWidth = 600; private double areaHeight = 400; private int nodes = 50; private long seed = 1234; public Nearest3() { } public Nearest3(int nodes, long seed) { this.nodes = nodes; this.seed = seed; } public int getNodes() { return nodes; } public void setNodes(int nodes) { this.nodes = nodes; } public long getSeed() { return seed; } public void setSeed(long seed) { this.seed = seed; } public double getAreaWidth() { return areaWidth; } public void setAreaWidth(double areaWidth) { this.areaWidth = areaWidth; } public double getAreaHeight() { return areaHeight; } public void setAreaHeight(double areaHeight) { this.areaHeight = areaHeight; } /** * Generates a connected graph with the given number of nodes and edges, and * no multiple connections between any two nodes. * * @return the node coordinates and edge list in a map */ @SuppressWarnings("unchecked") public Map generate() { double[] nodeX = new double[nodes]; double[] nodeY = new double[nodes]; int[] edgeSrc = new int[3*nodes]; int[] edgeDest = new int[3*nodes]; Random random = new Random(seed); // place nodes for (int i = 0; i =1 ? Integer.parseInt(args[0]) : 10; long seed = args.length>=2 ? Long.parseLong(args[1]) : System.currentTimeMillis(); Nearest3 nearest3 = new Nearest3(nodes, seed); nearest3.generate(); } }