import java.io.*; public class RandomGraf { /** Produces a random bipartite graph */ public RandomGraf() { } /** Produces a file containg a random bipartite graph */ public static void SkrivGraf(String Navn, int n1, int n2, int m) { BufferedWriter out; try { out = new BufferedWriter(new FileWriter(Navn)); out.write(n1 + "\n"); out.write(n2 + "\n"); out.write(m + "\n"); for (int i=0;i<m;i++) { int ui = (int)(n1*Math.random()); int wi = (int)(n2*Math.random()); out.write(ui + " " + wi + "\n"); }; out.close(); } catch (IOException e) { System.err.println("Filen kunne ikke oprettes\n"); System.exit(1); }; } /** Prints a small userguide to the standard output. */ public static void usage() { System.err.println("Følgende parametre kræves:"); System.err.println("\nLavGraf Navn n1 n2 m"); System.err.println("Hvor 'Navn' er navnet på filen grafen skal gemmes i."); System.err.println("n1, n2 og m er henholdsvis antallet af venstre, højre knuder og"); System.err.println("antallet af kanter"); } /** Runs the program. @param args the command-line arguments. */ public static void main(String[] args) { try { SkrivGraf(args[0], new Integer(args[1]).intValue(), new Integer(args[2]).intValue(), new Integer(args[3]).intValue()); } catch (ArrayIndexOutOfBoundsException e) { usage(); } catch (NumberFormatException e) { usage(); } } } // RandomGraf