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 n,m, 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 main(String[] args) throws Exception
{
int n, m, maxCapacity, i, j, minCapacity;
double maxProbability, value, x;
// System.out.println("
---------------------------------------------------");
// System.out.print("Enter number of nodes on the source side: \t");
// n = GetInt();
//n=100;
Scanner s=new Scanner(System.in);
System.out.println("Enter the n value: ");
n=s.nextInt();
// System.out.print("Enter number of nodes on the sink side: \t");
// m = GetInt();
System.out.println("Enter the m value: ");
m=s.nextInt();
//m =50;
System.out.print("Enter max probability: \t");
// maxProbability = GetReal();
//maxProbability =.5;
maxProbability=s.nextDouble();
// if(maxProbability >1)
//{
// System.out.println("Max probability should be less than or equal to 1");
// return;
//}
System.out.print("Enter minimum capacity: \t");
// minCapacity = GetInt();
//minCapacity =1;
minCapacity=s.nextInt();
// System.out.print("Enter maximum capacity: \t\t\t");
// maxCapacity = GetInt();
String directory = System.getProperty("user.dir");
// System.out.print("Enter the output file name: \t\t\t");
// System.out.println("---------------------------------------------------
");
//int[] capacity ={5,10,50,100,200,500,1000,2000,5000,10000};
System.out.print("Enter maximum capacity: \t");
capacity=s.nextBigInteger();
try
{
for(int c =0; c < capacity.length; c++){
String fileName = String.format("BipariteMaxCap_%s.txt", capacity[c]);
PrintWriter outFile = new PrintWriter(new FileWriter(new File(directory, fileName)));
double[][] edge = new double[n][m];
for (i =0; i < n; i++){
for (j =0; j < m; j++){
value = Math.random();
if (value <= maxProbability)
edge[i][j]= value;
else
edge[i][j]=0;
}
}
System.out.println("-----------------------------------------");
System.out.println("\tSource\tSink\tCapacity");
System.out.println("-----------------------------------------");
//computing the edges out of source
for (i =0; i < n; i++){
x = Math.random();
//Compute a capacity in range of [minCapacity, maxCapacity]
value = Math.floor(minCapacity +(x *(capacity[c]- minCapacity +1)));
System.out.println("\t"+"s"+"\tl"+(i +1)+"\t"+(int) value);
outFile.println("\t"+"s"+"\tl"+(i +1)+"\t"+(int) value);
}
for (i =0; i < n; i++){
for (j =0; j < m; j++){
if (edge[i][j]>0){
edge[i][j]= Math.floor(minCapacity +(edge[i][j]*(capacity[c]- minCapacity +1)));
System.out.println("\tl"+(i +1)+"\tr"+(j +1)+"\t"+(int) edge[i][j]);
//computing for the vertices between source and sink and writing them to the output file
outFile.println("\tl"+(i +1)+"\tr"+(j +1)+"\t"+(int) edge[i][j]);
}
}
}
//computing the edges into the sink
for (j =0; j < m; j++){
x = Math.random();
value = Math.floor(minCapacity +(x *(capacity[c]- minCapacity +1)));
System.out.println("\tr"+(j +1)+"\t"+"t"+"\t"+(int) value);
outFile.println("\tr"+(j +1)+"\t"+"t"+"\t"+(int) value);
}
System.out.println("
Output is created at: \t"+ directory +"\\"+ fileName);
outFile.close();
}
}
catch(Exception ex)
{
System.out.println(ex);
}
}
//helper functions
public static String GetString() throws IOException
{
BufferedReader stringIn = new BufferedReader (new
InputStreamReader(System.in));
return stringIn.readLine();
}
public static int GetInt() throws IOException
{
String aux = GetString();
return Integer.parseInt(aux);
}
public static double GetReal() throws IOException
{
String aux = GetString();
Double d = new Double(aux);
return d.doubleValue() ;
}
}
output i expect is an s-t flow in saved in a txt file as such
s l1882
s l2474
s l3300
s l4444
s l5523
s l6807
s l7859
s l8810
s l9851
thanks

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!