Question: I am in need of help, I have this code to generate a Scalingfordfulkerson, however i would like it to be flexible such at you
I am in need of help, I have this code to generate a Scalingfordfulkerson, however i would like it to be flexible such at you enter the nm probability and capacity.
I would like to program to save the output as a text file or ask the user to enter the output filename
the code for the bipartite graph in java
package graph.generation.bipartiteGraphGen;
import java.io;
import java.util.Scanner;
public class BipartiteGraph
public static void mainString args throws Exception
int n m maxCapacity, i j minCapacity;
double maxProbability, value, x;
System.out.println
;
System.out.printEnter number of nodes on the source side: t;
n GetInt;
n;
Scanner snew ScannerSystemin;
System.out.printlnEnter the n value: ;
nsnextInt;
System.out.printEnter number of nodes on the sink side: t;
m GetInt;
System.out.printlnEnter the m value: ;
msnextInt;
m ;
System.out.printEnter max probability: t;
maxProbability GetReal;
maxProbability ;
maxProbabilitysnextDouble;
ifmaxProbability
System.out.printlnMax probability should be less than or equal to ;
return;
System.out.printEnter minimum capacity: t;
minCapacity GetInt;
minCapacity ;
minCapacitysnextInt;
System.out.printEnter maximum capacity: ttt;
maxCapacity GetInt;
String directory System.getPropertyuserdir";
System.out.printEnter the output file name: ttt;
System.out.println
;
int capacity ;
System.out.printEnter maximum capacity: t;
capacitysnextBigInteger;
try
forint c ; c capacity.length; c
String fileName String.formatBipariteMaxCapstxt capacityc;
PrintWriter outFile new PrintWriternew FileWriternew Filedirectory fileName;
double edge new doublenm;
for i ; i n; i
for j ; j m; j
value Math.random;
if value maxProbability
edgeij value;
else
edgeij;
System.out.println;
System.out.printlntSourcetSinktCapacity;
System.out.println;
computing the edges out of source
for i ; i n; i
x Math.random;
Compute a capacity in range of minCapacity maxCapacity
value Math.floorminCapacity x capacityc minCapacity ;
System.out.printlntstli tint value;
outFile.printlntstli tint value;
for i ; i n; i
for j ; j m; j
if edgeij
edgeij Math.floorminCapacity edgeijcapacityc minCapacity ;
System.out.printlntli trj tint edgeij;
computing for the vertices between source and sink and writing them to the output file
outFile.printlntli trj tint edgeij;
computing the edges into the sink
for j ; j m; j
x Math.random;
value Math.floorminCapacity x capacityc minCapacity ;
System.out.printlntrj tttint value;
outFile.printlntrj tttint value;
System.out.println
Output is created at: t directory fileName;
outFile.close;
catchException ex
System.out.printlnex;
helper functions
public static String GetString throws IOException
BufferedReader stringIn new BufferedReader new
InputStreamReaderSystemin;
return stringIn.readLine;
public static int GetInt throws IOException
String aux GetString;
return Integer.parseIntaux;
public static double GetReal throws IOException
String aux GetString;
Double d new Doubleaux;
return ddoubleValue ;
output i expect is an st flow in saved in a txt file as such
s l
s l
s l
s l
s l
s l
s l
s l
s l
thanks
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
