DOC PREVIEW
UT Dallas CS 6385 - New Text Document

This preview shows page 1 out of 4 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

/** To change this template, choose Tools | Templates* and open the template in the editor.*/import java.io.*;import java.net.*;import java.math.*;/**** @author abidemi*/public class Project1{int N;int M;public static void main (String [] args) throws IOException{InputStreamReader nodesReader = new InputStreamReader (System.in);BufferedReader nodesInput = new BufferedReader (nodesReader);System.out.println ("Enter number of nodes N");String nodesText = nodesInput.readLine();int N = new Integer (nodesText).intValue();System.out.println(N);InputStreamReader mReader = new InputStreamReader (System.in);BufferedReader mInput = new BufferedReader (mReader);System.out.println ("Enter the value of M ");String mText = mInput.readLine();int M = new Integer (mText).intValue();System.out.println(M);int sd = 0 ;int s[] = new int [N];int d [] = new int [N] ;int xcounter = 0;int ycounter = 0 ;double costProb = 5.0 ; // use to set the probability of link connectiondouble trafficProb = 7.0 ;double nodesProb = 0.5 ;int[] [] a = new int[N] [N]; // link cost between neighboring nodes i and jint[] [] b = new int[N] [N]; // traffic demand between nodes i and jint[] [] z = new int[N] [N]; // total cost of sending traffic btween nodes i andjint[] [] PN = new int[N] [N];int[] [] Nodes = new int[N] [N];int[] [] G = new int[N] [N];/* Generates a n*n 2-D matrix at random to represent traffic demand between pairof nodes */for(int i=0 ; i<N; i++){for (int j= 0; j< N; j++){double trafficNumber =(double)(Math.random()*10);int trafficTemp = (int) (1 + (Math.random()*M) );if (trafficNumber < trafficProb) // set the probability of lin connectionshence (Pr of connection is prob/10){PN [i] [j] = 1;xcounter = xcounter +1;}else{PN [i] [j] = 0;ycounter = ycounter +1 ;}if (i==j){b[i][j] = 0;}else{b[i][j] = PN[i][j] * trafficTemp;}System.out.print(/* "\t b["+ i +"]" + "[" + j + "] = " */ + b[i][j] + "\t");}System.out.println();}/* Generates a 2-D n*n matrix to represent the unit cost of each link */for (int i = 0 ; i < N ; i++){for (int j = i+1 ; j < N ; j++){double costNumber =(double)(Math.random()*10); // generates a random numberbetween 0 and 10int costTemp = (int) (1 + (Math.random()*M) ); // generates a random numberbetween 1 and Mif (costNumber < costProb){PN [i] [j] = 1;xcounter = xcounter +1;}else{PN [i] [j] = 0;ycounter = ycounter +1 ;}if (i==j){a[i][j] = 0;}else{a[i][j] = PN[i][j] * costTemp;a[j][i] = PN[i][j] * costTemp;}}}for (int i=1; i< N; i++){for (int j=1; j<N; j++){if (a[i][j] == 0){a[i][j] = 99999999 ;}System.out.print(/* "\t a["+ i +"]" + "[" + j + "] = " */ + a[i][j] + "\t");}System.out.println();}// generate random source-destination pairs and trafic demand between themfor(int i=0 ; i< sd; i++){ // generates a random number between 0 and 10int temp = (int) (1 + (Math.random()*N) ); // generates a random number between 1and Ns[i] = temp;temp = (int) (1 + (Math.random()*N) );d[i] = temp;//System.out.print("\t s["+ i +"] -d[" + i + "] = " + s[i] + " "+ d[i]);String str2 = "";try {str2 = str2 + "\t s["+ i +"]" + " -d[" + i + "] = " + Integer.toString (s[i]) + " " + ""+Integer.toString (d[i]);BufferedWriter out2 = new BufferedWriter(new FileWriter("sourceDestPairs.txt"));out2.write(str2);out2.close();} catch (IOException e) {}}System.out.println();System.out.println();/* generates the random graph */for (int i = 0 ; i < N ; i++){for (int j = i+1 ; j < N ; j++){double temp = Math.random(); // generates random numbers to assignedges between nodes i and jif(temp >= nodesProb){G [i][j]++; //increments number of edges between nodes i and jG [j][i]++ ; ////increments number of edges between nodes i andj// ncrements the number of edges so far assigned tonode jNodes [i][j]++ ;Nodes [j][i]++ ;} // end of if(temp >= prob)} // end of inner for statement} // end of outer for statementfor (int i= 1; i< N ; i++){for (int j=1; j< N; j++){System.out.print(/* "\t a["+ i +"]" + "[" + j + "] = " */ + G[i][j] + "\t");}System.out.println() ;}// writeout the link cost a[][] to a file named costMatrix.txtString str = "";try {for(int i=0 ; i<PN.length; i++){for (int j= 0; j< PN[i].length; j++){ str = str + "\t a["+ i +"]" + "[" + j + "] = " + Integer.toString (a[i][j]);BufferedWriter out = new BufferedWriter(new FileWriter("costMatric.txt"));out.write(str);out.close();}str = str + "\n";}} catch (IOException e) {}System.out.println("xcounter = " + xcounter);System.out.println("ycounter = " + ycounter);double percent = 100* (ycounter / ((double)(xcounter+ycounter))) ;System.out.println("percent = " + percent + "%");}public static void FloydWarshall (int [][] path, int N){for (int k = 1; k<N ; k++){for (int i = 1; i<N ; i++){for (int j = 1; j<N ; j++){path[i][j] = Math.min ( path[i][j], path[i][k]+path[k][j] );}}}}public void FloydWarshallWithPathReconstruction (int [][] path){int [][] next = new int [N][N];for (int k = 1; k<N ; k++){for (int i= 1; i<N ; i++){for (int j= 1; j<N ; j++)if (path[i][k] + path[k][j] < path[i][j]){path[i][j] = path[i][k]+path[k][j];next[i][j] = k;}}}}public static int GetPath (int i, int j, int N, int [][] path ){int infinity = 99999 ;int [][] next = new int [N][N];if (path[i][j] == infinity){return 99999;}int intermediate = next[i][j];if (intermediate == 0 ){return 0; /* there is an edge from i to j, with no vertices between */}elsereturn GetPath(i,intermediate, N, path) + intermediate + GetPath(intermediate,j,N,


View Full Document

UT Dallas CS 6385 - New Text Document

Documents in this Course
assn1

assn1

2 pages

38rel2

38rel2

5 pages

Report

Report

3 pages

networks

networks

18 pages

lp2

lp2

44 pages

lp2 (2)

lp2 (2)

27 pages

lp1(1)

lp1(1)

21 pages

integer1

integer1

50 pages

FrankR2

FrankR2

3 pages

duality

duality

28 pages

CMST

CMST

44 pages

hw4

hw4

3 pages

for 1

for 1

11 pages

ENCh02

ENCh02

33 pages

pree

pree

2 pages

new  3

new 3

2 pages

new  2

new 2

2 pages

hw4a

hw4a

2 pages

T2_Sol

T2_Sol

4 pages

ISM3

ISM3

8 pages

hw4_sol

hw4_sol

6 pages

Elm04_06

Elm04_06

11 pages

atn proj2

atn proj2

20 pages

12CUT1

12CUT1

8 pages

09Ford

09Ford

23 pages

08FLOW

08FLOW

6 pages

03LP_su

03LP_su

6 pages

40REL40

40REL40

5 pages

39rel3

39rel3

5 pages

38arel2

38arel2

5 pages

37REL1

37REL1

3 pages

24TABU

24TABU

3 pages

22DYNPR

22DYNPR

3 pages

21B&C

21B&C

2 pages

20BBEX0

20BBEX0

3 pages

19BB

19BB

5 pages

14CAPBUD0

14CAPBUD0

11 pages

35BRXCH

35BRXCH

2 pages

34COMB

34COMB

4 pages

32CAPAS

32CAPAS

4 pages

31QUEUE

31QUEUE

3 pages

Load more
Download New Text Document
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view New Text Document and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view New Text Document 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?