Ejemplo n.º 1
0
int main()
{
	Engine_s engines[3];
	int i = 0;

	engines[0].weight = 0.5;

	engines[1].weight = 0.25;

	engines[2].weight = 3;

	for (i = 0; i < 3; i++)
	{
		printf("%f\n", engines[i].weight);
	}

	printf("\n");

	sortByWeight(engines, 3);

	for (i = 0; i < 3; i++)
	{
		printf("%f\n", engines[i].weight);
	}

	system("PAUSE");
}
Ejemplo n.º 2
0
unsigned int GaussianMixture<Landmark>::prune( const double t ){

  isSorted_ = false;

  unsigned int nPruned = 0;
  if( gList_.size() < 1 ){
    return nPruned;
  }

  sortByWeight(); // Sort from greatest to smallest weight
  
  // Binary search for the Gaussian with weight closest to and greater than t
  unsigned int min_idx = 0;
  unsigned int max_idx = gList_.size() - 1;
  unsigned int idx = (unsigned int)( (max_idx + min_idx) / 2 );
  unsigned int idx_old = idx + 1;
  double w = gList_[idx].weight;

  while(idx != idx_old){
    if( w <= t ){ 
      max_idx = idx;
    }else if ( w > t ){
      min_idx = idx;
    }
    idx_old = idx;
    idx = (unsigned int)( (max_idx + min_idx) / 2 );
    w = gList_[idx].weight;
  }
  while( w >= t ){
    idx++;
    if(idx >= gList_.size())
      break;
    w = gList_[idx].weight;
  }
  idx_old = idx; 
  while( idx < gList_.size() ){
    removeGaussian(idx); // this already takes care updating the Gaussian count
    idx++;
    nPruned++;
  }
  gList_.resize( gList_.size() - nPruned); 

  return nPruned;
}
Ejemplo n.º 3
0
// Get  independent subset A 
int greedy()
{
    int i = 0;
    int j = 0;
    int maxDeadline = MAX_DEADLINE;
    int recordCount[TASK_COUNT] = {0};
    int count = 0;
    int deadline = 0;
    int flag = 0;
    int tail = TASK_COUNT-1;

    sortByWeight();

    for(i = 0; i < TASK_COUNT; i++)
    {
        // Check if the task should be added into A[]
        deadline = tasks[i].deadline;
        flag = 0; 
        for(j = deadline; j <= maxDeadline; j++)
        {
            // Task can not added into A[]
            if(recordCount[j]+1 > j)
            {
                flag = 1;
                // Record the task in the tail of A[]
                A[tail--] = i;
                break;
            }
        }

        // Task can added into A[]
        if(!flag)
        {
            A[count++] = i;
            for(j = deadline; j < maxDeadline+1; j++)
            {
                recordCount[j]++;
            }
        }   
    }

    return count;
}