Finding the fastest route

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
48
49
50
51
52
53
54
55
56
57
58
59
I don't know whether i should post here or not, since i am a beginner, however, no one in that section could answer my question so i'll give it a try here S=.

#include <iostream>

using namespace std;

void greedyfunc(void);
double TSP(void);
void checkingvalid(void);
int size = 5;
int dummyroad[size];
bool myarray[5];

int main(void)
{
	;
}

void greedyfunc(void)
{
	int index;
	for(int i=1;i<index;i++) 

	if (vals[i] < loVal)
		loVal = vals[i];
}


}

double TSP(first.parent, second parent)
{
	int index;
	for(int i = 0;i<index;i++)
	if(first.parent.i == second.parent.i)
		return (first.parent.i);
	else 
	{
		 greedyfunc(second.parent.i);
	}
	




void checkingvalid(void)
{
	int num;
	int index;
	for(int i = 0; i < index; i++)
	{
		;//connnecting routes adding 1 each time, add 2 the first time. 
	}
	while (num != size)
		delete route; //remember to declare it. 
}




As you see i am NO WHERE near to complete. Now here's my approach.
1)assuming the array[5] is initialized with numbers, the numbers represent the length it takes it travel from each of the 5 cities, so right away you can imagine a 5 by 5 symmetric matrix.

2) my problem is i don't know how to start with cities, i recognize the city by length, as you see in line 29 i am trying to compare each parents route segment, and if the segment is the same(meaning if both routes have point A to point C) the new child route will also have that segment. Within that tsp function, i will also call greedyfunc, where greedyfunc is just a function that connect the closest city which i have no idea how to code it )=.

This method is call genetic algorithm, i know there are some code out there but i don't understand and i would like to stay in my approach. anyone can help me with it i will be greatly appreciated.

Just so you guys can understand what am i doing, line 17~24, i am trying to use greedyfunc which is a function that complete the child route. (but i don't know how to do it, i know how to find the mininum length but routes are a bunch of length adding together.

line 29~43, i am trying to compare the 2 parent, and if both parents has the same route i will return that route to the child. My problem is how to pass that route to the child? and what what the else statement? And what should i pass in greedyfunc? as u see i pass second.parent <-- i know i'm wrong.

line 48~59, i am trying to check whether the route is valid, e.g size = number of city and it's 50, and each time i pass through the city i add one so if the route is valid the number must if 50 if not then you either walk to the same place twice. so i wrote an if statement to check it. But my problem is how code "if i pass each city i will add it by one" since i am just recongizing it by length and not by city.
Topic archived. No new replies allowed.