Help with Array

I'm working on a Genetic Algorithm project and need to write a code to do the crossover operation. I need to select a few array and swap the array at a given point. For example, if an array have the values of

A [1][28] = 1110110010011000110110011110
B [1][28] = 0111001111100100001001110011

and the array will be swapped at the 12th column

A [1][28] = 1110110010011||000110110011110
B [1][28] = 0111001111100||100001001110011

The result would be the following array:

A' [1][28] = 1110110010011100001001110011
B' [1][28] = 0111001111100000110110011110

I've been successful in selecting the array but I'm having problem with swapping the array.

So far I have written this code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
float cross_prob_E1 [num_pop][1];
	float cross_prob_E2 [num_pop][1];
	float cross_prob_E3 [num_pop][1];
	float cross_parents_E1 [num_pop][28];
	float cross_parents_E2 [num_pop][26];
	float cross_parents_E3 [num_pop][22];
	
	// Assigning Cross Over Values//
	for (row = 0; row < num_pop; row++){
		cross_prob_E1 [row][1] = (double) rand()/RAND_MAX;
	}
	cout << endl;
	
	// Selecting Gene For Cross Over//
	for (row = 0; row < num_pop; row ++){
		if (cross_prob_E1 [row][1] < cross_rate) {
			for (column = 0; column < 28; column++){ 
				cross_parents_E1 [row][column] = population_bin_E1 [row][column];
					cout.precision (0);
					cout << cross_parents_E1 [row][column];
				}
		}
	cout << endl;
	}
	
	
	}
	//Gene Cross Over//
	int s,t,u;
	s = rand ()%28;
	t = rand ()%26;
	u = rand ()%22;
	
	cout << s << " " << t << " " << u << endl;
	
	float J [1][28];
	float K [1][28];
	
	for (row = 0; row < num_pop; row ++ ){
		for (column = s; column < 28; column ++){
			J [1][column] = cross_parents_E1 [row%2][column];
			K [1][column] = cross_parents_E1 [row%1][column];
			cout << J [row][column];
			cout << K [row][column];
		}
		cout << endl;
	}


Can anyone help me with this??
Topic archived. No new replies allowed.