const Vector& ElasticTimoshenkoBeam2d::getResistingForce()
{
    // zero the residual
    theVector.Zero();
    
    // get global trial displacements
    const Vector &dsp1 = theNodes[0]->getTrialDisp();
    const Vector &dsp2 = theNodes[1]->getTrialDisp();
    static Vector ug(6);
    for (int i=0; i<3; i++)  {
        ug(i)   = dsp1(i);
        ug(i+3) = dsp2(i);
    }
    
    // transform response from the global to the local system
    ul.addMatrixVector(0.0, Tgl, ug, 1.0);
    
    // get the resisting forces in local system
    ql.addMatrixVector(0.0, kl, ul, 1.0);
    
    // add P-Delta moments to local forces
    if ((ql(0) != 0.0) && (nlGeo == 1))
        ql.addMatrixVector(1.0, klgeo, ul, ql(0));
    
    // add effects of element loads, ql = ql(ul) + ql0
    ql.addVector(1.0, ql0, 1.0);
    
    // determine resisting forces in global system
    theVector.addMatrixTransposeVector(0.0, Tgl, ql, 1.0);
    
    return theVector;
}
void bond_order_analysis(Maximum<T>* input, int input_len, double h0, double h1, double h2, double _ths, double _boxsize, double _rlim, FILE* fp){
    ths = _ths; boxsize = _boxsize; rlim = _rlim;

    Pvec pvec;
    for(int i = 0; i < input_len; i++){
        Maximum<T>& m = input[i];
        if(m.field > ths)
            pvec.push_back(Point(m.i0 * h0, m.i1 * h1, m.i2 * h2));
    }
    std::cerr << "bond order > " << pvec.size() << " atoms above threshold" << std::endl;
    find_nbors(pvec, rlim, boxsize);
    std::cerr << "bond order > all nbors computed" << std::endl;

    // q_lm(i)
#pragma omp parallel for //schedule(dynamic, 1)
    for(int i=0; i<pvec.size(); i++) if(pvec[i].nbor_i.size() > 0) q_lm(pvec[i]);

    // q_l(i), q_l_bar(i)
#pragma omp parallel for //schedule(dynamic, 1)
    for(int i=0; i<pvec.size(); i++){
        Point& atom=pvec[i];
        if(atom.nbor_i.size() == 0) continue;
        atom.q4 = ql(atom.q4m, 4);
        atom.q6 = ql(atom.q6m, 6);
        atom.q8 = ql(atom.q8m, 8);
        //atom.w4 = w4(atom);
        atom.q4b = q4b(atom, pvec);
        atom.q6b = q6b(atom, pvec);
        atom.q8b = q8b(atom, pvec);
        //atom.w4b = w4b(atom, pvec);
    }
#pragma omp parallel for //schedule(dynamic, 1)
    for(int i=0; i<pvec.size(); i++){
        Point& atom=pvec[i];
        if(atom.nbor_i.size() == 0) continue;
        //atom.xi = xi(atom, pvec);
    }

    //FILE* outfile = fopen(outfn.c_str(), "w");
    //if(outfile == NULL){
        //std::cerr << "output file " << outfile << " cannot be created" << std::endl;
        //exit(EXIT_FAILURE);
    //}
    //fprintf(fp, "# x y z #nb xi q4 q6 q8 w4 q4b q6b q8b w4b\n");
    fprintf(fp, "# x y z #nb q4 q6 q8 q4b q6b q8b\n");
    for(Point& atom : pvec){
        if(atom.nbor_i.size() == 0) continue;
        // xi
        //fprintf(fp, "%.6f\t%.6f\t%.6f\t%d\t%d\t%.6f\t%.6f\t%.6f\t%.6f\t%.6f\t%.6f\t%.6f\t%.6f\n",
                //atom.x, atom.y, atom.z, atom.nbor_i.size(), atom.xi, atom.q4, atom.q6, atom.q8, atom.w4, atom.q4b, atom.q6b, atom.q8b, atom.w4b);
        // no xi
        fprintf(fp, "%.6f\t%.6f\t%.6f\t%d\t%.6f\t%.6f\t%.6f\t%.6f\t%.6f\t%.6f\n",
                atom.x, atom.y, atom.z, atom.nbor_i.size(), atom.q4, atom.q6, atom.q8, atom.q4b, atom.q6b, atom.q8b);
    }
    fflush(fp);
}
Exemple #3
0
void ata_byteswapidentity(uae_u8 *d)
{
	for (int i = 0; i < 512; i += 2)
	{
		uae_u8 t = d[i + 0];
		d[i + 0] = d[i + 1];
		d[i + 1] = t;
	}
	sl(d, 7);
	sl(d, 57);
	sl(d, 60);
	sl(d, 98);
	sl(d, 117);
	sl(d, 210);
	sl(d, 212);
	sl(d, 215);
	ql(d, 100);
	ql(d, 230);
}
 void process(aligned_vector<complex_type>::const_iterator i0,
              aligned_vector<complex_type>::const_iterator i1,
              int output_offset)
 {
   assert(std::distance(i0,i1) == q());
   for (int i=0, n=p()*q(); i<n; ++i) {
     const int i_mod_p(i%p());
     const int i_mod_q(i%q());
     if (!i_mod_p) {
       history_[counter_] = history_[counter_+ql()] = *i0++;
       counter_ = ((1+counter_) % ql());
     }
     if (!i_mod_q) {
       volk_32fc_32f_dot_prod_32fc(&out_[output_offset + i/q()],
                                   &history_[counter_],
                                   &b_[i_mod_p*ql()],
                                   ql());
     }
   }
 }
