Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: srusc2012/sru-littlefe-tsp
base: 58259f61a9
...
head fork: srusc2012/sru-littlefe-tsp
compare: 727a54d114
  • 1 commit
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
2  include/tsp.h
@@ -61,7 +61,7 @@ tour_t* roulette_select(tour_t tours[], int num_tours); // selects a random tour
void terminate_program(int ecode);
-void populate_tours(int N, int mpi_rank, tour_t** arr_tours);
+void populate_tours(int N, int mpi_rank, tour_t** arr_tours, tour_t* arr_cities);
void MPI_init(char *mpi_flag, int *mpi_rank, int *mpi_procs);
View
1  src/fitness.c
@@ -100,6 +100,7 @@ tour_t* create_tour_nn(city_t* city, int num_cities, tour_t* cities) {
// Iterate through the cities, adding new ones and marking them off.
for (i=1;i<num_cities;i++) {
next_city = find_nearest_neighbor(next_city,num_cities,cities,cities_visited);
+ printf("--> %i ",*next_city);
tour->city[i]=next_city;
cities_visited[ next_city->id ]=1;
}
View
52 src/main.c
@@ -27,6 +27,9 @@ void terminate_program(int ecode) {
printf("AB cycles structure gone...");
printf("done!\n");
+ //free tours
+ free(Tours);
+
// done (just used to make sure that the program ran to completion)
printf("Program ran to completion (done).\n");
}
@@ -35,40 +38,16 @@ void terminate_program(int ecode) {
exit(ecode);
}
-void populate_tours(int N, int mpi_rank, tour_t** arr_tours) {
+void populate_tours(int N, int mpi_rank, tour_t** arr_tours, tour_t* arr_cities) {
int i;
- tour_t* tourA, *tourB;
- tour_t* tstar;
- tourA = malloc(sizeof(*tourA));
- tourB = malloc(sizeof(*tourB));
- Tours = malloc(sizeof(*Tours) * N);
+ printf("N-->%i\n",N);
- tourA->size = Cities->size;
- for (i=0; i < N; i++)
- {
- tourA->city[i] = Cities->city[(i*2)%N];
+ for (i=0;i<N;i++) {
+ printf("-- %i ",i);
+ arr_tours[i] = create_tour_nn(arr_cities->city[i], N, arr_cities);
+ printf("\n");
+ print_tour(arr_tours[i]);
}
- tstar = create_tour_nn(Cities->city[0], Cities->size, Cities);
- tourB = tstar;
- // now, find fitness of the tours.
- set_tour_fitness(tourA,N);
- set_tour_fitness(tourB,N);
- DPRINTF("fitness of A,B is %f,%f.\n", tourA->fitness, tourB->fitness);
- // output the two tours
- printf("TourA: [%i]", tourA->city[0]->id);
- for (i=1; i < N; i++)
- printf(", [%i]", tourA->city[i]->id);
- printf("\nTourB: [%i]", tourB->city[0]->id);
- for (i=1; i < N; i++)
- printf(", [%i]", tourB->city[i]->id);
- printf("\n");
-
- // now, testing print tour function for A and B.
- print_tour(tourA);
- print_tour(tourB);
-
- Tours[0]=tourA;
- Tours[1]=tourB;
}
void MPI_init(char *mpi_flag, int *mpi_rank, int *mpi_procs) {
@@ -118,7 +97,9 @@ void run_genalg(int N, char *lcv) {
// Select parents for child creation (roulette wheel)
// Create children
+ printf("enter eax\n");
perform_eax(N);
+ printf("exit eax\n");
// Update sorted population array
@@ -332,9 +313,13 @@ int main(int argc, char** argv)
load_cities(mpi_rank,citiesFile,Cities);
// process the cities
int N = Cities->size;
+ // allocate memory for Tours
+ Tours = malloc( sizeof(tour_t*) * MAX_POPULATION );
// construct the distance table (on all processes)
+ printf("Enter dist table\n");
construct_distTable(Cities,N);
+ printf("Exit dist table\n");
// output the city information to the console
DPRINTF("\nNum Cities: %04i\n", Cities->size);
@@ -345,7 +330,9 @@ int main(int argc, char** argv)
}
// populate tours (on all processes)
- populate_tours(N,mpi_rank,Tours);
+ populate_tours(N,mpi_rank,Tours,Cities);
+ print_tour(Tours[0]);
+ print_tour(Tours[1]);
//----------------------------------------------------
@@ -353,6 +340,7 @@ int main(int argc, char** argv)
// Run Genetic Algorithm (Enter "The Islands")
//####################################################
while (lcv) {
+ printf("Loop . . .\n");
if (mpi_rank==0 && mpi_flag==1) {
// if you are the master AND mpi is on, start listening
master_listener();
View
BIN  tsp
Binary file not shown
View
335 tsp.out
@@ -0,0 +1,335 @@
+Picked a random seed (1351724931).
+Loading cities...done! (loaded 5 cities from the file)
+Enter dist table
+
+(1,0)->4.472136
+(2,0)->3.000000 (2,1)->4.123106
+(3,0)->2.236068 (3,1)->3.605551 (3,2)->4.472136
+(4,0)->6.082763 (4,1)->8.544003 (4,2)->9.055386 (4,3)->5.099020
+Exit dist table
+
+Num Cities: 0005
+---------------------------
+City[0000] at 0001, 0004 [id: 0000]
+City[0001] at 0005, 0002 [id: 0001]
+City[0002] at 0001, 0001 [id: 0002]
+City[0003] at 0003, 0005 [id: 0003]
+City[0004] at 0002, 0010 [id: 0004]
+N-->5
+-- 0 --> 3 --> 5 --> 1 --> 2
+Tour: [0], [3], [1], [2], [4]
+-- 1 --> 3 --> 1 --> 1 --> 2
+Tour: [1], [3], [0], [2], [4]
+-- 2 --> 1 --> 3 --> 5 --> 2
+Tour: [2], [0], [3], [1], [4]
+-- 3 --> 1 --> 1 --> 5 --> 2
+Tour: [3], [0], [2], [1], [4]
+-- 4 --> 3 --> 1 --> 1 --> 5
+Tour: [4], [3], [0], [2], [1]
+Tour: [0], [3], [1], [2], [4]
+Tour: [1], [3], [0], [2], [4]
+Loop . . .
+enter eax
+
+Merging A with B...
+creating empty graph (of size 5)...done!
+populating the graph (merging the edges)...Special cases...done!
+done!
+
+Graph R contains:
+0000 [id:0000] -> edges: [0003:t1], [0002:t1], [0004:t0], [0003:t0]
+0001 [id:0001] -> edges: [0003:t0], [0002:t0], [0004:t1], [0003:t1]
+0002 [id:0002] -> edges: [0001:t0], [0004:t0], [0000:t1], [0004:t1]
+0003 [id:0003] -> edges: [0000:t0], [0001:t0], [0001:t1], [0000:t1]
+0004 [id:0004] -> edges: [0002:t0], [0000:t0], [0002:t1], [0001:t1]
+Allocating cycles...done!
+Generating AB Cycles....Generating AB Cycle, edges left: 10[...
+Choosing a random vertex...
+first pick: [2]->s:4
+v2:2...
+next cycle #0...
+Initializing cycle...
+entering cycle loop...
+Adding edge to cycle...
+v2i: 0, c[0]: 0, c[1]: 1
+v1e0: 1, v1e1: 4, v1e2: 0, v1e3: 4
+next iteration...v1:2, v2:1
+removing edge(v[2]->v[1]t0 from graph...
+removing edge(v[1]->v[2]t0 from graph...
+Adding edge to cycle...
+v2i: 2, c[0]: 1, c[1]: 2
+v1e0: 3, v1e1: 3, v1e2: 4, v1e3: 2
+next iteration...v1:1, v2:4
+removing edge(v[1]->v[4]t1 from graph...
+removing edge(v[4]->v[1]t1 from graph...
+Adding edge to cycle...
+v2i: 1, c[0]: 0, c[1]: 1
+v1e0: 2, v1e1: 0, v1e2: 2, v1e3: 1
+next iteration...v1:4, v2:0
+removing edge(v[4]->v[0]t0 from graph...
+removing edge(v[0]->v[4]t0 from graph...
+Adding edge to cycle...
+v2i: 0, c[0]: 0, c[1]: 1
+v1e0: 3, v1e1: 2, v1e2: 3, v1e3: 4
+next iteration...v1:0, v2:3
+removing edge(v[0]->v[3]t1 from graph...
+removing edge(v[3]->v[0]t1 from graph...
+Adding edge to cycle...
+v2i: 1, c[0]: 0, c[1]: 1
+v1e0: 0, v1e1: 1, v1e2: 1, v1e3: 0
+next iteration...v1:3, v2:1
+removing edge(v[3]->v[1]t0 from graph...
+removing edge(v[1]->v[3]t0 from graph...
+Adding edge to cycle...
+v2i: 0, c[0]: 0, c[1]: -1
+v1e0: 3, v1e1: 3, v1e2: 4, v1e3: 2
+next iteration...v1:1, v2:3
+removing edge(v[1]->v[3]t1 from graph...
+removing edge(v[3]->v[1]t1 from graph...
+ITERATIONS : 3, 1, 0, 4, 2,
+Ab cycle generated: ->[2]->[1]->[4]->[0]->[3]->[1]
+Cycle with tail generated, removing tail...
+Ab cycle reversed: ->[1]->[3]->[0]->[4]->[1]->[2]
+v0,v1,v2: 3,1,2
+curCycle->city[5]->id = 2
+Restoring edge: 2->1
+restoring edge(v[2]->v[1]t0 to graph...
+restoring edge(v[1]->v[2]t0 to graph...
+curCycle->city[4]->id = 1
+Restoring edge: 1->4
+restoring edge(v[1]->v[4]t1 to graph...
+restoring edge(v[4]->v[1]t1 to graph...
+curCycle->city[3]->id = 4
+Restoring edge: 4->0
+restoring edge(v[4]->v[0]t0 to graph...
+restoring edge(v[0]->v[4]t0 to graph...
+curCycle->city[2]->id = 0
+Restoring edge: 0->3
+restoring edge(v[0]->v[3]t1 to graph...
+restoring edge(v[3]->v[0]t1 to graph...
+Ab cycle as fixed: ->[1]->[3]
+next AB Cycle (back to top of outer while)
+
+Graph R contains 5 nodes:
+0000 [id:0000] -> 4 edges: [0003:t0], [0002:t1], [0004:t0], [0003:t1]
+0001 [id:0001] -> 2 edges: [0002:t0], [0004:t1]
+0002 [id:0002] -> 4 edges: [0004:t1], [0004:t0], [0000:t1], [0001:t0]
+0003 [id:0003] -> 2 edges: [0000:t0], [0000:t1]
+0004 [id:0004] -> 4 edges: [0002:t0], [0002:t1], [0001:t1], [0000:t0]
+Generating AB Cycle, edges left: 8[...
+Choosing a random vertex...
+first pick: [3]->s:2
+v2:3...
+next cycle #1...
+Initializing cycle...
+entering cycle loop...
+Adding edge to cycle...
+v2i: 0, c[0]: 0, c[1]: -1
+v1e0: 0, v1e1: 0, v1e2: 1, v1e3: 1
+next iteration...v1:3, v2:0
+removing edge(v[3]->v[0]t0 from graph...
+removing edge(v[0]->v[3]t0 from graph...
+Adding edge to cycle...
+v2i: 1, c[0]: 0, c[1]: 1
+v1e0: 3, v1e1: 2, v1e2: 4, v1e3: 3
+next iteration...v1:0, v2:2
+removing edge(v[0]->v[2]t1 from graph...
+removing edge(v[2]->v[0]t1 from graph...
+Adding edge to cycle...
+v2i: 2, c[0]: 1, c[1]: 2
+v1e0: 4, v1e1: 4, v1e2: 1, v1e3: 0
+next iteration...v1:2, v2:1
+removing edge(v[2]->v[1]t0 from graph...
+removing edge(v[1]->v[2]t0 from graph...
+Adding edge to cycle...
+v2i: 0, c[0]: 0, c[1]: -1
+v1e0: 4, v1e1: 2, v1e2: 3, v1e3: 3
+next iteration...v1:1, v2:4
+removing edge(v[1]->v[4]t1 from graph...
+removing edge(v[4]->v[1]t1 from graph...
+Adding edge to cycle...
+v2i: 0, c[0]: 0, c[1]: 2
+v1e0: 2, v1e1: 2, v1e2: 0, v1e3: 1
+next iteration...v1:4, v2:2
+removing edge(v[4]->v[2]t0 from graph...
+removing edge(v[2]->v[4]t0 from graph...
+Adding edge to cycle...
+v2i: 0, c[0]: 0, c[1]: -1
+v1e0: 4, v1e1: 4, v1e2: 1, v1e3: 0
+next iteration...v1:2, v2:4
+removing edge(v[2]->v[4]t1 from graph...
+removing edge(v[4]->v[2]t1 from graph...
+ITERATIONS : 1, 3, 2, 0, 4,
+Ab cycle generated: ->[3]->[0]->[2]->[1]->[4]->[2]
+Cycle with tail generated, removing tail...
+Ab cycle reversed: ->[2]->[4]->[1]->[2]->[0]->[3]
+v0,v1,v2: 4,2,3
+curCycle->city[5]->id = 3
+Restoring edge: 3->0
+restoring edge(v[3]->v[0]t0 to graph...
+restoring edge(v[0]->v[3]t0 to graph...
+curCycle->city[4]->id = 0
+Restoring edge: 0->2
+restoring edge(v[0]->v[2]t1 to graph...
+restoring edge(v[2]->v[0]t1 to graph...
+curCycle->city[3]->id = 2
+Restoring edge: 2->1
+restoring edge(v[2]->v[1]t0 to graph...
+restoring edge(v[1]->v[2]t0 to graph...
+curCycle->city[2]->id = 1
+Restoring edge: 1->4
+restoring edge(v[1]->v[4]t1 to graph...
+restoring edge(v[4]->v[1]t1 to graph...
+Ab cycle as fixed: ->[2]->[4]
+next AB Cycle (back to top of outer while)
+
+Graph R contains 5 nodes:
+0000 [id:0000] -> 4 edges: [0003:t1], [0004:t0], [0003:t0], [0002:t1]
+0001 [id:0001] -> 2 edges: [0002:t0], [0004:t1]
+0002 [id:0002] -> 2 edges: [0000:t1], [0001:t0]
+0003 [id:0003] -> 2 edges: [0000:t1], [0000:t0]
+0004 [id:0004] -> 2 edges: [0000:t0], [0001:t1]
+Generating AB Cycle, edges left: 6[...
+Choosing a random vertex...
+first pick: [2]->s:2
+v2:2...
+next cycle #2...
+Initializing cycle...
+entering cycle loop...
+Adding edge to cycle...
+v2i: 1, c[0]: 1, c[1]: -1
+v1e0: 0, v1e1: 1, v1e2: 4, v1e3: 4
+next iteration...v1:2, v2:1
+removing edge(v[2]->v[1]t0 from graph...
+removing edge(v[1]->v[2]t0 from graph...
+Adding edge to cycle...
+v2i: 0, c[0]: 0, c[1]: -1
+v1e0: 4, v1e1: 2, v1e2: 3, v1e3: 3
+next iteration...v1:1, v2:4
+removing edge(v[1]->v[4]t1 from graph...
+removing edge(v[4]->v[1]t1 from graph...
+Adding edge to cycle...
+v2i: 0, c[0]: 0, c[1]: -1
+v1e0: 0, v1e1: 1, v1e2: 2, v1e3: 2
+next iteration...v1:4, v2:0
+removing edge(v[4]->v[0]t0 from graph...
+removing edge(v[0]->v[4]t0 from graph...
+Adding edge to cycle...
+v2i: 1, c[0]: 0, c[1]: 1
+v1e0: 3, v1e1: 2, v1e2: 3, v1e3: 4
+next iteration...v1:0, v2:2
+removing edge(v[0]->v[2]t1 from graph...
+removing edge(v[2]->v[0]t1 from graph...
+ITERATIONS : 3, 1, 0, 0, 2,
+Ab cycle generated: ->[2]->[1]->[4]->[0]
+No fixing necessary (no 'tail' on cycle)
+.next AB Cycle (back to top of outer while)
+
+Graph R contains 5 nodes:
+0000 [id:0000] -> 2 edges: [0003:t1], [0003:t0]
+0001 [id:0001] -> 0 edges:
+0002 [id:0002] -> 0 edges:
+0003 [id:0003] -> 2 edges: [0000:t1], [0000:t0]
+0004 [id:0004] -> 0 edges:
+Generating AB Cycle, edges left: 2[...
+Choosing a random vertex...
+first pick: [4]->s:0
+v2:0...
+next cycle #3...
+Initializing cycle...
+entering cycle loop...
+Adding edge to cycle...
+v2i: 1, c[0]: 1, c[1]: -1
+v1e0: 3, v1e1: 3, v1e2: 2, v1e3: 4
+next iteration...v1:0, v2:3
+removing edge(v[0]->v[3]t0 from graph...
+removing edge(v[3]->v[0]t0 from graph...
+Adding edge to cycle...
+v2i: 0, c[0]: 0, c[1]: -1
+v1e0: 0, v1e1: 0, v1e2: 1, v1e3: 1
+next iteration...v1:3, v2:0
+removing edge(v[3]->v[0]t1 from graph...
+removing edge(v[0]->v[3]t1 from graph...
+ITERATIONS : 0, 0, 0, 1, 0,
+Ab cycle generated: ->[0]->[3]
+No fixing necessary (no 'tail' on cycle)
+.next AB Cycle (back to top of outer while)
+
+Graph R contains 5 nodes:
+0000 [id:0000] -> 0 edges:
+0001 [id:0001] -> 0 edges:
+0002 [id:0002] -> 0 edges:
+0003 [id:0003] -> 0 edges:
+0004 [id:0004] -> 0 edges:
+done!
+Printing all 4 cycles...
+Cycle[0]: [1], [3], [1]
+Cycle[1]: [2], [4], [2]
+Cycle[2]: [2], [1], [4], [0], [2]
+Cycle[3]: [0], [3], [0]
+(r:0.000000)removing Cycle[0]: [1], [3], [1]
+(r:0.000000)removing Cycle[0]: [0], [3], [0]
+(r:0.809411)allowing Cycle[0]: [2], [1], [4], [0], [2]
+(r:0.000000)removing Cycle[1]: [2], [4], [2]
+Printing all 1 cycles in the E-set...
+Cycle[0]: [2], [1], [4], [0], [2]
+
+creating empty graph (of size 5)...done!
+populating the graph (merging the edges)...Special cases...done!
+
+Intermediate Tour T contains:
+0000 [id:0000] -> edges: [0004:t0], [0003:t0]
+0001 [id:0001] -> edges: [0003:t0], [0002:t0]
+0002 [id:0002] -> edges: [0001:t0], [0004:t0]
+0003 [id:0003] -> edges: [0000:t0], [0001:t0]
+0004 [id:0004] -> edges: [0002:t0], [0000:t0]
+allocating edges array...
+Applying the E-set.
+removing edge(v[2]->v[1]t0 from graph...
+removing edge(v[1]->v[2]t0 from graph (final edge v2)...
+adding edge to v2->(1)...
+adding edge to v1->(4)...
+removing edge(v[4]->v[0]t0 from graph...
+removing edge(v[0]->v[4]t0 from graph...
+adding edge to v2->(0)...
+adding edge to v1->(2)...
+
+INTERMEDIATE TOUR AFTER APPLYING E-SET:
+Intermediate Tour T contains:
+0000 [id:0000] -> edges: [0003:t0], [0002:t0]
+0001 [id:0001] -> edges: [0003:t0], [0004:t0]
+0002 [id:0002] -> edges: [0004:t0], [0000:t0]
+0003 [id:0003] -> edges: [0000:t0], [0001:t0]
+0004 [id:0004] -> edges: [0002:t0], [0001:t0]
+tracking disjoint cycles...
+grabbing first unvisited node: 0
+next node : 3
+p1<p2 inside lookup_distance: distTable[(3*(3-1)/2)+0==3]=2.236068
+(no inline):initialized edge = {0 -> 3 : i1 : c2.236068}
+next node : 1
+p1>p2 inside lookup_distance: distTable[(3*(3-1)/2)+1==4]=3.605551
+(no inline):initialized edge = {3 -> 1 : i1 : c3.605551}
+next node : 4
+p1<p2 inside lookup_distance: distTable[(4*(4-1)/2)+1==7]=8.544003
+(no inline):initialized edge = {1 -> 4 : i1 : c8.544003}
+next node : 2
+p1>p2 inside lookup_distance: distTable[(4*(4-1)/2)+2==8]=9.055386
+(no inline):initialized edge = {4 -> 2 : i1 : c9.055386}
+next node : 0
+p1>p2 inside lookup_distance: distTable[(2*(2-1)/2)+0==1]=3.000000
+(no inline):initialized edge = {2 -> 0 : i1 : c3.000000}
+Checking visited array.
+there were 1 disjoint cycles.
+
+Intermediate Tour T contains:
+0000 [id:0000] -> edges: [0003:t0], [0002:t0]
+0001 [id:0001] -> edges: [0003:t0], [0004:t0]
+0002 [id:0002] -> edges: [0004:t0], [0000:t0]
+0003 [id:0003] -> edges: [0000:t0], [0001:t0]
+0004 [id:0004] -> edges: [0002:t0], [0001:t0]
+Printing all 5 edges in the graph:
+Edge[0] = {0 -> 3 : i1 : c2.236068}
+Edge[1] = {3 -> 1 : i1 : c3.605551}
+Edge[2] = {1 -> 4 : i1 : c8.544003}
+Edge[3] = {4 -> 2 : i1 : c9.055386}
+E

No commit comments for this range

Something went wrong with that request. Please try again.