【发布时间】:2016-05-19 09:39:22
【问题描述】:
我正在为旅行商问题编写一个 3-opt 算法,我已经让 2-opt 工作,我正在尝试将其转换为 3-opt。 我不知道如何交换 3 点,谁能帮帮我?
我的代码:
private void ThreeOptSwap(int i, int k, int l) {
int size = route.size();
new_Route = new ArrayList<Point>();
new_Route.addAll(route);
// 1. take route[0] to route[i-1] and add them in order to new_route
for ( int c = 0; c <= i - 1; c++ )
{
new_Route.set(c, route.get(c) );
}
// 2. take route[i] to route[k] and add them in reverse order to new_route
int dec = 0;
for ( int c = i; c <= k; c++ )
{
new_Route.set( c, route.get( k - dec ) );
dec++;
}
// 3. take route[k+1] to end and add them in order to new_route
for ( int c = k + 1; c < size; c++ )
{
new_Route.set( c, route.get( c ) );
}
}
【问题讨论】:
标签: java algorithm traveling-salesman