Example #1
0
int main(int argc, char *argv[])
{
  int n, m, maxk;
  weight_t cut;
  float start, stop;
  packing pack;
  node *v;
  arc *a;
  
  parse(&n, &m);

  printf("c nodes: %14d    arcs: %16d\n", n, m);

  start = timer();
  
  minCap = MAXWEIGHT;
  ForAllNodes(v) deleteExtras(v);  

#ifndef NO_PR
  makeHeap(h, n);
  n = PRpreprocess(n); 
#endif  

  maxk = minCap;

  ForAllLeaderNodes(v)  /* put input in right place in data structures */
    {
      v->s_first = v->first;
      ForAllArcs(v, a)
	{
	  a->s_prev = a->prev;
	  a->s_next = a->next;
	  a->s_cap = a->cap;
	}
    }
Example #2
0
// The next two are used when query length changes.
void initializeQueries (QueryState_t * QS)
{
    int maxQueryLength = QS->maxQueryLength;
    int maxRO_QO_PairCount = maxQueryLength * QS->AAs->maxHits;

    // Make these arrays here where we know how big it needs to be.
    QS->usedFrags = makeBitArray(maxRO_QO_PairCount);
    assert(QS->usedFrags);

    QS->fragArray = (Fragment_t *)malloc(maxRO_QO_PairCount*sizeof(Fragment_t));
    assert(QS->fragArray);

    QS->offsetCounts = (OffsetCount_t *)malloc(maxQueryLength*sizeof(OffsetCount_t));
    assert(QS->offsetCounts);

    QS->sortHeap = makeHeap(maxRO_QO_PairCount);

    // Initialize any thing the graph algorithms need.
    QS->tempFragArrayLen = 0;
    QS->tempFragArray = NULL;
    QS->fragGraphNodesLen = 0;
    QS->fragGraphNodes = NULL;

    // Do this last to increase chances that a realloc, if needed, will succeed without a copy.
    DPInit(QS);
}
Example #3
0
		void TestHeap::testCase1() {
			int ia[9] = {0,1,2,3,4,8,9,3,5};
			Vector<int> ivec(ia, ia+9);
			makeHeap(ivec.begin(), ivec.end());
			for(int i=0; i<ivec.size(); ++i)
			std::cout << ivec[i] << ' ';
			// 9 5 8 3 4 0 2 3 1
			std::cout << std::endl;
			ivec.push_back(7);
			pushHeap(ivec.begin(), ivec.end());
			for(int i=0; i<ivec.size(); ++i)
			std::cout << ivec[i] << ' ';
			// 9 7 8 3 5 0 2 3 1 4
			std::cout << std::endl;
			popHeap(ivec.begin(), ivec.end());
			std::cout << ivec.back() << std::endl;
			// 9. return but no remove.
			ivec.pop_back();
			// remove last elem and no return
			for(int i=0; i<ivec.size(); ++i)
			std::cout << ivec[i] << ' ';
			std::cout << std::endl;
			// 8 7 4 3 5 0 2 3 1
			sortHeap(ivec.begin(), ivec.end());
			for(int i=0; i<ivec.size(); ++i)
			std::cout << ivec[i] << ' ';
			// 0 1 2 3 3 4 5 7 8
			std::cout << std::endl;
			std::cout << "case1 passed" << std::endl;
		}
int main() {
    int i;
    for (i = 0; i < n; i = i + 1) a[i] = i;
    makeHeap();
    heapSort();
    for (i = 0; i < n; i = i + 1)
        printf("%d ", a[i]);
    printf("\n");
    return 0;
}
	vector<int> sortElement(vector<int> A, int n, int k) {
		if (n < 2)
			return A;
		vector<int> myHeap(A.begin(), A.begin() + k);
		makeHeap(myHeap);
		for (int i = k; i < A.size(); ++i) {
			A[i - k] = myHeap[0];
			myHeap[0] = A[i];
			heapAdjust(myHeap, 0, k);
		}
		for (int i = A.size() - k; i < A.size(); ++i) {
			A[i] = myHeap[0];
			swap(myHeap[0], myHeap[k - 1]);
			heapAdjust(myHeap, 0, --k);
		}
		return A;
	}
int main() {
    int i;
    //n=getchar()-'0';
    //n=10*n+getchar()-'0';
    //n=10*n+getchar()-'0';
    //n=10*n+getchar()-'0';
    n = 9987;

    for (i = 0; i < n; i = i + 1) a[i] = i;
    makeHeap();
    heapSort();
    for (i = 0; i < n; i = i + 1)
        printf("%d ", a[i]);
    printf("\n");
    //system("pause");
    return 0;
}
Example #7
0
void printTrend(BiTree *tree){
	int i;
	BiTreeNode *currentTreeNode = tree->root;
	TreeStack *treeStack = makeStack();
	TreeHeap *treeHeap = makeHeap(tree->size + 1);
	push(treeStack, currentTreeNode);
	while(isStackEmpty(treeStack) != 0){
		currentTreeNode = pop(treeStack);
		setHeapElement(treeHeap, currentTreeNode);
		if(currentTreeNode->right != NULL)
			push(treeStack, currentTreeNode->right);
		if(currentTreeNode->left != NULL)
			push(treeStack, currentTreeNode->left);
	}
	makeMaxHeapify(treeHeap);
	heapSort(treeHeap);
	fprintf(stdout, "Trending Up:\n");
	for(i = treeHeap->size - 1; i >= treeHeap->size - 5; i--)
		fprintf(stdout, "%s (%+d)\n", getTreeNodeWord(treeHeap->array[i]), getTreeNodeResult(treeHeap->array[i]));
	fprintf(stdout, "Trending Down:\n");
	for(i = 1; i < 6; i++)
		fprintf(stdout, "%s (%+d)\n", getTreeNodeWord(treeHeap->array[i]), getTreeNodeResult(treeHeap->array[i]));
	freeHeap(treeHeap);
}
Example #8
0
int main (int argc, char *argv[])
{
  graph *g, *backup;
  node *v;
  float t;
  double epsilon=1.;
  int i, numPhases = 0;

  while ((i=getopt(argc, argv, "e:")) != -1)
    switch (i)
      {
      case '?': 
	fprintf(stderr, "usage: %s [-e epsilon]\n", argv[0]);
	exit(1);
      case 'e': 
	if (*optarg != '=') epsilon = atof(optarg); 
	else epsilon = atof(optarg+1); 
	break;
      }

  /* read input */
  g = dimacsParse(stdin);
  printf("c nodes:   %14d    arcs: %15d\n", g->currentN, g->m);

  t = timer ();

  /* initialization */
  makeHeap ( h, g->currentN);
  compact(g);  /* clean up multiple edges and/or self-loops in input */

#ifndef NO_PR
  PRpreprocess(g, 0.75, 0.5, 0.5);  /* preprocess with PR heuristics */
#endif  

  backup = makeBackupGraph(g);
  
  if (g->currentN > 2)
    {
      numPhases++;
      matulaApprox(g, epsilon);
      v = sparseCertContract(g, g->minCap);
      if (g->currentN > 1)
	{
	  compact(g);
	  sourcePR(g, v, 0.9);
	  PRpass(g, 0.75, 0.5, 0.5, 0);
	}
    }
 
  restoreBackupGraph(g, backup);
  sparseCertContract(g, g->minCap);

  freeBackupGraph(backup);
  freeHeap(h);

  g->dtime = g->dtime - t;
  t = timer() - t;

  printf("c sparse_nodes: %d  sparse_arcs: %d\n", g->currentN, g->currentM/2);

  /* print out stats */
#ifndef NO_PR
  printf("c internal PR: %-6d PR 1: %-6d PR 2: %-6d PR 3: %-6d PR 4: %-6d\n", 
	 g->PR1Cnt+g->PR2Cnt+g->PR3Cnt+g->PR4Cnt, g->PR1Cnt, g->PR2Cnt, 
	 g->PR3Cnt, g->PR4Cnt);
  printf("c PR internal edge scans 1+2: %-8ld 3+4: %-8ld\n", 
	 g->edgeScanCnt[PR12], g->edgeScanCnt[PR34]);
#endif

  printf("c phases:  %14d    scans: %14d\n", numPhases, g->numScans);
  printf("c edge scans: %11ld\n", totalEdgeScans(g));
  printf("c MinCuts discovered:%4d\n", g->cutCount);
  printf("c ttime: %16.2f    capacity: ", t);
  fprintf_wt(stdout, "%11", g->minCap);
  printf("\nc dtime: %16.2f\n", g->dtime);

  printf("\n");

  freeGraph(g);
  
  return 0;
}