Question: I would like an understanding of the following code in java without changing the meaning, it is a used to generate graphs code import java.io
I would like an understanding of the following code in java without changing the meaning, it is a used to generate graphs
code
import java.ioBufferedWriter;
import java.ioFileWriter;
import java.util.;
public class RandomGraph
private static final String NL
;
Entrance point for the program.
java RandomGraph v e m f
@param v the first endpoint of this edge
@param e the number of edges leaving each node
@param min the lower bound on the edge capacities
@param max the upper bound on the edge capacities
@param f path and file name for saving the graph
public static void mainString args
ifargslength
System.out.println
Invalid parameters!";
System.out.printlnUsage:;
System.out.printlnjava RandomGraph v e min, max, f;
System.out.printlnv the number of vertices in the graph";
System.out.printlne the number of edges leaving each node";
System.out.printlnmin the lower bound on edge capacities";
System.out.printlnmax the upper bound on edge capacities";
System.out.printlnf path and file name for saving this graph";
System.out.printlnExample: java RandomGraph graphtxt;
else ifIntegerparseIntargs Integer.parseIntargs
ifIntegerparseIntargs Integer.parseIntargs
toFilegraphBuilderIntegerparseIntargsInteger.parseIntargsInteger.parseIntargsInteger.parseIntargsargs;
System.out.println
DONE!";
else
System.out.println
FAIL!";
System.out.printlnMax must be greater than or equal to min.";
else
System.out.println
FAIL!";
System.out.printlnThe number of vertices must exceed the number of edges leaving each node.";
Constructor
This method creates a token representation of a graph.
@param v The number of vertices in the graph
@param e The number of edges leaving each vertice
@param min The lowerbound on the capacity value of each edge
@param max The upperbound on the capacity value of each edge
@return A string buffer, each line contains tokens corresponding
to a directed edge: the tail, the head, and the capacity.
public static StringBuffer graphBuilderint v int e int min, int max
int i;
int j;
int head;
int c;
SortedSet s;
Random gen new Random;
StringBuffer bfr new StringBuffer;
Add distinguished node s
j ;
s new TreeSet;
whilej e
head gen.nextIntv;
ifscontainshead
saddhead;
c min gen.nextIntmax min ;
bfrappendsvheadcNL;
j;
Add distinguished node t
j ;
s new TreeSet;
whilej e
int tail gen.nextIntv;
ifscontainstail
saddtail;
c min gen.nextIntmax min ;
bfrappendvtailtcNL;
j;
Add internal nodes
fori ; i v; i
s new TreeSet;
saddi;
j ;
whilej e
head gen.nextIntv;
ifscontainshead
saddhead;
c min gen.nextIntmax min ;
bfrappendvivheadcNL;
j;
return bfr;
This method attempts to save a string at a given location.
@param outString The StringBuffer containing the data being saved
@param filename The complete file path including file name
private static void toFileStringBuffer outString, String filename
try
BufferedWriter fout new BufferedWriternew FileWriterfilename;
fout.writeoutStringtoString;
fout.close;
catchException e
System.out.printlnError saving file.";
System.out.printlnPlease check file paths and restart this program.";
System.exit;
Errors
Cannot resolve symbol v
Cannot resolve symbol e
Cannot resolve symbol 'min'
Cannot resolve symbol 'max'
Cannot resolve symbol f
Raw use of parameterized class 'SortedSet'
Raw use of parameterized class 'TreeSet'
Unchecked call to 'addE as a member of raw type 'java.util.Set'
String concatenation as argument to 'StringBuffer.append call
Raw use of parameterized class 'TreeSet'
Unchecked call to 'addE as a member of raw type 'java.util.Set'
String concatenation as argument to 'StringBuffer.append call
Raw use of parameterized class 'TreeSet'
Unchecked call to 'addE as a member of raw type 'java.util.Set'
Unchecked call to 'addE as a member of raw type 'java.util.Set'
String concatenation as argument to 'StringBuffer.append call
output expected to a faile called graph
output.txt
s v
s v
s v
vt
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
