示例#1
0
文件: main.c 项目: madeinkrc/COMU
int main(int argc, char** argv) {
    struct hash_tablosu *htable=NULL;
    
    initialize_hash_table(&htable,3,5);
    print_hash_table(htable); 
    insert_hash_table(htable,"kadayif");
    insert_hash_table(htable,"Trabzonspor");
    insert_hash_table(htable,"kadayif");
    insert_hash_table(htable,"gundogdu");
    insert_hash_table(htable,"besiktas");
    insert_hash_table(htable,"baklava");
    insert_hash_table(htable,"dembaba");
    insert_hash_table(htable,"cardoza");
    
   
    print_hash_table(htable);
    
    hash_table_buyut(&htable,17,19);
    print_hash_table(htable);
    
    insert_hash_table(htable,"ankara");
    insert_hash_table(htable,"Ankara");
    print_hash_table(htable);
    return (EXIT_SUCCESS);
}
示例#2
0
文件: main.c 项目: madeinkrc/COMU
void hash_table_buyut(struct hash_tablosu **htable,
          int multiplier, int tablo_uzunlugu){
    int i;
    struct CELL *liste_basi;
    struct hash_tablosu *yeni_tablo;
    
    if(*htable){
    initialize_hash_table(&yeni_tablo, multiplier, tablo_uzunlugu);
    for(i=0; i<(*htable)->tablo_uzunlugu; i++){
        liste_basi=((*htable)->tablo_basi+i)->header;
        while(liste_basi!=NULL){
            insert_hash_table(yeni_tablo,liste_basi->anahtar);
            liste_basi=liste_basi->next;
        }
    }
    hash_table_yok_et(htable);
    *htable=yeni_tablo;
    }   
}
示例#3
0
void bfs_bbr(int upper_bound)
/*
   1. This function uses breadth first search (BFS) branch bound and remember (BBR) to find an optimal solution
	  for the simple assembly line balancing problem.
   2. upper_bound = upper bound on the number of stations needed.  Search for a solution with fewer than upper_bound stations.
   3. Written 3/3/06.
*/
{
   char     LB;
   int      count, i, j, index, LB1, level, n_eligible, status, t_sum;
   double   cpu;
   clock_t  start_time;

   start_time = clock();

   UB = upper_bound;

   initialize_hash_table();
   reinitialize_states();

   // Add the root problem to the hash table and the list of states.

   t_sum = 0;
   for(i = 1; i <= n_tasks; i++) {
	  count = 0;
	  t_sum += t[i];
	  for(j = 1; j <= n_tasks; j++) {
		 if(predecessor_matrix[j][i] == 1) count++;
	  }
	  degrees[i] = count;
   }
   LB1 = (int) ceil((double) t_sum / (double) cycle);
   if(LB1 < UB) {
	  LB = (char) LB1;
	  index = find_or_insert(0.0, degrees, 0, LB, 0, 0, -1, 0, &status);
   }
   if(bin_pack_flag == -1) bin_pack_flag = bin_pack_lb;

   // Main loop
   // Modified 5/19/09 to call gen_loads iff states[index].open = 1.

   index = get_state();
   level = 0;
   count = 0;
   while( index >= 0) {
	  cpu = (double) (clock() - search_info.start_time) / CLOCKS_PER_SEC;
		if (cpu > CPU_LIMIT) {
		   printf("Time limit reached\n");
			verified_optimality = 0;;
		   break;
		}
	  if(state_space_exceeded == 1) {
		 verified_optimality = 0;
		 break;
	  }

	  if (states[index].n_stations > level) {
		 level = states[index].n_stations;
		 printf("%2d %10d %10d\n", level, count, last_state - first_state + 2);
		 count = 0;
		 //prn_states(level);
		 //if(level >= 3) return;
	  }

	  if(states[index].open == 1) {
		 states[index].open = 0;
		 count++;
		 search_info.n_explored++;
		 station = states[index].n_stations + 1;
		 idle = states[index].idle;
		 hash_value = states[index].hash_value;
		 previous = states[index].previous;
		 for(i = 1; i <= n_tasks; i++) degrees[i] = states[index].degrees[i];
		 n_eligible = 0;
		 for(i = 1; i <= n_tasks; i++) {
			assert((-1 <= degrees[i]) && (degrees[i] <= n_tasks));
			if(degrees[i] == 0) {
			   eligible[++n_eligible] = i;
			}
		 }

		 gen_loads(1, cycle, 1, n_eligible);

	  } else {
		 states[index].open = 0;
	  }
	  
	  index = get_state();
   }

   search_info.bfs_bbr_cpu += (double) (clock() - start_time) / CLOCKS_PER_SEC;
   free_hash_table();
}