static void Test( ) { std::cout << std::endl << AW_FUNKTIONS_NAME << std::endl << std::endl; Rechteck<NUMERISCH> r1( 0, 0, 10, 20 ); Rechteck<NUMERISCH> r2( 100, 200, 30, 40 ); Rechteck<NUMERISCH> rk( r1 ); Objekt::testAusgabe( ) << "r1: " << r1 << std::endl; Objekt::testAusgabe( ) << "r2: " << r2 << std::endl; Objekt::testAusgabe( ) << "rk: " << rk << std::endl; assert( r1 != r2 ); assert( r1 == rk ); Objekt::testAusgabe( ) << "r1+r2: " << r1+r2 << std::endl; Rechteck<NUMERISCH> e( 0, 0, r2.x() + r2.w(), r2.y() + r2.h() ); assert( (r1+r2) == e ); assert( Rechteck<NUMERISCH>( 0, 0, r2.x() + r2.w(), r2.y() + r2.h() ) == e ); r2 = rk; assert( r1 == r2 ); std::cout << AW_FUNKTIONS_NAME << " all test done. " << std::endl << std::endl; }
bool CDirectedGraphImpl::CheckDiameter(CList<TInt>& Nodes) { CALLSTACKITEM_N(_CL("CDirectedGraphImpl"), _CL("CheckDiameter")); auto_ptr<CGenericIntMap> to_remove(CGenericIntMap::NewL()); CList<TInt>::Node *n, *n2; n=Nodes.iFirst; while (n) { n2=Nodes.iFirst; while (n2) { if (n->Item != n2->Item) to_remove->AddDataL(n2->Item, (void*)1); n2=n2->Next; } TDbSeekKey rk(n->Item); if (iTable.SeekL(rk)) { TInt from, to; iTable.GetL(); from=iTable.ColUint32(1); while (from==n->Item) { to=iTable.ColUint32(2); to_remove->DeleteL(to); if (! iTable.NextL() ) from=-1; else { iTable.GetL(); from=iTable.ColUint32(1); } } } if (to_remove->Count() == 0 ) return true; to_remove->Reset(); n=n->Next; } return false; }
Disposable<Matrix> Expm(const Matrix& M, Real t, Real tol) { const Size n = M.rows(); QL_REQUIRE(n == M.columns(), "Expm expects a square matrix"); AdaptiveRungeKutta<> rk(tol); AdaptiveRungeKutta<>::OdeFct odeFct = MatrixVectorProductFct(M); Matrix result(n, n); for (Size i=0; i < n; ++i) { std::vector<Real> x0(n, 0.0); x0[i] = 1.0; const std::vector<Real> r = rk(odeFct, x0, 0.0, t); std::copy(r.begin(), r.end(), result.column_begin(i)); } return result; }
int main(int narg, char* argc[]) { std::vector<Function*> functions; functions.push_back( new Function1() ); functions.push_back( new Function2() ); functions.push_back( new Function3() ); functions.push_back( new Function4() ); RungeKutta rk(argc[1], functions, atoi(argc[2])); rk.solveProblem(); return 0; }
TBool CTupleStoreImpl::SeekIdL(TUint aId) { CALLSTACKITEM_N(_CL("CTupleStoreImpl"), _CL("SeekIdL")); TDbSeekKey rk(aId); SwitchIndexL(EIndexId); TBool ret=EFalse; ret=iTable.SeekL(rk); return ret; }
void CSavedPoints::IncUsage(TEndPoint p, TInt PointIdx) { SwitchIndexL(0); TDbSeekKey rk( (*iIdxs[p])[PointIdx]); if (iTable.SeekL(rk) ) { iTable.GetL(); TUint count=iTable.ColUint32(3+p)+1; iTable.UpdateL(); iTable.SetColL(3+p, count); PutL(); } else { // TODO } }
void bases::update_database(cell_list_node* n, bool is_current) { CALLSTACKITEM_N(_CL("bases"), _CL("update_database")); if (test_flags & NO_DB_UPDATE) return; if (!n) { post_error(_L("int error, n is NULL"), KErrGeneral); return; } if (n->in_db) { TDbSeekKey rk(n->id); TInt ret; if (! (ret=table.SeekL(rk)) ) { // TODO: do what? User::Leave(ret); } table.UpdateL(); } else { if (NoSpaceLeft()) return; table.InsertL(); if (colno_cellid>0) table.SetColL(colno_cellid, _L("")); table.SetColL(colno_id, n->id); } table.SetColL(colno_t, n->t); table.SetColL(colno_f, n->f); table.SetColL(colno_merged_to, n->merged_to); table.SetColL(colno_unaged_t, n->unaged_t); table.SetColL(colno_rescaled, bases_info->rescaled); TUint32 isbase=0; if (n->is_base) { isbase=1; } table.SetColL(colno_isbase, isbase); table.SetColL(colno_last_seen, n->last_seen); TUint32 iscurrent=0; if (is_current) iscurrent=1; table.SetColL(colno_iscurrent, iscurrent); PutL(); n->in_db=true; }
cell_list_node* bases::get_single(TInt id) { CALLSTACKITEM_N(_CL("bases"), _CL("get_single")); cell_list_node *n; n=(cell_list_node*)cell_hash->GetData(id); if (n) return n; TDbSeekKey rk(id); if (! table.SeekL(rk) ) { return 0; } table.GetL(); n=new (ELeave) cell_list_node(id, table.ColTime(colno_last_seen)); n->t=table.ColReal(colno_t); n->f=table.ColUint32(colno_f); n->in_db=true; n->merged_to=table.ColUint32(colno_merged_to); if (n->merged_to==0) n->merged_to=n->id; n->unaged_t=table.ColReal(colno_unaged_t); n->rescaled=table.ColUint32(colno_rescaled); if (table.ColUint32(colno_isbase)==1) n->is_base=true; if (n->t < 0.0) n->t=0.0; if (n->unaged_t < 0.0) n->unaged_t=0.0; if (id>0) { rescale_single(n); cell_hash->AddDataL(id, n); n->prev=last_cell; if (last_cell) { last_cell->next=n; n->cum_t=last_cell->cum_t+n->t; n->pos=last_cell->pos+1; } else { n->cum_t=n->t; n->pos=0; } last_cell=n; if (! first_cell) first_cell=n; } return n; }
void init(double pb[]) { int i, n; CDFRNG *r; VirtualGenomeParamBlock vpb; r = new CDFRNG(WDistFile); if (r->bad()) throw COHO_INIT_ERROR; vpb.R = r; VirtualGenome::set_parameters(&vpb); VirtualGenome::class_status(cout); LogNormalLogRNG rk(pb[PopSizeM],pb[PopSizeSD]); n = 0; for (i = 0; i < NYEARS-1; i++) { AGSize[i] = int(++rk + 0.5) * exp(0.5); n += AGSize[i]; } }
/** * Transforms a chromosome in the CITIES encoding into a chromosome in the RANDOMKEYS encoding. * If the starting chromosome is unfeasible, the resulting chromosome in the RANDOMKEYS encoding will contain zeros, * and yet still be feasible. Its inversion using randomkeys2cities will result in a feasible tour. * * @param[in] x a chromosome in the CITIES encoding * @param[in] orig_random_keys a chromosome in the RANDOMKEYS encoding. * @return a chromosome in the RANDOMKEYS encoding */ pagmo::decision_vector base_tsp::cities2randomkeys(const pagmo::decision_vector &cities,const pagmo::decision_vector &orig_random_keys) const { if (cities.size() != orig_random_keys.size()) { pagmo_throw(value_error,"the random keys original vector and the cities vector need to have the same length"); } if (cities.size() != m_n_cities) { pagmo_throw(value_error,"input representation of a tsp solution (CITIES encoding) looks unfeasible [wrong length]"); } if ( (*std::max_element(cities.begin(),cities.end()) >= m_n_cities) || (*std::min_element(cities.begin(),cities.end()) < 0) ) { pagmo_throw(value_error,"city indexes outside the allowed bounds"); } pagmo::decision_vector rk(orig_random_keys); pagmo::decision_vector retval(m_n_cities); std::sort(rk.begin(),rk.end()); for (pagmo::decision_vector::size_type i=0;i<m_n_cities;++i) { retval[cities[i]] = rk[i]; } return retval; }
std::vector<double> Adams::Result(const std::function<double(double, double)>& deriv, double x0, double y0, int n /*= 10*/) { double h = 1./abs(n); double f[4]; std::vector<double> y; // Getting initial values using Runge-Kutta method double x = x0; std::function<double(double)> rk = RKM::Solution(deriv, x0, y0, n); for (size_t i = 0; i < 4; i++) { y.push_back(rk(x)); x += h; } for (int i = 4; i <= n; i++) { y.push_back(y[i-1] + h/24*(55*deriv(x - h, y[i-1]) - 59*deriv(x - 2*h, y[i-2]) + 37*deriv(x - 3*h, y[i-3]) - 9*deriv(x - 4*h, y[i-4]))); x += h; } return y; }
CList<TInt>* CMergedImpl::GetCells(TInt In) { CALLSTACKITEM_N(_CL("CMergedImpl"), _CL("GetCells")); auto_ptr< CList<TInt> > cells(CList<TInt>::NewL()); TDbSeekKey rk(In); if (iTable.SeekL(rk)) { TInt i=In, m; iTable.GetL(); while (i==In) { m=iTable.ColUint32(2); cells->AppendL(m); if (iTable.NextL()) { iTable.GetL(); i=iTable.ColUint32(1); } else { i=-1; } } } cells->AppendL(In); return cells.release(); }
TBool SeenIdL(TUint aId) { SwitchIndexL(0); TDbSeekKey rk(aId); return iTable.SeekL(rk); }
//#include "System.h" void Average_ekt::randomize(Wavefunction_data * wfdata, Wavefunction * wf, System * sys, Sample_point * sample_tmp) { int nup=sys->nelectrons(0); int ndown=sys->nelectrons(1); totnelectrons = nup + ndown; Array2 <dcomplex> movals1(nmo,1),movals2(nmo,1); //Make a copy of the Sample so that it doesn't have to update the wave function. Sample_point * sample; sys->generateSample(sample); for(int i=0; i< npoints_eval; i++) { int k=0,l=0; while(k==l) { k=int(rng.ulec()*(nup+ndown)); l=int(rng.ulec()*(nup+ndown)); if(nup==1 and ndown==1) { k=0; l=1; } else if(nup==1) { if(i%2==0) { k=0; l=nup+int(rng.ulec()*ndown); } else { k=nup+int(rng.ulec()*ndown); l=nup+int(rng.ulec()*ndown); } } else if(ndown==1) { if(i%2==0) { k=int(rng.ulec()*nup); l=nup; } else { k=int(rng.ulec()*nup); l=int(rng.ulec()*nup); } } else if(ndown==0) { k=int(rng.ulec()*nup); l=int(rng.ulec()*nup); } else { if(i%4==0) { k=int(rng.ulec()*nup); l=int(rng.ulec()*nup); } else if(i%4==1) { k=int(rng.ulec()*nup); l=nup+int(rng.ulec()*ndown); } else if(i%4==2) { k=nup+int(rng.ulec()*ndown); l=int(rng.ulec()*nup); } else if(i%4==3) { k=nup+int(rng.ulec()*ndown); l=nup+int(rng.ulec()*ndown); } } } rk(i)=k; rk(npoints_eval+i)=l; Array1 <doublevar> r1=saved_r(i); Array1 <doublevar> r2=saved_r(npoints_eval+i); sample->setElectronPos(k,r1); sample->setElectronPos(l,r2); doublevar dist1=gen_sample(nstep_sample,1.0,k,movals1, sample); doublevar dist2=gen_sample(nstep_sample,1.0,l,movals2, sample); sample->getElectronPos(k,saved_r(i)); sample->getElectronPos(l,saved_r(npoints_eval+i)); } delete sample; }
/* Returns a satTypeValueMap object, adding the new data generated * when calling this object. * * @param epoch Time of observations. * @param gData Data object holding the data. */ satTypeValueMap& EclipsedSatFilter::Process( const CommonTime& epoch, satTypeValueMap& gData ) throw(ProcessingException) { try { SatIDSet satRejectedSet; // Set the threshold to declare that satellites are in eclipse // threshold = cos(180 - coneAngle/2) double threshold( std::cos(PI - coneAngle/2.0*DEG_TO_RAD) ); // Compute Sun position at this epoch, and store it in a Triple SunPosition sunPosition; Triple sunPos(sunPosition.getPosition(epoch)); // Define a Triple that will hold satellite position, in ECEF Triple svPos(0.0, 0.0, 0.0); // Loop through all the satellites satTypeValueMap::iterator it; for (it = gData.begin(); it != gData.end(); ++it) { // Check if satellite position is not already computed if( ( (*it).second.find(TypeID::satX) == (*it).second.end() ) || ( (*it).second.find(TypeID::satY) == (*it).second.end() ) || ( (*it).second.find(TypeID::satZ) == (*it).second.end() ) ) { // If satellite position is missing, then schedule this // satellite for removal satRejectedSet.insert( (*it).first ); continue; } else { // Get satellite position out of GDS svPos[0] = (*it).second[TypeID::satX]; svPos[1] = (*it).second[TypeID::satY]; svPos[2] = (*it).second[TypeID::satZ]; } // Unitary vector from Earth mass center to satellite Triple rk( svPos.unitVector() ); // Unitary vector from Earth mass center to Sun Triple ri( sunPos.unitVector() ); // Get dot product between unitary vectors = cosine(angle) double cosAngle(ri.dot(rk)); // Check if satellite is within shadow if(cosAngle <= threshold) { // If satellite is eclipsed, then schedule it for removal satRejectedSet.insert( (*it).first ); // Keep track of last known epoch the satellite was in eclipse shadowEpoch[(*it).first] = epoch; continue; } else { // Maybe the satellite is out fo shadow, but it was recently // in eclipse. Check also that. if( shadowEpoch.find( (*it).first ) != shadowEpoch.end() ) { // If satellite was recently in eclipse, check if elapsed // time is less or equal than postShadowPeriod if( std::abs( ( epoch - shadowEpoch[(*it).first] ) ) <= postShadowPeriod ) { // Satellite left shadow, but too recently. Delete it satRejectedSet.insert( (*it).first ); } else { // If satellite left shadow a long time ago, set it free shadowEpoch.erase( (*it).first ); } } } } // Remove satellites with missing data gData.removeSatID(satRejectedSet); return gData; } catch(Exception& u) { // Throw an exception if something unexpected happens ProcessingException e( getClassName() + ":" + u.what() ); GPSTK_THROW(e); } } // End of 'EclipsedSatFilter::Process()'
void SolveSLE(const Matrix &A, Matrix &Z, const Matrix &b, float initialZ) { int aCols = A.GetColsCount(); int aRows = A.GetRowsCount(); int zCols = Z.GetColsCount(); int zRows = Z.GetRowsCount(); int bCols = b.GetColsCount(); int bRows = b.GetRowsCount(); if (aCols != aRows || zCols != 1 || bCols != 1 || zRows != bRows || zRows != aCols) throw("SLE solver: This is not a SLE!\n"); printf(" Solving SLE ... \n"); clock_t time = clock(); int m = aCols; float normb = b.Norm(); Matrix rk(m, 1); Matrix pk(m, 1); Matrix Ark(m, 1); Matrix Apk(m, 1); Matrix zp(m, 1); Matrix zpp(m, 1); Matrix tmpV(m, 1); zpp.Fill(initialZ); pk.Fill(0.0f); rk.Fill(0.0f); Ark.Fill(0.0f); Apk.Fill(0.0f); zp.Fill(0.0f); tmpV.Fill(0.0f); rk = A * zpp - b; float normr = rk.Norm(); Ark = A * rk; float d = Ark.Dot(rk); zp = zpp - rk * (normr * normr / d); int flag = 1; int iterations = 1; while (flag == 1) { rk = A * zp - b; normr = rk.Norm(); pk = zp - zpp; Ark = A * rk; Apk = A * pk; float dot1 = Ark.Dot(pk); float dot2 = rk.Dot(pk); float dot3 = Ark.Dot(rk); float dot4 = Apk.Dot(pk); d = dot3 * dot4 - dot1 * dot1; float gamma = ((normr * normr) * dot4 - dot2 * dot1) / d; float beta = ((normr * normr) * dot1 - dot2 * dot3) / d; zpp = zp; zp -= rk * gamma - pk * beta; tmpV = A * zp - b; double norm = tmpV.Norm(); double error = norm / normb; printf(" Iteration:%d\terror:%f\n", iterations, error); if (error < 0.0001) flag = 0; iterations++; } printf(" SLE solved with %d iterations for %f\n", iterations, (double)(clock() - time) / (CLOCKS_PER_SEC * 60)); Z = zp; return; }
/* CXXCircle::CXXCircle (const CXXCircle &oldOne) : theAtomJ(oldOne.getAtomJ()), theBallJ(oldOne.getBallJ()), theParent(oldOne.getParent()), centreOfSecondSphere(oldOne.getCentreOfSecondSphere()), theNormal(oldOne.getNormal()), radiusOfSecondSphere(oldOne.getRadiusOfSecondSphere()), radiusOfSphere(oldOne.getRadiusOfSphere()), centreOfCircle(oldOne.centreOfCircle), centreToCircle(oldOne.getCentreToCircle()), referenceUnitRadius(oldOne.getReferenceUnitRadius()), radiusOfCircle(oldOne.getRadiusOfCircle()), theNodes(oldOne.getNodes()), nIntersectingCircles(oldOne.getNIntersectingCircles()), completelyEaten(oldOne.getEaten()) { for (unsigned i=0; i<oldOne.getNNodes(); i++){ theNodes[i].setParent(this); } theStarts.resize(oldOne.nSegments()); theStops.resize(oldOne.nSegments()); for (unsigned i=0; i<oldOne.nSegments(); i++){ theStarts[i] = oldOne.start(i); theStops[i] = oldOne.stop(i); } } */ int CXXCircle::meetsCircle(const CXXCircle &otherCircle, vector<CXXCoord, CXX::CXXAlloc<CXXCoord> > &nodeList) const{ // check if there is an intersection between this circle and another circle // return 0 if there is intersection // 2 if the this circle is entirely swallowedd by the atom that generates the otherCircle, // 1 if the converse of the above applies // and 3 otherwise CXXCoord intersectA, intersectB; // some simplifications: rj - centreToCircle of current (this) arc circle // rk - centreToCircle of newArc circle CXXCoord rj(getCentreToCircle()); CXXCoord rk(otherCircle.getCentreToCircle()); CXXCoord rjxrk; // following Totrovs vector match - plane intersection of the two circles. // PlaneIntersectioon points at intersection of two this- and new- circlePlanes // with plane spanned by the centre of the two VDW spheres and the centre of thisArc // some dummy variables double rjrk, rjSquared, rkSquared; double a, b, distSq, radiusOfSphereSq, x; rjSquared = rj*rj; rkSquared = rk*rk; rjrk = rj*rk; a = ((rjSquared - rjrk)*rkSquared)/(rjSquared*rkSquared - rjrk*rjrk); b = ((rkSquared - rjrk)*rjSquared)/(rjSquared*rkSquared - rjrk*rjrk); // with this now: CXXCoord planeIntersect((rj*a) + (rk*b)); // if the distance between the intersection point of the three planes is closer then //the radius of the VDW + probe sphere, then the two circle of this arc and new arc intersect.... // distance of intersectino point distSq = planeIntersect*planeIntersect; radiusOfSphereSq = radiusOfSphere*radiusOfSphere; // distance of (VDW + probe) sphere of thisAtom = radiusOfSphere therefore: if (distSq < radiusOfSphereSq) { // the CIRCLES corresponding to the new and the current (old) arc cross each other // the crossingpoints of the two CIRCLES are the points where the line defined by the // intersection of the two arcplanes cuts throught the new circle // the intersection line is perpendicular the plane spanned by rj and rk - that is parallel to: rjxrk = rj ^ rk; rjxrk.normalise(); //the intersection line is defined by this vector and one of its point - the planeIntersection vector: // => line planeIntersect + x*(rjxrk), x some real number // intersection points have x=+-0.5*length of the secante of circle therefore: x = sqrt(radiusOfSphereSq - distSq); rjxrk.scale(x); //We need to see whether the centreToCircle vectors of these circles indicate that the //corresponding torus is "behind" the centre of the first circle, or in front. This determines //Whether the first or the second calculated intersection point represents a point to start drawing. //It boils down to a sort of parity thing. Think about it ! CXXCoord unitCentreToCircle(centreToCircle); unitCentreToCircle.normalise(); int forwardOne = (theNormal*unitCentreToCircle > 0.?1:-1); CXXCoord otherCircleUnitCentreToCircle(otherCircle.getCentreToCircle()); otherCircleUnitCentreToCircle.normalise(); int forwardTwo = (otherCircle.getNormal()*otherCircleUnitCentreToCircle > 0.?1:-1); if (forwardOne*forwardTwo > 0){ intersectA = planeIntersect+rjxrk; intersectB = planeIntersect-rjxrk; } else { intersectB = planeIntersect+rjxrk; intersectA = planeIntersect-rjxrk; } nodeList[0] = intersectA + getCentreOfSphere(); nodeList[1] = intersectB + getCentreOfSphere(); return 0; } else { //We get here if the two circles don't intersect //Now check whether this circle falls somewhere inside the //sphere indicated by the other circle. If it does, then //(given it doesn't intersect), it must *always* be inside // otherwise it must *always* be outside if (otherCircle.accIsBehind(getCentreOfCircle()) == 0) return 2; if(accIsBehind(otherCircle.getCentreOfCircle()) == 0) return 1; return 3; } }
/* Compute the value of satellite antenna phase correction, in meters. * @param satid Satellite ID * @param time Epoch of interest * @param satpos Satellite position, as a Triple * @param sunpos Sun position, as a Triple * * @return Satellite antenna phase correction, in meters. */ double ComputeSatPCenter::getSatPCenter( const SatID& satid, const DayTime& time, const Triple& satpos, const Triple& sunPosition ) { // Unitary vector from satellite to Earth mass center (ECEF) Triple rk( ( (-1.0)*(satpos.unitVector()) ) ); // Unitary vector from Earth mass center to Sun (ECEF) Triple ri( sunPosition.unitVector() ); // rj = rk x ri: Rotation axis of solar panels (ECEF) Triple rj(rk.cross(ri)); // Redefine ri: ri = rj x rk (ECEF) ri = rj.cross(rk); // Let's convert ri to an unitary vector. (ECEF) ri = ri.unitVector(); // Get vector from Earth mass center to receiver Triple rxPos(nominalPos.X(), nominalPos.Y(), nominalPos.Z()); // Compute unitary vector vector from satellite to RECEIVER Triple rrho( (rxPos-satpos).unitVector() ); // When not using Antex information, if satellite belongs to block // "IIR" its correction is 0.0, else it will depend on satellite model. // This variable that will hold the correction, 0.0 by default double svPCcorr(0.0); // Check is Antex antenna information is available or not, and if // available, whether satellite phase center information is absolute // or relative bool absoluteModel( false ); if( pAntexReader != NULL ) { absoluteModel = pAntexReader->isAbsolute(); } if( absoluteModel ) { // We will need the elevation, in degrees. It is found using // dot product and the corresponding unitary angles double elev( 90.0 - (std::acos( rrho.dot(rk) ) * RAD_TO_DEG) ); // Get satellite information in Antex format. Currently this // only works for GPS and Glonass. if( satid.system == SatID::systemGPS ) { std::stringstream sat; sat << "G"; if( satid.id < 10 ) { sat << "0"; } sat << satid.id; // Get satellite antenna information out of AntexReader object Antenna antenna( pAntexReader->getAntenna( sat.str(), time ) ); // Get antenna eccentricity for frequency "G01" (L1), in // satellite reference system. // NOTE: It is NOT in ECEF, it is in UEN!!! Triple satAnt( antenna.getAntennaEccentricity( Antenna::G01) ); // Now, get the phase center variation. Triple var( antenna.getAntennaPCVariation( Antenna::G01, elev) ); // We must substract them satAnt = satAnt - var; // Change to ECEF Triple svAntenna( satAnt[2]*ri + satAnt[1]*rj + satAnt[0]*rk ); // Projection of "svAntenna" vector to line of sight vector rrho svPCcorr = (rrho.dot(svAntenna)); } else { // Check if this satellite belongs to Glonass system if( satid.system == SatID::systemGlonass ) { std::stringstream sat; sat << "R"; if( satid.id < 10 ) { sat << "0"; } sat << satid.id; // Get satellite antenna information out of AntexReader object Antenna antenna( pAntexReader->getAntenna( sat.str(), time ) ); // Get antenna offset for frequency "R01" (Glonass), in // satellite reference system. // NOTE: It is NOT in ECEF, it is in UEN!!! Triple satAnt( antenna.getAntennaEccentricity( Antenna::R01) ); // Now, get the phase center variation. Triple var( antenna.getAntennaPCVariation( Antenna::R01, elev) ); // We must substract them satAnt = satAnt - var; // Change to ECEF Triple svAntenna( satAnt[2]*ri + satAnt[1]*rj + satAnt[0]*rk ); // Project "svAntenna" vector to line of sight vector rrho svPCcorr = (rrho.dot(svAntenna)); } else { // In this case no correction will be computed svPCcorr = 0.0; } } // End of 'if( satid.system == SatID::systemGPS )...' } else { // If no Antex information is given, or if phase center information // uses a relative model, then use a simpler, older approach // Please note that in this case all GLONASS satellite are // considered as having phase center at (0.0, 0.0, 0.0). The former // is not true for 'GLONASS-M' satellites (-0.545, 0.0, 0.0 ), but // currently there is no simple way to take this into account. // For satellites II and IIA: if( (satData.getBlock( satid, time ) == "II") || (satData.getBlock( satid, time ) == "IIA") ) { // First, build satellite antenna vector for models II/IIA Triple svAntenna(0.279*ri + 1.023*rk); // Projection of "svAntenna" vector to line of sight vector rrho svPCcorr = (rrho.dot(svAntenna)); } else { // For satellites belonging to block "I" if( (satData.getBlock( satid, time ) == "I") ) { // First, build satellite antenna vector for model I Triple svAntenna(0.210*ri + 0.854*rk); // Projection of "svAntenna" to line of sight vector (rrho) svPCcorr = (rrho.dot(svAntenna)); } } // End of 'if( (satData.getBlock( satid, time ) == "II") ||...' } // End of 'if( absoluteModel )...' // This correction is interpreted as an "advance" in the signal, // instead of a delay. Therefore, it has negative sign return (-svPCcorr); } // End of method 'ComputeSatPCenter::getSatPCenter()'
JNIEXPORT void JNICALL Java_JaCl_setRemoteKey(JNIEnv *env, jobject obj, jlong ptr, jstring j_rk) { NaClInterface* nacl_interface = reinterpret_cast<NaClInterface*>(ptr); std::string rk((const char*)env->GetStringChars(j_rk, 0), (size_t)env->GetStringLength(j_rk)); nacl_interface->set_remote_key(rk); }
void WF_percentile<T>::operator()(int64_t b, int64_t e, int64_t c) { int64_t idx = fFieldIndex[1]; fRow.setData(getPointer(fRowData->at(b))); if (idx != -1) { if (idx != -1) { fNveNull = fRow.isNullValue(idx); implicit2T(idx, fNve, 0); if (!fNveNull && (fNve < 0 || fNve > 1)) { ostringstream oss; oss << fNve; throw IDBExcept(IDBErrorInfo::instance()->errorMsg(ERR_WF_ARG_OUT_OF_RANGE, oss.str()), ERR_WF_ARG_OUT_OF_RANGE); } } } if (fNveNull) { for (c = b; c <= e; c++) { if (c % 1000 == 0 && fStep->cancelled()) break; fRow.setData(getPointer(fRowData->at(c))); setValue(fRow.getColType(fFieldIndex[0]), b, e, c, (T*) NULL); } return; } idx = fFieldIndex[2]; int64_t rank = 0; int64_t dups = 0; int64_t b1 = -1; int64_t e1 = -1; scoped_array<int64_t> rk(new int64_t[e - b + 1]); for (c = b; c <= e; c++) { if (c % 1000 == 0 && fStep->cancelled()) break; fRow.setData(getPointer(fRowData->at(c))); if (fRow.isNullValue(idx)) continue; // ignore nulls if (b1 == -1) b1 = c; e1 = c; if (fFunctionId == WF__PERCENTILE_DISC) { // need cume_rank if (c != b && fPeer->operator()(getPointer(fRowData->at(c)), getPointer(fRowData->at(c-1)))) { dups++; } else { rank++; rank += dups; dups = 0; } rk[c-b] = rank; } } T* p = NULL; T v; int ct = (fFunctionId == WF__PERCENTILE_CONT) ? CalpontSystemCatalog::DOUBLE : fRow.getColType(idx); if (b1 != -1) { double cnt = (e1 - b1 + 1); if (fFunctionId == WF__PERCENTILE_CONT) { // @bug5820, this "rn" is the normalized row number, not the real row number. // Using real row number here will introduce a small calculation error in double result. double rn = fNve * (cnt - 1); double crn = ceil(rn); double frn = floor(rn); double vd = 0; if (crn == rn && rn == frn) { fRow.setData(getPointer(fRowData->at((size_t) rn + (size_t) b1))); implicit2T(idx, vd, 0); } else { double cv = 0.0, fv = 0.0; fRow.setData(getPointer(fRowData->at((size_t) frn + (size_t) b1))); implicit2T(idx, fv, 0); fRow.setData(getPointer(fRowData->at((size_t) crn + (size_t) b1))); implicit2T(idx, cv, 0); vd = (crn - rn) * fv + (rn - frn) * cv; } v = *(reinterpret_cast<T*>(&vd)); p = &v; } else // (fFunctionId == WF__PERCENTILE_DISC) { int prevRank = ++rank + dups; double cumeDist = 1; fRow.setData(getPointer(fRowData->at(e1))); for (c = e1; c >= b1; c--) { int currRank = rk[c-b]; if (currRank != prevRank) { cumeDist = ((double) (prevRank-1)) / cnt; if (cumeDist < fNve) break; prevRank = currRank; } } c++; fRow.setData(getPointer(fRowData->at(c))); getValue(idx, v); p = &v; } } for (c = b; c <= e; c++) { if (c % 1000 == 0 && fStep->cancelled()) break; fRow.setData(getPointer(fRowData->at(c))); setValue(ct, b, e, c, p); } }
int main(int argc, char *argv[]){ //verify that the correct number of arguments were passed assert(argc==5 || argc==4); double h = 0.005; //step size parameter to be passed into rk double t = 0; //thermal paramaters file FILE *tpfp; //power trace file FILE *ptfp; //output file FILE *ofp; //initialize ambient temperature and resistance ambientTemp = 300; //check to see if an argument was passed for ambient temp if(argc==5){ //if it was, set ambientTemp to it sscanf(argv[3], "%lf", &ambientTemp); //if there was, the output file is argument 4 ofp = fopen(argv[4], "w");} //open the files tpfp = fopen(argv[1], "rb"); ptfp = fopen(argv[2], "rb"); //if there wasn't an ambient temp argument, output file is argument 3 if(ofp==NULL){ofp = fopen(argv[3], "w");} //make sure the files are there assert(tpfp != NULL); assert(ptfp != NULL); assert(ofp != NULL); //number of rows in each input file int thermalParamLength=row_count(tpfp); //verify that the thermal parameter file is the correct length assert(thermalParamLength==6); powerTraceLength=row_count(ptfp); //read the files into pointer arrays for thermal param and power trace thermalParam = fileArray(tpfp, thermalParamLength, 4); powerTrace = fileArray(ptfp, powerTraceLength, 5); int i; int j; //verify that none of the thermal parameters less than or equal to zero, which isn't possible for(i=0; i<thermalParamLength; i++){ for(j=0; j<4; j++){assert(thermalParam[i][j]>0);} } //T holds the temperatures. cores 0-3 are T[0]-T[3], T[4] is ambient double *T; T = initializeT(); double* aP = (double *) malloc(4*sizeof(double)); //age pointer... for(i=0; i<4; i++){aP[i] = 1;} double* age; //step through updating the temperature //counts how many timesteps are taken in each entry of powerTrace int counter; //placeholder variable for t (used in output) double t_temp; for(j=0; j<(powerTraceLength); j++){ counter=0; while(t<(powerTrace[j][0]-h/2)){ T = rk(&calculatedTdt, h, t, T, 5); //verify that none of the temperatures are below ambient (this can't happen) for(i=0; i<4; i++){assert(T[i]>=T[4]);} aP = ageRate(t, T); age = rk(&ageRate, h, t, aP, 4); //verify that none of the effective ages are less than 1 for(i=0; i<4; i++){assert(age[i]>=1);} counter++; t+=h; } //file output stuff fprintf(ofp, "%lf ", t); for(i=0; i<4; i++){ fprintf(ofp, "%lf ", T[i]); fprintf(ofp, "%lf ", age[i]); } fprintf(ofp, "\r\n"); } }
int main() { FILE *fin = fopen("packrec.in", "r"); FILE *fout = fopen("packrec.out", "w"); int i, j, k, l, p, index; int min = 0x7fff; index = 0; struct rec in[4], out[100]; for(i = 0; i < 4; i++) fscanf(fin, "%d %d", &in[i].side[0], &in[i].side[1]); for(i = 0; i < 4; i++){ for(j = 0; j < 4; j++){ if(i == j) continue; for(k = 0; k < 4; k++){ if(k == i || k == j) continue; l = 6 - i - j - k; for(p = 0; p < 16; p++){ int h1, w1, h2, w2, h3, w3, h4, w4; h1 = in[i].side[1 - (ri(p))]; w1 = in[i].side[ri(p)]; h2 = in[j].side[1 - (rj(p))]; w2 = in[j].side[rj(p)]; h3 = in[k].side[1 - (rk(p))]; w3 = in[k].side[rk(p)]; h4 = in[l].side[1 - (rl(p))]; w4 = in[l].side[rl(p)]; int win, hin; win = w1 + w2 + w3 + w4; hin = max4(h1, h2, h3, h4); store(out, &index, win, hin, &min); win = max2(w1+w2+w3, w4); hin = max3(h1, h2, h3)+h4; store(out, &index, win, hin, &min); win = max2(w1+w2, w3)+w4; hin = max3(h1+h3, h2+h3, h4); store(out, &index, win, hin, &min); win = w1+w4+max2(w2, w3); hin = max3(h1, h2+h3, h4); store(out, &index, win, hin, &min); if(h3 >= h2+h4) win = max3(w1, w2+w3, w3+w4); else if(h3 > h4 && h3 < h2+h4) win = max3(w1+w2, w2+w3, w3+w4); else if(h3 < h4 && h2+h4 <= h1+h3) win = max3(w1+w2, w1+w4, w3+w4); else if(h4 >= h1+h3) win = max3(w2, w1+w4, w3+w4); else if(h3 == h4) win = max2(w1+w2, w3+w4); hin = max2(h1+h3, h2+h4); store(out, &index, win, hin, &min); } } } } insertionSort(out, index); fprintf(fout, "%d\n", min); for(i = 0; i < index; i++){ if(i != 0 && out[i].side[0] == out[i-1].side[0]) continue; fprintf(fout, "%d %d\n", out[i].side[0], out[i].side[1]); } fclose(fin); fclose(fout); }
//------------------------------------------------------------------------------ void ExtendedKalmanInv::UpdateCovarianceJoseph() { #ifdef DEBUG_ESTIMATION MessageInterface::ShowMessage("Updating covariance using Joseph " "method\n"); #endif // Update the covariance Real khSum; Rmatrix temp(stateSize, stateSize), krk(stateSize, stateSize); Rmatrix pikh(stateSize, stateSize), r(measSize, measSize); Rmatrix ikh(stateSize, stateSize), rk(measSize, stateSize); // First calc (I - K H) #ifdef DEBUG_JOSEPH MessageInterface::ShowMessage("Calcing I - K H\n K:\n"); for (UnsignedInt i = 0; i < stateSize; ++i) { for (UnsignedInt j = 0; j < measSize; ++j) MessageInterface::ShowMessage(" %.12lf ", kalman(i,j)); MessageInterface::ShowMessage("\n"); } MessageInterface::ShowMessage("\n H:\n"); for (UnsignedInt i = 0; i < measSize; ++i) { for (UnsignedInt j = 0; j < stateSize; ++j) MessageInterface::ShowMessage(" %.12lf ", hTilde[i][j]); MessageInterface::ShowMessage("\n"); } MessageInterface::ShowMessage("\n"); #endif for (UnsignedInt i = 0; i < stateSize; ++i) { for (UnsignedInt j = 0; j < stateSize; ++j) { if (i == j) ikh(i,j) = 1.0; else ikh(i,j) = 0.0; khSum = 0.0; for (UnsignedInt k = 0; k < measSize; ++k) khSum += kalman(i,k) * hTilde[k][j]; ikh(i,j) -= khSum; } } #ifdef DEBUG_JOSEPH MessageInterface::ShowMessage(" I - K H:\n"); for (UnsignedInt i = 0; i < stateSize; ++i) { for (UnsignedInt j = 0; j < stateSize; ++j) MessageInterface::ShowMessage(" %.12lf ", ikh(i,j)); MessageInterface::ShowMessage("\n"); } MessageInterface::ShowMessage("\n pBar:\n"); for (UnsignedInt i = 0; i < stateSize; ++i) { for (UnsignedInt j = 0; j < stateSize; ++j) MessageInterface::ShowMessage(" %.12lf ", pBar(i,j)); MessageInterface::ShowMessage("\n"); } MessageInterface::ShowMessage("\n (I - K H) \bar P (I - K H)^T:\n"); #endif // Build (I - K H) \bar P (I - K H)^T for (UnsignedInt i = 0; i < stateSize; ++i) { for (UnsignedInt j = 0; j < stateSize; ++j) { pikh(i,j) = 0.0; for (UnsignedInt k = 0; k < stateSize; ++k) pikh(i,j) += pBar(i,k) * ikh(j,k); } } for (UnsignedInt i = 0; i < stateSize; ++i) { for (UnsignedInt j = 0; j < stateSize; ++j) { temp(i,j) = 0.0; for (UnsignedInt k = 0; k < stateSize; ++k) temp(i,j) += ikh(i,k) * pikh(k,j); } } #ifdef DEBUG_JOSEPH for (UnsignedInt i = 0; i < stateSize; ++i) { for (UnsignedInt j = 0; j < stateSize; ++j) MessageInterface::ShowMessage(" %.12lf ", temp(i,j)); MessageInterface::ShowMessage("\n"); } MessageInterface::ShowMessage("\n"); #endif #ifdef DEBUG_JOSEPH MessageInterface::ShowMessage("Prepping to fake up R\n R:\n"); #endif // Fake up the measurement covariance if needed if (measCovariance) r = *(measCovariance->GetCovariance()); else for (UnsignedInt i = 0; i < measSize; ++i) for (UnsignedInt j = 0; j < measSize; ++j) if (i == j) r(i,j) = DEFAULT_MEASUREMENT_COVARIANCE; else r(i,j) = 0.0; // Now K R K^T #ifdef DEBUG_JOSEPH for (UnsignedInt i = 0; i < measSize; ++i) { for (UnsignedInt j = 0; j < measSize; ++j) MessageInterface::ShowMessage(" %.12lf ", r(i,j)); MessageInterface::ShowMessage("\n"); } MessageInterface::ShowMessage("\n"); MessageInterface::ShowMessage("Calcing RK:\n"); #endif for (UnsignedInt i = 0; i < measSize; ++i) { for (UnsignedInt j = 0; j < stateSize; ++j) { rk(i,j) = 0.0; for (UnsignedInt k = 0; k < measSize; ++k) rk(i,j) += r(i,k) * kalman(j,k); } } #ifdef DEBUG_JOSEPH for (UnsignedInt i = 0; i < measSize; ++i) { for (UnsignedInt j = 0; j < stateSize; ++j) MessageInterface::ShowMessage(" %.12lf ", rk(i,j)); MessageInterface::ShowMessage("\n"); } MessageInterface::ShowMessage("\n"); MessageInterface::ShowMessage("Calcing KRK:\n"); #endif for (UnsignedInt i = 0; i < stateSize; ++i) { for (UnsignedInt j = 0; j < stateSize; ++j) { krk(i,j) = 0.0; for (UnsignedInt k = 0; k < measSize; ++k) krk(i,j) += kalman(i,k) * rk(k,j); } } #ifdef DEBUG_JOSEPH for (UnsignedInt i = 0; i < stateSize; ++i) { for (UnsignedInt j = 0; j < stateSize; ++j) MessageInterface::ShowMessage(" %.12lf ", krk(i,j)); MessageInterface::ShowMessage("\n"); } MessageInterface::ShowMessage("\n"); #endif // Add 'em up #ifdef DEBUG_JOSEPH MessageInterface::ShowMessage("Summing covariance\n"); #endif for (UnsignedInt i = 0; i < stateSize; ++i) for (UnsignedInt j = 0; j < stateSize; ++j) (*stateCovariance)(i,j) = temp(i,j) + krk(i,j); #ifdef DEBUG_JOSEPH for (UnsignedInt i = 0; i < stateSize; ++i) { for (UnsignedInt j = 0; j < stateSize; ++j) MessageInterface::ShowMessage(" %.12lf ", (*covariance)(i,j)); MessageInterface::ShowMessage("\n"); } MessageInterface::ShowMessage("\n"); throw EstimatorException("Intentional debug break!"); #endif }