string Polynom::toString() { string str; for (auto i = getDegree(); i >= 0; i--) { if (coefficients[i] != MegaRational(0)) { if (coefficients[i].getNumerator() < 0) str += "-"; else if (i != getDegree()) str += "+"; if (coefficients[i].getDenominator() != 1) str += '('; str += coefficients[i].getNumerator().abs().toString(); if (coefficients[i].getDenominator() != 1) str += '/' + coefficients[i].getDenominator().toString() + ')'; if (i > 0) { str += 'x'; if (i > 1) { str += '^'; str += i + '0'; } } } } return str; }
bool isConvexPoint(tuple *o, tuple *prevous, tuple *current, tuple *nextone) { double ocn = getDegree(current, o, nextone); double pco = getDegree(current, prevous, o); double pcn = getDegree(current, prevous, nextone); if (ocn == 0) { int pco_ = (int) pco; int pcn_ = (int) pcn; if ((ocn + pco_) > pcn_) { // this is a convex point return true ; } else { //this is not convex point return false ; } } if ((ocn + pco) > pcn) { // this is a convex point return true ; } else { //this is not convex point return false ; } }
BezierCurve BezierCurve::getDerivative() const { if (getDegree() < 1) throw Exception("Cannot derive a curve of degree < 1."); // actually we can, it just doesn't make any sense. vector<Vector> forward_differences(controlPoints.size()-1); float degree = float(getDegree()); for (size_t i = 0; i < forward_differences.size(); ++i) forward_differences[i] = (controlPoints[i+1] - controlPoints[i]) * degree; return BezierCurve(forward_differences); }
std::string toString(std::size_t precision = 3) const { std::string r; for (std::size_t i = 0; i < mFactors.size(); i++) { if (getDegree() == 1 && mFactors[i] == 0) { return "0"; } else if (mFactors[i] != 0) { std::ostringstream oss; oss << std::setprecision(precision) << mFactors[i]; if (mFactors[i] != 1.f || i == 0) { r += oss.str(); } if (i != 0) { r += "x"; if (i != 1) { r += std::to_string(i); } } r += " + "; } } if (r.size() >= 3) r.erase(r.size()-3); return r; }
void RSpline::print(QDebug dbg) const { dbg.nospace() << "RSpline("; RShape::print(dbg); dbg.nospace() << ", degree: " << getDegree(); dbg.nospace() << ", order: " << getOrder(); dbg.nospace() << ", closed: " << isClosed(); dbg.nospace() << ", periodic: " << isPeriodic(); dbg.nospace() << ", start point: " << getStartPoint(); dbg.nospace() << ", end point: " << getEndPoint(); QList<RVector> controlPoints = getControlPointsWrapped(); dbg.nospace() << ",\ncontrolPoints (" << controlPoints.count() << "): "; for (int i=0; i<controlPoints.count(); ++i) { dbg.nospace() << i << ": " << controlPoints.at(i); } QList<RVector> fitPoints = getFitPoints(); dbg.nospace() << ",\nfitPoints (" << fitPoints.count() << "): "; for (int i=0; i<fitPoints.count(); ++i) { dbg.nospace() << i << ": " << fitPoints.at(i) << ", "; } QList<double> knotVector = getKnotVector(); dbg.nospace() << ",\nknots (" << knotVector.count() << "): "; for (int i=0; i<knotVector.count(); ++i) { dbg.nospace() << i << ": " << knotVector.at(i) << ", "; } knotVector = getActualKnotVector(); dbg.nospace() << ",\ninternally used knots (" << knotVector.count() << "): "; for (int i=0; i<knotVector.count(); ++i) { dbg.nospace() << i << ": " << knotVector.at(i) << ", "; } }
//------------------------------------------------------------------------------ // serialize() -- print the value of this object to the output stream sout. //------------------------------------------------------------------------------ std::ostream& Polynomial::serialize(std::ostream& sout, const int i, const bool slotsOnly) const { int j = 0; if (!slotsOnly) { sout << "( " << getFactoryName() << std::endl; j = 4; } int mm = getDegree() + 1; if (mm > 0) { const double* aa = getCoefficients(); indent(sout,i+j); sout << "coefficients: [ "; for (int i = 0; i < mm; i++) { std::cout << aa[i] << " "; } sout << " ]" << std::endl; } BaseClass::serialize(sout, i + j, true); if (!slotsOnly) { indent(sout, i); sout << ")" << std::endl; } return sout; }
/** * \return List of bezier spline segments which together represent this curve. */ QList<RSpline> RSpline::getBezierSegments() const { // spline is a single bezier segment: if (countControlPoints()==getDegree()+1) { return QList<RSpline>() << *this; } updateInternal(); QList<RSpline> ret; #ifndef R_NO_OPENNURBS ON_NurbsCurve* dup = dynamic_cast<ON_NurbsCurve*>(curve.DuplicateCurve()); if (dup==NULL) { return ret; } dup->MakePiecewiseBezier(); for (int i=0; i<=dup->CVCount() - dup->Order(); ++i) { ON_BezierCurve bc; if (!dup->ConvertSpanToBezier(i, bc)) { continue; } QList<RVector> ctrlPts; for (int cpi=0; cpi<bc.CVCount(); cpi++) { ON_3dPoint onp; bc.GetCV(cpi, onp); ctrlPts.append(RVector(onp.x, onp.y, onp.z)); } ret.append(RSpline(ctrlPts, degree)); } delete dup; #endif return ret; }
void printVexs(MGraph G){ int i; for(i = 0; i < G.vexnum; i++){ int inDegree, outDegree; getDegree(G, i, &inDegree, &outDegree); printf("序号: %d, 名称: %c, 入度: %d, 出度: %d\n", i, G.vexs[i], inDegree, outDegree); } }
void Variable::deconnect(DLink<ConstraintLink> *link, bool reuse) { if (!link->removed) { // if (link->content.constr->isTriangle()) getTriangles()->erase(link, true); // else getConstrs()->erase(link, true); if (getDegree() <= ToulBar2::elimDegree_ || (ToulBar2::elimDegree_preprocessing_ >= 0 && (getDegree() <= min(1,ToulBar2::elimDegree_preprocessing_) || getTrueDegree() <= ToulBar2::elimDegree_preprocessing_))) queueEliminate(); } if (reuse) { assert(wcsp->getStore()->getDepth()==0); link->prev = NULL; link->next = NULL; } }
void IntervalVariable::print(ostream& os) { os << " [" << inf << "," << sup << "]"; os << "/" << getDegree(); if (ToulBar2::weightedDegree) os << "/" << getWeightedDegree(); if (unassigned()) { os << " < " << getInfCost() << "," << getSupCost() << " >"; } }
T value(T const& x) const { T y = 0; const std::size_t degree = getDegree(); if (!degree) return 0; for (std::size_t i=0; i < degree; ++i) y += mFactors[i] * pow(x, (T)(int)i); return y; }
point3 CourbeBezier::calculPuBernstein(const float &progressionCourbe) { point3 pU; for(int j=0; j< tabPoint.size(); j++){ pU = pU + tabPoint[j]*Bernstein(j, getDegree(), progressionCourbe); } return pU; }
const Polynomial<T>& operator+=(Polynomial<T> const& other) { const std::size_t otherDegree = other.getDegree(); if (otherDegree > getDegree()) mFactors.resize(otherDegree); for (std::size_t i = 0; i < otherDegree; ++i) { setFactor(i, other.mFactors[i] + mFactors[i]); } return *this; }
float GoToBase::getDiffYawInDegree(float deltaXInMeter, float deltaYInMeter) { float curYawInDegree = this->_robot->getYaw(); while(curYawInDegree < 0) curYawInDegree += 360; // check if the goal is in front of us with MAX_DIFF_YAW tolerance float goalYawInDegree = getDegree(deltaXInMeter, deltaYInMeter); float difYawInDegree = curYawInDegree - goalYawInDegree; return difYawInDegree; }
int cilk_main( std::string _inputname, std::string _coloringAlgorithm, std::string _numWorkers, std::string _ordering) { __cilkrts_set_param("nworkers", _numWorkers.c_str()); sparseRowMajor<int, int> inputGraph; // Parse the graph in .mtx or adjacency list representation. if (_inputname.find(".mtx") != string::npos) { graph<int> inter = graphFromEdges<int>(edgesFromMtxFile<int>(_inputname.c_str()), true); inputGraph = sparseFromGraph<int>(inter); } else if (_inputname.find(".edges") != string::npos) { graph<int> inter = graphFromEdges<int>(readEdgeArrayFromFile<int>((char*)_inputname.c_str()), true); inputGraph = sparseFromGraph<int>(inter); } else { graph<int> inter = graphFromEdges<int>(edgesFromGraph<int>(readGraphFromFile<int>((char*)_inputname.c_str())), true); inputGraph = sparseFromGraph<int>(inter); } // Initialize the vertex color array, and the permutation. // int* vertexColors = (int*) malloc(sizeof(int)*inputGraph.numRows); if (inputGraph.Values == NULL) { inputGraph.Values = (int*) malloc(sizeof(int)*inputGraph.numRows); } int* vertexColors = inputGraph.Values; unsigned int seed = 1234134; double beginTime = getTime(); int numColors; if (_coloringAlgorithm.compare("JP") == 0) { numColors = colorGraphJP(&inputGraph, vertexColors, _ordering, seed); } else { printf("Invalid coloring algorithm\n"); } double endTime = getTime(); for (int i = 0; i < inputGraph.numRows; i++) { for (int j = 0; j < getDegree(&inputGraph, i); j++) { int nbr = getNeighbor(&inputGraph, i, j); if (vertexColors[i] == vertexColors[nbr]) { printf("Error: vertex %d and vertex %d are neighbors and share color %d\n", i, nbr, vertexColors[i]); return -1; } } } printf("Total colors: %d\n", numColors); printf("Total time: %f\n", endTime - beginTime); return 0; }
double BlobParameters::evaluateModifiedBessel(double x, unsigned int numberOfSummands) const { // implementing http://en.wikipedia.org/wiki/Bessel_function#Modified_Bessel_functions_:_I.CE.B1.2C_K.CE.B1 double sum = 0.0; unsigned int alpha = getDegree(); double summand = NumericalAlgorithms::uintPow(0.5 * x, alpha) / (double)NumericalAlgorithms::factorial(alpha); for(unsigned int m = 0; m < numberOfSummands; ++m) { sum += summand; summand *= 0.25 * x * x / (double)((m + 1) * (m + alpha + 1)); } return sum; }
/* private static */ void PolygonizeGraph::findIntersectionNodes(PolygonizeDirectedEdge *startDE, long label, std::vector<Node*>& intNodes) { PolygonizeDirectedEdge *de=startDE; do { Node *node=de->getFromNode(); if (getDegree(node, label) > 1) { intNodes.push_back(node); } de=de->getNext(); assert(de!=NULL); // found NULL DE in ring assert(de==startDE || !de->isInRing()); // found DE already in ring } while (de!=startDE); }
const Polynomial<T>& operator*=(Polynomial<T>& other) { const std::size_t degree = getDegree(); const std::size_t otherDegree = other.getDegree(); std::vector<T> tmp(mFactors); mFactors.clear(); mFactors.resize(degree + otherDegree - 1); for (std::size_t i = 0; i < degree; ++i) { for (std::size_t j = 0; j < otherDegree; ++j) { setFactor(i+j, tmp[i] * other[j] + mFactors[i+j]); } } return *this; }
static void updateDistribution(IDnum * distribution, Node * node) { IDnum degree = getDegree(node); if (degree < 4) distribution[degree]++; else distribution[3]++; degree = getReverseDegree(getTwinNode(node)); if (degree < 4) distribution[degree]++; else distribution[3]++; }
/* * Finds all nodes in a maximal edgering which are self-intersection nodes * @param startDE * @param label * @return the list of intersection nodes found, * or <code>NULL</code> if no intersection nodes were found. * Ownership of returned object goes to caller. */ vector<planarNode*>* PolygonizeGraph::findIntersectionNodes(PolygonizeDirectedEdge *startDE, long label) { PolygonizeDirectedEdge *de=startDE; vector<planarNode*> *intNodes=NULL; do { planarNode *node=de->getFromNode(); if (getDegree(node, label) > 1) { if (intNodes==NULL) intNodes=new vector<planarNode*>(); intNodes->push_back(node); } de=de->getNext(); Assert::isTrue(de!=NULL, "found NULL DE in ring"); Assert::isTrue(de==startDE || !de->isInRing(), "found DE already in ring"); } while (de!=startDE); return intNodes; }
double BlobParameters::evaluate(double x) const { // implementing R.M. Lewitt, Phys. Med. Biol. 37 (1992) 708 double a = getSupportRadius(); unsigned int m = getDegree(); double alpha = getDensityFallOff(); if(0 <= x && x <= a) { double rootOfOneMinusROverAlphaSquared = sqrt(1.0 - (x * x) / (a * a)); double firstIm = evaluateModifiedBessel(alpha, NUMBER_OF_MODIFIED_BESSEL_SUMMANDS); double secondEvalParam = alpha * rootOfOneMinusROverAlphaSquared; double secondIm = evaluateModifiedBessel(secondEvalParam, NUMBER_OF_MODIFIED_BESSEL_SUMMANDS); return 1.0 / firstIm * NumericalAlgorithms::uintPow(rootOfOneMinusROverAlphaSquared, m) * secondIm; } else { return 0.0; } }
int getCoolness(char *name) { int node; int degree; int nodeCount; // Get the starting node in the network node = getNodeByName(name); // If this person isn't in the network, their coolness is zero if (node < 0) return 0; // Get the "degree" of this node, which is the number of people // directly connected to it. This is the first part of the coolness degree = getDegree(node); // Get the number of nodes directly or indirectly connected to this node nodeCount = componentCount(node); // Return the "coolness", which is the degree plus the node count, minus // one (we don't count ourselves in the coolness factor) return degree + nodeCount - 1; }
void cube::evaluateSimpleInt() { int ax,r,g,b; double NandL; double VandR; for (int i=2;i>-1;i--) { for (int k = 0;k<2;k++) { r=g=b=1; Polygon poly = m_faceArr[i].getNPolygon(k); for (int j=0;j<m_lights.count();j++) { // QVector3D L = this->createVectorByPoint(m_cubeCenter,m_lights[j].pos); QVector3D L(m_lights[j].pos.getX(),m_lights[j].pos.getY(),m_lights[j].pos.getZ()); double distance = createVectorByPoint(poly.getMid(),m_lights[j].pos).length(); L.normalize(); QVector3D n = poly.getNormal(); NandL = QVector3D::dotProduct(n,L); //may be vector L need * -1 QVector3D tmp; tmp.setX(-1*L.x()); tmp.setY(-1*L.y()); tmp.setZ(-1*L.z()); QVector3D R = getReflVector(tmp,n); QVector3D V = getCameraVector(poly.getMid()); VandR = QVector3D::dotProduct(V,R); double reflPart = 0; double reflAngle = getDegree(VandR); if (reflPart>=0 && reflAngle <=90) { reflPart = 10 * pow(VandR,2); qDebug() << "reflPart" << reflPart; } float angle = getDegree(NandL); double lightPart = 0; if (angle >= 0 && angle<=90) { lightPart = (m_lights[j].amp*(m_diff*NandL + reflPart))/(distance+0.2); } a = 0.3*0.3+lightPart; r+= m_lights[j].color.red()*a; g+= m_lights[j].color.green()*a; b+= m_lights[j].color.blue()*a; if (r>255) r = 255;if (r<0) r = 0; if (g>255) g = 255;if (g<0) g = 0; if (b>255) b = 255;if (b<0) b = 0; QColor clr(r,g,b); drawPolyColor(poly,clr); } } } }
void EncryptedArrayDerived<type>::mat_mul(Ctxt& ctxt, const PlaintextBlockMatrixBaseInterface& mat) const { FHE_TIMER_START; assert(this == &mat.getEA().getDerived(type())); assert(&context == &ctxt.getContext()); RBak bak; bak.save(); tab.restoreContext(); const PlaintextBlockMatrixInterface<type>& mat1 = dynamic_cast< const PlaintextBlockMatrixInterface<type>& >( mat ); ctxt.cleanUp(); // not sure, but this may be a good idea Ctxt res(ctxt.getPubKey(), ctxt.getPtxtSpace()); // a new ciphertext, encrypting zero long nslots = size(); long d = getDegree(); mat_R entry; entry.SetDims(d, d); vector<RX> entry1; entry1.resize(d); vector< vector<RX> > diag; diag.resize(nslots); for (long j = 0; j < nslots; j++) diag[j].resize(d); for (long i = 0; i < nslots; i++) { // process diagonal i bool zDiag = true; long nzLast = -1; for (long j = 0; j < nslots; j++) { bool zEntry = mat1.get(entry, mcMod(j-i, nslots), j); assert(zEntry || (entry.NumRows() == d && entry.NumCols() == d)); // get(...) returns true if the entry is empty, false otherwise if (!zEntry && IsZero(entry)) zEntry=true; // zero is an empty entry too if (!zEntry) { // non-empty entry zDiag = false; // mark diagonal as non-empty // clear entries between last nonzero entry and this one for (long jj = nzLast+1; jj < j; jj++) { for (long k = 0; k < d; k++) clear(diag[jj][k]); } nzLast = j; // recode entry as a vector of polynomials for (long k = 0; k < d; k++) conv(entry1[k], entry[k]); // compute the lin poly coeffs buildLinPolyCoeffs(diag[j], entry1); } } if (zDiag) continue; // zero diagonal, continue // clear trailing zero entries for (long jj = nzLast+1; jj < nslots; jj++) { for (long k = 0; k < d; k++) clear(diag[jj][k]); } // now diag[j] contains the lin poly coeffs Ctxt shCtxt = ctxt; rotate(shCtxt, i); // apply the linearlized polynomial for (long k = 0; k < d; k++) { // compute the constant bool zConst = true; vector<RX> cvec; cvec.resize(nslots); for (long j = 0; j < nslots; j++) { cvec[j] = diag[j][k]; if (!IsZero(cvec[j])) zConst = false; } if (zConst) continue; ZZX cpoly; encode(cpoly, cvec); // FIXME: record the encoded polynomial for future use Ctxt shCtxt1 = shCtxt; shCtxt1.frobeniusAutomorph(k); shCtxt1.multByConstant(cpoly); res += shCtxt1; } } ctxt = res; }
long Network::getDegree(const std::string& vertex_name) const { return getDegree(getVertexId(vertex_name)); }