/* EXPORT->TermHGraf: Terminate Graphics (also called via at_exit) */ void TermHGraf() { if (theBrush) DeleteObject(theBrush); if (thePen) DeleteObject(thePen); if (thinPen) DeleteObject(thinPen); if (theFont) DeleteObject(theFont); if (theBitmap) DeleteObject(theBitmap); DeleteHeap(&btnHeap); DestroyWindow(theWindow); }
/* EXPORT->ResetUtilItemList: frees all the memory from the ItelList heap */ void ResetUtilItemList() { DeleteHeap(&itemHeap); CreateHeap(&itemHeap,"HUtil: ItemList Heap",MHEAP,sizeof(ItemRec), 1.0,200,8000); }
static void FreeLMCache (LMCache *cache) { DeleteHeap (&cache->nodeHeap); }
//--------------------------------------------------------------------------- void __fastcall TfKnapsack::btBranchAndBoundClick(TObject *Sender) { //如果已存在 ndHeapArray 先清除 if (ndHeapArray) { delete[] ndHeapArray; ndHeapArray = NULL; } //讀入背包限制 iBagCapacity = StrToInt(edBagCapacity->Text); //產生 Heap 陣列 iHeapCount = 0; ndHeapArray = new Node[iTotalNum +1]; //產生 Heap 的第一個節點 Node u, v; u.iLevel = -1; u.iNowProfit = 0; u.iNowWeight = 0; u.iUpperBound = UpperBound(u); u.iLowerBound = LowerBound(u); InsertHeap(u); Item *itm; int iNowUpper = INT_MAX; while (iHeapCount > 0) { u = DeleteHeap(); if (u.iLevel == iTotalNum-1) continue; v.iLevel = u.iLevel +1; itm = wrItems[v.iLevel].itm; //現在的重量加下一個 Item 的重量沒超過限重 //才去計算 UpperBound 與 LowerBound if (u.iNowWeight + itm->iWeight <= iBagCapacity) { //拿這個東西 v.iNowProfit = u.iNowProfit + itm->iProfit; v.iNowWeight = u.iNowWeight + itm->iWeight; v.iUpperBound = UpperBound(v); v.iLowerBound = LowerBound(v); if (v.iUpperBound > v.iLowerBound && v.iLowerBound < iNowUpper) InsertHeap(v); if (v.iUpperBound < iNowUpper) iNowUpper = v.iUpperBound; } //不拿這個東西 v.iNowProfit = u.iNowProfit; v.iNowWeight = u.iNowWeight; v.iUpperBound = UpperBound(v); v.iLowerBound = LowerBound(v); if (v.iUpperBound > v.iLowerBound && v.iLowerBound < iNowUpper) InsertHeap(v); if (v.iUpperBound < iNowUpper) iNowUpper = v.iUpperBound; } memSolution->Lines->Add("----------------------------------------------"); memSolution->Lines->Add("Maximum possible profit:"); memSolution->Lines->Add(-iNowUpper); }
/* EXPORT-> ClearVocab: Clears vocabulary datastructure */ void ClearVocab(Vocab *voc) { DeleteHeap(&voc->wordHeap); DeleteHeap(&voc->pronHeap); DeleteHeap(&voc->phonesHeap); }
void DeleteNodeHeap(NBNodeHeap *nodeheap) { DeleteHeap(&nodeheap->nehHeap); Dispose(&gcheap,nodeheap); }
/* EXPORT->TermHGraf: Terminate Graphics (also called via at_exit) */ void TermHGraf() { if (theDisp != NULL) XCloseDisplay(theDisp); DeleteHeap(&btnHeap); }
void AccumulateStats (DecoderInst *dec) { MemHeap statsHeap; LayerStats *layerStats; int l; CreateHeap (&statsHeap, "Token Stats Heap", MSTAK, 1, 1.5, 10000, 100000); layerStats = (LayerStats *) New (&statsHeap, dec->nLayers * sizeof (LayerStats)); memset ((void *) layerStats, 0, dec->nLayers * sizeof (LayerStats)); for (l = 0; l < dec->nLayers; ++l) { layerStats[l].nInst = layerStats[l].nTS = layerStats[l].nTok = 0; layerStats[l].bestScore = LZERO; layerStats[l].worstScore = - LZERO; } /* count inst/ts/tok, find best/worst scores */ { int l, N, s, i; LayerStats *ls; LexNodeInst *inst; LexNode *ln; TokenSet *ts; RelToken *tok; TokScore score; TokScore instBest; for (l = 0; l < dec->nLayers; ++l) { ls = &layerStats[l]; for (inst = dec->instsLayer[l]; inst; inst = inst->next) { ++ls->nInst; ln = inst->node; switch (ln->type) { case LN_MODEL: N = ln->data.hmm->numStates; break; case LN_CON: case LN_WORDEND: N = 1; break; default: abort (); break; } instBest = LZERO; for (s = 0; s < N; ++s) { /* for each state/TokenSet */ ts = &inst->ts[s]; if (ts->n > 0) { ++ls->nTS; if (ts->score > instBest) instBest = ts->score; for (i = 0; i < ts->n; ++i) { /* for each token */ tok = &ts->relTok[i]; ++ls->nTok; score = ts->score + tok->delta; if (score > ls->bestScore) ls->bestScore = score; if (score < ls->worstScore) ls->worstScore = score; #if 0 /* sanity check for Lat Rescore */ if (tok->path && tok->lmState != (Ptr) 0xfffffffe ) { assert (dec->net->pronlist[tok->path->pron]->word == ((FSLM_LatNode *) tok->lmState)->word); } #endif } } } assert (instBest == inst->best); } /* for each inst */ printf ("STATS layer %d ", l); printf ("%5d Insts %5d TokenSets %6d Tokens %.2f Tok/TS ", ls->nInst, ls->nTS, ls->nTok, (float) ls->nTok / ls->nTS); printf ("best: %.4f ", ls->bestScore); printf ("worst: %.4f\n", ls->worstScore); } /* for each layer */ } ResetHeap (&statsHeap); DeleteHeap (&statsHeap); }