void RecordFactory::PrintCurrency(ostream &os, double value) { long double dv = value * 100; // stupid library! divides by 100 for some reason... // Construct a ostreamb12uf_iterator on cout typedef std::ostreambuf_iterator<char, std::char_traits<char> > Iter; Iter begin(os); // Get a money put facet const std::money_put<char, Iter> &mp = std::use_facet<std::money_put<char, Iter> >(std::locale()); ios::fmtflags flgs = os.setf(ios_base::showbase|ios_base::internal); streamsize orig = os.width(5); mp.put(begin, false, os, '0', dv); os.width(orig); os.flags(flgs); }
void Rule:: print(ostream& os) { stringstream ss; ss<<prob; string temp; ss>>temp; //os.setf( os.precision(5); os.setf(ios::fixed,ios::floatfield); os<<prob<<" "; //if(temp.length()<8) // os<<"\t"; os<<left<<" --> "<<right<<endl; }
void numMatrix::print(ostream &out){ for(int i=0; i<_n_rows; i++){ out << "Row " << i << endl; for(int j=0; j<_n_cols; j++){ out.setf(ios::scientific); out.precision(4); out.width(13); out << _coeff[i][j]; if((j+1)%6 == 0){ out << endl; } } out << endl; out << endl; } }
void PrintParticleData(ostream &out, const Ipp32f particledata[][8], const int startrow, const int endrow, const int framenumber, const int stacknumber) { //totalrows is (basically) number of particles (one for each row); can be a very large number out.setf(ios::fixed); out.precision(1); for(int j = startrow; j < endrow; j++) { out << stacknumber << "\t" << framenumber + 1 << "\t"; out << particledata[j][1] << "\t"; //x-position out << particledata[j][2] << "\t"; //y-position out << particledata[j][5] << "\t"; //total mass out << sqrt(particledata[j][6]); //radius of gyration out << endl; } out.precision(5); }
void DataPoint::print(ostream& os) { os.setf(ios::fixed, ios::floatfield); os.precision(4); os.fill('0'); // Pad on left with '0' os << setw(2) << getTime().tm_mon << '\\' << setw(2) << getTime().tm_mday << '\\' << setw(2) << getTime().tm_year << ' ' << setw(2) << getTime().tm_hour << ':' << setw(2) << getTime().tm_min << ':' << setw(2) << getTime().tm_sec; os.fill(' '); // Pad on left with ' ' os << " Lat:" << setw(9) << getLatitude() << ", Long:" << setw(9) << getLongitude() << ", depth:" << setw(9) << getDepth() << ", temp:" << setw(9) << getTemperature() << endl; } ///:~
void Dof::print(ostream &out) const{ out << " EqnNum = "; out.width(6); out << _eqn_number; if (_active) { out << " Active, "; } else { out << " Not Active, "; } out << " Value = "; out.setf(ios::scientific); out.precision(3); out.width(11); out << _value; }
//prints the results into readable form void simplex::printSimplexTable(ostream& out, Data* data) { out.setf(ios::fixed); out.precision(3); int row = data->system.size(); int col = data->system[0].size(); out.width(N); out << "Base"; out.width(N); out << "Plan"; for (int j = 0; j < col; j++) { out.width(N - 1); out << "x"; out << j + 1; } out << endl; for (int i = 0; i < row; i++) { out.width(N - 1); out << "x"; out << data->base[i]; out.width(N); out << data->freeMembers[i]; for (int j = 0; j < col; j++) { out.width(N); out << data->system[i][j]; } out << endl; } out.width(N); out << "F"; out.width(N); out <<data-> max; int a = data->coefficients.size(); for (int i = 0; i < a; i++) { out.width(N); out << data->coefficients[i]; } out << endl << endl; }
/*------------------------------------------------------------------------------- Class: Util Method: Print Description: Prints output to a stream. Parameters: ostream& out : in : Stream where to write const string& aMsg : in : Message to output const VerboseLevel aLevel : in : Verbose level of message const long aCode : in : Possible error code if != 0 Return Values: None Errors/Exceptions: None -------------------------------------------------------------------------------*/ void Util::Print(ostream& out, const string& aMsg, const VerboseLevel aLevel, const long aCode) { #ifdef ENABLE_LOG_SYNC iCritical.Lock(); #endif if (aLevel <= iVerbose) { if (iTimestamp) { char timestamp[128]; _strdate(timestamp); char tmp[16]; _strtime(tmp); strcat(timestamp, " "); strcat(timestamp, tmp); struct _timeb tb; _ftime(&tb); sprintf(tmp, ".%03d", tb.millitm); strcat(timestamp, tmp); out << "[" << timestamp << "] "; } out << aMsg; //if (aLevel == debug) { OutputDebugString(aMsg.c_str()); OutputDebugString("\r\n"); } if (aCode != 0) { out.setf(ios_base::hex, ios_base::basefield); out << " (error: 0x" << aCode << ")"; } out << endl; } #ifdef ENABLE_LOG_SYNC iCritical.Unlock(); #endif }
void process(istream &input, ostream &output) { int bottles, level, n; input >> bottles >> level >> n; int row = 0; int first = 1; while (first + row + 1 <= n) { ++row; first += row; } cache.clear(); double value = get_value(level, row, n - first, 750.0 * bottles); output.setf(ios_base::fixed, ios_base::floatfield); output.precision(7); output << ' ' << min(250.0, value) << '\n'; }
void ImagerDoc::NavigationParameters(ostream & out){ out.setf(std::ios::left | std::ios::showpoint | std::ios::fixed); out << std::setw(19) << Iscan.imcStatus() << "imc " << "\tIMC status (1 == on)\n"; out << std::setw(19) << W_pix_of_frame << "x1 " << "\tWestern-most visible pixel in current frame\n"; out << std::setw(19) << E_pix_of_frame << "x2 " << "\tEastern-most visible pixel in current frame\n"; out << std::setw(19) << N_line_of_frame << "y1 " << "\tNorthern-most visible pixel in current frame\n"; out << std::setw(19) << S_line_of_frame << "y2 " << "\tSouthern-most visible pixel in current frame\n"; out << std::setw(19) << pix_of_zero_az << "x_zero " << "\tpixel of zero azimuth\n"; out << std::setw(19) << line_of_zero_elev << "y_zero " << "\tline of zero elevation\n"; out << std::setw(19) << (double)ReferenceLongitude << "ref_lon " << "\tReference Longitude (positive east, radians) \n"; out << std::setw(19) << (double)ReferenceRadialDistance << "ref_dist " << "\tReference Radial Distance from nominal (kilometers [km]) \n"; out << std::setw(19) << (double)ReferenceLatitude << "ref_lat " << "\tReference Latitude (positive north, radians)\n"; out << std::setw(19) << (double)ReferenceOrbitYaw << "ref_yaw " << "\tReference Orbit Yaw (radians) \n"; out << std::setw(19) << (double)ReferenceAttitudeRoll << "att_roll " << "\tReference Attitude Roll (radians) \n"; out << std::setw(19) << (double)ReferenceAttitudePitch << "att_pitch " << "\tReference Attitude Pitch (radians) \n"; out << std::setw(19) << (double)ReferenceAttitudeYaw << "att_yaw " << "\tReference Attitude Yaw (radians) \n"; out << "\n\n"; }
void PatternConverter::formatAndAppend(ostream& output, const InternalLoggingEvent& loggingEvent) { string str; convert(str, loggingEvent); std::size_t len = str.length(); if(len > _maxLen) output << str.substr(len - _maxLen); else if(static_cast<int>(len) < _minLen) { std::ios_base::fmtflags const original_flags = output.flags(); char const fill = output.fill(' '); output.setf(_leftAlign ? std::ios_base::left : std::ios_base::right, std::ios_base::adjustfield); output.width(_minLen); output << str; output.fill(fill); output.flags(original_flags); } else output << str; }
void CNavDataElement::timeDisplay( ostream & os, const CommonTime& t ) { os.setf(ios::dec, ios::basefield); // Convert to CommonTime struct from GPS wk,SOW to M/D/Y, H:M:S. GPSWeekSecond dummyTime; dummyTime = GPSWeekSecond(t); os << setw(4) << dummyTime.week << "("; os << setw(4) << (dummyTime.week & 0x03FF) << ") "; os << setw(6) << setfill(' ') << dummyTime.sow << " "; switch (dummyTime.getDayOfWeek()) { case 0: os << "Sun-0"; break; case 1: os << "Mon-1"; break; case 2: os << "Tue-2"; break; case 3: os << "Wed-3"; break; case 4: os << "Thu-4"; break; case 5: os << "Fri-5"; break; case 6: os << "Sat-6"; break; default: break; } os << printTime(t," %3j %5.0s %02m/%02d/%04Y %02H:%02M:%02S"); }
void CNAVEphemeris :: dump(ostream& s) const throw() { s.setf(ios::fixed, ios::floatfield); s.setf(ios::right, ios::adjustfield); s.setf(ios::uppercase); s.precision(0); s.fill(' '); s << "****************************************************************" << "************" << endl << "CNAV Message Types 10 and 11" << endl << endl << "PRN : " << setw(2) << PRNID << " " << "System : " << satSys << " " << "Carrier: " << ObsID::cbDesc[obsID.band] << " " << "Code: " << ObsID::tcDesc[obsID.code] << endl << endl; s << " Week SOW DOW UTD SOD" << " MM/DD/YYYY HH:MM:SS\n"; s << "Transmit Time: "; timeDisplay(s, getTransmitTime()); s << endl; s << "Time of Predict:"; timeDisplay(s, getTimeOfPrediction()); s << endl; s << endl << " ACCURACY PARAMETERS" << endl << endl << "URAoe index: " << setw(4) << orbit.getURAoe() << endl; s.setf(ios::scientific, ios::floatfield); s.precision(11); s << endl << " SIGNAL PARAMETERS" << endl << endl << "L1 Health bit: " << setw(2) << L1Health << endl << "L2 Health bit: " << setw(2) << L2Health << endl << "L5 Health bit: " << setw(2) << L5Health << endl << setfill(' ') << endl; s << endl << " ORBIT PARAMETERS" << endl << endl << "Semi-major axis: " << setw(18) << orbit.getAhalf() << " m**.5" << endl << "Motion correction: " << setw(18) << orbit.getDn() << " rad/sec" << endl << "Eccentricity: " << setw(18) << orbit.getEcc() << endl << "Arg of perigee: " << setw(18) << orbit.getW() << " rad" << endl << "Mean anomaly at epoch: " << setw(18) << orbit.getM0() << " rad" << endl << "Right ascension: " << setw(18) << orbit.getOmega0() << " rad " << setw(18) << orbit.getOmegaDot() << " rad/sec" << endl << "Inclination: " << setw(18) << orbit.getI0() << " rad " << setw(18) << orbit.getIDot() << " rad/sec" << endl; s << endl << " HARMONIC CORRECTIONS" << endl << endl << "Radial Sine: " << setw(18) << orbit.getCrs() << " m Cosine: " << setw(18) << orbit.getCrc() << " m" << endl << "Inclination Sine: " << setw(18) << orbit.getCis() << " rad Cosine: " << setw(18) << orbit.getCic() << " rad" << endl << "In-track Sine: " << setw(18) << orbit.getCus() << " rad Cosine: " << setw(18) << orbit.getCuc() << " rad" << endl; s << "****************************************************************" << "************" << endl; } // end of CNAVEphemeris::dump()
// ======================================================= // * Generate a listing of cartesian coordinates for a // cell propogated through (i,j,k) translations. The // coordinates are centered on the origin. void CrystalCell::Propogate( unsigned i, unsigned j, unsigned k, ostream& os, unsigned opts ) { TVector3D xform = { 0.0 , 0.0 , 0.0 }; TPoint3D pt; unsigned li,lj,lk,bb; ios_base::fmtflags savedFlags = os.flags(); ANSRDB* periodicTable = ANSRDB::DefaultANSRDB(); // Vector-transform to be used on each point such // that we center the generated lattice at the // origin: if (opts == kCrystalCellPropogateCentered) { Vector3D_ScaledSum(&xform,(double)i,&av[0],&xform); Vector3D_ScaledSum(&xform,(double)j,&av[1],&xform); Vector3D_ScaledSum(&xform,(double)k,&av[2],&xform); Vector3D_Scalar(&xform,-0.5,&xform); } // Simply loop and generate points: os.setf(ios::fixed); for ( li = 0 ; li < i ; li++ ) { for ( lj = 0 ; lj < j ; lj++ ) { for ( lk = 0 ; lk < k ; lk++ ) { for ( bb = 0 ; bb < basisCount ; bb++ ) { pt = basis[bb].atomPosition; if (li) pt.x += (double)li; if (lj) pt.y += (double)lj; if (lk) pt.z += (double)lk; pt = FractionalToCartesian(pt); Vector3D_Sum(&pt,&xform,&pt); TElementSymbol symbol = periodicTable->LookupSymbolForNumber(basis[bb].atomicNumber); if (symbol == kANSRInvalidSymbol) { os.setf(ios::left); os << " " << setw(3) << basis[bb].atomicNumber << " "; os.unsetf(ios::left); os << setprecision(6) << setw(12) << pt.x << ' '; os << setprecision(6) << setw(12) << pt.y << ' '; os << setprecision(6) << setw(12) << pt.z << endl; } else { os.setf(ios::left); os << " " << setw(3) << (char*)&symbol << " "; os.unsetf(ios::left); os << setprecision(6) << setw(12) << pt.x << ' '; os << setprecision(6) << setw(12) << pt.y << ' '; os << setprecision(6) << setw(12) << pt.z << endl; } } } } } os.setf(savedFlags); }
void Agent::streamData(ostream& out, std::set<string> &aFilter, bool current, unsigned int aInterval, uint64_t start, unsigned int count, unsigned int aHeartbeat ) { // Create header string boundary = md5(intToString(time(NULL))); ofstream log; if (mLogStreamData) { string filename = "Stream_" + getCurrentTime(LOCAL) + "_" + int64ToString((uint64_t) dlib::get_thread_id()) + ".log"; log.open(filename.c_str()); } out << "HTTP/1.1 200 OK\r\n" "Date: " << getCurrentTime(HUM_READ) << "\r\n" "Server: MTConnectAgent\r\n" "Expires: -1\r\n" "Connection: close\r\n" "Cache-Control: private, max-age=0\r\n" "Content-Type: multipart/x-mixed-replace;boundary=" << boundary << "\r\n" "Transfer-Encoding: chunked\r\n\r\n"; // This object will automatically clean up all the observer from the // signalers in an exception proof manor. ChangeObserver observer; // Add observers std::set<string>::iterator iter; for (iter = aFilter.begin(); iter != aFilter.end(); ++iter) mDataItemMap[*iter]->addObserver(&observer); uint64_t interMicros = aInterval * 1000; uint64_t firstSeq = getFirstSequence(); if (start < firstSeq) start = firstSeq; try { // Loop until the user closes the connection timestamper ts; while (out.good()) { // Remember when we started this grab... uint64_t last = ts.get_timestamp(); // Fetch sample data now resets the observer while holding the sequence // mutex to make sure that a new event will be recorded in the observer // when it returns. string content; uint64_t end; bool endOfBuffer = true; if (current) { content = fetchCurrentData(aFilter, NO_START); } else { // Check if we're falling too far behind. If we are, generate an // MTConnectError and return. if (start < getFirstSequence()) { sLogger << LWARN << "Client fell too far behind, disconnecting"; throw ParameterError("OUT_OF_RANGE", "Client can't keep up with event stream, disconnecting"); } else { // end and endOfBuffer are set during the fetch sample data while the // mutex is held. This removed the race to check if we are at the end of // the bufffer and setting the next start to the last sequence number // sent. content = fetchSampleData(aFilter, start, count, end, endOfBuffer, &observer); } if (mLogStreamData) log << content << endl; } ostringstream str; // Make sure we're terminated with a <cr><nl> content.append("\r\n"); out.setf(ios::dec, ios::basefield); str << "--" << boundary << "\r\n" "Content-type: text/xml\r\n" "Content-length: " << content.length() << "\r\n\r\n" << content; string chunk = str.str(); out.setf(ios::hex, ios::basefield); out << chunk.length() << "\r\n"; out << chunk << "\r\n"; out.flush(); // Wait for up to frequency ms for something to arrive... Don't wait if // we are not at the end of the buffer. Just put the next set after aInterval // has elapsed. Check also if in the intervening time between the last fetch // and now. If so, we just spin through and wait the next interval. // Even if we are at the end of the buffer, or within range. If we are filtering, // we will need to make sure we are not spinning when there are no valid events // to be reported. we will waste cycles spinning on the end of the buffer when // we should be in a heartbeat wait as well. if (!endOfBuffer) { // If we're not at the end of the buffer, move to the end of the previous set and // begin filtering from where we left off. start = end; // For replaying of events, we will stream as fast as we can with a 1ms sleep // to allow other threads to run. dlib::sleep(1); } else { uint64 delta; if (!current) { // Busy wait to make sure the signal was actually signaled. We have observed that // a signal can occur in rare conditions where there are multiple threads listening // on separate condition variables and this pops out too soon. This will make sure // observer was actually signaled and instead of throwing an error will wait again // for the remaining hartbeat interval. delta = (ts.get_timestamp() - last) / 1000; while (delta < aHeartbeat && observer.wait(aHeartbeat - delta) && !observer.wasSignaled()) { delta = (ts.get_timestamp() - last) / 1000; } { dlib::auto_mutex lock(*mSequenceLock); // Make sure the observer was signaled! if (!observer.wasSignaled()) { // If nothing came out during the last wait, we may have still have advanced // the sequence number. We should reset the start to something closer to the // current sequence. If we lock the sequence lock, we can check if the observer // was signaled between the time the wait timed out and the mutex was locked. // Otherwise, nothing has arrived and we set to the next sequence number to // the next sequence number to be allocated and continue. start = mSequence; } else { // Get the sequence # signaled in the observer when the earliest event arrived. // This will allow the next set of data to be pulled. Any later events will have // greater sequence numbers, so this should not cause a problem. Also, signaled // sequence numbers can only decrease, never increase. start = observer.getSequence(); } } } // Now wait the remainder if we triggered before the timer was up. delta = ts.get_timestamp() - last; if (delta < interMicros) { // Sleep the remainder dlib::sleep((interMicros - delta) / 1000); } } } } catch (ParameterError &aError) { sLogger << LINFO << "Caught a parameter error."; if (out.good()) { ostringstream str; string content = printError(aError.mCode, aError.mMessage); str << "--" << boundary << "\r\n" "Content-type: text/xml\r\n" "Content-length: " << content.length() << "\r\n\r\n" << content; string chunk = str.str(); out.setf(ios::hex, ios::basefield); out << chunk.length() << "\r\n"; out << chunk << "\r\n"; out.flush(); } } catch (...) { sLogger << LWARN << "Error occurred during streaming data"; if (out.good()) { ostringstream str; string content = printError("INTERNAL_ERROR", "Unknown error occurred during streaming"); str << "--" << boundary << "\r\n" "Content-type: text/xml\r\n" "Content-length: " << content.length() << "\r\n\r\n" << content; string chunk = str.str(); out.setf(ios::hex, ios::basefield); out << chunk.length() << "\r\n"; out << chunk; out.flush(); } } out.setstate(ios::badbit); // Observer is auto removed from signalers }
void generate_inp(const IO_Header& io, ostream& out) { out.setf(ios_base::scientific); out.precision(14); out << io.spectrum_identifier << endl; out << io.sample_identifier << endl; out << io.project << endl; out << io.sample_location << endl; out << io.latitude << endl; out << io.latitude_unit << endl; out << io.longitude << endl; out << io.longitude_unit << endl; out << io.sample_height << endl; out << io.sample_weight << endl; out << io.sample_density << endl; out << io.sample_volume << endl; out << io.sample_quantity << endl; out << io.sample_uncertainty << endl; out << io.sample_unit << endl; out << io.detector_identifier << endl; out << io.year << endl; out << io.beaker_identifier << endl; out << io.sampling_start << endl; out << io.sampling_stop << endl; out << io.reference_time << endl; out << io.measurement_start << endl; out << io.measurement_stop << endl; out << io.real_time << endl; out << io.live_time << endl; out << io.measurement_time << endl; out << io.dead_time << endl; out << io.nuclide_library << endl; out << io.lim_file << endl; out << io.channel_count << endl; out << io.format << endl; out << io.record_length << endl; out << io.FWHMPS << endl; out << io.FWHMAN << endl; out << io.THRESH << endl; out << io.BSTF << endl; out << io.ETOL << endl; out << io.LOCH << endl; out << io.ICA << endl; out << io.energy_file << endl; out << io.pef_file << endl; out << io.tef_file << endl; out << io.background_file << endl; out << io.PA1 << endl; out << io.PA2 << endl; out << io.PA3 << endl; out << io.PA4 << endl; out << io.PA5 << endl; out << io.PA6 << endl; out << io.print_out << endl; out << io.plot_out << endl; out << io.disk_out << endl; out << io.ex_print_out << endl; out << io.ex_disk_out << endl; out << io.PO1 << endl; out << io.PO2 << endl; out << io.PO3 << endl; out << io.PO4 << endl; out << io.PO5 << endl; out << io.PO6 << endl; out << io.complete << endl; out << io.analysed << endl; out << io.ST1 << endl; out << io.ST2 << endl; out << io.ST3 << endl; out << io.ST4 << endl; out << io.ST5 << endl; out << io.ST6 << endl; out.unsetf(ios_base::scientific); }
void ImagerDoc::NavigationFiles(ostream & out1, ostream & out2){ out1.setf(std::ios::left | std::ios::showpoint | std::ios::fixed); out1 << std::setw(19) << NW_lat_of_frame << "DLAT INPUT LATITUDE\n\n"; out1 << std::setw(19) << NW_lon_of_frame << "DLON INPUT LONGITUDE\n\n"; out1 << std::setw(19) << std::setprecision(2) << float(N_line_of_frame) << "L(1) INPUT LINE FOR IMAGER\n\n"; out1 << std::setw(19) << std::setprecision(2) << float(477) << "L(2) INPUT LINE FOR SOUNDER\n\n"; out1 << std::setw(19) << std::setprecision(4) << float(W_pix_of_frame) << "IP(1) INPUT PIXEL FOR IMAGER\n\n"; out1 << std::setw(19) << std::setprecision(4) << float(910) << "IP(2) INPUT PIXEL FOR SOUNDER\n\n"; out1 << std::setw(19) << 2 << "KEY 1-LAT/LONG-->LINE/PIX 2-LINE/PIX-->LAT/LONG\n\n"; out1 << std::setw(19) << Iscan.imcStatus() << "IMC 0-ON, 1-OFF(COMPUTE CHANGES IN ORBIT)\n\n"; out1 << std::setw(19) << 1 << "INSTR 1-IMAGER, 2-SOUNDER\n\n"; out1.unsetf(std::ios::left); out1 << std::setfill('0'); out1 << std::setw(4) << EpochDate.year() << " NYE EPOCH YEAR\n\n"; out1 << std::setw(3) << EpochDate.day() << " NDE EPOCH DAY\n\n"; out1 << std::setw(2) << EpochDate.hrs() << " NHE EPOCH HOUR\n\n"; out1 << std::setw(2) << EpochDate.min() << " NME EPOCH MINUTES\n\n"; out1 << std::setw(6) << std::setprecision(3) << (float)EpochDate.sec() + EpochDate.msec()/1000.0 << " SE EPOCH SECONDS\n\n"; out1 << std::setw(4) << T_current_header.year() << " NY CURRENT YEAR\n\n"; out1 << std::setw(3) << T_current_header.day() << " ND CURRENT DAY\n\n"; out1 << std::setw(2) << T_current_header.hrs() << " NH CURRENT HOUR\n\n"; out1 << std::setw(2) << T_current_header.min() << " NM CURRENT MINUTES\n\n"; out1 << std::setw(6) << std::setprecision(3) << (float)T_current_header.sec() + T_current_header.msec()/1000.0 << " S CURRENT SECONDS\n\n"; out1.setf(std::ios::left | std::ios::showpoint | std::ios::fixed); out1 << std::setfill(' '); out1 << std::setw(19) << (uint)ew_cycles << "IEW_NAD_CY IMAGER EW NADIR POSITION (CYCLES PORTION)\n\n"; out1 << std::setw(19) << ew_incr << "IEW_NAD_INC IMAGER EW NADIR POSITION (INCREMENTS PORTION)\n\n"; out1 << std::setw(19) << (uint)ns_cycles << "INS_NAD_CY IMAGER NS NADIR POSITION (CYCLES PORTION)\n\n"; out1 << std::setw(19) << ns_incr << "INS_NAD_INC IMAGER NS NADIR POSITION (INCREMENTS PORTION)\n\n"; out1 << std::setw(19) << 2 << "SEW_NAD_CY SOUNDER EW NADIR POSITION (CYCLES PORTION)\n\n"; out1 << std::setw(19) << 1293 << "SEW_NAD_INC SOUNDER EW NADIR POSITION (INCREMENTS PORTION)\n\n"; out1 << std::setw(19) << 4 << "SNS_NAD_CY SOUNDER NS NADIR POSITION (CYCLES PORTION)\n\n"; out1 << std::setw(19) << 868 << "SNS_NAD_INC SOUNDER NS NADIR POSITION (INCREMENTS PORTION)\n\n"; EpochDate.print(out2); out2 << "\tEpoch Time\n"; T_current_header.print(out2); out2 << "\tMost Recent Header Time\n"; T_sps_current.print(out2); out2 << "\tCurrent SPS Time\n"; out2.setf(std::ios::left | std::ios::showpoint | std::ios::fixed); out2.precision(14); out2 << std::setfill(' '); out2 << std::setw(24) << (uint)instrument() << "Instrument\n"; out2 << std::setw(24) << (double)ReferenceLongitude << "Reference Longitude\n"; out2 << std::setw(24) << (double)ReferenceRadialDistance << "Reference Radial Distance\n"; out2 << std::setw(24) << (double)ReferenceLatitude << "Reference Radial Latitude\n"; out2 << std::setw(24) << (double)ReferenceOrbitYaw << "Reference Orbit Yaw\n"; out2 << std::setw(24) << (double)ReferenceAttitudeRoll << "ReferenceAttitudeRoll\n"; out2 << std::setw(24) << (double)ReferenceAttitudePitch << "Reference Attitude Pitch\n"; out2 << std::setw(24) << (double)ReferenceAttitudeYaw << "ReferenceAttitudeYaw\n"; out2 << std::setw(24) << EpochDate.ieeea() << "Epoch Date\n"; out2 << std::setw(24) << EpochDate.ieeeb() << "Epoch Date\n"; out2 << std::setw(24) << (double)IMCenableFromEpoch << "IMC enable from epoch\n"; out2 << std::setw(24) << (double)CompensationRoll << "CompensationRoll\n"; out2 << std::setw(24) << (double)CompensationPitch << "Compensation Pitch\n"; out2 << std::setw(24) << (double)CompensationYaw << "Compensation Yaw\n"; for(int i = 0; i < 13; i++){ out2 << std::setw(24) << (double)ChangeLongitude[i] << "Change Longitude "<< i << "\n"; } for (int j=0; j < 11 ; j++){ out2 << std::setw(24) << (double)ChangeRadialDistance[j] << "Change Radial Distance " << j << "\n"; } for(int k=0; k < 9; k++){ out2 << std::setw(24) << (double)SineGeocentricLatitude[k] << "Change Geocentric Latitude " << k << "\n"; } for(int k=0; k < 9; k++){ out2 << std::setw(24) << (double)SineOrbitYaw[k] << "Sine Orbit Yaw " << k << "\n"; } out2 << std::setw(24) << (double)DailySolarRate << "Daily Solar Rate\n"; out2 << std::setw(24) << (double)ExponentialStartFromEpoch << "Exponential Start From Epoch\n"; // out2 << "\nRoll Angle\n"; out2 << RollAngle; //out2 <<"\nPitch Angle\n"; out2 << PitchAngle; //out2 << "\nYaw Angle\n"; out2 << YawAngle; //out2 << "\nRoll Misalignment\n"; out2 << RollMisalignment; //out2 << "\nPitch Misalignment\n"; out2 << PitchMisalignment; // these aren't actually needed for gimloc out2 << std::setw(24) << N_Line_In_Scan << "Northern-most visible detector scan line in current scan\n"; out2 << std::setw(24) << W_pix_of_frame << "Western-most visible pixel in current frame\n"; out2 << std::setw(24) << E_pix_of_frame << "Eastern-most visible pixel in current frame\n"; out2 << std::setw(24) << N_line_of_frame <<"Northern-most visible pixel in current frame\n"; out2 << std::setw(24) << S_line_of_frame <<"Southern-most visible pixel in current frame\n"; for ( int l = 0; l < 4; l++) out2 << Imc_identifier[l]; out2 << " IMC identifier \n"; out2 << "\n\n"; }
void OrbSysGpsC_30::dumpBody(ostream& s) const throw( InvalidRequest ) { if (!dataLoadedFlag) { InvalidRequest exc("Required data not stored."); GPSTK_THROW(exc); } s << endl << " GROUP DELAY CORRECTIONS" << endl << "Parameter Avail? Value" << endl; s.setf(ios::scientific, ios::floatfield); s.precision(8); s.setf(ios::right, ios::adjustfield); s.fill(' '); s << "Tgd "; if (avail_Tgd) s << "Y " << setw(16) << Tgd << endl; else s << "N" << endl; s << "ISC(L1CA) "; if (avail_L1CA) s << "Y " << setw(16) << ISC_L1CA << endl; else s << "N" << endl; s << "ISC(L2C) "; if (avail_L2C) s << "Y " << setw(16) << ISC_L2C << endl; else s << "N" << endl; s << "ISC(L5I5) "; if (avail_L5I5) s << "Y " << setw(16) << ISC_L5I5 << endl; else s << "N" << endl; s << "ISC(L5Q5) "; if (avail_L5Q5) s << "Y " << setw(16) << ISC_L5Q5 << endl; else s << "N" << endl; s << endl << " IONOSPHERIC PARAMETERS" << endl; s << " Alpha 0: " << setw(16) << alpha[0] << " sec " << " Beta 0: " << setw(16) << beta[0] << " sec " << endl; s << " Alpha 1: " << setw(16) << alpha[1] << " sec/rad " << " Beta 1: " << setw(16) << beta[1] << " sec/rad " << endl; s << " Alpha 2: " << setw(16) << alpha[2] << " sec/rad**2" << " Beta 2: " << setw(16) << beta[2] << " sec/rad**2" << endl; s << " Alpha 3: " << setw(16) << alpha[3] << " sec/rad**3" << " Beta 3: " << setw(16) << beta[3] << " sec/rad**3" << endl; } // end of dumpBody()
void OrbElemRinex::dumpHeader(ostream& s) const throw( InvalidRequest ) { if (!dataLoaded()) { InvalidRequest exc("Required data not stored."); GPSTK_THROW(exc); } OrbElem::dumpHeader(s); /* s << "Source : " << getNameLong() << endl; SVNumXRef svNumXRef; int NAVSTARNum = 0; s << endl; s << "PRN : " << setw(2) << satID.id << " / " << "SVN : " << setw(2); try { NAVSTARNum = svNumXRef.getNAVSTAR(satID.id, ctToe ); s << NAVSTARNum << " "; } catch(NoNAVSTARNumberFound) { s << "XX"; } s << endl << endl */ s << " SUBFRAME OVERHEAD" << endl << endl << " SOW DOW:HH:MM:SS IOD\n"; s << " " << " HOW: " << setw(7) << HOWtime << " "; shortcut( s, HOWtime); s << " "; s << "0x" << setfill('0') << hex; s << setw(3) << IODC; s << dec << " " << setfill(' '); s << endl; s << endl << " SV STATUS" << endl << endl << "Health bits : 0x" << setfill('0') << hex << setw(2) << health << dec << ", " << health; s << endl << "Fit duration (Hrs) : " << setw(1) << fitDuration << " hrs"; s << endl << "Accuracy(m) : " << setfill(' ') << setw(4) << accuracyValue << " m" << endl << "Code on L2 : "; switch (codeflags) { case 0: s << "reserved "; break; case 1: s << " P only "; break; case 2: s << " C/A only"; break; case 3: s << " P & C/A "; break; default: break; } s << endl <<"L2 P Nav data : "; if (L2Pdata!=0) s << "off"; else s << "on"; s.setf(ios::uppercase); s << endl; s << "Tgd : " << setw(13) << setprecision(6) << scientific << Tgd << " sec"; s << endl; } // end of dumpHeader()
void VirtualGenome::print(ostream &sout) { sout.setf(ios::fixed, ios::floatfield); sout.precision(4); sout << w << endl; }
void Benchmark::run( shared_ptr<LabeledImageSource> source, shared_ptr<FeatureExtractor> extractor, shared_ptr<TrainableProbabilisticClassifier> classifier, float confidenceThreshold, size_t negatives, size_t initialNegatives, ostream& frameOut, ostream& resultOut) const { uint32_t frameCount = 0; uint64_t extractedPatchCountSum = 0; // total amount of extracted patches uint64_t classifiedPatchCountSum = 0; // total amount of classified patches uint64_t negativePatchCountSum = 0; // amount of negative patches of all frames except the first ones (where classifier is not usable) uint32_t positivePatchCountSum = 0; uint64_t updateTimeSum = 0; uint64_t extractTimeSum = 0; uint64_t falseRejectionsSum = 0; uint64_t falseAcceptancesSum = 0; uint64_t classifyTimeSum = 0; double locationAccuracySum = 0; float worstLocationAccuracy = 1; uint32_t positiveTrainingCountSum = 0; uint32_t negativeTrainingCountSum = 0; uint64_t trainingTimeSum = 0; cv::Size patchSize; bool initialized = false; float aspectRatio = 1; while (source->next()) { Mat image = source->getImage(); const LandmarkCollection landmarks = source->getLandmarks(); if (landmarks.isEmpty()) continue; const shared_ptr<Landmark> landmark = landmarks.getLandmark(); bool hasGroundTruth = landmark->isVisible(); if (!hasGroundTruth && !initialized) continue; Rect_<float> groundTruth; if (hasGroundTruth) { groundTruth = landmark->getRect(); aspectRatio = groundTruth.width / groundTruth.height; if (!initialized) { DirectPyramidFeatureExtractor* pyramidExtractor = dynamic_cast<DirectPyramidFeatureExtractor*>(extractor.get()); if (pyramidExtractor != nullptr) { patchSize = pyramidExtractor->getPatchSize(); double dimension = patchSize.width * patchSize.height; double patchHeight = sqrt(dimension / aspectRatio); double patchWidth = aspectRatio * patchHeight; pyramidExtractor->setPatchSize(cvRound(patchWidth), cvRound(patchHeight)); } initialized = true; } } steady_clock::time_point extractionStart = steady_clock::now(); extractor->update(image); steady_clock::time_point extractionBetween = steady_clock::now(); shared_ptr<Patch> positivePatch; if (hasGroundTruth) { positivePatch = extractor->extract( cvRound(groundTruth.x + 0.5f * groundTruth.width), cvRound(groundTruth.y + 0.5f * groundTruth.height), cvRound(groundTruth.width), cvRound(groundTruth.height)); if (!positivePatch) continue; } vector<shared_ptr<Patch>> negativePatches; vector<shared_ptr<Patch>> neutralPatches; int patchCount = hasGroundTruth ? 1 : 0; for (float size = sizeMin; size <= sizeMax; size *= sizeScale) { float realHeight = size * image.rows; float realWidth = aspectRatio * realHeight; int width = cvRound(realWidth); int height = cvRound(realHeight); int minX = width / 2; int minY = height / 2; int maxX = image.cols - width + width / 2; int maxY = image.rows - height + height / 2; float stepX = std::max(1.f, step * realWidth); float stepY = std::max(1.f, step * realHeight); for (float x = minX; cvRound(x) < maxX; x += stepX) { for (float y = minY; cvRound(y) < maxY; y += stepY) { shared_ptr<Patch> patch = extractor->extract(cvRound(x), cvRound(y), width, height); if (patch) { patchCount++; if (!hasGroundTruth || computeOverlap(groundTruth, patch->getBounds()) <= allowedOverlap) negativePatches.push_back(patch); else neutralPatches.push_back(patch); } } } } steady_clock::time_point extractionEnd = steady_clock::now(); milliseconds updateDuration = duration_cast<milliseconds>(extractionBetween - extractionStart); milliseconds extractDuration = duration_cast<milliseconds>(extractionEnd - extractionBetween); frameOut << source->getName().filename().generic_string() << ": " << updateDuration.count() << "ms " << patchCount << " " << extractDuration.count() << "ms"; frameCount++; extractedPatchCountSum += patchCount; updateTimeSum += updateDuration.count(); extractTimeSum += extractDuration.count(); if (classifier->isUsable()) { classifiedPatchCountSum += patchCount; if (hasGroundTruth) positivePatchCountSum++; // amount needed for false acceptance rate, therefore only positive patches that are tested negativePatchCountSum += negativePatches.size(); // amount needed for false acceptance rate, therefore only negative patches that are tested steady_clock::time_point classificationStart = steady_clock::now(); // positive patch shared_ptr<ClassifiedPatch> classifiedPositivePatch; if (hasGroundTruth) classifiedPositivePatch = make_shared<ClassifiedPatch>(positivePatch, classifier->classify(positivePatch->getData())); // negative patches vector<shared_ptr<ClassifiedPatch>> classifiedNegativePatches; classifiedNegativePatches.reserve(negativePatches.size()); for (const shared_ptr<Patch>& patch : negativePatches) classifiedNegativePatches.push_back(make_shared<ClassifiedPatch>(patch, classifier->classify(patch->getData()))); // neutral patches vector<shared_ptr<ClassifiedPatch>> classifiedNeutralPatches; classifiedNeutralPatches.reserve(neutralPatches.size()); for (const shared_ptr<Patch>& patch : neutralPatches) classifiedNeutralPatches.push_back(make_shared<ClassifiedPatch>(patch, classifier->classify(patch->getData()))); steady_clock::time_point classificationEnd = steady_clock::now(); milliseconds classificationDuration = duration_cast<milliseconds>(classificationEnd - classificationStart); int falseRejections = !hasGroundTruth || classifiedPositivePatch->isPositive() ? 0 : 1; int falseAcceptances = std::count_if(classifiedNegativePatches.begin(), classifiedNegativePatches.end(), [](shared_ptr<ClassifiedPatch>& patch) { return patch->isPositive(); }); frameOut << " " << falseRejections << "/" << (hasGroundTruth ? "1 " : "0 ") << falseAcceptances << "/" << negativePatches.size() << " " << classificationDuration.count() << "ms"; falseRejectionsSum += falseRejections; falseAcceptancesSum += falseAcceptances; classifyTimeSum += classificationDuration.count(); if (hasGroundTruth) { shared_ptr<ClassifiedPatch> bestNegativePatch = *std::max_element(classifiedNegativePatches.begin(), classifiedNegativePatches.end(), [](shared_ptr<ClassifiedPatch>& a, shared_ptr<ClassifiedPatch>& b) { return a->getProbability() > b->getProbability(); }); shared_ptr<ClassifiedPatch> bestNeutralPatch = *std::max_element(classifiedNeutralPatches.begin(), classifiedNeutralPatches.end(), [](shared_ptr<ClassifiedPatch>& a, shared_ptr<ClassifiedPatch>& b) { return a->getProbability() > b->getProbability(); }); float overlap = 0; if (classifiedPositivePatch->getProbability() >= bestNeutralPatch->getProbability() && classifiedPositivePatch->getProbability() >= bestNegativePatch->getProbability()) overlap = computeOverlap(groundTruth, classifiedPositivePatch->getPatch()->getBounds()); else if (bestNeutralPatch->getProbability() >= bestNegativePatch->getProbability()) overlap = computeOverlap(groundTruth, bestNeutralPatch->getPatch()->getBounds()); else overlap = computeOverlap(groundTruth, bestNegativePatch->getPatch()->getBounds()); frameOut << " " << cvRound(100 * overlap) << "%"; locationAccuracySum += overlap; worstLocationAccuracy = std::min(worstLocationAccuracy, overlap); } vector<shared_ptr<ClassifiedPatch>> negativeTrainingCandidates; for (shared_ptr<ClassifiedPatch>& patch : classifiedNegativePatches) { if (patch->isPositive() || patch->getProbability() > 1 - confidenceThreshold) negativeTrainingCandidates.push_back(patch); } if (negativeTrainingCandidates.size() > negatives) { std::partial_sort(negativeTrainingCandidates.begin(), negativeTrainingCandidates.begin() + negatives, negativeTrainingCandidates.end(), [](shared_ptr<ClassifiedPatch>& a, shared_ptr<ClassifiedPatch>& b) { return a->getProbability() > b->getProbability(); }); negativeTrainingCandidates.resize(negatives); } vector<Mat> negativeTrainingExamples; negativeTrainingExamples.reserve(negativeTrainingCandidates.size()); for (const shared_ptr<ClassifiedPatch>& patch : negativeTrainingCandidates) negativeTrainingExamples.push_back(patch->getPatch()->getData()); vector<Mat> positiveTrainingExamples; if (hasGroundTruth && (!classifiedPositivePatch->isPositive() || classifiedPositivePatch->getProbability() < confidenceThreshold)) positiveTrainingExamples.push_back(classifiedPositivePatch->getPatch()->getData()); steady_clock::time_point trainingStart = steady_clock::now(); classifier->retrain(positiveTrainingExamples, negativeTrainingExamples); steady_clock::time_point trainingEnd = steady_clock::now(); milliseconds trainingDuration = duration_cast<milliseconds>(trainingEnd - trainingStart); frameOut << " " << positiveTrainingExamples.size() << "+" << negativeTrainingExamples.size() << " " << trainingDuration.count() << "ms"; positiveTrainingCountSum += positiveTrainingExamples.size(); negativeTrainingCountSum += negativeTrainingExamples.size(); trainingTimeSum += trainingDuration.count(); } else { int step = negativePatches.size() / initialNegatives; int first = step / 2; vector<Mat> negativeTrainingExamples; negativeTrainingExamples.reserve(initialNegatives); for (size_t i = first; i < negativePatches.size(); i += step) negativeTrainingExamples.push_back(negativePatches[i]->getData()); vector<Mat> positiveTrainingExamples; if (hasGroundTruth) positiveTrainingExamples.push_back(positivePatch->getData()); steady_clock::time_point trainingStart = steady_clock::now(); classifier->retrain(positiveTrainingExamples, negativeTrainingExamples); steady_clock::time_point trainingEnd = steady_clock::now(); milliseconds trainingDuration = duration_cast<milliseconds>(trainingEnd - trainingStart); frameOut << " " << positiveTrainingExamples.size() << "+" << negativeTrainingExamples.size() << " " << trainingDuration.count() << "ms"; positiveTrainingCountSum += positiveTrainingExamples.size(); negativeTrainingCountSum += negativeTrainingExamples.size(); trainingTimeSum += trainingDuration.count(); } frameOut << endl; } DirectPyramidFeatureExtractor* pyramidExtractor = dynamic_cast<DirectPyramidFeatureExtractor*>(extractor.get()); if (pyramidExtractor != nullptr) { pyramidExtractor->setPatchSize(patchSize.width, patchSize.height); } if (frameCount == 0) { frameOut << "no valid frames" << endl; resultOut << "no valid frames" << endl; } else if (frameCount == 1 || positivePatchCountSum < 1) { frameOut << "too few valid frames" << endl; resultOut << "too few valid frames" << endl; } else if (extractedPatchCountSum == 0) { frameOut << "no valid patches" << endl; resultOut << "no valid patches" << endl; } else if (negativePatchCountSum == 0) { frameOut << "no valid negative patches" << endl; resultOut << "no valid negative patches" << endl; } else { frameOut << frameCount << " " << extractedPatchCountSum << " " << classifiedPatchCountSum << " " << negativePatchCountSum << " " << positivePatchCountSum << " " << updateTimeSum << "ms " << extractTimeSum << "ms " << falseRejectionsSum << " " << falseAcceptancesSum << " " << classifyTimeSum << "ms " << cvRound(100 * locationAccuracySum / positivePatchCountSum) << "% " << cvRound(100 * worstLocationAccuracy) << "% " << positiveTrainingCountSum << " " << negativeTrainingCountSum << " " << trainingTimeSum << "ms" << endl; float falseRejectionRate = static_cast<float>(falseRejectionsSum) / static_cast<float>(frameCount - 1); float falseAcceptanceRate = static_cast<float>(falseRejectionsSum) / static_cast<float>(negativePatchCountSum); float avgPositiveTrainingCount = static_cast<float>(positiveTrainingCountSum) / static_cast<float>(frameCount); float avgNegativeTrainingCount = static_cast<float>(negativeTrainingCountSum) / static_cast<float>(frameCount); uint64_t normalizedExtractionTime = updateTimeSum / frameCount + (1000 * extractTimeSum) / extractedPatchCountSum; uint64_t normalizedClassificationTime = (1000 * classifyTimeSum) / classifiedPatchCountSum; uint64_t normalizedTrainingTime = trainingTimeSum / frameCount; uint64_t normalizedFrameTime = normalizedExtractionTime + normalizedClassificationTime + normalizedTrainingTime; resultOut.setf(std::ios::fixed); resultOut.precision(2); resultOut << falseRejectionRate << " " << falseAcceptanceRate << " " << cvRound(100 * locationAccuracySum / positivePatchCountSum) << "% " << cvRound(100 * worstLocationAccuracy) << "% " << avgPositiveTrainingCount << " " << avgNegativeTrainingCount << " " << normalizedFrameTime << "ms (" << normalizedExtractionTime << "ms " << normalizedClassificationTime << "ms " << normalizedTrainingTime << "ms)" << endl; } }
int real_tdmrg(ostream& fout, vector<ZTensor<3> >& mpsts, bool restart, int L, int M, double J, double Jz, double h, double f, int N, double dt) { fout.setf(ios::fixed,ios::floatfield); fout.precision(4); fout << "==================== LATTICE INFO ====================" << endl; fout << "\tL =" << setw(4) << L << ", M =" << setw(4) << M << ", J =" << setw(7) << J << ", Jz =" << setw(7) << Jz << endl; // initialize mpstates // create anti-parallel spins state : ababab... // and this will always be kept as right-canonical if(!restart) { int M0 = 1; mpsts.resize(L); mpsts[0].resize(1,2,M0); mpsts[0](0,0,0) = 1.0; for(int i = 1; i < L-1; ++i) { mpsts[i].resize(M0,2,M0); if(i & 1) mpsts[i](0,1,0) = Complx( 1.0, 0.0); else mpsts[i](0,0,0) = Complx( 1.0, 0.0); } mpsts[L-1].resize(M0,2,1); if(L & 1) mpsts[L-1](0,0,0) = Complx( 1.0, 0.0); else mpsts[L-1](0,1,0) = Complx( 1.0, 0.0); } // mpo's vector< ZTensor<4> > mpops; mpops.resize(L); { // [ 0 JS+ JS- JzSz I ] ZTensor<4> mpo0(1,5,2,2); mpo0 = Complx( 0.0, 0.0); mpo0(0,1,0,1) = Complx( J /2, 0.0); // S+ mpo0(0,2,1,0) = Complx( J /2, 0.0); // S- mpo0(0,3,0,0) = Complx( Jz/2, 0.0); // Sz(a) mpo0(0,3,1,1) = Complx(-Jz/2, 0.0); // Sz(b) mpo0(0,4,0,0) = Complx( 1.00, 0.0); // I(a) mpo0(0,4,1,1) = Complx( 1.00, 0.0); // I(b) Zcopy(mpo0,mpops[0]); } for(int i = 1; i < L-1; ++i) { // [ I 0 0 0 0 ] // [ S- 0 0 0 0 ] // [ S+ 0 0 0 0 ] // [ Sz 0 0 0 0 ] // [ 0 JS+ JS- JzSz I ] ZTensor<4> mpoI(5,5,2,2); mpoI = Complx( 0.0, 0.0); mpoI(0,0,0,0) = Complx( 1.00, 0.0); // I(a) mpoI(0,0,1,1) = Complx( 1.00, 0.0); // I(b) mpoI(1,0,1,0) = Complx( 1.00, 0.0); // S- mpoI(2,0,0,1) = Complx( 1.00, 0.0); // S+ mpoI(3,0,0,0) = Complx( 0.50, 0.0); // Sz(a) mpoI(3,0,1,1) = Complx(-0.50, 0.0); // Sz(b) mpoI(4,1,0,1) = Complx( J /2, 0.0); // S+ mpoI(4,2,1,0) = Complx( J /2, 0.0); // S- mpoI(4,3,0,0) = Complx( Jz/2, 0.0); // Sz(a) mpoI(4,3,1,1) = Complx(-Jz/2, 0.0); // Sz(b) mpoI(4,4,0,0) = Complx( 1.00, 0.0); // I(a) mpoI(4,4,1,1) = Complx( 1.00, 0.0); // I(b) Zcopy(mpoI,mpops[i]); } { // [ I ] // [ S- ] // [ S+ ] // [ Sz ] // [ 0 ] ZTensor<4> mpoN(5,1,2,2); mpoN = Complx( 0.0, 0.0); mpoN(0,0,0,0) = Complx( 1.00, 0.0); // I(a) mpoN(0,0,1,1) = Complx( 1.00, 0.0); // I(b) mpoN(1,0,1,0) = Complx( 1.00, 0.0); // S- mpoN(2,0,0,1) = Complx( 1.00, 0.0); // S+ mpoN(3,0,0,0) = Complx( 0.50, 0.0); // Sz(a) mpoN(3,0,1,1) = Complx(-0.50, 0.0); // Sz(b) Zcopy(mpoN,mpops[L-1]); } int nodd = L/2; int neven = L/2; if(L%2 == 0) --neven; // time-evolution fout << "==================== TIME-EVOLUTION ====================" << endl; double e = 0.0; double t = 0.0; int itr = 0; bool fwd = true; // // free-field propagator : exp(-iHt) = exp(-iEt) // // ZTensor<4> hodd (propagator(J, Jz, 0.0, 0.0, 0.0, dt/2)); // ZTensor<4> heven(propagator(J, Jz, 0.0, 0.0, 0.0, dt )); // while(itr < N) { if(itr % 100 == 0) { e = compute_energy(fwd,mpsts,mpops); fout.precision(4); fout << "\tt = " << setw(8) << t; fout.precision(16); fout << " : E = " << setw(20) << e << endl; } // time-evolution ZTensor<4> hodd (propagator(J, Jz, h, f, t, dt/2)); ZTensor<4> heven(propagator(J, Jz, h, f, t, dt )); tdmrg_sweeping(fwd,hodd,heven,mpsts,M); t += dt; ++itr; } e = compute_energy(fwd,mpsts,mpops); fout.precision(4); fout << "\tt = " << setw(8) << t; fout.precision(16); fout << " : E = " << setw(20) << e << endl; fout << "==================== FINISHED STEPS ====================" << endl; return 0; }
IRPrinter::IRPrinter(ostream &s) : stream(s), indent(0) { s.setf(std::ios::fixed, std::ios::floatfield); }
int dmrg(ostream& fout, vector<DTensor<3> >& mpsts, bool restart, int L, int M, double J, double Jz) { fout.setf(ios::fixed,ios::floatfield); fout.precision(4); fout << "==================== LATTICE INFO ====================" << endl; fout << "\tL =" << setw(4) << L << ", M =" << setw(4) << M << ", J =" << setw(7) << J << ", Jz =" << setw(7) << Jz << endl; DTensor<4> mpo0(1,5,2,2); DTensor<4> mpoI(5,5,2,2); DTensor<4> mpoN(5,1,2,2); // [ 0 JS+ JS- JzSz I ] mpo0 = 0.0; mpo0(0,1,0,1) = J /2; // S+ mpo0(0,2,1,0) = J /2; // S- mpo0(0,3,0,0) = Jz/2; // Sz(a) mpo0(0,3,1,1) =-Jz/2; // Sz(b) mpo0(0,4,0,0) = 1.00; // I(a) mpo0(0,4,1,1) = 1.00; // I(b) // [ I 0 0 0 0 ] // [ S- 0 0 0 0 ] // [ S+ 0 0 0 0 ] // [ Sz 0 0 0 0 ] // [ 0 JS+ JS- JzSz I ] mpoI = 0.0; mpoI(0,0,0,0) = 1.00; // I(a) mpoI(0,0,1,1) = 1.00; // I(b) mpoI(1,0,1,0) = 1.00; // S- mpoI(2,0,0,1) = 1.00; // S+ mpoI(3,0,0,0) = 0.50; // Sz(a) mpoI(3,0,1,1) =-0.50; // Sz(b) mpoI(4,1,0,1) = J /2; // S+ mpoI(4,2,1,0) = J /2; // S- mpoI(4,3,0,0) = Jz/2; // Sz(a) mpoI(4,3,1,1) =-Jz/2; // Sz(b) mpoI(4,4,0,0) = 1.00; // I(a) mpoI(4,4,1,1) = 1.00; // I(b) // [ I ] // [ S- ] // [ S+ ] // [ Sz ] // [ 0 ] mpoN = 0.0; mpoN(0,0,0,0) = 1.00; // I(a) mpoN(0,0,1,1) = 1.00; // I(b) mpoN(1,0,1,0) = 1.00; // S- mpoN(2,0,0,1) = 1.00; // S+ mpoN(3,0,0,0) = 0.50; // Sz(a) mpoN(3,0,1,1) =-0.50; // Sz(b) // dummy storage DTensor<3> stdum(1,1,1); stdum = 1.0; // initialize mpsts if(!restart) { mpsts.resize(L); mpsts[0].resize(1,2,M); for(int i = 1; i < L-1; ++i) { mpsts[i].resize(M,2,M); } mpsts[L-1].resize(M,2,1); srand(time(NULL)); for(int i = 0; i < L; ++i) { for(DTensor<3>::iterator it = mpsts[i].begin(); it != mpsts[i].end(); ++it) { *it = 2.0 * ((double) rand() / RAND_MAX - 0.5); } } } // initialize storages vector< DTensor<3> > storages; storages.resize(L); // set thermodynamic limit mps and backward canonicalization for(int i = L-1; i > 0; --i) { DTensor<2> res; canonicalize(0,mpsts[i],res); DTensor<3> guess; Dgemm(NoTrans,NoTrans,1.0,mpsts[i-1],res,1.0,guess); Dcopy(guess,mpsts[i-1]); if(i == L-1) { renormalize(0,mpsts[i],mpoN,stdum,storages[i]); } else { renormalize(0,mpsts[i],mpoI,storages[i+1],storages[i]); } } normalize(mpsts[0]); // starting sweep optimization fout.precision(16); double energy = 0.0; double radius = 1.0; int iter = 0; while(iter < 100 && radius > 1.0e-8) { fout << "==================== SWEEP ITER[" << setw(2) << iter << "] ====================" << endl; double energy_save = energy; vector<double> sweep_energy; sweep_energy.reserve(2*L); // forward sweep fout << "++++++++++++++++++++ FORWARD SWEEP ++++++++++++++++++++" << endl; for(int i = 0; i < L-1; ++i) { double esite; if(i == 0) { esite = optimize(mpsts[i],mpo0,stdum,storages[i+1]); DTensor<2> res; canonicalize(1,mpsts[i],res); DTensor<3> guess; Dgemm(NoTrans,NoTrans,1.0,res,mpsts[i+1],1.0,guess); Dcopy(guess,mpsts[i+1]); renormalize(1,mpsts[i],mpo0,stdum,storages[i]); } else { esite = optimize(mpsts[i],mpoI,storages[i-1],storages[i+1]); DTensor<2> res; canonicalize(1,mpsts[i],res); DTensor<3> guess; Dgemm(NoTrans,NoTrans,1.0,res,mpsts[i+1],1.0,guess); Dcopy(guess,mpsts[i+1]); renormalize(1,mpsts[i],mpoI,storages[i-1],storages[i]); } fout << "\tENERGY @ SITE[" << setw(3) << i << "] = " << setw(20) << esite << endl; sweep_energy.push_back(esite); } // backward sweep fout << "++++++++++++++++++++ BACKWARD SWEEP ++++++++++++++++++++" << endl; for(int i = L-1; i > 0; --i) { double esite; if(i == L-1) { esite = optimize(mpsts[i],mpoN,storages[i-1],stdum); DTensor<2> res; canonicalize(0,mpsts[i],res); DTensor<3> guess; Dgemm(NoTrans,NoTrans,1.0,mpsts[i-1],res,1.0,guess); Dcopy(guess,mpsts[i-1]); renormalize(0,mpsts[i],mpoN,stdum,storages[i]); } else { esite = optimize(mpsts[i],mpoI,storages[i-1],storages[i+1]); DTensor<2> res; canonicalize(0,mpsts[i],res); DTensor<3> guess; Dgemm(NoTrans,NoTrans,1.0,mpsts[i-1],res,1.0,guess); Dcopy(guess,mpsts[i-1]); renormalize(0,mpsts[i],mpoI,storages[i+1],storages[i]); } fout << "\tENERGY @ SITE[" << setw(3) << i << "] = " << setw(20) << esite << endl; sweep_energy.push_back(esite); } energy = *min_element(sweep_energy.begin(),sweep_energy.end()); radius = fabs(energy-energy_save); sweep_energy.clear(); ++iter; } fout << "==================== FINISHED SWEEP ====================" << endl; return 0; }
void CompactionConstraintGraphBase::writeGML(ostream &os, NodeArray<bool> one) const { const Graph &G = *this; NodeArray<int> id(*this); int nextId = 0; os.setf(ios::showpoint); os.precision(10); os << "Creator \"ogdf::CompactionConstraintGraphBase::writeGML\"\n"; os << "graph [\n"; os << " directed 1\n"; for(node v : G.nodes) { os << " node [\n"; os << " id " << (id[v] = nextId++) << "\n"; os << " graphics [\n"; os << " x 0.0\n"; os << " y 0.0\n"; os << " w 30.0\n"; os << " h 30.0\n"; if ((one[v])) { os << " fill \"#FF0F0F\"\n"; } else { os << " fill \"#FFFF00\"\n"; } os << " ]\n"; // graphics os << " ]\n"; // node } for(edge e : G.edges) { os << " edge [\n"; os << " source " << id[e->source()] << "\n"; os << " target " << id[e->target()] << "\n"; #if 0 // show edge lengths as edge lables (not yet supported) os << " label \""; writeLength(os,e); os << "\"\n"; #endif os << " graphics [\n"; os << " type \"line\"\n"; os << " arrow \"last\"\n"; switch(m_type[e]) { case cetBasicArc: // red os << " fill \"#FF0000\"\n"; break; case cetVertexSizeArc: // blue os << " fill \"#0000FF\"\n"; break; case cetVisibilityArc: // green os << "fill \"#00FF00\"\n"; break; case cetReducibleArc: // rose os << " fill \"#FF00FF\"\n"; break; case cetFixToZeroArc: //violett os << " fill \"#3F00FF\"\n"; break; OGDF_NODEFAULT } os << " ]\n"; // graphics #if 0 os << " LabelGraphics [\n"; os << " type \"text\"\n"; os << " fill \"#000000\"\n"; os << " anchor \"w\"\n"; os << " ]\n"; #endif os << " ]\n"; // edge } os << "]\n"; // graph }
void PlanRep::writeGML(ostream &os, const OrthoRep &OR, const GridLayout &drawing) { const Graph &G = *this; NodeArray<int> id(*this); int nextId = 0; os.setf(ios::showpoint); os.precision(10); os << "Creator \"ogdf::GraphAttributes::writeGML\"\n"; os << "graph [\n"; os << " directed 1\n"; for(node v : G.nodes) { os << " node [\n"; os << " id " << (id[v] = nextId++) << "\n"; os << " label \"" << v->index() << "\"\n"; os << " graphics [\n"; os << " x " << ((double) drawing.x(v)) << "\n"; os << " y " << ((double) drawing.y(v)) << "\n"; os << " w " << 3.0 << "\n"; os << " h " << 3.0 << "\n"; os << " type \"rectangle\"\n"; os << " width 1.0\n"; if (typeOf(v) == Graph::generalizationMerger) { os << " type \"oval\"\n"; os << " fill \"#0000A0\"\n"; } else if (typeOf(v) == Graph::generalizationExpander) { os << " type \"oval\"\n"; os << " fill \"#00FF00\"\n"; } else if (typeOf(v) == Graph::highDegreeExpander || typeOf(v) == Graph::lowDegreeExpander) os << " fill \"#FFFF00\"\n"; else if (typeOf(v) == Graph::dummy) os << " type \"oval\"\n"; else if (v->degree() > 4) os << " fill \"#FFFF00\"\n"; else os << " fill \"#000000\"\n"; os << " ]\n"; // graphics os << " ]\n"; // node } for (node v : nodes) { if (expandAdj(v) != nullptr && (typeOf(v) == Graph::highDegreeExpander || typeOf(v) == Graph::lowDegreeExpander)) { node vOrig = original(v); const OrthoRep::VertexInfoUML &vi = *OR.cageInfo(v); node ll = vi.m_corner[odNorth]->theNode(); node ur = vi.m_corner[odSouth]->theNode(); os << " node [\n"; os << " id " << nextId++ << "\n"; if (m_pGraphAttributes->attributes() & GraphAttributes::nodeLabel) { os << " label \"" << m_pGraphAttributes->label(vOrig) << "\"\n"; } os << " graphics [\n"; os << " x " << 0.5 * (drawing.x(ur) + drawing.x(ll)) << "\n"; os << " y " << 0.5 * (drawing.y(ur) + drawing.y(ll)) << "\n"; os << " w " << widthOrig(vOrig) << "\n"; os << " h " << heightOrig(vOrig) << "\n"; os << " type \"rectangle\"\n"; os << " width 1.0\n"; os << " fill \"#FFFF00\"\n"; os << " ]\n"; // graphics os << " ]\n"; // node } } for(edge e : G.edges) { os << " edge [\n"; os << " source " << id[e->source()] << "\n"; os << " target " << id[e->target()] << "\n"; os << " generalization " << typeOf(e) << "\n"; os << " graphics [\n"; os << " type \"line\"\n"; if (typeOf(e) == Graph::generalization) { if (typeOf(e->target()) == Graph::generalizationExpander) os << " arrow \"none\"\n"; else os << " arrow \"last\"\n"; os << " fill \"#FF0000\"\n"; os << " width 2.0\n"; } else { if (typeOf(e->source()) == Graph::generalizationExpander || typeOf(e->source()) == Graph::generalizationMerger || typeOf(e->target()) == Graph::generalizationExpander || typeOf(e->target()) == Graph::generalizationMerger) { os << " arrow \"none\"\n"; os << " fill \"#FF0000\"\n"; } else if (original(e) == nullptr) { os << " arrow \"none\"\n"; os << " fill \"#AFAFAF\"\n"; } else os << " arrow \"none\"\n"; if (isBrother(e)) os << " fill \"#00AF0F\"\n"; if (isHalfBrother(e)) os << " fill \"#0F00AF\"\n"; os << " width 1.0\n"; }//else generalization os << " ]\n"; // graphics os << " ]\n"; // edge } os << "]\n"; // graph }