You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
3.2 KiB

3 months ago
  1. /* tsplib.h */
  2. /* Written by Andrew Makhorin <mao@gnu.org>, October 2015. */
  3. #ifndef TSPLIB_H
  4. #define TSPLIB_H
  5. typedef struct TSP TSP;
  6. struct TSP
  7. { /* TSP (or related problem) instance in the format described in
  8. * [G.Reinelt, TSPLIB 95] */
  9. /*--------------------------------------------------------------*/
  10. /* specification part */
  11. char *name;
  12. /* identifies the data file */
  13. int type;
  14. /* specifies the type of data: */
  15. #define TSP_UNDEF 0 /* undefined */
  16. #define TSP_TSP 1 /* symmetric TSP */
  17. #define TSP_ATSP 2 /* asymmetric TSP */
  18. #define TSP_TOUR 3 /* collection of tours */
  19. char *comment;
  20. /* additional comments (usually the name of the contributor or
  21. * creator of the problem instance is given here) */
  22. int dimension;
  23. /* for a TSP or ATSP, the dimension is the number of its nodes
  24. * for a TOUR it is the dimension of the corresponding problem */
  25. int edge_weight_type;
  26. /* specifies how the edge weights (or distances) are given: */
  27. #define TSP_UNDEF 0 /* undefined */
  28. #define TSP_EXPLICIT 1 /* listed explicitly */
  29. #define TSP_EUC_2D 2 /* Eucl. distances in 2-D */
  30. #define TSP_CEIL_2D 3 /* Eucl. distances in 2-D rounded up */
  31. #define TSP_GEO 4 /* geographical distances */
  32. #define TSP_ATT 5 /* special distance function */
  33. int edge_weight_format;
  34. /* describes the format of the edge weights if they are given
  35. * explicitly: */
  36. #define TSP_UNDEF 0 /* undefined */
  37. #define TSP_FUNCTION 1 /* given by a function */
  38. #define TSP_FULL_MATRIX 2 /* given by a full matrix */
  39. #define TSP_UPPER_ROW 3 /* upper triangular matrix (row-wise
  40. * without diagonal entries) */
  41. #define TSP_LOWER_DIAG_ROW 4 /* lower triangular matrix (row-wise
  42. * including diagonal entries) */
  43. int display_data_type;
  44. /* specifies how a graphical display of the nodes can be
  45. * obtained: */
  46. #define TSP_UNDEF 0 /* undefined */
  47. #define TSP_COORD_DISPLAY 1 /* display is generated from the node
  48. * coordinates */
  49. #define TSP_TWOD_DISPLAY 2 /* explicit coordinates in 2-D are
  50. * given */
  51. /*--------------------------------------------------------------*/
  52. /* data part */
  53. /* NODE_COORD_SECTION: */
  54. double *node_x_coord; /* double node_x_coord[1+dimension]; */
  55. double *node_y_coord; /* double node_y_coord[1+dimension]; */
  56. /* DISPLAY_DATA_SECTION: */
  57. double *dply_x_coord; /* double dply_x_coord[1+dimension]; */
  58. double *dply_y_coord; /* double dply_y_coord[1+dimension]; */
  59. /* TOUR_SECTION: */
  60. int *tour; /* int tour[1+dimension]; */
  61. /* EDGE_WEIGHT_SECTION: */
  62. int *edge_weight; /* int edge_weight[1+dimension*dimension]; */
  63. };
  64. TSP *tsp_read_data(const char *fname);
  65. /* read TSP instance data */
  66. int tsp_distance(const TSP *tsp, int i, int j);
  67. /* compute distance between two nodes */
  68. void tsp_free_data(TSP *tsp);
  69. /* free TSP instance data */
  70. #endif
  71. /* eof */