const Matrix& ElasticTimoshenkoBeam2d::getTangentStiff()
{
    // zero the matrix
    theMatrix.Zero();
    
    if (nlGeo == 0)  {
        // transform from local to global system
        theMatrix.addMatrixTripleProduct(0.0, Tgl, kl, 1.0);
        
    } else  {
        // initialize local stiffness matrix
        static Matrix klTot(6,6);
        klTot.addMatrix(0.0, kl, 1.0);
        
        // get global trial displacements
        const Vector &dsp1 = theNodes[0]->getTrialDisp();
        const Vector &dsp2 = theNodes[1]->getTrialDisp();
        static Vector ug(6);
        for (int i=0; i<3; i++)  {
            ug(i)   = dsp1(i);
            ug(i+3) = dsp2(i);
        }
        
        // transform response from the global to the local system
        ul.addMatrixVector(0.0, Tgl, ug, 1.0);
        
        // get the resisting forces in local system
        ql.addMatrixVector(0.0, kl, ul, 1.0);
        
        // add geometric stiffness to local stiffness
        if (ql(0) != 0.0)
            klTot.addMatrix(1.0, klgeo, ql(0));
        
        // transform from local to global system
        theMatrix.addMatrixTripleProduct(0.0, Tgl, klTot, 1.0);
    }
    
    return theMatrix;
}
Exemple #6
0
const Vector& TwoNodeLink::getResistingForce()
{
    // zero the residual
    theVector->Zero();
    
    // get resisting forces
    for (int i=0; i<numDir; i++)
        qb(i) = theMaterials[i]->getStress();
    
    // determine resisting forces in local system
    Vector ql(numDOF);
    ql.addMatrixTransposeVector(0.0, Tlb, qb, 1.0);
    
    // add P-Delta effects to local forces
    if (Mratio.Size() == 4)
        this->addPDeltaForces(ql);
    
    // determine resisting forces in global system    
    theVector->addMatrixTransposeVector(0.0, Tgl, ql, 1.0);
    
    return *theVector;
}
Exemple #7
0
void MT(void)
{
    char buf[10];
    while(1)
    {
        sen.pro = 2;
        system("clear");
        printf("-----欢迎进入MT-----\n\n");
        printf("--------------------\n");
        printf("1--------私聊-------\n");
        printf("2--------群聊-------\n");
        printf("3---------FTP-------\n");
        printf("4---------VIP-------\n");
        printf("5------修改状态-----\n");
        printf("6------修改密码-----\n");
        printf("7--------注销-------\n");
        printf("8--------退出-------\n");
        printf("--------------------\n\n");

        printf("请输入你的选择:");
        memset(buf,0,10);
        fgets(buf,10,stdin);
        if(strlen(buf) > 2)
        {
            continue;
        }
        if(buf[0] == '1')
        {
            sl();
        }
        else if(buf[0] == '2')
        {
            ql();
        }
        else if(buf[0] == '3')
        {
            ftp();
        }
        else if(buf[0] == '4')
        {
            vip();
        }
        else if(buf[0] == '5')
        {
            zt();
        }
        else if(buf[0] == '6')
        {
            gm();   
        }
        else if(buf[0] == '7')
        {
            sen.pro = 6;
            strcpy(sen.message,"ZX");
            send(fd,&sen,len_data,0);
            MAIN(); 
        }
        else if(buf[0] == '8')
        {
            sen.pro = 6;
            strcpy(sen.message,"MT");
            send(fd,&sen,len_data,0);
            exit(0);
        }
    }
}
//void PieceAppearanceWidget::applyCurrentTemplate( QObject * tgt )
void PieceAppearanceWidget::applyCurrentTemplate( QGIPiece * tgt )
{
    if( !tgt ) return;
    typedef QList<QGraphicsItem*> QIL;
    QIL li( impl->gv->scene()->selectedItems() );
    impl->pc = 0;
    // If there are multiple items selected, simply pick the first
    // selected item which has an associated piece (the order has no
    // meaning, however).
    for( QIL::iterator it = li.begin();
	 li.end() != it;
	 ++it )
    {
	QGIPiece * pvi = dynamic_cast<QGIPiece*>(*it);
	if( pvi )
	{
	    impl->pc = pvi;
	}
    }
    if( ! impl->pc ) return;

    /**
       We want to keep certain properties intact:
    
       pixmap: b/c the game client normally sets this

       pos: we don't want to use the template's pos

       dragDisabled: that property was developed to support
       this class. The client will almost always expect
       his pieces to be draggable.
    */
    QVariant pix( tgt->property("pixmap") );
    QVariant pos( tgt->property("pos") );
    QVariant dragDisabled( tgt->property("dragDisabled") );
    {
#if 0
	QObject * src = impl->pc;
	typedef QList<QByteArray> QL;
	QL ql( src->dynamicPropertyNames() );
	QL::const_iterator it( ql.begin() );
	QL::const_iterator et( ql.end() );
	for( ; et != it; ++it )
	{
	    char const * key = it->constData();
	    if( !key || (*key == '_') ) continue; // Qt reserves the "_q_" prefix, so we'll elaborate on that.
	    tgt->setProperty( key, src->property(key) );
	}
#else
	S11nNode n;
	impl->pc->serialize(n);
	// Lame kludge to ensure that we don't throw
	// here if tgt is a subclass of QGIType:
	const QString cn1( S11nNodeTraits::class_name(n).c_str() );
	const QString cn2( tgt->s11nClass() );
	if( cn1 != cn2 )
	{
	    S11nNodeTraits::class_name(n,cn2.toAscii().constData());
	}
	tgt->deserialize(n);
#endif
    }
    tgt->setProperty("pos", pos );
    tgt->setProperty("pixmap", pix );
    tgt->setProperty("dragDisabled", dragDisabled );
}
Exemple #9
0
void FriendListWidget::setMode(Mode mode)
{
    if (this->mode == mode)
        return;

    this->mode = mode;

    if (mode == Name) {
        circleLayout = new GenericChatItemLayout;
        circleLayout->getLayout()->setSpacing(0);
        circleLayout->getLayout()->setMargin(0);

        for (int i = 0; i < Settings::getInstance().getCircleCount(); ++i) {
            addCircleWidget(i);
            CircleWidget::getFromID(i)->setVisible(false);
        }

        // Only display circles once all created to avoid artifacts.
        for (int i = 0; i < Settings::getInstance().getCircleCount(); ++i)
            CircleWidget::getFromID(i)->setVisible(true);

        int count = activityLayout ? activityLayout->count() : 0;
        for (int i = 0; i < count; i++) {
            QWidget* widget = activityLayout->itemAt(i)->widget();
            CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(widget);
            if (categoryWidget) {
                categoryWidget->moveFriendWidgets(this);
            } else {
                qWarning() << "Unexpected widget";
            }
        }

        listLayout->addLayout(listLayout->getLayoutOnline());
        listLayout->addLayout(listLayout->getLayoutOffline());
        listLayout->addLayout(circleLayout->getLayout());
        onGroupchatPositionChanged(groupsOnTop);

        if (activityLayout != nullptr) {
            QLayoutItem* item;
            while ((item = activityLayout->takeAt(0)) != nullptr) {
                delete item->widget();
                delete item;
            }
            delete activityLayout;
            activityLayout = nullptr;
        }

        reDraw();
    } else if (mode == Activity) {
        QLocale ql(Settings::getInstance().getTranslation());
        QDate today = QDate::currentDate();
#define COMMENT "Category for sorting friends by activity"
        // clang-format off
        const QMap<Time, QString> names {
            { Time::Today,     tr("Today",                      COMMENT) },
            { Time::Yesterday, tr("Yesterday",                  COMMENT) },
            { Time::ThisWeek,  tr("Last 7 days",                COMMENT) },
            { Time::ThisMonth, tr("This month",                 COMMENT) },
            { Time::LongAgo,   tr("Older than 6 Months",        COMMENT) },
            { Time::Never,     tr("Never",                      COMMENT) },
            { Time::Month1Ago, ql.monthName(today.addMonths(-1).month()) },
            { Time::Month2Ago, ql.monthName(today.addMonths(-2).month()) },
            { Time::Month3Ago, ql.monthName(today.addMonths(-3).month()) },
            { Time::Month4Ago, ql.monthName(today.addMonths(-4).month()) },
            { Time::Month5Ago, ql.monthName(today.addMonths(-5).month()) },
        };
// clang-format on
#undef COMMENT

        activityLayout = new QVBoxLayout();
        bool compact = Settings::getInstance().getCompactLayout();
        for (Time t : names.keys()) {
            CategoryWidget* category = new CategoryWidget(compact, this);
            category->setName(names[t]);
            activityLayout->addWidget(category);
        }

        moveFriends(listLayout->getLayoutOffline());
        moveFriends(listLayout->getLayoutOnline());
        moveFriends(circleLayout->getLayout());

        for (int i = 0; i < activityLayout->count(); ++i) {
            QWidget* widget = activityLayout->itemAt(i)->widget();
            CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(widget);
            categoryWidget->setVisible(categoryWidget->hasChatrooms());
        }

        listLayout->removeItem(listLayout->getLayoutOnline());
        listLayout->removeItem(listLayout->getLayoutOffline());

        if (circleLayout != nullptr) {
            listLayout->removeItem(circleLayout->getLayout());

            QLayoutItem* item;
            while ((item = circleLayout->getLayout()->takeAt(0)) != nullptr) {
                delete item->widget();
                delete item;
            }
            delete circleLayout;
            circleLayout = nullptr;
        }

        listLayout->insertLayout(1, activityLayout);

        reDraw();
    }
}
Exemple #10
0
  void operator<< ( std::vector<SPOTriplet> triplets )
  {

    if ( !triplets.size() )
      return;

    for ( auto triplet : triplets )
      {
        if ( program.size() >= stmt_max )
          program.pop();

        program.push ( triplet );
      }

    boost::posix_time::ptime now = boost::posix_time::second_clock::universal_time();
    std::string image_file = "samu_vi_"+boost::posix_time::to_simple_string ( now ) +".png";

#ifndef CHARACTER_CONSOLE
    char * image_file_p = strdup ( image_file.c_str() );
    pngwriter image ( 256, 256, 65535, image_file_p );
    free ( image_file_p );
#else
    char console[10][80];
    std::memset ( console, ' ', 10*80 );
#endif

    char stmt_buffer[1024];
    char *stmt_buffer_p = stmt_buffer;

    std::queue<SPOTriplet> run = program;

#ifndef Q_LOOKUP_TABLE

    std::string prg;
    stmt_counter = 0;
    while ( !run.empty() )
      {
        auto triplet = run.front();

        prg += triplet.s.c_str();
        prg += triplet.p.c_str();
        prg += triplet.o.c_str();

        std::snprintf ( stmt_buffer, 1024, "%s.%s(%s);", triplet.s.c_str(), triplet.p.c_str(), triplet.o.c_str() );

#ifndef CHARACTER_CONSOLE
        char font[] = "/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf";
        char *font_p = font;

        image.plot_text_utf8 ( font_p,
                               11,
                               5,
                               256- ( ++stmt_counter ) *28,
                               0.0,
                               stmt_buffer_p, 0, 0, 0 );
#else

        std::strncpy ( console[stmt_counter++], stmt_buffer, 80 );

#endif

        run.pop();
      }

#ifndef CHARACTER_CONSOLE
    double *img_input = new double[256*256];

    for ( int i {0}; i<256; ++i )
      for ( int j {0}; j<256; ++j )
        {
          img_input[i*256+j] = image.dread ( i, j );
        }
#else
    double *img_input = new double[10*80];

    for ( int i {0}; i<10; ++i )
      for ( int j {0}; j<80; ++j )
        {
          img_input[i*80+j] = ( ( double ) console[i][j] ) / 255.0;
        }
#endif


#else
    std::string prg;
    while ( !run.empty() )
      {
        auto triplet = run.front();

        prg += triplet.s.c_str();
        prg += triplet.p.c_str();
        prg += triplet.o.c_str();

        run.pop();
      }
#endif

    auto start = std::chrono::high_resolution_clock::now();

    std::cerr << "QL start... ";

#ifndef Q_LOOKUP_TABLE

    SPOTriplet response = ql ( triplets[0], prg, img_input );

    std::cout << std::endl
              << "Jacob@AI"
#ifdef QNN_DEBUG
              << "."
              << ql.get_action_count()
              << "."
              << ql.get_action_relevance()
              << "%"
#endif
              <<"> "
              << response << std::endl;

#else

    std::cerr << ql ( triplets[0], prg ) << std::endl;

#endif


    std::cerr << std::chrono::duration_cast<std::chrono::milliseconds> (
                std::chrono::high_resolution_clock::now() - start ).count()
              << " ms " <<  std::endl;

#ifndef CHARACTER_CONSOLE

#ifndef Q_LOOKUP_TABLE
    delete[] img_input;
    image.close();
#endif

#endif
  }
