int min_cost_max_flow(int src, int dst, int n){
     int maxflow = 0, mincost = 0;
     for(;;){
         if( !spfa(src, dst, n)){
             return mincost ;
         }
         int aug = oo;
         for(int i = from[dst]; i != -1; i = from[name[i^1]] ){
             checkMin( aug, flow[i] );
         }
         if( !aug ) return mincost;
  
         maxflow += aug;
         mincost += sp[dst] * aug;
         for(int i = from[dst]; i != -1; i = from[name[i^1]] ){
             flow[i] -= aug;
             flow[i^1] += aug;
         }
     }
     return mincost;
 }
Esempio n. 2
0
void Check_Unique_CRID(FILE *pFile, dd_uint64_t Current_Unique_CRID, long position, long distance, long cache_size, long window_size, long bloom_filter_size)
{
	
	
  long i, victim_index;
  dd_uint64_t Temp_Unique_CRID;
  paper_rec_t Temp_DedupeTrace;
  long window_counter=0;
  long max_counter=0, temp_index=0;
  dd_uint8_t *sha1_value=NULL;
  HTItem *chunk_item, *item;
  unsigned long hash1, hash2;
  unsigned long access_counter;
  size_t keySize = sizeof(Temp_DedupeTrace.fp_bytes),iCnt;
  bool flag=true;
  std::list<paper_rec_t>::iterator itr;
  /* Heap Data structure variables */
  /* Check the size of sliding window vector if its empty
   * the check unique crid has been called first time
   * initialize the vector with size of sliding window */
  if(SlidingWindow.size() == 0)
    {
	    
      fseek(pFile, position, SEEK_SET);
      while (1) 
	{  
	  fread(&Temp_DedupeTrace, sizeof(struct _paper_rec_t),1, pFile);
	  /*if(Temp_DedupeTrace.fp_bytes[0] == 0)
	    Temp_DedupeTrace.fp_bytes[0] = '0';*/
	  if(feof(pFile)) 
	    break;
	  SlidingWindow.push_back(Temp_DedupeTrace);
		
	  if(SlidingWindow.size() >= window_size) {
	    break;
	  }
	}
    }
  else if(SlidingWindow.size() == window_size){
    /* Remove one old record and insert the latest record */
    SlidingWindow.pop_front();
    fseek(pFile, position + window_size, SEEK_SET);
    fread(&Temp_DedupeTrace, sizeof(struct _paper_rec_t),1, pFile);
    SlidingWindow.push_back(Temp_DedupeTrace);
  }
  for(itr = SlidingWindow.begin();itr!=SlidingWindow.end();itr++){
    Temp_Unique_CRID = ((*itr).cmc_id << 16) | (*itr).creg_id;

    /* if any data chunk in current CR appear within the future window */
    if(Temp_Unique_CRID == Current_Unique_CRID) {

      DEBUG_INFO("[Found~!!] A chunk in current access CR will appeare within a future window.\n");

      chunk_item = HashFind(ht_cache, PTR_KEY(ht_cache,(*itr).fp_bytes));

      if(chunk_item) { //Cache Hit
	DEBUG_INFO("Cache Hit - New\n");

	//Update Bloom filter counters
	hash1 = hash_djb2((*itr).fp_bytes,keySize)%bloom_filter_size;
	hash2 = hash_sdbm((*itr).fp_bytes,keySize)%bloom_filter_size;
	/* DEBUG_INFO("### Returned hash values are %ld and %ld\n",bloom_filter[hash1],bloom_filter[hash2]);*/
	max_counter = bloom_filter[hash1]++;
	if((bloom_filter[hash2]++) > max_counter)
	  max_counter = bloom_filter[hash2];
	temp_index = (u32)chunk_item->data;
	/* DEBUG_INFO("Index its updating is %ld:\n",temp_index);*/
	heapUpdate(heap, max_counter, temp_index,&ht_cache);
				
      }
      else {
	//Sandeep - Choose victim from heap and strcpy Sha1 Value of the victim chunk to "sha1_value" variable
	/*sha1_value = fnDeleteItemHeap(cache_heap);*/
				  
	//GP - Increment the BF counters for this chunk
	hash1 = hash_djb2((*itr).fp_bytes,keySize)%bloom_filter_size;
	hash2 = hash_sdbm((*itr).fp_bytes,keySize)%bloom_filter_size;
	//DEBUG_INFO("### Returned hash values are before insert cache miss %ld and %ld\n",bloom_filter[hash1],bloom_filter[hash2]);
	max_counter = bloom_filter[hash1]++;
	if((bloom_filter[hash2]++) > max_counter)
	  max_counter = bloom_filter[hash2];
	flag = checkMin(heap,max_counter);
	/* If Min on heap is less than the new chuck then only replace with new
	 * else just skip */
	if(flag){
	  heapPopMin(heap,&sha1_value,&access_counter,&ht_cache);
	  if(!sha1_value)
	    ERROR("SHA1 Value in Check Unique CR is NULL\n");
	  /*for(iCnt = 0;iCnt<sizeof((*itr).fp_bytes);++iCnt)
	    printf("%c",sha1_value[iCnt]);*/
	  //Update Bloom filter counters
	  hash1 = hash_djb2(sha1_value,sizeof(sha1_value))%bloom_filter_size;
	  hash2 = hash_sdbm(sha1_value,sizeof(sha1_value))%bloom_filter_size;
	  //DEBUG_INFO("### Before Decrementing values are %ld and %ld\n",bloom_filter[hash1],bloom_filter[hash2]);
	  //Decrement BF counters
	  bloom_filter[hash1]--;
	  bloom_filter[hash2]--;
	  free(sha1_value);
	  //Sandeep - Insert chunk into Heap with max_counter
	  heapInsert(heap,(*itr).fp_bytes,max_counter,&ht_cache);
	}
      }

    } 
  }
	  
}
void GlobalArgsTabu::checkArgs() const {
    checkEmpty();
    checkMin();
    checkFilePath();
}