BNode* Trie :: Optimize(BNode* root) { if(root == NULL) return NULL; if(root->l == NULL && root->r == NULL) { return root; } BNode *l = Optimize(root->l); BNode *r = Optimize(root->r); if(l == NULL || r== NULL) { if(l == NULL) { if(isLeafNode(r)) { return r; } } else { if(isLeafNode(l)) { return l; } } } if(isLeafNode(l) && isLeafNode(r)) { int leftData = ((TNode*)l)->data; int rightData = ((TNode*)r)->data; if(leftData == rightData) { //When we arrived at tha Leaf Node and both the leaf nodes have same Neaxt Hop then we do trie shrinking return r; } } root->l = l; root->r = r; return root; }
void dgPolygonSoupDatabaseBuilder::End(bool optimize) { Optimize(optimize); // build the normal array and adjacency array // calculate all face the normals hacd::HaI32 indexCount = 0; m_normalPoints[m_faceCount].m_x = hacd::HaF64 (0.0f); for (hacd::HaI32 i = 0; i < m_faceCount; i ++) { hacd::HaI32 faceIndexCount = m_faceVertexCount[i]; hacd::HaI32* const ptr = &m_vertexIndex[indexCount + 1]; dgBigVector v0 (&m_vertexPoints[ptr[0]].m_x); dgBigVector v1 (&m_vertexPoints[ptr[1]].m_x); dgBigVector e0 (v1 - v0); dgBigVector normal (hacd::HaF32 (0.0f), hacd::HaF32 (0.0f), hacd::HaF32 (0.0f), hacd::HaF32 (0.0f)); for (hacd::HaI32 j = 2; j < faceIndexCount - 1; j ++) { dgBigVector v2 (&m_vertexPoints[ptr[j]].m_x); dgBigVector e1 (v2 - v0); normal += e0 * e1; e0 = e1; } normal = normal.Scale (dgRsqrt (normal % normal)); m_normalPoints[i].m_x = normal.m_x; m_normalPoints[i].m_y = normal.m_y; m_normalPoints[i].m_z = normal.m_z; indexCount += faceIndexCount; } // compress normals array m_normalIndex[m_faceCount] = 0; m_normalCount = dgVertexListToIndexList(&m_normalPoints[0].m_x, sizeof (dgBigVector), 3, m_faceCount, &m_normalIndex[0], hacd::HaF32 (1.0e-4f)); }
void LLRegion::InitPoints( size_t n, const double *points) { if(n < 3) { printf("invalid point count\n"); return; } std::list<contour_pt> pts; bool adjust = false; bool ccw = PointsCCW(n, points); for(unsigned int i=0; i<2*n; i+=2) { contour_pt p; p.y = points[i+0]; p.x = points[i+1]; if(p.x < -180 || p.x > 180) adjust = true; if(ccw) pts.push_back(p); else pts.push_front(p); } contours.push_back(pts); if(adjust) AdjustLongitude(); Optimize(); }
void LLRegion::Put( const LLRegion& region, int winding_rule, bool reverse) { work w(*this); gluTessCallback( w.tobj, GLU_TESS_VERTEX_DATA, (_GLUfuncptr) &LLvertexCallback ); gluTessCallback( w.tobj, GLU_TESS_BEGIN, (_GLUfuncptr) &LLbeginCallback ); gluTessCallback( w.tobj, GLU_TESS_COMBINE_DATA, (_GLUfuncptr) &LLcombineCallback ); gluTessCallback( w.tobj, GLU_TESS_END_DATA, (_GLUfuncptr) &LLendCallback ); gluTessCallback( w.tobj, GLU_TESS_ERROR, (_GLUfuncptr) &LLerrorCallback ); gluTessProperty(w.tobj, GLU_TESS_WINDING_RULE, winding_rule); gluTessProperty(w.tobj, GLU_TESS_BOUNDARY_ONLY, GL_TRUE); // gluTessProperty(w.tobj, GLU_TESS_TOLERANCE, 1e-5); gluTessNormal( w.tobj, 0, 0, 1); gluTessBeginPolygon(w.tobj, &w); PutContours(w, *this); PutContours(w, region, reverse); contours.clear(); gluTessEndPolygon( w.tobj ); Optimize(); m_box.Invalidate(); }
BOOL C4UpdatePackage::Optimize(C4Group *pGroup, const char *strTarget) { // Open target group C4GroupEx TargetGrp; if (!TargetGrp.Open(strTarget)) return FALSE; // Both groups must be packed if (!pGroup->IsPacked() || !TargetGrp.IsPacked()) { TargetGrp.Close(FALSE); return FALSE; } // update children char ItemFileName[_MAX_PATH]; pGroup->ResetSearch(); while (pGroup->FindNextEntry("*", ItemFileName)) if (!SEqual(ItemFileName, C4CFN_UpdateCore) && !SEqual(ItemFileName, C4CFN_UpdateEntries)) Optimize(pGroup, &TargetGrp, ItemFileName); // set header if (TargetGrp.HeadIdentical(*pGroup, true)) TargetGrp.SetHead(*pGroup); // save TargetGrp.Close(FALSE); // okay return TRUE; }
void Optimize(arma::Cube<eT>& weights, arma::Cube<eT>& gradient, arma::Cube<eT>& momWeights) { for (size_t s = 0; s < weights.n_slices; s++) Optimize(weights.slice(s), gradient.slice(s), momWeights.slice(s)); }
BOOL C4UpdatePackage::Optimize(C4Group *pGrpFrom, C4GroupEx *pGrpTo, const char *strFileName) { // group file? C4Group ItemGroupFrom; if (!ItemGroupFrom.OpenAsChild(pGrpFrom, strFileName)) return TRUE; // try to open target group C4GroupEx ItemGroupTo; char strTempGroup[_MAX_PATH + 1]; strTempGroup[0] = 0; if (!ItemGroupTo.OpenAsChild(pGrpTo, strFileName)) return TRUE; // update children char ItemFileName[_MAX_PATH]; ItemGroupFrom.ResetSearch(); while (ItemGroupFrom.FindNextEntry("*", ItemFileName)) Optimize(&ItemGroupFrom, &ItemGroupTo, ItemFileName); // set head if (ItemGroupTo.HeadIdentical(ItemGroupFrom, true)) ItemGroupTo.SetHead(ItemGroupFrom); // write group (do not change any headers set by DoGrpUpdate!) ItemGroupTo.Close(FALSE); // set core (C4Group::Save overwrites it) pGrpTo->SaveEntryCore(*pGrpFrom, strFileName); pGrpTo->SetSavedEntryCore(strFileName); return TRUE; }
void SubExpressionTap::Optimize(Block *block){ blocks.push(block); SubExpressionBlock *exprList = block->GetExprBlock(); const int size = block->body.size(); for(int i = 0; i < size; i++){ Node *expr = block->body[i + temp_counter]; if(expr->isCycle()) continue; if(Block* b = dynamic_cast<Block*>(expr)){ Optimize(b); continue; } if(FuncCallNode *cNode = dynamic_cast<FuncCallNode*>(expr)){ for(Node *arg : cNode->args) GetArgs(*exprList, arg); continue; } if(IfStatement *$if = dynamic_cast<IfStatement*>(expr)){ Optimize(dynamic_cast<Block*>($if->if_branch)); if($if->else_branch) Optimize(dynamic_cast<Block*>($if->else_branch)); continue; } if(ReturnStatement *retNode = dynamic_cast<ReturnStatement*>(expr)) expr = retNode->value; if(!expr->isExpression()) continue; Node *t = OptimizeExpression(expr); if(t != expr){ block->body[i + temp_counter] = t; } } ReplaceFirstOccur(); blocks.pop(); }
//=========================================================== //ディグリーからのsin値取得 //=========================================================== float CMath::tSin_deg(int deg) { int degree = deg; degree = Optimize(degree); return _tsin[degree]; }
/* 翻译一个函数 */ static void TranslateFunction (AstFunction func) { BBlock bb; FSYM = func->fsym; if (!FSYM->defined) return; TempNum = 0; /* 创建函数中间代码的开始结束 */ FSYM->entryBB = CreateBBlock (); FSYM->exitBB = CreateBBlock (); /* 当前中间代码的入口点 */ CurrentBB = FSYM->entryBB; /* 翻译函数体中的语句 */ TranslateStatement (func->stmt); /* 函数结束 */ StartBBlock (FSYM->exitBB); /* 中间代码优化 */ Optimize (FSYM); static int i = 0; /* 给基本块创建名字 */ for (bb = FSYM->entryBB; bb; bb = bb->next) { if (bb->ref != 0) { bb->sym = CreateLabel (); } } }
//=========================================================== //ディグリーからのcos値取得 //=========================================================== float CMath::tCos_deg(int deg) { int degree=deg; degree = Optimize(degree); return _tcos[degree]; }
//=========================================================== //ディグリーからのtan値取得 //=========================================================== float CMath::tTan_deg(int deg) { int degree=deg; degree = Optimize(degree); return _ttan[degree]; }
/** * Optimize the given function using steepest descent. */ void Optimize() { if (momWeights.n_elem == 0) { momWeights = function.Weights(); momWeights.zeros(); } Optimize(function.Weights(), gradient, momWeights); }
bool AugLagrangian<LagrangianFunction>::Optimize(arma::mat& coordinates, const arma::vec& initLambda, const double initSigma, const size_t maxIterations) { augfunc.Lambda() = initLambda; augfunc.Sigma() = initSigma; return Optimize(coordinates, maxIterations); }
/** * Optimize the given function using RmsProp. */ void Optimize() { if (meanSquaredGad.n_elem == 0) { meanSquaredGad = function.Weights(); meanSquaredGad.zeros(); } Optimize(function.Weights(), gradient, meanSquaredGad); }
void AstOptimizer::VisitSwitchStatement(SwitchStatement* node) { Visit(node->tag()); for (int i = 0; i < node->cases()->length(); i++) { CaseClause* clause = node->cases()->at(i); if (!clause->is_default()) { Visit(clause->label()); } Optimize(clause->statements()); } }
//----------------------------------------------------------------------------- bool AsmOptimization::Optimize(AsmCode& code) { bool res = false; for (int i = 0; i < code.Size(); ++i) { res = Optimize(code, i) || res; } return res; }
Function::Function(Symbol *s, const std::vector<Symbol *> &a, Stmt *c) { sym = s; args = a; code = c; maskSymbol = m->symbolTable->LookupVariable("__mask"); Assert(maskSymbol != NULL); if (code != NULL) { code = TypeCheck(code); if (code != NULL && g->debugPrint) { fprintf(stderr, "After typechecking function \"%s\":\n", sym->name.c_str()); code->Print(0); fprintf(stderr, "---------------------\n"); } if (code != NULL) { code = Optimize(code); if (g->debugPrint) { fprintf(stderr, "After optimizing function \"%s\":\n", sym->name.c_str()); code->Print(0); fprintf(stderr, "---------------------\n"); } } } if (g->debugPrint) { printf("Add Function %s\n", sym->name.c_str()); code->Print(0); printf("\n\n\n"); } const FunctionType *type = dynamic_cast<const FunctionType *>(sym->type); Assert(type != NULL); for (unsigned int i = 0; i < args.size(); ++i) if (dynamic_cast<const ReferenceType *>(args[i]->type) == NULL) args[i]->parentFunction = this; if (type->isTask) { threadIndexSym = m->symbolTable->LookupVariable("threadIndex"); Assert(threadIndexSym); threadCountSym = m->symbolTable->LookupVariable("threadCount"); Assert(threadCountSym); taskIndexSym = m->symbolTable->LookupVariable("taskIndex"); Assert(taskIndexSym); taskCountSym = m->symbolTable->LookupVariable("taskCount"); Assert(taskCountSym); } else threadIndexSym = threadCountSym = taskIndexSym = taskCountSym = NULL; }
void DatabaseCleaner::Run() { Log.Notice("DatabaseCleaner", "Stage 1 of 3: Cleaning characters..."); CleanCharacters(); Log.Notice("DatabaseCleaner", "Stage 2 of 3: Cleaning world..."); CleanWorld(); Log.Notice("DatabaseCleaner", "Stage 3 of 3: Optimizing databases..."); Optimize(); }
void Optimize(arma::Cube<eT>& weights, arma::Cube<eT>& gradient, arma::Cube<eT>& mean, arma::Cube<eT>& variance) { for (size_t s = 0; s < weights.n_slices; s++) { Optimize(weights.slice(s), gradient.slice(s), mean.slice(s), variance.slice(s)); } }
void Optimize(arma::Cube<eT>& weights, arma::Cube<eT>& gradient, arma::Cube<eT>& meanSquaredGradient, arma::Cube<eT>& meanSquaredGradientDx) { for (size_t s = 0; s < weights.n_slices; s++) { Optimize(weights.slice(s), gradient.slice(s), meanSquaredGradient.slice(s), meanSquaredGradientDx.slice(s)); } }
void Model::LoadPostProcess(bool needToOptimize) { if (needToOptimize) { #ifdef MODEL_ENABLE_OPTIMIZER Optimize(); #else assert(0); #endif } }
/// /// A-Star를 통해서 나온 위치값들을 가시성 판단, 직선화 실시 /// 몇 번 돌리면 아주 심플하게 된다. BOOL CTileManager::Optimize() { std::deque<IPathNode*> t_deq_Original; std::deque<IPathNode*> t_deq_Optimize; std::deque<IPathNode*> t_deq_Optimize2; HTR_S(eRT_Optimize1); Optimize(m_AStarPath, t_deq_Optimize); HTR_E(eRT_Optimize1); HTR_S(eRT_Optimize2); Optimize(t_deq_Optimize, t_deq_Optimize2); HTR_E(eRT_Optimize2); // 최종적으로 최적화된 리스트 (값전달) m_AStarPath_Optimize = t_deq_Optimize2; return TRUE; }
/** * Optimize the given function using Adam. */ void Optimize() { if (mean.n_elem == 0) { mean = function.Weights(); mean.zeros(); variance = mean; } Optimize(function.Weights(), gradient, mean, variance); }
/** * Optimize the given function using AdaDelta. */ void Optimize() { if (meanSquaredGradient.n_elem == 0) { meanSquaredGradient = function.Weights(); meanSquaredGradient.zeros(); meanSquaredGradientDx = meanSquaredGradient; } Optimize(function.Weights(), gradient, meanSquaredGradient, meanSquaredGradientDx); }
// alle Projekt-Merkmale lesen Bool MerkmalsBaum :: Init (void) { // Daten init. ENUMLONGKEY Data; memset (&Data, 0, sizeof (Data)); Data.eKey = 'm'; // alle Merkmale Data.ePtr = (void *) this; // User-Daten Data.eFcn = (ENUMLONGKEYPROC) EnumMerkmaleProc; // zu rufende Funktion if (DEX_EnumPBDData (Data)) // alle Merkmalskodes lesen { Optimize (); return True; } return False; }
int main(int argc, char** argv) { int result = getopt(argc, argv, "oabewrdsc:"); int tuple_amount = 3; if (-1 == result) { Usage(); return 0; } switch (result) { case 'a': About(); break; case 'b': Remove(); break; case 'o': Optimize(); break; case 'c': Create(tuple_amount, Convert(optarg)); break; case 'd': Destroy(); break; case 'w': Write(); break; case 'r': Read(); break; case 's': Show(); break; case 'e': Clear(); break; default: Usage(); break; } return 0; }
void CDetail::Load (IReader* S) { // Shader string256 fnT,fnS; S->r_stringZ (fnS,sizeof(fnS)); S->r_stringZ (fnT,sizeof(fnT)); shader.create (fnS, fnT); // Params m_Flags.assign (S->r_u32 ()); m_fMinScale = S->r_float(); m_fMaxScale = S->r_float(); number_vertices = S->r_u32 (); number_indices = S->r_u32 (); R_ASSERT (0==(number_indices%3)); // Vertices u32 size_vertices = number_vertices*sizeof(fvfVertexIn); vertices = xr_alloc<CDetail::fvfVertexIn> (number_vertices); S->r (vertices,size_vertices); // Indices u32 size_indices = number_indices*sizeof(u16); indices = xr_alloc<u16> (number_indices); S->r (indices,size_indices); // Validate indices #ifdef DEBUG for (u32 idx = 0; idx<number_indices; idx++) R_ASSERT (indices[idx]<(u16)number_vertices); #endif // Calc BB & SphereRadius bv_bb.invalidate (); for (u32 i=0; i<number_vertices; i++) bv_bb.modify (vertices[i].P); bv_bb.getsphere (bv_sphere.P,bv_sphere.R); #ifndef _EDITOR Optimize (); #endif }
byte CRCrack3::CrackSche() { //破解深度 g_dwCrackDepth = m_tCrackParam.dwCrackDepth; byte byWinBitmap = m_tCrackParam.byWinBitmap; byte byChair1 = m_tCrackParam.byChair1; byte byType = m_tCrackParam.byType; byte byRspType = m_tCrackParam.byRspType; byte byGrade = m_tCrackParam.byGrade; byte byCount = m_tCrackParam.byCount; byte byResult = Crack(byWinBitmap, byChair1, byType, byRspType, byGrade, byCount, SCORE_5); //暴力破解成功 if (byResult == CONTRACT_YES) { GetResult(&m_tCrackResult); if (IsStupidPut(m_tCrackResult.byRspType, m_tCrackResult.byGrade, m_tCrackResult.byCount)) { //寻找更优解 byResult = Optimize(byWinBitmap, byChair1, byType, m_tCrackResult.byRspType, m_tCrackResult.byGrade, m_tCrackResult.byCount, SCORE_5); if (byResult != CONTRACT_YES) { //还原为第一个Stupid解 SetResult(&m_tCrackResult); } } return SCORE_5; } //采用类人思考 InitThkParam(); Think(byChair1, byType, byRspType, byGrade, byCount); return byResult == INTERRUPT ? SCORE_UNK : SCORE_1; }
void KDTree::ProcessNode(KDTreeNode* N,KDTreeNode *RS[]) { if(N->Type==LEFT) { for(int i=0;i<6;i++) N->ropes[i] = RS[i]; return ; } for(int i=0; i< 6; i++) { Optimize(RS[i],(Side)i,N->box); } Side SL=Left,SR = Right; if(N->m_Axis==1) { SL = Bottom; SR =Top; }else if(N->m_Axis==2) { SL = Back; SR = Front; } float V = N->m_Split; KDTreeNode* RSL[6]; for(int i=0;i<6;i++) RSL[i] = RS[i]; RSL[SR] = N->m_rchild; ProcessNode(N->m_lchild,RSL); KDTreeNode* RSR[6]; for(int i=0; i<6; i++) RSR[i] = RS[i]; RSR[SL] = N->m_lchild; ProcessNode(N->m_rchild,RSR); }