NNH.c
Go to the documentation of this file.
1 #include "LKH.h"
2 
3 int NNH()
4 {
5  Node *From, *To, *Start, *NN;
6  int Max = INT_MIN, Min, Visited = 0, D, i;
7 
8  for (i = 2; i <= DimensionSaved; i++)
9  NodeSet[i].V = 0;
10  Start = From = &NodeSet[1];
11  while (++Visited < DimensionSaved) {
12  From->V = 1;
13  Min = INT_MAX;
14  NN = 0;
15  for (i = 2; i <= DimensionSaved; i++) {
16  To = &NodeSet[i];
17  if (!To->V &&
18  (D = ProblemType != ATSP ? Distance(From, To) :
19  From->C[To->Id]) < Min) {
20  Min = D;
21  NN = To;
22  }
23  }
24  From = NN;
25  if (Min > Max)
26  Max = Min;
27  }
28  D = ProblemType != ATSP ? Distance(From, Start) : From->C[Start->Id];
29  if (D > Max)
30  Max = D;
31  return Max;
32 }
CostFunction D
Definition: LKH.h:304
Definition: LKH.h:68
int Id
Definition: LKH.h:69
CostFunction Distance
Definition: LKH.h:304
Node * NodeSet
Definition: LKH.h:235
Definition: LKH.h:41
int DimensionSaved
Definition: LKH.h:191
int * C
Definition: LKH.h:88
int V
Definition: LKH.h:75
int ProblemType
Definition: LKH.h:290
Definition: LKH.h:51
int NNH()
Definition: NNH.c:3


glkh_solver
Author(s): Francisco Suarez-Ruiz
autogenerated on Mon Jun 10 2019 13:50:26