storing a value

Apr 19, 2011 at 3:26pm
1
2
3
4
5
6
7
8
9
10
11
double TSP(first.parent, second parent)
{
	int index;
	for(int i = 0;i<5;i++)
	if(first.parent.i == second.parent.i)
		return (first.parent.i);
	else 
	{
		 greedyfunc(i);
	}
	


I am working on finding the fastest route.
as you can see i am comparing two parents, the first if statement check whether the routes are the same, then i try to write an else statement.
Like if first.parent.2 = 13 and second.parent.2 = 12. you can see first.parent.2 is bigger so we should choose the second parent, my question is what if there are more then two cases when both parents are differ?
e.g first.parent.1 = 2 first.parent.1 = 3, and first.parent.2 = 1, second.parent.2 = 4. How to store those value? Or let the program recongize there are more then 1 route that differ?
Apr 19, 2011 at 4:10pm
A chain of if-else?
eg:
1
2
3
4
5
6
if ( first < second )
    // ...
else if ( second < first )
   // ...
else // they are the same
   // ... 
Apr 19, 2011 at 9:50pm
No, that whole if else only check for ONE route. ok here an example

parent.1[1, 3, 4, 5, 6]
parent.2[1, 3, 3, 7, 6]

as you see both parent have the same 0, 1, 4 while 2 and 3 are differ. So what i want is the child route will have
child [ 1, 3, x, y, 6] while x and y will call a function that will complete the route.
Apr 20, 2011 at 4:03am
hello? anyone can help me out on this one?
Apr 20, 2011 at 6:26am
Do you want a greedy algorithm ( as is implied by line 9 of your code above ) or an optimal solution? ( which may require dynamic programming )
Apr 20, 2011 at 3:51pm
ignore the greedyfunc for now, i just want the program to recongize the child has [1,3,x,y,6] the greedyfunc will deal with x and y (which means completing the route) but for now i want to focus on storing 1, 3, and 6 in the child array.
Apr 20, 2011 at 8:54pm
??
Topic archived. No new replies allowed.