/***********************************************************************//** * @brief Insert vector column into matrix * * @param[in] vector Vector. * @param[in] col Column index (starting from 0). * * @exception GException::out_of_range * Invalid column index specified. * @exception GException::matrix_vector_mismatch * Matrix dimension mismatches the vector size. * * Inserts the content of a vector into a matrix column. Any previous * content in the matrix column will be overwritted. ***************************************************************************/ void GMatrix::insert_col(const GVector& vector, const int& col) { // Raise an exception if the column index is invalid #if defined(G_RANGE_CHECK) if (col < 0 || col >= m_cols) { throw GException::out_of_range(G_INSERT_COL, col, 0, m_cols-1); } #endif // Raise an exception if the matrix and vector dimensions are not // compatible if (m_rows != vector.size()) { throw GException::matrix_vector_mismatch(G_INSERT_COL, vector.size(), m_rows, m_cols); } // Continue only if we have elements if (m_elements > 0) { // Get start index of data in matrix int i = m_colstart[col]; // Insert column into vector for (int row = 0; row < m_rows; ++row) { m_data[i++] = vector[row]; } } // endif: matrix had elements // Return return; }
/** * Push solutions into the solution container * * @param sv solution vector * @param info informational parameter */ void pushSolutions (GVector < Solution > &sv, BNBBranchInfo * info = NULL) { while (!sv.empty ()) { Solution s; s = sv.back (); sv.pop_back (); if(!mSetFactory->discard (s, getRecord())){ setRecord(s.getValue()); } mSolutionContainer->push(s); } }
GLink() { RigidB=NULL; RigidB2=NULL; OffsetA.clear(); OffsetB.clear(); Axis=GVector(1,0,0); Angle=0.0f; Length=1.0f; SpringK=1.0f; DamperK=0.5f; FrictionK=0; DestroyK=0; PreDestroyRatio=0; }
void discard(typename Factory::Set& s, GVector<typename Factory::Set > &sv, GVector<typename Factory::Solution > &solv, FT record, BNBBranchInfo* info) { int n = s.mA.size(); int I = s.mSplitI; int m = s.mSegments.size(); if(m > 0) { for(int i = 0; i <= m; i ++) { typename Factory::Set sn(n); bool put = false; for(int j = 0; j < n; j ++) { sn.mA[j] = s.mA[j]; sn.mB[j] = s.mB[j]; } if(i == 0) { Segment<FT> seg = s.mSegments.at(i); if(s.mA[I] < seg.mA) { sn.mB[I] = seg.mA; put = true; } } else if(i == m) { Segment<FT> pseg = s.mSegments.at(i-1); if(s.mB[I] > pseg.mB) { sn.mA[I] = pseg.mB; put = true; } } else { Segment<FT> pseg = s.mSegments.at(i-1); Segment<FT> seg = s.mSegments.at(i); sn.mA[I] = pseg.mB; sn.mB[I] = seg.mA; put = true; } if(put) { sn.mSplitI = BoxUtils::getLongestEdge(sn); sv.push_back(sn); } } if(sv.size() == 1) { typename Factory::Set ss; ss = sv[0]; sv.pop_back(); split(ss, sv); } } else { split(s, sv); } if(!sv.empty()) info->mBranched ++; }
int sort_comparison(GVector other) { if (_x < other.x()) { return -1; } else if (_x > other.x()) { return 1; } if (_y < other.y()) { return -1; } else if (_y > other.y()) { return 1; } return 0; }
GVector<Real> SingularValueDecomposition<Real>::HouseholderVector ( const GVector<Real>& X) { GVector<Real> V = X; Real length = V.Length(); Real beta = X[0] + Math<Real>::Sign(X[0])*length; if (beta != (Real)0) { Real invBeta = ((Real)1)/beta; for (int i = 1; i < V.GetSize(); ++i) { V[i] *= invBeta; } } V[0] = (Real)1; return V; }
void multVarTest(void) { GaussDist g1(2.0, 10.0); GaussDist g2(2.0, 20.0); GaussDist g3(2.0, 30.0); GMatrix c(3, 3); c.setDiag(1); c[0][1] = 0.9; c[0][2] = 0.8; c[1][2] = 0.7; cout << "Correlation Matrix C" << endl; cout << c << endl; c.topRight_to_lowerLeft(); c.doCholeskyDecomposition(); c.set_lowerLeft(0.0); cout << " Cholesky Decomp. computing U with C = U * transposed(U):" << endl; cout << c << endl; ofstream of; of.open("multvar.csv"); for (int i = 0; i < 100; i++) { GVector v(3); v[0] = g1.nextVal(); v[1] = g2.nextVal(); v[2] = g3.nextVal(); GVector r = v * c; r.put(of, ", "); of << endl; } of.close(); }
//------------------------------------------------------------------------------ void CPostEffectLoader::PreLoadEffects( GVector<CPostEffectPtr>& outEffects ) { Ast(outEffects.empty()); for (TiXmlNode* node = xmlConfig->FirstChild(); node != NULL; node = node->NextSibling()) { TiXmlElement* pElement = node->ToElement(); if (pElement && pElement->ValueStr() == "PostEffect") { CPostEffectPtr effect = new CPostEffect(); string name = pElement->Attribute("name"); string reset = pElement->Attribute("reset"); effect->SetName(name); effect->SetReset("true" == reset); outEffects.push_back(effect); } } }
/** * Push sets into the set container * * @param sv set vector * @param info informational parameter */ void pushSets (GVector < Set > &sv, BNBBranchInfo * info = NULL) { while (!sv.empty ()) { Set s; s = sv.back (); sv.pop_back (); //BNB_ASSERT(!mSetFactory->isFinal(s)); if(!mSetFactory->discard (s, getRecord())) { mTaskQueue.push (s); } else if(info) { info->mDiscardedByRecord ++; } } if(info) { InfiniInt tmpi; tmpi = mTaskQueue.size(); info->mMaxCandidateProblems = BNBMAX(info->mMaxCandidateProblems, tmpi); } }
/***********************************************************************//** * @brief Vector multiplication * * @param[in] vector Vector. * * @exception GException::matrix_vector_mismatch * Vector length differs from number of columns in matrix. * * This method performs a vector multiplication of a matrix. The vector * multiplication will produce a vector. The matrix multiplication can only * be performed when the number of matrix columns is equal to the length of * the vector. ***************************************************************************/ GVector GMatrix::operator*(const GVector& vector) const { // Raise an exception if the matrix and vector dimensions are not compatible if (m_cols != vector.size()) { throw GException::matrix_vector_mismatch(G_OP_MUL_VEC, vector.size(), m_rows, m_cols); } // Perform vector multiplication GVector result(m_rows); for (int row = 0; row < m_rows; ++row) { double sum = 0.0; for (int col = 0; col < m_cols; ++col) { sum += (*this)(row,col) * vector[col]; } result[row] = sum; } // Return result return result; }
void SingularValueDecomposition<Real>::HouseholderPostmultiply ( const GVector<Real>& V, GMatrix<Real>& A) { GVector<Real> W = (((Real)-2)/V.SquaredLength())*(A*V); int numRows = A.GetNumRows(); int numCols = A.GetNumColumns(); for (int row = 0; row < numRows; ++row) { for (int col = 0; col < numCols; ++col) { A[row][col] += W[row]*V[col]; } } }
/***********************************************************************//** * @brief Insert vector column into matrix * * @param[in] vector Vector. * @param[in] col Column index (starting from 0). * * @exception GException::out_of_range * Invalid column index specified. * @exception GException::matrix_vector_mismatch * Matrix dimension mismatches the vector size. * * Inserts the content of a vector into a matrix column. Any previous * content in the matrix column will be overwritted. ***************************************************************************/ void GSymMatrix::insert_col(const GVector& vector, const int& col) { // Raise an exception if the column index is invalid #if defined(G_RANGE_CHECK) if (col < 0 || col >= m_cols) { throw GException::out_of_range(G_INSERT_COL, col, 0, m_cols-1); } #endif // Raise an exception if the matrix and vector dimensions are not // compatible if (m_rows != vector.size()) { throw GException::matrix_vector_mismatch(G_INSERT_COL, vector.size(), m_rows, m_cols); } // Insert column into vector for (int row = 0; row < m_rows; ++row) { (*this)(row,col) = vector[row]; } // Return return; }
void split(const typename Factory::Set &s, GVector<typename Factory::Set > &sv) { int n = s.mA.size(); int I = s.mSplitI; FT mid = 0.5 * (s.mA[I] + s.mB[I]); typename Factory::Set sl(n), sr(n); for(int i = 0; i < n; i ++) { sl.mA[i] = sr.mA[i] = s.mA[i]; sl.mB[i] = sr.mB[i] = s.mB[i]; } sl.mB[I] = mid; sr.mA[I] = mid; sl.mSplitI = BoxUtils::getLongestEdge(sl); sr.mSplitI = BoxUtils::getLongestEdge(sr); sv.push_back(sr); sv.push_back(sl); }
/** * MANDATORY, decompose rectangle * * @param s set, representing rectangle to decompose * * @param sv resulting two (or more) rectangles * * @param record the incumbent value * */ virtual void branch (Set & s, GVector < Set > & sv, GVector < Solution > & solv, Solution & incumbent, BNBBranchInfo * info, InfiniInt ql) { bool rv; Set asetv[MAX_BNB_CHILDREN]; FixedVector < Set > setv(asetv, MAX_BNB_CHILDREN); rv = false; sv.push_back(s); if(!mDiscarders.empty()) { int sz = mDiscarders.size(); for(int i = 0; i < sz; i++){ if(sv.empty()) break; while(!sv.empty()) { Set s = sv.back(); sv.pop_back(); mDiscarders[i]->discard(s, setv, solv, incumbent, info); } int sz = setv.size(); for(int i = 0; i < sz; i ++) { sv.push_back(setv[i]); } setv.clear(); //sv.insert(sv.end(), setv.begin(), setv.end()); } } //TODO make selection of sets to produce solutions int sz = sv.size(); for(int i = 0; i < sz; i ++) { Solution sol; if(makeSolution(sv[i], sol)) solv.push_back(sol); } /* if(mOptions & Options::DO_LOCAL_SEARCH) { int sz = solv.size(); for(int i = 0; i < sz; i++){ improveSolution(solv[i]); } } */ }
Rectangle(GVector p1, GVector p2, GVector p3, GVector p4) : _p1(p1), _p2(p2),_p3(p3), _p4(p4) { _left = p1.x(); _left = (_left < p2.x()) ? _left : p2.x(); _left = (_left < p3.x()) ? _left : p3.x(); _left = (_left < p4.x()) ? _left : p4.x(); _right = p1.x(); _right = (_right > p2.x()) ? _right : p2.x(); _right = (_right > p3.x()) ? _right : p3.x(); _right = (_right > p4.x()) ? _right : p4.x(); _top = p1.y(); _top = (_top > p2.y()) ? _top : p2.y(); _top = (_top > p3.y()) ? _top : p3.y(); _top = (_top > p4.y()) ? _top : p4.y(); _bottom = p1.y(); _bottom = (_bottom < p2.y()) ? _bottom : p2.y(); _bottom = (_bottom < p3.y()) ? _bottom : p3.y(); _bottom = (_bottom < p4.y()) ? _bottom : p4.y(); }
/** @brief translate text lines and write result in destString*/ void GLogicProcessor::lineTextTranslation(string &destString){ GMemory *longMemory=(GMemory*)inputData.longMemory; int translationMode=((GStr<int>*)inputData.pref)->get(22); string ln=inputData.data["ln"]; if(ln!=""){ if(ln=="rus")translationMode=TRANSLATE_RUS; if(ln=="eng")translationMode=TRANSLATE_ENG; } GVector *dk; GMap *d; string str; if(translationMode==TRANSLATE_ENG){ str="translationDictEng"; }else{ str="translationDictRus"; } longMemory->loadTable(str); dk=longMemory->table[str].data; indexRecord indexRec=longMemory->createIndex(longMemory->table[str], 0, HASH_SEARCH); d=indexRec.mIndex; str="mainDict"; longMemory->loadTable(str); indexRec=longMemory->createIndex(longMemory->table[str], 0, HASH_SEARCH); GMap *dictKey=indexRec.mIndex; string src,line,ld,l1,c,c1,c2,report,res,resD; int i,j,start,end,lng,index; int mode=inputData.mode; destString=str_replace("། ","།\n",destString); destString=str_replace("།་","།\n",destString); destString=str_replace("༎","།\n",destString); destString=str_replace("༔ ","༔\n",destString); destString=str_replace("༴ ","༴\n",destString); destString=str_replace("ག ","ག\n",destString); vector<string>text=explode("\n",destString); int id=1; //text.resize(1); text[0]="གང་ཟག་ཏུ་ལྟ་(༦)བའམ།"; //line="རྣམས་"; //TString st; //dk->getTStr(109073, &st); //cout<<"st="<<st.size()<<" st[0]="<<st[0]<<endl; //exit(0); //index=d->getHKey(line); //cout<<"index="<<index<<endl; //exit(0); //cout<<"text.size()="<<text.size()<<endl; //dictKey->hashError=0; //dictKey->maxHashError=0; //dictKey->hashCount=0; report=""; int step=0; for(int lineIndex=0;lineIndex<text.size();lineIndex++){ if(step==1000){ print(lineIndex<<" from "<<text.size()); step=0; } step++; str=text[lineIndex]; //cout<<"str="<<str<<endl; src=str; lng=(int)str.size(); if(lng<2)continue; if(str.find("་")==-1){ report+=src+"\n<br>"; continue; } str=clearText(str); //str=str_replace("[ _\d\ " \"\*\(\)\{\}\[\]@//\%\&༄༅༔༴༡༢༣༤༥༦༧༨༩༠༎།༑༈༌༐༼༽ऀ-ॿ]","་",str) str=str_replace("ཿ","་ཿ་",str); str=str_replace("│","",str); str=str+"་།"; str=str_replace("་་","་",str); //str=str_replace("([^་])འོ་།","\1་(точка)་",str); //str=str_replace("([^་])འམ་།","\1་[འམ=или]་",str); str=str_replace("ག་གོ་།","ག་(¶)་",str); str=str_replace("ང་ངོ་།","ང་(¶)་",str); str=str_replace("ད་དོ་།","ད་(¶)་",str); str=str_replace("ན་ནོ་།","ན་(¶)་",str); str=str_replace("བ་བོ་།","བ་(¶)་",str); str=str_replace("མ་མོ་།","མ་(¶)་",str); str=str_replace("ར་རོ་།","ར་(¶)་",str); str=str_replace("ལ་ལོ་།","ལ་(¶)་",str); str=str_replace("ས་སོ་།","ས་(¶)་",str); str=str_replace("་ཏོ་།","་(¶)་",str); //str=str_replace("་པའང་","་པ་[འང=уступ.]་",str); //str=str_replace("་བའང་","་བ་[འང=уступ.]་",str); vector<string>l=explode("་",str); res=""; resD=""; lng=(int)l.size(); start=0; end=lng-1; i=lng; while(start<lng){ //make query string decrease end end=lng; while(end>-1){ j=start; line=""; //increase start while (j < end){ line+=l[j]+"་"; j++; } //count+=1 //cout<<line<<" "<<start<<" "<<end<<endl; //if (count >120): //return index=d->getHKey(line,0); if(index!=-1){ TString st; dk->getTStr(index, &st); c="="+st[1]; res+="["+linkDict(line,&id)+linkEdit(c,&id)+"]་"; if(c.find("__")!=-1){ end-=1; res+="<br>\n"; continue; } if(mode==FULL_REPORT && start==0 && end==lng-1){ end-=1; continue; } start=end-1; break; } //next check big dictionary report index=dictKey->getHKey(line,0); if(line.size()>3 && index!=-1){ resD+="["+linkDict(line,&id)+linkEdit("=",&id)+"] "; } ln=line+"@"; l1=str_replace("འི་@","་",ln); index=d->getHKey(l1,0); if(index!=-1){ TString st; dk->getTStr(index, &st); c="="+st[1]; res+="["+linkDict(l1,&id)+linkEdit(c,&id)+"]་["+linkDict("-འི་",&id)+linkEdit("=g.p",&id)+"]་"; start=end-1; break; } //next check big dictionary report index=dictKey->getHKey(l1,0); if(line.size()>3 && index!=-1){ resD+="["+linkDict(l1,&id)+linkEdit("=",&id)+"] "; } l1=str_replace("ས་@","་",ln); index=d->getHKey(l1,0); if(index!=-1){ TString st; dk->getTStr(index, &st); c="="+st[1]; res+="["+linkDict(l1,&id)+linkEdit(c,&id)+"]་["+linkDict("-ས་",&id)+linkEdit("=i.p.",&id)+"]་"; start=end-1; break; } //next check big dictionary report index=dictKey->getHKey(l1,0); if(line.size()>3 && index!=-1){ resD+="["+linkDict(l1,&id)+linkEdit("=",&id)+"] "; } l1=str_replace("ར་@","་",ln); index=d->getHKey(l1,0); if(index!=-1){ TString st; dk->getTStr(index, &st); c="="+st[1]; res+="["+linkDict(l1,&id)+linkEdit(c,&id)+"]་["+linkDict("-ར་",&id)+linkDict("=d.l.",&id)+"]་"; start=end-1; break; } //next check big dictionary report index=dictKey->getHKey(l1,0); if(line.size()>3 && index!=-1){ resD+="["+linkDict(l1,&id)+linkEdit("=",&id)+"] "; } l1=str_replace("འོ་@","་",ln); index=d->getHKey(l1,0); if(index!=-1){ TString st; dk->getTStr(index, &st); c="="+st[1]; res+="["+linkDict(l1,&id)+linkEdit(c,&id)+"]་["+linkDict("-འོ་",&id)+linkEdit("=(точка)",&id)+"]་"; start=end-1; break; } //next check big dictionary report index=dictKey->getHKey(l1,0); if(line.size()>3 && index!=-1){ resD+="["+linkDict(line,&id)+linkEdit("=",&id)+"] "; } l1=str_replace("འམ་@","་",ln); index=d->getHKey(l1,0); if(index!=-1){ TString st; dk->getTStr(index, &st); c="="+st[1]; res+="["+linkDict(l1,&id)+linkEdit(c,&id)+"]་["+linkDict("-འམ་",&id)+linkEdit("=или",&id)+"]་"; start=end-1; break; } //next check big dictionary report index=dictKey->getHKey(l1,0); if(line.size()>3 && index!=-1){ resD+="["+linkDict(l1,&id)+linkEdit("=",&id)+"] "; } end-=1; if(end==start){ res+=line; break; } } start++; } res=str_replace(":|:YP","",res); report+=linkOriginal(src,&id)+"<br>\n@<c>"+res+"</c>\n"; if(resD.size()>10){ report+="@"; report+=resD+"<br>\n"; }else{ report+="<br>\n"; } if(mode==FULL_REPORT){ res=""; for (int t=0;t<l.size();t++){ line=l[t]; l1=line+"་"; index=d->getHKey(l1,0); if(index!=-1){ TString st; dk->getTStr(index, &st); c="="+st[1]; res+="["+linkDict(l1,&id)+linkEdit(c,&id)+"]་"; } } res=str_replace(":|:YP","",res); report+="<c>"+res+"</c>\n<br>\n"; } //break; } report=str_replace("<br>\n<br>", "<br>\n",report); //print("@@@@"<<report); destString=report; //cout<<" dictKey->hashError="<<dictKey->hashError<<" dictKey->maxHashError="<<dictKey->maxHashError<<" dictKey->hashCount="<<dictKey->hashCount<<endl; //cout<<"maxHashSize="<<(0xffffffff>>7)<<endl; //exit(0); }
int GRegExp::longRes(GVector<GString> *res, unsigned int pos, unsigned int reg, GString &str) { if ( pos > str.Size() || res->Size() < reg) return -1; if (!res || res->Size() == reg) { if (this->_opt.Size() == 0 || (this->_opt.Size() > reg && (_opt[reg].getObliWord().Size() == 0))) { if (_opt.Size() != 0) { GString tmp = _opt[reg].getStopChar(); for (unsigned int i = pos; i < str.Size(); i++) for (unsigned int j = 0; j < tmp.Size(); j++) if (tmp[j] == str[i]) return -1; if (_opt[reg].getEmp() == NOEMPTY && (str.Size() - pos) == 0) return -1; return str.Size() - pos; } return str.Size() - pos; } return str.Size(); } if (this->_opt.Size() == 0 || (this->_opt.Size() > reg && (_opt[reg].getObliWord().Size() == 0))) { unsigned int i = pos; while (i < str.Size() - (*res)[reg].Size() + 1) { if (this->_opt.Size() > reg) { GString tmp = _opt[reg].getStopChar(); for (unsigned int j = 0; j < tmp.Size(); j++) { if (tmp[j] == str[i]) { if ((int)i - (int)pos < 0) return -1; else if (this->_opt.Size() == 0 || (this->_opt.Size() > reg && _opt[reg].getEmp() == EMPTY)) return i - pos; else if (i - pos > 0) return i - pos; return -1; } } } if (_opt.Size() > reg + 1 && _opt[reg + 1].getStopChar() == "" && _opt[reg + 1].getObliWord().Size() == 0) { if (_opt[reg].getStopChar().Size() == 0 && _opt[reg].getObliWord().Size() == 0) { unsigned int j = 0; while ((*res)[reg].Size() > j && (*res)[reg][j] == str[i + j]) j++; if (j == (*res)[reg].Size()) return i - pos; } i++; } else { unsigned int j = 0; if ((*res)[reg].Size() == 0) { if (this->_opt.Size() > reg && _opt[reg].getEmp() == NOEMPTY && (i - pos) > 0) { if (longRes(res, i, reg + 1, str) != -1) return i - pos; } else { if (this->_opt.Size() <= reg || (this->_opt.Size() > reg && _opt[reg].getEmp() == EMPTY)) return i - pos; } } else { while ((*res)[reg].Size() > j && (*res)[reg][j] == str[i + j]) j++; /* test fin avec (.*)t sans opt*/ if (j == (*res)[reg].Size()) { if (this->_opt.Size() > reg) { if ((_opt[reg].getEmp() == NOEMPTY && (i - pos) > 1) || _opt[reg].getEmp() == EMPTY) if ((reg + 1 < res->Size()) || (reg + 1 == res->Size() && str.Size() == i + (*res)[reg].Size())) return i - pos; } else { if ((reg + 1 < res->Size()) || (reg + 1 == res->Size() && str.Size() == i + (*res)[reg].Size())) return i - pos; } } } i++; } } return -1; } if (this->_opt.Size() > reg && _opt[reg].getObliWord().Size() > 0) { GVector<GString> tmp = _opt[reg].getObliWord(); for (unsigned int i = 0; i < tmp.Size(); i++) { if (tmp[i].Size() <= str.Size() + pos) { unsigned int j = 0; while (j < tmp[i].Size() && tmp[i][j] == str[pos + j]) j++; if (j == tmp[i].Size()) { if (reg == res->Size() && str.Size() == pos + j) return j; if (reg < res->Size()) { unsigned int k = 0; while (k < str.Size() && k < (*res)[reg].Size() && str[k + pos + j] == (*res)[reg][k]) k++; /*test fin de chaine */ if ((*res)[reg].Size() == k) return tmp[i].Size(); } } } } return -1; } return -1; }
GVector<GString> *GRegExp::pregMatch(GString &str) { str = BurnCorner(str); GString t = this->skipDouble(str); GStringList s = _preg.Explode("(.*)", G::KEEP_EMPTY_PARTS); GVector<GString> r; for (unsigned int i = 0; i < s.Size(); i++) { if (this->isPos(s[i], "(.*)") > -1) r+=GString(""); else r+=BurnCorner(GString(s[i])); } if (isNPos(_preg, "(.*)", _preg.Size() - 4) > 0) { r.Erase(r.Size() - 1); } GVector<GString> *res = new GVector<GString>; if (r.Size() < 1) { if (this->isContener(_preg, "(.*)")) { (*res)+= str; return res; } else { return NULL; } } unsigned int pos = 0; unsigned int reg = 0; if (!this->isContener(_preg, "(.*)")) { if (this->isContener(str,r[0])) { pos+=r[0].Size(); r.Erase(0); } else return NULL; } else { if (r.Size() > 0 && r[r.Size() - 1].Size() == 0) r.Erase(r.Size() - 1); } for (; reg < r.Size(); reg++) { int restmp = longRes(&r, pos, reg, str); if (restmp < 0) return NULL; GString mot = ""; for (unsigned int i = 0; i < (unsigned int)restmp; i++) mot += str[pos + i]; (*res)+= BurnCorner(mot); pos += restmp + r[reg].Size(); } if (reg == r.Size() && _preg.Size() > 4 && isNPos(_preg, "(.*)", _preg.Size() - 4) > 0) { int restmp; if (str.Size() == pos && (_opt.Size() == 0 || (_opt.Size() > reg && _opt[reg].getEmp() == EMPTY))) restmp = 0; else restmp = longRes(&r, pos, reg, str); if (restmp < 0) return NULL; if (pos + restmp > str.Size()) throw GException("Error RegExp"); GString mot = ""; for (unsigned int i = 0; i < (unsigned int)restmp; i++) mot += str[pos + i]; (*res)+= BurnCorner(mot); return res; } return res; }
void GLogicProcessor::saveToTranslationDictionary(string &srcStr){ vector<string>text=explode("[",srcStr); int index; string key,value; GMemory *longMemory=(GMemory*)inputData.longMemory; int translationMode=((GStr<int>*)inputData.pref)->get(22); GVector *dv; GMap *d; if(translationMode==TRANSLATE_ENG){ dv=longMemory->translationDictEng; d=longMemory->translationDictGMapEng; }else{ dv=longMemory->translationDictRus; d=longMemory->translationDictGMapRus; } //GMap *dictKey=longMemory->dictionaryGMap; for(int i=0;i<text.size();i++){ string line=text[i]; string reStr="<[^>]*>"; std::regex key_regex(reStr); line = std::regex_replace(line, key_regex, ""); reStr=".*=.*"; std::regex key_regex_(reStr); line = std::regex_replace(line, key_regex_, ""); if(line.size()<3)continue; index=(int)line.find("/"); if(index<3)continue; index=(int)line.find("]"); if(index<3)continue; line=substr(0, index, line); line=str_replace("/_", "/", line); vector<string>data=explode("/",line); if(data.size()<2)continue; key=data[0]; value=data[1]; key=key+"་"; key=str_replace(" ","",key); key=str_replace("་་","་",key); value=str_replace("__","#",value); value=str_replace("_@","@",value); value=str_replace("#","__",value); value+="@"; value=str_replace("@@","@",value); value=str_replace("{","༼",value); value=str_replace("«","༼",value); value=str_replace("}","༽",value); value=str_replace("»","༽",value); value=str_replace("༼༼","༼",value); value=str_replace("༽༽","༽",value); if(value.size()<3)continue; //cout<<"key="<<key<<" value="<<value<<endl; index=d->getHKey(key,0); //cout<<"index="<<index; TString st; if(value!="---"){ st+=key; st+=value; }else{ st+=""; st+=""; } if(index>-1){ dv->putTStr(index, &st); }else{ d->addRecord(&st); } } }
/***********************************************************************//** * @brief Cholesky solver * * @param[in] vector Vector for which should be solved. * @param[in] compress Use zero-row/column compression (default: true). * * @exception GException::matrix_vector_mismatch * Matrix and vector do not match. * @exception GException::matrix_zero * All matrix elements are zero. * * Solves the linear equation A*x=b using a Cholesky decomposition of A. * This function is to be applied on a decomposition GSymMatrix matrix * that is produced by 'cholesky_decompose'. Case A operates on a full * matrix, Case B on a zero rows/columns (logically) compressed matrix. ***************************************************************************/ GVector GSymMatrix::cholesky_solver(const GVector& vector, bool compress) { // Raise an exception if the matrix and vector dimensions are not compatible if (m_rows != vector.size()) { throw GException::matrix_vector_mismatch(G_CHOL_SOLVE, vector.size(), m_rows, m_cols); } // Allocate result vector GVector x(m_rows); // Check if zero-row/col compression is needed int no_zeros = ((compress && (m_num_inx == m_rows)) || !compress); // Case A: no zero-row/col compression needed if (no_zeros) { // Solve L*y=b, storing y in x (row>k) for (int row = 0; row < m_rows; ++row) { double sum = vector[row]; for (int k = 0; k < row; ++k) { sum -= m_data[m_colstart[k]+(row-k)] * x[k]; // sum -= M(row,k) * x(k) } x[row] = sum/m_data[m_colstart[row]]; // x(row) = sum/M(row,row) } // Solve trans(L)*x=y (k>row) for (int row = m_rows-1; row >= 0; --row) { double sum = x[row]; double* ptr = m_data + m_colstart[row] + 1; for (int k = row+1; k < m_rows; ++k) { sum -= *ptr++ * x[k]; // sum -= M(k,row) * x(k) } x[row] = sum/m_data[m_colstart[row]]; // x(row) = sum/M(row,row) } } // endif: no zero-row/col compression needed // Case B: zero-row/col compression needed else if (m_num_inx > 0) { // Allocate loop variables and pointers int row; int k; int* row_ptr; int* k_ptr; // Solve L*y=b, storing y in x (row>k) for (row = 0, row_ptr = m_inx; row < m_num_inx; ++row, ++row_ptr) { double sum = vector[*row_ptr]; double* ptr = m_data + *row_ptr; for (k = 0, k_ptr = m_inx; k < row; ++k, ++k_ptr) { sum -= *(ptr + m_colstart[*k_ptr] - *k_ptr) * x[*k_ptr]; // sum -= M(row,k) * x(k) } x[*row_ptr] = sum/m_data[m_colstart[*row_ptr]]; // x(row) = sum/M(row,row) } // Solve trans(L)*x=y (k>row) for (row = m_num_inx-1, row_ptr = m_inx+m_num_inx-1; row >= 0; --row, --row_ptr) { double sum = x[*row_ptr]; double* ptr_diag = m_data + m_colstart[*row_ptr]; double* ptr = ptr_diag - *row_ptr; for (k = row+1, k_ptr = m_inx+row+1; k < m_num_inx; ++k, ++k_ptr) { sum -= *(ptr + *k_ptr) * x[*k_ptr]; // sum -= M(k,row) * x(k) } x[*row_ptr] = sum/(*ptr_diag); // x(row) = sum/M(row,row) } } // endelse: zero-row/col compression needed // Case C: all matrix elements are zero else { throw GException::matrix_zero(G_CHOL_SOLVE); } // Return result vector return x; }
void BubbleManager::NewBubbleCenter(GVector shipVelocity, GPoint & newBubbleCenter) { shipVelocity.normalize(); newBubbleCenter += (shipVelocity *(BUBBLE_DIAMETER_METERS /2 -BUBBLE_HYSTERESIS_METERS)); }
VTYPE distance_from(GVector other) { GVector v = this->minus(other); return v.norm(); }
VTYPE dot(GVector other) { return (_x * other.x()) + (_y * other.y()); }
GVector minus(GVector other) { return GVector(_x - other.x(), _y - other.y()); }
GVector plus(GVector other) { return GVector(_x + other.x(), _y + other.y()); }
int main() { { // GVector tests GVector a(1.0, 2.0); GVector b; GVector c(-3.0, -5.0); GVector d(1.0, 3.0); GVector e(1.0, 1.0); GVector f(1.0, -1.0); { // Constructor Tests ASSERT(a.x() == 1.0d); ASSERT(a.y() == 2.0d); ASSERT(b.x() == 0.0d); ASSERT(b.y() == 0.0d); } { // Adding Zero Tests GVector sum_zero = a.plus(b); ASSERT(sum_zero.x() == 1.0d); ASSERT(sum_zero.y() == 2.0d); } { // Adding Tests GVector sum = a.plus(a); ASSERT(sum.x() == 2.0d); ASSERT(sum.y() == 4.0d); } { // Subtracting Tests GVector diffz = a.minus(a); ASSERT(diffz.x() == 0.0d); ASSERT(diffz.y() == 0.0d); GVector diff = a.minus(c); ASSERT(diff.x() == 4.0d); ASSERT(diff.y() == 7.0d); } { // Min Tests ASSERT(a.min() == 1.0d); ASSERT(b.min() == 0.0d); ASSERT(c.min() == -5.0d); } { // Max Tests ASSERT(a.max() == 2.0d); ASSERT(b.max() == 0.0d); ASSERT(c.max() == -3.0d); } { // Comparison Tests ASSERT(a.sort_comparison(a) == 0); ASSERT(b.sort_comparison(b) == 0); ASSERT(c.sort_comparison(c) == 0); ASSERT(a.sort_comparison(b) == 1); ASSERT(a.sort_comparison(c) == 1); ASSERT(a.sort_comparison(d) == -1); ASSERT(a.sort_comparison(e) == 1); } { // Sum2d Tests ASSERT(a.sum2d() == 3.0); ASSERT(b.sum2d() == 0.0); ASSERT(c.sum2d() == -8.0); ASSERT(d.sum2d() == 4.0); ASSERT(e.sum2d() == 2.0); } { // Dot Tests ASSERT(a.dot(a) == 5.0); ASSERT(a.dot(b) == 0.0); ASSERT(a.dot(e) == 3.0); ASSERT(a.dot(c) == -13.0); } { // Norm Tests GVector rnd1(0.0, 3.0); ASSERT(rnd1.norm() == 3.0); ASSERT(a.norm() == sqrt(5.0)); } { // Unit Tests GVector three(0.0, 3.0); GVector u = three.unit(); ASSERT(u.x() == 0.0); ASSERT(u.y() == 1.0); } { // Scale Tests GVector a2 = a.scale(2.0); GVector a3 = a.scale(3.0); ASSERT(a2.x() == 2.0); ASSERT(a2.y() == 4.0); ASSERT(a3.x() == 3.0); ASSERT(a3.y() == 6.0); } { // Distance From Tests ASSERT(a.distance_from(f) == 3.0); ASSERT(a.distance_from(a) == 0.0); } } { // Circle Tests GVector circle_pos(10, 5); Primitives::Circle circle(circle_pos, 3); { // Circle position and radius Tests ASSERT(circle.radius() == 3); ASSERT(circle_pos.x() == circle.position().x()); ASSERT(circle_pos.y() == circle.position().y()); } { // User Data Tests std::string userdata = "Foo"; Primitives::Circle ud(circle_pos, 1, &userdata); ASSERT(circle.user_data() == NULL); ASSERT(ud.user_data() != NULL); } { // Collision Type Tests ASSERT(circle.collision_response_type() == "Circle"); ASSERT(circle.collision_type() == "Circle"); ASSERT(circle.to_collision().position().x() == circle_pos.x()); ASSERT(circle.to_collision().position().y() == circle_pos.y()); ASSERT(circle.to_collision().radius() == circle.radius()); } } { // LineSegment Tests GVector ls_p1(10, 5); GVector ls_p2(30, 25); Primitives::LineSegment ls(ls_p1, ls_p2); { // Linesegment start/end x/y Tests ASSERT(ls.sx() == ls_p1.x()); ASSERT(ls.sy() == ls_p1.y()); ASSERT(ls.ex() == ls_p2.x()); ASSERT(ls.ey() == ls_p2.y()); } { // Linesegment p1, p2 ASSERT(ls.p1().x() == ls_p1.x()); ASSERT(ls.p1().y() == ls_p1.y()); ASSERT(ls.p2().x() == ls_p2.x()); ASSERT(ls.p2().y() == ls_p2.y()); } { // Collision Type Tests ASSERT(ls.collision_response_type() == "LineSegment"); ASSERT(ls.collision_type() == "LineSegment"); ASSERT(ls.to_collision().p1().x() == ls_p1.x()); ASSERT(ls.to_collision().p1().y() == ls_p1.y()); ASSERT(ls.to_collision().p2().x() == ls_p2.x()); ASSERT(ls.to_collision().p2().y() == ls_p2.y()); } } { // Rectangle Tests GVector r_p1(0, 1); GVector r_p2(0, 9); GVector r_p3(8, 9); GVector r_p4(8, 1); Primitives::Rectangle r(r_p1, r_p2, r_p3, r_p4); { // Rectangle p1, p2 p3 p4 ASSERT(r.p1().x() == r_p1.x()); ASSERT(r.p1().y() == r_p1.y()); ASSERT(r.p2().x() == r_p2.x()); ASSERT(r.p2().y() == r_p2.y()); ASSERT(r.p3().x() == r_p3.x()); ASSERT(r.p3().y() == r_p3.y()); ASSERT(r.p4().x() == r_p4.x()); ASSERT(r.p4().y() == r_p4.y()); } { // Collision Type Tests ASSERT(r.collision_response_type() == "Rectangle"); ASSERT(r.collision_type() == "Rectangle"); ASSERT(r.to_collision().p1().x() == r_p1.x()); ASSERT(r.to_collision().p1().y() == r_p1.y()); } { // Left Right Bottom Top Axis aligned tests ASSERT(r.left() == 0); ASSERT(r.right() == 8); ASSERT(r.bottom() == 1); ASSERT(r.top() == 9); } } { // Triangle Tests GVector t_p1(0, 0); GVector t_p2(0, 9); GVector t_p3(8, 9); Primitives::Triangle t(t_p1, t_p2, t_p3); { // Triangle p1, p2 ASSERT(t.p1().x() == t_p1.x()); ASSERT(t.p1().y() == t_p1.y()); ASSERT(t.p2().x() == t_p2.x()); ASSERT(t.p2().y() == t_p2.y()); ASSERT(t.p3().x() == t_p3.x()); ASSERT(t.p3().y() == t_p3.y()); } { // Collision Type Tests ASSERT(t.collision_response_type() == "Triangle"); ASSERT(t.collision_type() == "Triangle"); ASSERT(t.to_collision().p1().x() == t_p1.x()); ASSERT(t.to_collision().p1().y() == t_p1.y()); } } cout << "Hello world!" << endl; return 0; }
void GLogicProcessor::writeDictReportLocal(string &srcStr){ int id=1; //int print=1; string str,dL,line; vector<dictKey> keyArray; ostringstream out; GMemory *longMemory=(GMemory*)inputData.longMemory; GMap *dict; GVector *dt; int translationMode=((GStr<int>*)inputData.pref)->get(22); GVector *dk; GMap *d; if(translationMode==TRANSLATE_ENG){ str="translationDictEng"; }else{ str="translationDictRus"; } longMemory->loadTable(str); dk=longMemory->table[str].data; indexRecord indexRec=longMemory->createIndex(longMemory->table[str], 0, HASH_SEARCH); d=indexRec.mIndex; str="mainDict"; longMemory->loadTable(str); indexRec=longMemory->createIndex(longMemory->table[str], 0, HASH_SEARCH); dt=longMemory->table[str].data; GMap *dictKey=indexRec.mIndex; vector<uint>searchResult; //d->getKey(srcStr, searchResult,HASH_FIND); searchResult.push_back(d->getHKey(srcStr,0)); for(int m=0;m<searchResult.size();m++) { TString st; dk->getTStr(searchResult[m], &st); str="="+st[1]; out<<"["<<linkDict(st[0].c_str(),&id)<<linkEdit(str,&id)<<"]<hr>\n"<<endl; } searchResult.resize(0); //d->getKey(srcStr, searchResult,HASH_FIND); searchResult.push_back(d->getHKey(srcStr,0)); for(int m=0;m<searchResult.size();m++) { TString st; dk->getTStr(searchResult[m], &st); str="="+st[1]; str=str_replace(":|:YP", "", str); out<<"["<<linkDict(st[0].c_str(),&id)<<linkEdit(str,&id)<<"]<hr>\n"<<endl; } searchResult.resize(0); inputData.start=1; dict->getHKey(searchResult,srcStr,0); //dict->getKey(srcStr, searchResult,HASH_FIND); //cout<<"searchResult="<<searchResult.size()<<endl; vector<string>report; report.resize(25); for(int m=0;m<searchResult.size();m++) { TString st; dt->getTStr(searchResult[m], &st); str=st[2]; line=st[1]; if(str.find("[MG]")!=-1){ report[0]=line+"<br>\n"+st[2]; continue; } if(str.find("[HP]")!=-1){ report[1]=line+"<br>\n"+st[2]; continue; } if(str.find("[TD]")!=-1){ report[2]=line+"<br>\n"+st[2]; continue; } if(str.find("[MV]")!=-1){ report[3]=line+"<br>\n"+st[2]; continue; } if(str.find("[VD]")!=-1){ report[4]=line+"<br>\n"+st[2]; continue; } if(str.find("[EP]")!=-1){ report[5]=line+"<br>\n"+st[2]; continue; } if(str.find("[RE]")!=-1){ report[6]=line+"<br>\n"+st[2]; continue; } if(str.find("[SD]")!=-1){ report[7]=line+"<br>\n"+st[2]; continue; } if(str.find("[IW]")!=-1){ report[8]=line+"<br>\n"+st[2]; continue; } if(str.find("[JW]")!=-1){ report[9]=line+"<br>\n"+st[2]; continue; } if(str.find("[TT]")!=-1){ lineTextTranslation(line); report[10]=line+"<br>\n"+st[2]; continue; } if(str.find("[DK]")!=-1){ lineTextTranslation(line); report[11]=line+"<br>\n"+st[2]; continue; } if(str.find("[BB]")!=-1){ continue; } if(str.find("[TS]")!=-1){ continue; } if(str.find("[TR]")!=-1){ continue; } string str=line+"<br>\n"+st[2]; report.push_back(str); } for(int m=0;m<report.size();m++) { if(report[m].size()) out<<srcStr<<"<br>\n"<<report[m]<<"<hr>\n"<<endl; } inputData.start=0; srcStr=out.str(); //print(srcStr); }//_____________________________________________________________________________