void QueryTermVector::processTerms(Collection<String> queryTerms) { if (queryTerms) { std::sort(queryTerms.begin(), queryTerms.end()); MapStringInt tmpSet(MapStringInt::newInstance()); // filter out duplicates Collection<String> tmpList(Collection<String>::newInstance()); Collection<int32_t> tmpFreqs(Collection<int32_t>::newInstance()); int32_t j = 0; for (int32_t i = 0; i < queryTerms.size(); ++i) { String term(queryTerms[i]); MapStringInt::iterator position = tmpSet.find(term); if (position == tmpSet.end()) { tmpSet.put(term, j++); tmpList.add(term); tmpFreqs.add(1); } else { int32_t freq = tmpFreqs[position->second]; tmpFreqs[position->second] = freq + 1; } } terms = tmpList; termFreqs = Collection<int32_t>::newInstance(tmpFreqs.size()); int32_t i = 0; for (Collection<int32_t>::iterator freq = tmpFreqs.begin(); freq != tmpFreqs.end(); ++freq) termFreqs[i++] = *freq; } }
NS_IMETHODIMP nsSVGDisplayContainerFrame::InsertFrames(nsIAtom* aListName, nsIFrame* aPrevFrame, nsIFrame* aFrameList) { // memorize last new frame nsIFrame* lastNewFrame = nsnull; { nsFrameList tmpList(aFrameList); lastNewFrame = tmpList.LastChild(); } // Insert the new frames nsSVGContainerFrame::InsertFrames(aListName, aPrevFrame, aFrameList); // Call InitialUpdate on the new frames ONLY if our nsSVGOuterSVGFrame has had // its initial reflow (our NS_FRAME_FIRST_REFLOW bit is clear) - bug 399863. if (!(GetStateBits() & NS_FRAME_FIRST_REFLOW)) { nsIFrame* end = nsnull; if (lastNewFrame) end = lastNewFrame->GetNextSibling(); for (nsIFrame* kid = aFrameList; kid != end; kid = kid->GetNextSibling()) { nsISVGChildFrame* SVGFrame = nsnull; CallQueryInterface(kid, &SVGFrame); if (SVGFrame) { SVGFrame->InitialUpdate(); } } } return NS_OK; }
static void *messagePush_func(void *args) { DEBUG_PRINT("Job progress pusher started\n"); char *buf = (char *)malloc(64); int pendingMsg; LenJob *job = NULL; //////////////////////////////// // hands shaking with sched server // send init message to sched server // we use pending message // for it has to be sent first // sprintf(buf, "#start#%s|end", gl_cfg.localIP); sprintf(buf, "%s%s", PRO_INIT_MESSAGE, PRO_MESSAGE_TAIL); pendingMsg = TRUE; while(gl_cfg.flag != STATUS_EXIT) { // when there are pending messages, send first if(pendingMsg) { if(pushMessage(buf) > 0) { pendingMsg = FALSE; free(buf); } }else if(gl_cfg.pendingReport != 0) { // if there are finished task, then connect to server // else wait for a while job = gl_cfg.lenList[0]; ////////////////////// // currently only 1 len is supported ////////////////////// pthread_mutex_lock(&job->jobMutex); // copy finished list to tmp list and clear it std::vector<Task *> tmpList(job->finishedList); job->finishedList.clear(); pthread_mutex_unlock(&job->jobMutex); pthread_mutex_lock(&gl_cfg.lenMutex); gl_cfg.totalReported += tmpList.size(); gl_cfg.pendingReport -= tmpList.size(); pthread_mutex_unlock(&gl_cfg.lenMutex); // generate progress message buf = genProgressMessage(tmpList); tmpList.clear(); if(pushMessage(buf) < 0) pendingMsg = TRUE; else free(buf); } // sleep for several second mySleep(SERVER_WAIT_TIME); } // save pending message DEBUG_PRINT("Job progress pusher ended\n"); }
void FlightLogManager::clearLogList() { QList<ExtendedDebugLogEntry *> tmpList(m_logEntries); m_logEntries.clear(); emit logEntriesChanged(); setDisableExport(true); while (!tmpList.isEmpty()) { delete tmpList.takeFirst(); } }
static void SaveTree(HWND hwndDlg) { HWND hTree = GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE); TVITEM tvi = { 0 }; tvi.hItem = TreeView_GetRoot(hTree); tvi.stateMask = TVIS_STATEIMAGEMASK; tvi.mask = TVIF_PARAM | TVIF_HANDLE | TVIF_STATE; LIST<TopButtonInt> tmpList(8); while(tvi.hItem != NULL) { TreeView_GetItem(hTree, &tvi); TopButtonInt* btn = (TopButtonInt*)tvi.lParam; Buttons.remove(btn); if (TreeView_GetCheckState(hTree,tvi.hItem)) btn->dwFlags |= TTBBF_VISIBLE; else btn->dwFlags &= ~TTBBF_VISIBLE; btn->dwFlags &= ~TTBBF_OPTIONAL; btn->arrangedpos = tmpList.getCount(); tmpList.insert(btn); tvi.hItem = TreeView_GetNextSibling(hTree, tvi.hItem); } { mir_cslock lck(csButtonsHook); for (int i=0; i < Buttons.getCount(); i++) delete Buttons[i]; Buttons = tmpList; } SaveAllButtonsOptions(); }
//---------- Begin of function Finance::optimize_policy_3 -----------// //! bool Finance::optimize_policy_3() { Department *deptPtr; int i; int deptCount = department_array.department_count; #ifdef TEST_MATHCA deptCount = 10; #endif const double weight_intrinsic = 0.45f; // c148 Weight on intrinsic value (v. TL) //const double weight_response = 0.7f; // c149 Weight on responsiveness (v. stability) err_when(deptCount<=0); //----------------------------// //ColumnVector avgSalary(deptCount); // column E 153:162 // $000 //ColumnVector facCount(deptCount); // column I 153:162 //----------------------------// check player input //## chea check the total_hires & totaltarget int totalupper = 0; for (int r=0; r<department_array.department_count; r++ ) { HiringPolicy* finPr2 = &(finance.hiring_policy_array[r]); totalupper += finPr2 -> upper_bound; } if (totalupper < total_hires) { box.msg("The total of your upper bound values is less than the total faculty you wanted to be hired. "); return false; } //## chea check the total_hires & totaltarget ColumnVector targetHire(deptCount), weightsIV3(deptCount), upperBound(deptCount); for (i=deptCount; i>0; i--) { err_if ( department_array.is_deleted(i) ) err_here(); deptPtr = department_array[i]; DepartmentInfo* deptInfo = department_res[deptPtr->department_id]; weightsIV3(i) = (double)1/(double)max( 1,deptPtr->faculty_array.size() ); //## chea try to avoid the bug below if (finance.hiring_policy_array[i-1].upper_bound< finance.hiring_policy_array[i-1].target_value) { finance.hiring_policy_array[i-1].upper_bound = finance.hiring_policy_array[i-1].target_value; } upperBound(i) = finance.hiring_policy_array[i-1].upper_bound; targetHire(i) = finance.hiring_policy_array[i-1].target_value; err_when(upperBound(i) < targetHire(i)); } #ifdef TEST_MATHCA double dummyArr[] = {3,7,13,2,2, 1,5,0,1,4}; double dummyW[] = {1.000,1.135,1.450,1.000,0.955,1.000,1.000,0.775,1.000,1.000}; targetHire << dummyArr; upperBound << dummyArr; weightsIV3 << dummyW; #endif //----------------------------// construct quad_program input matrices PART A ColumnVector c(deptCount); DiagonalMatrix Q(deptCount); c = -SP(targetHire, weightsIV3); Q.set_diagonal(weightsIV3); //----------------------------// PART B // for (i=1; i <=deptCount; i++) // { // surplusRHS(1) += avgSalary(i) * facCount(i) * (1+growthRate); // surplusCoefs3(i) = avgSalary(i) * (1+growthRate); // } // { // double maxSavingAtNewSalary = 0; // J177 // for (i=1; i <=deptCount; i++) // { // maxSavingAtNewSalary += (lowerBound3(i) - facCount(i)) * avgSalary(i) * (1+growthRate); // } // double C136 = finance.cost_rise_policy_array[PL_FACULTY_FTE].result_value / 100; // double C203 = finance.stage1_expense[S1_FACULTY_SALARY_INCREASES].base_value; // // #ifdef TEST_MATHCA // surplusRHS(1) += -520.327f; // #else // surplusRHS(1) += max(C136*C203,maxSavingAtNewSalary); // += i178 where i178=MAX(C136*C203,J177) // #endif // } DiagonalMatrix I(deptCount); I = 1; Matrix A = -I; ColumnVector b = -upperBound; err_when(total_hires<0); // check player input RowVector tmpList(deptCount); tmpList = 1; ColumnVector totalHires(1); totalHires(1) = total_hires; #ifdef TEST_MATHCA err_here(); totalHires(1) = -10; for (i=1;i<=deptCount;i++) totalHires(1) += targetHire(i); #endif A = A & -tmpList; b = b & -totalHires; //----------------------------// Go run it! ColumnVector xNames(deptCount); if (!LinearAlgebra::quadratic_prog(c,Q,A,b,xNames)) return false; print_vector2(xNames); //----------------------------// //int deptCount = department_array.size(); int resultTotal = 0; // 990423 //int resultArr[MAX_DEPARTMENT]; // use following procedures : // i) find the largest (remaining) value in xNames and round it to the nearest integer. // For ties, just use the department that comes up first in the search // ii) if that integer >= 1 put it into the Results vector ELSE put 1 in the result vector // iii) repeat from (i) until sum of results equals maxHires. If the value in the (ii) // is greate than the remaining hires, use the remaining hires instead of (ii) int deptRank; double lastXNames; int lastDept=0; for(deptRank=0; deptRank<deptCount; ++deptRank) { int curDept=0; double curXNames; for( i=1; i<=deptCount; ++i ) { double xNamesValue = xNames(i); // this department has been searched if( lastDept != 0 && (xNamesValue > lastXNames || xNamesValue == lastXNames && i <= lastDept) ) continue; // find the department with maximum xNames if( curDept != 0 && xNamesValue <= curXNames ) continue; curDept = i; curXNames = xNamesValue; } // find a department, mark it so next for(deptRank) won't scan it again i = lastDept = curDept; lastXNames = curXNames; int xNamesInt = int( curXNames + 0.5 ); //round to integer // at least get 1 place // or use ceil((total_hires-resultTotal)/(deptCount-deptRank)), if 1 can't fill up all the vacancies xNamesInt = max( xNamesInt, 1 ); // check remaining err_when( resultTotal > total_hires ); if( xNamesInt > total_hires - resultTotal ) xNamesInt = total_hires - resultTotal; // place the result and add the total finance.hiring_policy_array[curDept-1].result_value = xNamesInt; resultTotal += xNamesInt; } //## chea fix the rounding error int counter =0; if (resultTotal > total_hires) { counter = resultTotal - total_hires; //## chea set upper bound to target for (int q=0; q<department_array.department_count; q++ ) { HiringPolicy* finPr5 = &(finance.hiring_policy_array[q]); if (finPr5 -> result_value >=1) { finPr5 -> result_value --; counter--; } if (counter == 0) break; } resultTotal = total_hires; } // readjust result_value may cause bug int diff = total_hires - resultTotal; int deptRecno = 0; for (i=0; i<diff; i++) { finance.hiring_policy_array[deptRecno].result_value ++; if(finance.hiring_policy_array[deptRecno].result_value > 10) { finance.hiring_policy_array[deptRecno].result_value --; diff++; } if ( ++deptRecno == deptCount ) deptRecno = 0; } //## chea set upper bound to target for (int cq=0; cq<department_array.department_count; cq++ ) { HiringPolicy* finPr3 = &(finance.hiring_policy_array[cq]); // finPr3 -> target_value = finPr3 -> result_value; //BUGHERE if (finPr3 -> upper_bound < finPr3 -> result_value) finPr3 -> upper_bound = finPr3 -> result_value; } return true; }