Exemple #11
0
/* Finds needed eigenvalues of tridiagonal T using either the QL algorithm
   or Sturm sequence bisection, whichever is predicted to be faster based
   on a simple complexity model. If one fails (which is rare), the other
   is tried. The return value is 0 if one of the routines succeeds. If they
   both fail, the return value is 1, and Lanczos should compute the best
   approximation it can based on previous iterations. */
int get_ritzvals(double *alpha,         /* vector of Lanczos scalars */
                 double *beta,          /* vector of Lanczos scalars */
                 int     j,             /* number of Lanczos iterations taken */
                 double  Anorm,         /* Gershgorin estimate */
                 double *workj,         /* work vector for Sturm sequence */
                 double *ritz,          /* array holding evals */
                 int     d,             /* problem dimension = num. eigenpairs needed */
                 int     left_goodlim,  /* number of ritz pairs checked on left end */
                 int     right_goodlim, /* number of ritz pairs checked on right end */
                 double  eigtol,        /* tolerance on eigenpair */
                 double  bis_safety     /* bisection tolerance function divisor */
                 )
{
  extern int DEBUG_EVECS;     /* debug flag for eigen computation */
  extern int WARNING_EVECS;   /* warning flag for eigen computation */
  int        nvals_left;      /* numb. evals to find on left end of spectrum */
  int        nvals_right;     /* numb. evals to find on right end of spectrum */
  double     bisection_tol;   /* width of interval bisection should converge to */
  int        pred_steps;      /* predicts # of required bisection steps per eval */
  int        tot_pred_steps;  /* predicts total # of required bisection steps */
  double *   ritz_sav = NULL; /* copy of ritzvals for debugging */
  int        bisect_flag;     /* return status of bisect() */
  int        ql_flag;         /* return status of ql() */
  int        local_debug;     /* whether to check bisection results with ql */
  int        bisect();        /* locates eigvals using bisection on Sturm seq. */
  int        ql();            /* computes eigenvalues of T using eispack algorithm */
  void       shell_sort();    /* sorts vector of eigenvalues */
  double *   mkvec();         /* to allocate a vector */
  void       frvec();         /* free vector */
  void       cpvec();         /* vector copy */
  void       bail();          /* our exit routine */
  void       strout();        /* string out to screen and output file */

  /* Determine number of ritzvals to find on left and right ends */
  nvals_left  = max(d, left_goodlim);
  nvals_right = min(j - nvals_left, right_goodlim);

  /* Estimate work for bisection vs. ql assuming bisection takes 5j flops per
     step, ql takes 30j^2 flops per call. (Ignore sorts, copies, addressing.) */

  bisection_tol  = eigtol * eigtol / bis_safety;
  pred_steps     = (log10(Anorm / bisection_tol) / log10(2.0)) + 1;
  tot_pred_steps = (nvals_left + nvals_right) * pred_steps;

  bisect_flag = ql_flag = 0;

  if (5 * tot_pred_steps < 30 * j) {
    if (DEBUG_EVECS > 2)
      printf("  tridiagonal solver: bisection\n");

    /* Set local_debug = TRUE for a table checking bisection against QL. */
    local_debug = FALSE;
    if (local_debug) {
      ritz_sav = mkvec(1, j);
      cpvec(ritz_sav, 1, j, alpha);
      cpvec(workj, 0, j, beta);
      ql_flag = ql(ritz_sav, workj, j);
      if (ql_flag != 0) {
        bail("Aborting debugging procedure in get_ritzvals().\n", 1);
      }
      shell_sort(j, &ritz_sav[1]);
    }

    bisect_flag = bisect(alpha, beta, j, Anorm, workj, ritz, nvals_left, nvals_right, bisection_tol,
                         ritz_sav, pred_steps + 10);

    if (local_debug)
      frvec(ritz_sav, 1);
  }

  else {
    if (DEBUG_EVECS > 2)
      printf("  tridiagonal solver: ql\n");
    cpvec(ritz, 1, j, alpha);
    cpvec(workj, 0, j, beta);
    ql_flag = ql(ritz, workj, j);
    shell_sort(j, &ritz[1]);
  }

  if (bisect_flag != 0 && ql_flag == 0) {
    if (DEBUG_EVECS > 0 || WARNING_EVECS > 0) {
      strout("WARNING: Sturm bisection of T failed; switching to QL.\n");
    }
    if (DEBUG_EVECS > 1 || WARNING_EVECS > 1) {
      if (bisect_flag == 1)
        strout("         - failure detected in sturmcnt().\n");
      if (bisect_flag == 2)
        strout("         - maximum number of bisection steps reached.\n");
    }
    cpvec(ritz, 1, j, alpha);
    cpvec(workj, 0, j, beta);
    ql_flag = ql(ritz, workj, j);
    shell_sort(j, &ritz[1]);
  }

  if (ql_flag != 0 && bisect_flag == 0) {
    if (DEBUG_EVECS > 0 || WARNING_EVECS > 0) {
      strout("WARNING: QL failed for T; switching to Sturm bisection.\n");
    }
    bisect_flag = bisect(alpha, beta, j, Anorm, workj, ritz, nvals_left, nvals_right, bisection_tol,
                         ritz_sav, pred_steps + 3);
  }

  if (bisect_flag != 0 && ql_flag != 0) {
    if (DEBUG_EVECS > 0 || WARNING_EVECS > 0) {
      return (1); /* can't recover; bail out with error code */
    }
  }

  return (0); /* ... things seem ok. */
}
Exemple #12
0
    void operator<< ( std::vector<SPOTriplet> triplets )
    {

      if ( !triplets.size() )
        return;

      for ( auto triplet : triplets )
        {
          if ( program.size() >= stmt_max )
            program.pop();

          program.push ( triplet );
        }

#ifdef FEELINGS
      if ( feelings.size() >= stmt_max )
        feelings.pop();

      feelings.push ( ql.feeling() );
#endif

      boost::posix_time::ptime now = boost::posix_time::second_clock::universal_time();

#ifndef CHARACTER_CONSOLE
      std::string image_file = "samu_vi_"+boost::posix_time::to_simple_string ( now ) +".png";
      char * image_file_p = strdup ( image_file.c_str() );
      pngwriter image ( 256, 256, 65535, image_file_p );
      free ( image_file_p );
#else
      char console[nrows][ncols];
      std::memset ( console, 0, nrows*ncols );
#endif

      char stmt_buffer[1024];
      char *stmt_buffer_p = stmt_buffer;

      std::queue<SPOTriplet> run = program;
#ifdef FEELINGS
      std::queue<Feeling> feels = feelings;
#endif

#ifndef Q_LOOKUP_TABLE

      std::string prg;
      stmt_counter = 0;
#ifdef PYRAMID_VI
      SPOTriplets pyramid;
#endif

#ifdef PLACE_VALUE
      double wbuf[nrows][3];
#endif

      while ( !run.empty() )
        {
          auto triplet = run.front();

          prg += triplet.s.c_str();
          prg += triplet.p.c_str();
          prg += triplet.o.c_str();

#ifdef PLACE_VALUE

          // std::cerr << "iter " << triplet.s << "iter " << triplet.p<< "iter " << triplet.o<< std::endl;

          wbuf[stmt_counter][0] = w2d ( triplet.s );
          wbuf[stmt_counter][1] = w2d ( triplet.p );
          wbuf[stmt_counter][2] = w2d ( triplet.o );
#endif

#ifdef PYRAMID_VI
          pyramid.push_back ( triplet );
          SPOTriplets reverse_pyramid ( pyramid.size() );
          std::reverse_copy ( pyramid.begin(), pyramid.end(), reverse_pyramid.begin() );

          int cnt {0};
          for ( SPOTriplets::iterator it=reverse_pyramid.begin(); it!=reverse_pyramid.end() && cnt < 80; ++it )
            //while ( cnt < 80 )
            //cnt += std::snprintf ( stmt_buffer+cnt, 1024-cnt, "%s.%s(%s);", triplet.s.c_str(), triplet.p.c_str(), triplet.o.c_str() );
            cnt += std::snprintf ( stmt_buffer+cnt, 1024-cnt, "%s.%s(%s);", ( *it ).s.c_str(), ( *it ).p.c_str(), ( *it ).o.c_str() );
#elif JUSTIFY_VI
          int cnt {0};
          while ( cnt < mcols )
            cnt += std::snprintf ( stmt_buffer+cnt, 1024-cnt, "%s.%s(%s);", triplet.s.c_str(), triplet.p.c_str(), triplet.o.c_str() );
#else

#ifndef FEELINGS
#ifdef DRAW_WNUM
          std::snprintf ( stmt_buffer, 1024, "%s.%s(%s); %f.%f(%f)",
                          triplet.s.c_str(), triplet.p.c_str(), triplet.o.c_str(),
                          w2d ( triplet.s ), w2d ( triplet.p ), w2d ( triplet.o ) );
#else
          std::snprintf ( stmt_buffer, 1024, "%s.%s(%s);", triplet.s.c_str(), triplet.p.c_str(), triplet.o.c_str() );
#endif

#else
          if ( !feels.empty() )
            {
              auto s = feels.front();
              std::stringstream ss;
#ifndef FEELINGS
              ss << triplet.s << "." << triplet.p << "(" << triplet.o << ");";
#else
              ss << triplet.s << "." << triplet.p << "(" << triplet.o << "); "
                 << w2d ( triplet.s ) << "." << w2d ( triplet.p ) << "(" << w2d ( triplet.o ) << "); ";
#endif
              std::string spo = ss.str();
              std::snprintf ( stmt_buffer, 1024, "%-30s %s", spo.c_str(), s.c_str() );
            }
#endif
#endif


#ifndef CHARACTER_CONSOLE
          char font[] = "/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf";
          char *font_p = font;

          image.plot_text_utf8 ( font_p,
                                 11,
                                 5,
                                 256- ( ++stmt_counter ) *28,
                                 0.0,
                                 stmt_buffer_p, 0, 0, 0 );
#else

          std::strncpy ( console[stmt_counter++], stmt_buffer, 80 );

#endif

          run.pop();
#ifdef FEELINGS
          feels.pop();
#endif
        }


#ifdef CELL_AUTOMATA
      char console2[nrows][ncols];
      for ( int i {1}; i<nrows-1; ++i )
        for ( int j {1}; j<ncols-1; ++j )
          console2[i][j] = console[i-1][j]+console[i][j-1]+console[i+1][j]+console[i][j+1];


      for ( int i {1}; i<nrows-1; ++i )
        for ( int j {1}; j<ncols-1; ++j )
          console[i][j] = console2[i][j];
#endif

#ifdef PLACE_VALUE

      double *img_input = new double[nrows*3];
      for ( int i {0}; i<nrows; ++i )
        {
          for ( int j {0}; j<3; ++j )
            {
              img_input[i*3+j] = wbuf[i][j];
              //std::cerr << "iter " << img_input[i*3+j] << " | ";

            }
          //std::cerr << "iter " << std::endl;
        }
#elif CHARACTER_CONSOLE

#ifdef FOUR_TIMES
      double *img_input = new double[2*nrows*2*ncols];
#else
      double *img_input = new double[nrows*ncols];
#endif

#ifdef DISP_CURSES
      std::stringstream con;
#endif

      for ( int i {0}; i<nrows; ++i )
        {
#ifdef DISP_CURSES
          std::string ci;
#endif
          for ( int j {0}; j<ncols; ++j )
            {
#ifdef FOUR_TIMES
              img_input[2*i*ncols+2*j] = ( ( double ) console[i][j] ) / 255.0;
              img_input[2*i*ncols+2*j+1] = ( ( double ) console[i][j] ) / 255.0;
              img_input[2* ( i+1 ) *ncols+2*j] = ( ( double ) console[i][j] ) / 255.0;
              img_input[2* ( i+1 ) *ncols+2*j+1] = ( ( double ) console[i][j] ) / 255.0;
#else
              img_input[i*ncols+j] = ( ( double ) console[i][j] ) / 255.0;
#endif

#ifdef DISP_CURSES
              //if ( isgraph ( console[i][j] ) )
              if ( isprint ( console[i][j] ) )
                ci += console[i][j];
#endif
            }

#ifdef DISP_CURSES
          con << " " << i << ". " << ( ( ci.length() <75 ) ?ci:ci.substr ( 0, 75 ) ) << std::endl;

#endif
        }

#ifdef DISP_CURSES

#ifndef PRINTING_CHARBYCHAR
      samu.disp.vi ( con.str() );
#else
      samu.disp.vi ( &console[0][0] );
#endif

#endif

#else

      double *img_input = new double[256*256];

      for ( int i {0}; i<256; ++i )
        for ( int j {0}; j<256; ++j )
          {
            img_input[i*256+j] = image.dread ( i, j );
          }

#endif

#else
      std::string prg;
      while ( !run.empty() )
        {
          auto triplet = run.front();

          prg += triplet.s.c_str();
          prg += triplet.p.c_str();
          prg += triplet.o.c_str();

          run.pop();
        }
#endif

      auto start = std::chrono::high_resolution_clock::now();

      std::cerr << "QL start... ";

#ifndef Q_LOOKUP_TABLE

      SPOTriplet response = ql ( triplets[0], prg, img_input );

      std::stringstream resp;

      resp << samu.name
#ifdef QNN_DEBUG
           << "@"
           << ( samu.sleep_?"sleep":"awake" )
           << "."
           << ql.get_action_count()
           << "."
           << ql.get_action_relevance()
           << "%"
#endif
           <<"> "
           << response;

      std::string r = resp.str();

      std::cerr << r << std::endl;

#ifdef DISP_CURSES
      samu.disp.log ( r );
#endif

#else

      std::cerr << ql ( triplets[0], prg ) << std::endl;

#endif

      std::cerr << std::chrono::duration_cast<std::chrono::milliseconds> ( std::chrono::high_resolution_clock::now() - start ).count()
                << " ms "
                <<  std::endl;

#ifndef CHARACTER_CONSOLE

#ifndef Q_LOOKUP_TABLE
      delete[] img_input;
      image.close();
#endif

#else

#ifndef Q_LOOKUP_TABLE
      delete[] img_input;
#endif

#endif
    }
