Travelling Sales Man Problem - Raviteja Namburu
Travelling Sales Man Problem - Raviteja Namburu
Travelling Sales Man Problem - Raviteja Namburu
-Raviteja Namburu
int main() {
int matrix[10][10] =
{ { 0, 94, 100, 135, 235, 280, 190, 120, 35, 100 },
int route[10][10] =
{ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 },
{ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }
};
int hold = 38340;
int ind1 = 0;
int ind2 = 0;
int loop = 0;
int x = 0;
do {
int distance = 0;
int row = 0;
int column = 0;
int penalty = 0;
int penality1 = 0;
int penality2 = 0;
if (route[ind1][ind2] == 0)
{
route[ind1][ind2] = 1;
}
else
{
route[ind1][ind2] = 0;
}
if (row != 1)
{
penality1 = 5000*(abs(1-row));
penalty += penality1;
}
if (column != 1)
{
penality2 = 5000*(abs(1 - column));
penalty += penality2;
}
penality1 = 0;
penality2 = 0;
row = 0;
column = 0;
}
if (route[ind1][ind1] == 1)
{
penalty += 50000;
}
distance += penalty;
}
else
{
if (route[ind1][ind2] == 0)
{
route[ind1][ind2] = 1;
}
else
{
route[ind1][ind2] = 0;
}
}
ind1++;
if (ind1 > 9)
{
ind1 = 0;
ind2++;
}
if (ind2 > 9)
{
ind2 = 0;
loop++;
}
else
{
cout << route[i][j] << endl;
}
}
}
cout << x << endl;
cout << hold << endl;
return 0;
}
Results:
Total distance =1052
0 0 0
0 0 0
0 0 0
1 0 0
0 0 0
0 0 0
0 0 0
0 1 0
0 0 1
0 0 0
0
1052
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
0
0
0
0
0
0
0
0
0