Question: Some one please run for me this code and help me understand why am not able to get an output and where i can adjust
Some one please run for me this code and help me understand why am not able to get an output and where i can adjust the v e in and max values
code
import java.ioBufferedWriter;
import java.ioFileWriter;
import java.util.;
public class RandomGraph
private static final String NL
;
Main method: Entry point for the program.
Usage: java RandomGraph v e min max f
@param args Commandline arguments: v vertices e edges per node min min capacity max max capacity f file path
public static void mainString args
if argslength
System.out.printlnInvalid parameters!";
System.out.printlnUsage:;
System.out.printlnjava RandomGraph v e min max f;
System.out.printlnv Number of vertices in the graph";
System.out.printlne Number of edges leaving each node";
System.out.printlnmin Lower bound on edge capacities";
System.out.printlnmax Upper bound on edge capacities";
System.out.printlnf File path for saving this graph";
System.out.printlnExample: java RandomGraph graphtxt;
return;
try
int v Integer.parseIntargs;
int e Integer.parseIntargs;
int min Integer.parseIntargs;
int max Integer.parseIntargs;
String filePath args;
if v e
System.out.printlnFAIL The number of vertices must exceed the number of edges leaving each node.";
return;
if max min
System.out.printlnFAIL Max must be greater than or equal to min.";
return;
StringBuffer graphData graphBuilderv e min, max;
toFilegraphData filePath;
System.out.printlnDONE Graph saved to filePath;
catch NumberFormatException e
System.out.printlnError: Parameters v e min, and max must be integers.";
Builds the graph data.
@param v Number of vertices in the graph
@param e Number of edges leaving each vertex
@param min Lower bound on edge capacities
@param max Upper bound on edge capacities
@return A StringBuffer containing the graph representation
public static StringBuffer graphBuilderint v int e int min, int max
Random gen new Random;
StringBuffer bfr new StringBuffer;
Add edges from source node s
SortedSet s new TreeSet;
int j ;
while j e
int head gen.nextIntv;
if scontainshead
saddhead;
int c min gen.nextIntmax min ;
bfrappendStringformats vd ds head, c NL;
j;
Add edges to sink node t
sclear;
j ;
while j e
int tail gen.nextIntv;
if scontainstail
saddtail;
int c min gen.nextIntmax min ;
bfrappendStringformatvd t ds tail, c NL;
j;
Add edges for internal nodes
for int i ; i v; i
sclear;
saddi;
j ;
while j e
int head gen.nextIntv;
if scontainshead
saddhead;
int c min gen.nextIntmax min ;
bfrappendStringformatvd vd ds i head, c NL;
j;
return bfr;
Writes the graph data to a file.
@param outString The graph data as a StringBuffer
@param filename The file path where the graph will be saved
private static void toFileStringBuffer outString, String filename
try BufferedWriter fout new BufferedWriternew FileWriterfilename
fout.writeoutStringtoString;
catch Exception e
System.out.printlnError saving file.";
System.out.printlnPlease check the file path and try again.";
System.exit;
output
s v
s v
s v
v t
v t
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