Exemple #13
0
int main() {
    int n;
    int start, goal;
    scanf("%d", &n);
    scanf("%d %d", &start, &goal);
    int left, right;
    std::vector<int> l(n+1), r(n+1);
    for (int i = 0; i <= n; ++i) {
        scanf("%d %d", &left, &right);
        l[i] = left;
        r[i] = right;
    }
    l[0] = start; r[0] = start;
    l[n] = goal; r[n] = goal;
    std::vector<int> ql(n+1);
    int lmin = 0, lmax = 0;
    std::vector<int> qr(n+1);
    int rmin = 0, rmax = 0;

    long double distance = 0.0;
    int x = start;
    int y = 0;
    for (int i = 1; i <= n; ++i) {
        for (; lmax > lmin; ) {
            int py = ql[--lmax];
            int px = l[py];
            int ppy = y;
            int ppx = x;
            if (lmax > lmin) {
                ppy = ql[lmax-1];
                ppx = l[ppy];
            }
            if ((long double)(px - ppx) / (long double)(py - ppy) > (long double)(l[i] - px) / (long double)(i - py)) {
                lmax++;
                break;
            }
        }
        for (; rmax > rmin; ) {
            int py = qr[--rmax];
            int px = r[py];
            int ppy = y;
            int ppx = x;
            if (rmax > rmin) {
                ppy = qr[rmax - 1];
                ppx = r[ppy];
            }
            if ((long double)(ppx - px) / (long double)(ppy - py) < (long double)(r[i] - px) / (long double)(i - py)) {
                rmax++;
                break;
            }
        }
        ql[lmax++] = qr[rmax++] = i;
        while ((long double)(l[ql[lmin]] - x) / (long double)(ql[lmin] - y) > (long double)(r[qr[rmin]] - x) / (long double)(qr[rmin] - y)) {
            if (ql[lmin] < qr[rmin]) {
                distance += hypot((long double)(y - ql[lmin]), (long double)(x - l[ql[lmin]]));
                y = ql[lmin];
                x = l[y];
                lmin++;
            } else {
                distance += hypot((long double)(y - qr[rmin]), (long double)(x - r[qr[rmin]]));
                y = qr[rmin];
                x = r[y];
                rmin++;
            }
        }
    }
    while (lmin < lmax) {
        distance += hypot((long double)(y - ql[lmin]), (long double)(x - l[ql[lmin]]));
        y = ql[lmin];
        x = l[y];
        lmin++;
    }
    printf("%0.15Lf\n", distance);
}