示例#1
0
TSP tsp_init(char *name) {
  // Load the TSP file
  int n = 0; // no. of towns
  Town *towns = tsp_open(name, &n);
  
  // The number of unique pairs of towns
  int npairs = (n * (n - 1)) / 2;
  
  Pair *pairs = malloc(sizeof(Pair) * npairs);
  double *dists = malloc(sizeof(double) * npairs);
  
  for (int i = 0; i < n; ++i) {
    if (i >= n - 1) continue;
    
    for (int j = i + 1; j < n; ++j) {
      if (i == j) continue;
      int pos = pair_pos(i, j, n);
      
      dists[pos] = hsine(towns[i].y, towns[i].x, towns[j].y, towns[j].x);
      Pair pair = { pos, towns[i], towns[j] };
      pairs[pos] = pair;
    }
  }
  
  TSP tsp = {n, npairs, dists, pairs};
  
  return tsp;
}
示例#2
0
int main (int argc, char **argv) {
    int fd;
    int rc;
    fd = tsp_open(argv[1]);
    printf ("tsp_open (%s) = %d\n", argv[1], fd);
    rc = tsp_analyse(fd);
    printf ("tsp_analyse = %d\n", rc);
    tsp_close(fd);
}
示例#3
0
文件: tm.c 项目: reeftinker/Tycoon-2
int tm_main(int argc, char *argv[])
{
  tsp_ErrorCode wErrorCode;

  tm_nArguments = argc;
  tm_pArguments = argv;
  tm_pszProg = argv[0];

  tos_init();
  
#ifdef BOOTSTRAP
  if(argc <= 1) {
    tosLog_error("tm", "main", "Usage: %s store [arguments] || %s -bootstrap dump\n",
            argv[0], argv[0]);
    exit(-1);
  }
  if(strcmp(argv[1], "-bootstrap") == 0) {
    tmdebug_init();
    return tsp_createFromFile(argv[2]);
  }
  else {
    if ((wErrorCode = tsp_open(argv[1])) != 0) {
      tosLog_error("tm", "main", "Cannot open store %s: %s", argv[1], tsp_errorCode(wErrorCode));
      tosError_ABORT();
    }
    rtdll_begin(rtstatic_aStaticLibs);

    /* init multithreading support (mutexes and variables) */
    tmthread_init();

    tyc_init();
    tmdebug_init();
    tsp_setEnumRootPtr(tyc_enumRootPtr);
    tsp_setEnumAmbiguousRootPtr(tyc_enumAmbiguousRootPtr);
    
    tmthread_restart();
  }
#else
  if(argc <= 1) {
    tosLog_error("tm", "main", "Usage: %s store [arguments]\n", argv[0]);
    exit(-1);
  }
  if ((wErrorCode = tsp_open(argv[1]))) {
    tosLog_error("tm", "main", "Cannot open store %s: %s", argv[1], tsp_errorCode(wErrorCode));
    tosError_ABORT();
  }
  rtdll_begin(rtstatic_aStaticLibs);

  /* init multithreading support (mutexes and variables) */
  tmthread_init();

  tyc_init();
  tmdebug_init();
  tsp_setEnumRootPtr(tyc_enumRootPtr);
  tsp_setEnumAmbiguousRootPtr(tyc_enumAmbiguousRootPtr);
  
  tmthread_restart();
#endif

  return 0;
}