Ejemplo n.º 1
0
void tsp_partiel (int hops, int len, Path_t path, int *cuts)
{
 int i ;
 int me, dist ;

 if (len >= minimum)
   {
     cuts[hops]++ ;
     return;
   }

 if (hops == NUM)
   {
     add_job (&q, path, hops, len);
   }
 else
   {
   me = path [hops-1] ;

   for (i=0; i < NrTowns; i++)
     {
     if (!present (i, hops, path))
       {
         path [hops] = i ;
         dist = distance[me][i] ;
         tsp_partiel (hops+1, len+dist, path, cuts) ;
       }
     }
 
  }
}
Ejemplo n.º 2
0
void tsp_partiel (int hops, int len, Path_t path, int *cuts)
{
	int i ;
	int me, dist ;

	if (len >= minimum)
	{
		(*cuts)++ ;
		return;
	}

	if (hops == MINNBHOPS)
	{
#ifdef DEBUG
		PrintPath("Add job : ", hops, path);
#endif
		add_job (&listeTaches, path, hops, len);
	}
	else
	{
		me = path [hops-1] ;

		for (i=0; i < NbCities; i++)
		{
			if (!present (i, hops, path))
			{
				path [hops] = i ;
				dist = distance[me][i] ;
				tsp_partiel (hops+1, len+dist, path, cuts) ;
			}
		}

	}
}
Ejemplo n.º 3
0
int main (int argc, char **argv)
{
   unsigned long temps;
   int i;
   struct timeval t1, t2;

   int *cuts = NULL; /* Juste à des fins de statistiques pour savoir combien de fois on a pu optimiser */

   if (argc != 3)
     {
	fprintf (stderr, "Usage: %s  <ncities> <seed> \n",argv[0]) ;
	exit (1) ;
     }
   
   Argc = argc ;
   Argv = argv ;
   minimum = INT_MAX ;
      
   printf ("ncities = %3d\n", atoi(argv[1])) ;
   
   init_queue (&q);
   genmap () ; 

   gettimeofday(&t1,NULL);

   {
      Path_t path;
      int i;

      for(i=0;i<MAXE;i++)
        path[i] = -1 ;
      path [0] = 0;
      
      tsp_partiel (1, 0, path, cuts);

      no_more_jobs (&q);
   }
    
   gettimeofday(&t2,NULL);

   temps = TIME_DIFF(t1,t2);
  
   printf("time = %ld.%03ldms\n", temps/1000, temps%1000);
   {
      Path_t path;
      int hops, len, n = 0;

      cuts = calloc(NrTowns+1,sizeof(*cuts));

      while (!empty_queue(&q))
	 {
	    n++;
	    get_job(&q, path, &hops, &len);
	    tsp(hops, len, path, cuts);
	 }
      printf("%d jobs", n);
   }
    
   gettimeofday(&t2,NULL);

   temps = TIME_DIFF(t1,t2);
   printf("time = %ld.%03ldms (cuts :", temps/1000, temps%1000);
   for (i=0; i<NrTowns; i++)
     printf(" %d",cuts[i]);
   printf(")\n");

   return 0 ;
}
Ejemplo n.º 4
0
int main (int argc, char **argv)
{
	unsigned long temps;
	int cuts = 0;
	struct timeval t1, t2;

	if (argc != 3)
	{
		fprintf (stderr, "Usage: %s  <nbcities ( MAXNBCITIES = %d )> <seed> \n", argv[0], MAXNBCITIES) ;
		exit (1) ;
	}

	NbCities = atoi (argv[1]) ;
	seed = atoi(argv[2]);

	minimum = INT_MAX ;

	//	printf ("NbCities = %3d\n", NbCities) ;

	init_queue (&listeTaches) ;
	genmap () ;

	gettimeofday(&t1,NULL);

	{
		Path_t path;
		int i;

		for(i = 0; i < MAXNBCITIES; i++)
			path[i] = -1 ;

		/* Ville de d�part : Ville 0 */
		path [0] = 0;

		tsp_partiel (1, 0, path, &cuts);
	}

	gettimeofday(&t2,NULL);

	temps = TIME_DIFF(t1,t2);
	//	printf("time = %ld.%03ldms (%d coupures)\n", temps/1000, temps%1000, cuts);

	gettimeofday(&t1,NULL);

	{
		int j;
		Path_t path;
		int hops, len, nbjobs;
		cuts = 0;

		nbjobs = get_nbjobs(&listeTaches);

#pragma omp parallel for private (path, hops, len) schedule (static, 50)
		for (j = 0; j < nbjobs; j++)
		{
			if (get_job(&listeTaches, j, path, &hops, &len))
				plop(hops, len, path, &cuts);
		}
	}

	gettimeofday(&t2,NULL);
	temps = TIME_DIFF(t1,t2);
	printf("minimum = %d time = %ld ms (%d coupures)\n", minimum, temps, cuts);
	return 0 ;
}