public void BuildToTour() { int i; cTSP_LIST_NODE l; l = first; for (i = 0; i < tsp.GetN(); i++, l = l.Next) { tsp.setTourNode(i, l.Value); } }
private bool std2opt() { int imod, nj; if (i == n2) { ret = false; i = 0; } for (; i < n2; i++) { if (i == 0) { nj = n1; } else { nj = tsp.GetN(); } e1 = tsp.GetTourNode(i); e2 = tsp.GetTourNode((imod = i + 1)); if (_j > 0) { j = _j; _j = 0; } else { j = i + 2; } for (; j < nj; j++) { e3 = tsp.GetTourNode(j); e4 = tsp.GetTourNode((j + 1) % tsp.GetN()); diff = (tsp.GetDistance(e2, e4) + tsp.GetDistance(e1, e3)) - (tsp.GetDistance(e1, e2) + tsp.GetDistance(e3, e4)); if (diff < 0) { int ii, jj; int tmp; tsp.setTourNode(imod, e3); tsp.setTourNode(j, e2); for (ii = imod + 1, jj = j - 1; ((jj > ii) || (ii < jj)); jj--, ii++) { tmp = tsp.GetTourNode(ii); tsp.setTourNode(ii, tsp.GetTourNode(jj)); tsp.setTourNode(jj, tmp); } if (showprog) { //tsp.UpdateTourLength(diff); _j = j; return(ret = true); } else { ret = true; e2 = tsp.GetTourNode(i + 1); } //return ret = true; } } } return(false); }