MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / tspdp

Method tspdp

Dynamic Programming/TSP.java:40–63  ·  view source on GitHub ↗
(int c[][], int tour[], int start, int n)

Source from the content-addressed store, hash-verified

38System.out.println("*** ***** *****");
39}
40static int tspdp(int c[][], int tour[], int start, int n)
41{
42int mintour[]=new int[10], temp[]=new int[10], mincost=999, ccost, i, j, k;
43if(start == n-1)
44{
45return (c[tour[n-1]][tour[n]] + c[tour[n]][1]);
46}
47for(i=start+1; i<=n; i++)
48{
49 for(j=1; j<=n; j++)
50 temp[j] = tour[j];
51 temp[start+1] = tour[i];
52 temp[i] = tour[start+1];
53 if((c[tour[start]][tour[i]]+(ccost=tspdp(c,temp,start+1,n)))<mincost)
54 {
55 mincost = c[tour[start]][tour[i]] + ccost;
56 for(k=1; k<=n; k++)
57 mintour[k] = temp[k];
58 }
59}
60for(i=1; i<=n; i++)
61tour[i] = mintour[i];
62return mincost;
63}
64}
65

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected