void Continuous::setWeights(double* weights) { delete [] _weights; _weights = new double[ nSize() ]; for (int i=0; i < nSize(); i++) _weights[i] = weights[i]; }
void OSM_Model400::calculateA( int comp ) { int i = 0; int j = 0; // Set A[][] to identity matrix A = 0; for( i=0; i<nSize(); i++ ) A[i][i] = 1; double logT10 = log( T10[comp] ); double t1Size = 0; double tSize = 0; double yPass = 0; // 1. Generate square upper triangular matrix of appearance // functions. ie. the complete appearance function table // any size to any other size for( i=0; i<nSize()-1; i++ ) { // t1 marker size basis for this row t1Size = nominal()[i]; // from 2nd coarsest size (i+1) to 2nd finest (nSize-1) for( j=(i+1); j<(nSize()-1); j++ ) { tSize = t1Size / nominal()[j]; yPass = 0.01 * exp( m0 + m1 * logT10 - m2 * log(tSize) + m3 / (tSize*(T10[comp]+10)) ) / tSize; if( yPass > 1.0 ) yPass = 1.0; if( tSize < 1.0001 ) yPass = 1.0; A[i][j] = yPass; } A[i][nSize()-1] = 0; } // 2. Convert to a FRACTION retained basis for( i=0; i<nSize(); i++ ) { // ultrafine sink size a special case A[i][nSize()-1] = A[i][nSize()-2]; for( j=nSize()-2; j>i; j-- ) { // retained by difference A[i][j] = A[i][j-1] - A[i][j]; } // diagonal element is zero A[i][i] = 0; } }
void Life::setBirths(int *births) { int i, size; if (!_births) _births = new int[nSize()]; for (i = 0; i < nSize(); i++) { _births[i] = 0; } if (births) { size = sizeof(births) / sizeof(int); for (i = 0; i < size; i++) { _births[births[i]] = 1; } } }
void Life::setSurvivals(int *survivals) { int i, size; if (!_survivals) _survivals = new int[nSize()]; for (i = 0; i < nSize(); i++) { _survivals[i] = 0; } if (survivals) { size = sizeof(survivals) / sizeof(int); for (i = 0; i < size; i++) { _survivals[survivals[i]] = 1; } } }
double OSM_cSizeDist::percentPassing( double size ) { double retVal = 0.0; int i, N = nSize(); OSM_Vector& sVec = sieve(); if (N>0 && size>=sVec[0]) retVal = cDist[0]; //assume data for largest size for( i=0; i<(N-1); i++ ) { if( sVec[i] == size ) { retVal = cDist[i]; break; } else if( sVec[i] > size && sVec[i+1] < size ) { setRR( sVec[i], sVec[i+1], cDist[i], cDist[i+1] ); retVal = percentRR( size ); break; } } return retVal; }
Foam::pointField Foam::polySplineEdge::intervening ( const pointField& otherknots, const label nbetweenKnots, const vector& fstend, const vector& sndend ) { BSpline spl(knotlist(points_, start_, end_, otherknots), fstend, sndend); label nSize(nsize(otherknots.size(), nbetweenKnots)); pointField ans(nSize); label N = spl.nKnots(); scalar init = 1.0/(N - 1); scalar interval = (N - scalar(3))/N; interval /= otherknots.size() + 1; interval /= nbetweenKnots + 1; ans[0] = points_[start_]; register scalar index(init); for (register label i=1; i<nSize-1; i++) { index += interval; ans[i] = spl.realPosition(index); } ans[nSize-1] = points_[end_]; return ans; }
void SizeAttribute::setValue(const int w,const int h) { QPointF nSize(w,h); if ( nSize != _size ) { _size = nSize; emit changed(this); } }
void wxGxOpenFileGDB::FillMetadata(bool bForce) { if (m_bIsMetadataFilled && !bForce) return; m_bIsMetadataFilled = true; wxGISDataset* pDSet = GetDatasetFast(); if (NULL == pDSet) { return; } VSIStatBufL BufL; wxULongLong nSize(0); wxDateTime dt(1,wxDateTime::Jan, 1900); int ret = VSIStatL(m_sPath, &BufL); if (ret == 0) { //nSize += BufL.st_size; //dt = wxDateTime(BufL.st_mtime); if (VSI_ISDIR(BufL.st_mode)) { char **papszItems = CPLReadDir(wxGxObjectContainer::GetPath()); if (papszItems && CSLCount(papszItems) > 0) { for (int i = 0; papszItems[i] != NULL; ++i) { if (wxGISEQUAL(papszItems[i], ".") || wxGISEQUAL(papszItems[i], "..")) continue; CPLString szFullPathFrom = CPLFormFilename(wxGxObjectContainer::GetPath(), papszItems[i], NULL); ret = VSIStatL(szFullPathFrom, &BufL); if (ret == 0) { nSize += BufL.st_size; wxDateTime dtt(BufL.st_mtime); if (dtt > dt) dt = dtt; } } } CSLDestroy(papszItems); } } m_nSize = nSize; m_dtMod = dt; wsDELETE(pDSet); }
void OSM_Model400::makeDaughters( OSM_Vector& feed, OSM_Vector& broken ) { int size = 0; double tonnes = 0; // No material in broken yet broken = 0; // Contribute breakage of each non-zero size fraction to broken for( size=0; size<nSize(); size++ ) if( (tonnes=feed[size]) != 0.0 ) broken.addProduct( A[size], tonnes ); }
int NonLinearLSQ::curvefit() { size_t n(nSize()); size_t p(nParms()); // Initialize the solver function information _nlsqPointer d = { this }; gsl_multifit_function_fdf mf; mf.f = &f; mf.df = &df; mf.fdf = &fdf; mf.n = n; mf.p = p; mf.params = &d; const gsl_multifit_fdfsolver_type *T = gsl_multifit_fdfsolver_lmsder; gsl_multifit_fdfsolver *s = gsl_multifit_fdfsolver_alloc(T, n, p); _fitParms = guess(); gsl_vector *x = NlsqTogsl(_fitParms); gsl_matrix *covar = gsl_matrix_alloc(p, p); gsl_multifit_fdfsolver_set(s, &mf, x); _nIters = 0; checkIteration(_nIters, gslToNlsq(s->x), NLVector(p,999.0), gsl_blas_dnrm2(s->f), GSL_CONTINUE); do { _nIters++; _status = gsl_multifit_fdfsolver_iterate(s); _fitParms = gslToNlsq(s->x); gsl_multifit_covar(s->J, 0.0, covar); _uncert = getUncertainty(covar); _status = checkIteration(_nIters, _fitParms, _uncert, gsl_blas_dnrm2(s->f), _status); if ( _status ) { break; } if(!doContinue()) { break; } _status = gsl_multifit_test_delta(s->dx, s->x, absErr(), relErr()); } while ((_status == GSL_CONTINUE) && (_nIters < _maxIters)); // Clean up gsl_multifit_fdfsolver_free(s); gsl_matrix_free(covar); return (_status); }
void SizeAttribute::setValue(QString size) { QStringList sl = size.split(","); if ( sl.length() == 2) { QPointF nSize(sl[0].toInt(),sl[1].toInt()); if ( nSize != _size ) { _size = nSize; emit changed(this); } } }
void OSM_Model400::calculateC( ) { // Calculate C[] for each size for( int size=0; size<nSize(); size++ ) { double nomSize = nominal()[size]; if( size==nSize()-1 ) // Ugly patch nomSize = 0; if( nomSize < k1 ) { C[size] = 0.0; } else if( nomSize < k2 ) { C[size] = 1.0 - pow( (k2-nomSize)/(k2-k1), k3 ); } else { C[size] = 1.0; } } }
OSM_cSizeDist::OSM_cSizeDist( OSM_Stream& S ) : OSM_HasType( S ) // same OSM type as Stream { int size, comp; // Initialize cumulative passing Vector cDist.dimension( nSize() ); // Calculate tons per hour in size distribution tph = S.sum(); // Add all component size distributions of S into cDist[] cDist = 0; for( comp=0; comp<nComp(); comp++ ) cDist.loadSum( cDist, S[comp] ); // Convert to cumulative passing distribution (tph basis) for( size=0; size<nSize()-1; size++ ) cDist[size] = cDist[size+1]; cDist[nSize()-1] = 0; for( size=nSize()-2; size>=0; size-- ) cDist[size] += cDist[size+1]; // Scale cumulative distribution by tph (percent basis) if( tph > 0 ) { cDist.loadProduct( cDist, (100/tph) ); } else { cDist = 0; } }
OSM_Model400::OSM_Model400( OSM_Type& sType ) : OSM_Crusher( sType ) { // Set defaults m0 = 1.4936; // Appearance function m1 = 0.9543; // regression parameters m2 = -0.3856; m3 = 23.7200; k1 = 0; // Machine k2 = 50; // parameters k3 = 2.3; T10 = 10; // Applied energy - rock hardness relation tolerance = 1e-9; // Convergence tolerance maxIteration = 100; // Iteration limit // Dimension classification Vector C.dimension( nSize() ); // Dimension appearance Matrix A.dimension( nSize(), nSize() ); }
void Continuous::next(Cell *current, int index) { int nextIndex, state, i; double avg, wsum; nextIndex = wrapi(index + 1, 0, 2); state = current->states[index]; avg = 0.0; wsum = 0.0; for (i = 0; i < nSize(); i++ ) { avg += (getNeighbor(current, i)->states[index] * _weights[i]); wsum += _weights[i]; } avg /= wsum; current->states[nextIndex] = wrapd(avg + _add, 0.0, 1.0); }
double OSM_cSizeDist::sizePassing( double percent ) { double retVal = 0.0; int i, N = nSize(); OSM_Vector& sVec = sieve(); for( i=0; i<(N-1); i++ ) { if( cDist[i] == percent ) { retVal = sVec[i]; break; } else if( cDist[i]>percent && cDist[i+1]<percent ) { setRR( sVec[i], sVec[i+1], cDist[i], cDist[i+1] ); retVal = sizeRR( percent ); break; } } return retVal; }
OSM_Stream::OSM_Stream( OSM_Type& sType, double* compMatrix) : OSM_HasType( sType ) { dimension( nComp(), nSize(), compMatrix ); }
int OSM_Model400::calculate( ) { // Return value, assume successful int retVal = 0; // Vectors for internal component streams OSM_Vector x( nSize() ); // net crusher contents OSM_Vector y( nSize() ); // material classified for breakage OSM_Vector z( nSize() ); // breakage products of y // Calculate classification function: C[] calculateC( ); // Create contents matrix if required if( contents.rows()!=nComp() || contents.columns()!=nSize() ) { contents.dimension( nComp(), nSize() ); } //-- Main Loop - loop over components in the feed ----------------------- for( int comp=0; comp<nComp(); comp++ ) { // Aliases to component vectors OSM_Vector& feedC = feed()[comp]; OSM_Vector& prodC = product()[comp]; OSM_Vector& x = contents[comp]; if( feedC.sum() > 0 ) // Component present ? { calculateA( comp ); // Make appearance function double misconvergence = 1e20; // Force misconvergence long iteration = 0; // No iterations yet //-- Iteration Loop - until converged or maximum iterations ----- while( misconvergence>tolerance && iteration<maxIteration ) { // classify material for breakage y = C(x) y.loadProduct( C, x ); // obtain breakage products z = A(y) makeDaughters( y, z ); // obtain next iteration of recycle: x = feed + z misconvergence = x.loadSumWithCompare( feedC, z ); // a successful iteration (hopefully) iteration++; } // product component by balance prodC.loadSubtraction( x, y ); } else { // product component is 0 prodC = 0; } } // indicate success return retVal; }
void CTCExeVersionManager::changedExeIcon(LPCTSTR lpExeName, LPCTSTR lpIconFile) { LPICONDIRENTRY pIconDirEntry(NULL); LPGRPICONDIR pGrpIconDir(NULL); HEADER header; LPBYTE pIconBytes(NULL); HANDLE hIconFile(NULL); DWORD dwRet(0), nSize(0), nGSize(0), dwReserved(0); HANDLE hUpdate(NULL); BOOL ret(FALSE); WORD i(0); //打开图标文件 hIconFile = CreateFile(lpIconFile, GENERIC_READ, NULL, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hIconFile == INVALID_HANDLE_VALUE) { return; } //读取文件头部信息 ret=ReadFile(hIconFile, &header, sizeof(HEADER), &dwReserved, NULL); if (!ret) { CloseHandle(hIconFile); return; } //建立每一个图标的目录信息存放区域 pIconDirEntry = (LPICONDIRENTRY)new BYTE[header.idCount*sizeof(ICONDIRENTRY)]; if (pIconDirEntry==NULL) { CloseHandle(hIconFile); return; } //从Icon文件中读取每一个图标的目录信息 ret = ReadFile(hIconFile, pIconDirEntry, header.idCount*sizeof(ICONDIRENTRY), &dwReserved, NULL); if (!ret) { delete[] pIconDirEntry; CloseHandle(hIconFile); return; } //建立EXE文件中RT_GROUP_ICON所需的数据结构存放区域 nGSize=sizeof(GRPICONDIR)+header.idCount*sizeof(ICONDIRENTRY); pGrpIconDir=(LPGRPICONDIR)new BYTE[nGSize]; //填充信息,这里相当于一个转换的过程 pGrpIconDir->idReserved=header.idReserved; pGrpIconDir->idType=header.idType; pGrpIconDir->idCount=header.idCount; //复制信息并设置每一个图标对应的ID。ID为位置索引号 for(i=0;i<header.idCount;i++) { pGrpIconDir->idEntries[i].bWidth=pIconDirEntry[i].bWidth; pGrpIconDir->idEntries[i].bHeight=pIconDirEntry[i].bHeight; pGrpIconDir->idEntries[i].bColorCount=pIconDirEntry[i].bColorCount; pGrpIconDir->idEntries[i].bReserved=pIconDirEntry[i].bReserved; pGrpIconDir->idEntries[i].wPlanes=pIconDirEntry[i].wPlanes; pGrpIconDir->idEntries[i].wBitCount=pIconDirEntry[i].wBitCount; pGrpIconDir->idEntries[i].dwBytesInRes=pIconDirEntry[i].dwBytesInRes; pGrpIconDir->idEntries[i].nID=i; } //开始更新EXE中的图标资源,ID定为最小0,如果原来存在0ID的图标信息则被替换为新的。 hUpdate = BeginUpdateResourceW(lpExeName, false); if (hUpdate!=NULL) { //首先更新RT_GROUP_ICON信息 ret = UpdateResource(hUpdate, RT_GROUP_ICON, MAKEINTRESOURCE(0), MAKELANGID(LANG_CHINESE, SUBLANG_SYS_DEFAULT), (LPVOID)pGrpIconDir, nGSize); if (!ret) { delete[] pIconDirEntry; delete[] pGrpIconDir; CloseHandle(hIconFile); return; } //接着的是每一个Icon的信息存放 for(i=0;i<header.idCount;i++) { //Icon的字节数 nSize = pIconDirEntry[i].dwBytesInRes; //偏移文件的指针到当前图标的开始处 dwRet=SetFilePointer(hIconFile, pIconDirEntry[i].dwImageOffset, NULL, FILE_BEGIN); if (dwRet==INVALID_SET_FILE_POINTER) { break; } //准备pIconBytes来存放文件里的Byte信息用于更新到EXE中。 delete[] pIconBytes; pIconBytes = new BYTE[nSize]; ret = ReadFile(hIconFile, (LPVOID)pIconBytes, nSize, &dwReserved, NULL); if(!ret) { break; } //更新每一个ID对应的RT_ICON信息 ret = UpdateResourceW(hUpdate, RT_ICON, MAKEINTRESOURCE(pGrpIconDir->idEntries[i].nID), MAKELANGID(LANG_CHINESE, SUBLANG_SYS_DEFAULT), (LPVOID)pIconBytes, nSize); if(!ret) { break; } } //结束EXE资源的更新操作 if (pIconBytes!=NULL) { delete[] pIconBytes; } EndUpdateResourceW(hUpdate, false); } //清理资源并关闭Icon文件,到此更新操作结束! delete[] pGrpIconDir; delete[] pIconDirEntry; CloseHandle(hIconFile); m_isChangeExeIcon=true; }