Esempio n. 1
0
void PathEvaluator::test_filtering()
{
	/// Export results:
	QString sessionName = QString("session_%1").arg(QDateTime::currentDateTime().toString("dd.MM.yyyy_hh.mm.ss"));
	QString path = "results/" + sessionName;
	QDir d("");	d.mkpath( path ); d.mkpath( path + "/images" );

	int timeLimit = 5000; // ms
	int numInBetweens = 8;
	int numSamplesPerPath = numInBetweens * 3;

	/// Get number of paths to evaluate:
	int numPaths = 0;
	{
		Scheduler defaultSchedule( *b->m_scheduler );

		// Find time it takes for a single path
		QElapsedTimer timer; timer.start();
		{
			defaultSchedule.setSchedule( b->m_scheduler->getSchedule() ); // default
			defaultSchedule.timeStep = 1.0 / numSamplesPerPath;
			defaultSchedule.executeAll();
		}

		// FIXME
		// numPaths = qMax(1.0, double(timeLimit) / timer.elapsed() * omp_get_num_threads());
		numPaths = qMax(1.0, double(timeLimit) / timer.elapsed() * 4);

		// Export source and target images
		QColor inputColor(255,255,255);
		b->renderer->quickRender(defaultSchedule.allGraphs.front(), inputColor).save(path + "/images/source.png");
		b->renderer->quickRender(defaultSchedule.allGraphs.back(), inputColor).save(path + "/images/target.png");
	}

	// Force number of paths
	numPaths = 30;

	// Do this once for input graphs
	QVector<Structure::Graph*> inputGraphs;
	inputGraphs << b->s->inputGraphs[0]->g << b->s->inputGraphs[1]->g;

	ScorerManager r_manager(b->m_gcorr, b->m_scheduler.data(), inputGraphs);
	r_manager.parseConstraintPair();
	r_manager.parseConstraintGroup();
	r_manager.parseGlobalReflectionSymm();

	QVector<ScorerManager::PathScore> ps( numPaths );
	MatrixXd allRanges( numPaths, 3 * 4 );

	QVector<ScheduleType> allPaths = b->m_scheduler->manyRandomSchedules( numPaths );

	QElapsedTimer evalTimer; evalTimer.start();

	//#pragma omp parallel for
	for(int i = 0; i < allPaths.size(); i++)
	{
		// Setup schedule
		Scheduler s( *b->m_scheduler );
		s.setSchedule( allPaths[i] );
		s.timeStep = 1.0 / numSamplesPerPath;

		// Execute blend
		s.executeAll();

		// Compute its score
		ps[i] = r_manager.pathScore( s.allGraphs );

		QVector<QColor> colors;
		colors.push_back(QColor(255,0,0));
		colors.push_back(QColor(0,255,0));
		colors.push_back(QColor(0,0,255));

		// Range of values
		MatrixXd ranges = ps[i].computeRange();

		allRanges.row(i) = VectorXd::Map(ranges.data(), ranges.rows()*ranges.cols());

		//#pragma omp critical
		{
			QImage img(QSize(600,130), QImage::Format_ARGB32);
			img.fill(qRgba(0,0,0,0));

			QPainter painter(&img);
			painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);

			// Text option
			QFont font("Monospace",8);
			font.setStyleHint(QFont::TypeWriter);
			painter.setFont(font);

			QVector<Structure::Graph*> inBetweens = s.topoVaryingInBetweens( numInBetweens );

			QVector< QVector<double> > scores(numInBetweens);

			int imgWidth = 0;

			for(int k = 0; k < numInBetweens; k++)
			{
				inBetweens[k]->moveCenterTo( AlphaBlend(inBetweens[k]->property["t"].toDouble(), 
					inBetweens[k]->property["sourceGraphCenter"].value<Vector3>(), 
					inBetweens[k]->property["targetGraphCenter"].value<Vector3>()), true);

				// Draw images
				QImage inBetween = b->renderer->quickRender(inBetweens[k], Qt::white);
				imgWidth = inBetween.width();

				// Rendered shape
				int newWidth = inBetween.width() * 0.5;
				int startX = k * newWidth;
				painter.drawImage(startX, 0, inBetween);

				// Store scores
				int idx = inBetweens[k]->property["graphIndex"].toInt();
				QVector<double> vals;
				vals << ps[i].connectivity[idx] << ps[i].localSymmetry[idx] << ps[i].globalSymmetry[idx];

				scores[k] = vals;
			}
			
			// Draw score lines
			for(int u = 0; u < scores.front().size(); u++)
			{
				// Graph
				QPainterPath poly;
				int padding = 0;

				QColor clr = colors[u];
				painter.setPen(QPen(clr, 1));

				// Render path
				for(int k = 0; k < numInBetweens; k++)
				{
					// Score graph
					//double minVal = ranges(u,0);
					//double range = ranges(u,2);

					//double val = (scores[k][u] - minVal) / range;
					double val = scores[k][u];

					// Graph line
					int newWidth = imgWidth * 0.5;
					int startX = k * newWidth;
					int x = startX + newWidth;
					int y = padding + (img.height() - (img.height() * val));

					if(k == 0)
						poly.moveTo(x, y);
					else
						poly.lineTo(x, y);

					// Dots
					painter.drawEllipse(QPoint(x,y), 2, 2);
				}

				painter.setBrush(Qt::NoBrush);
				painter.drawPath(poly);
			}

			// Draw ranges
			QStringList vals;
			for(int r = 0; r < 3; r++){
				QStringList curVals;
				for(int c = 0; c < 4; c++)
					curVals << QString::number(ranges(r,c),'f',2);
				vals << curVals.join("  ");
			}

			if( false )
			{
				painter.setPen(Qt::white);
				painter.drawText(11, img.height() - 9, vals.join("   #   "));

				painter.setPen(Qt::black);
				painter.drawText(10, img.height() - 10, vals.join("   #   "));
			}

			img.save( path + QString("/images/%1.png").arg(i) );
		}
	}

	// Get global average for the measures
	Vector3d globalAvg (allRanges.col(9).mean(), allRanges.col(10).mean(), allRanges.col(11).mean());

	// Sort based on score
	QMap<int,double> scoreMap;
	for(int i = 0; i < numPaths; i++) scoreMap[i] = ps[i].score();

	QVector<int> sortedIndices;
	typedef QPair<double,int> ValIdx;
	foreach(ValIdx d, sortQMapByValue( scoreMap )){
		sortedIndices.push_back( d.second );
	}
Esempio n. 2
0
// *************************************************************
//   Configuration helpers
// *************************************************************
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("PSSL_Test"));


  if (cfg.parse_args (argc, argv) < 0)
    return -1;

  disable_signal (ACE_SIGRTMIN, ACE_SIGRTMAX);
  disable_signal (SIGPIPE, SIGPIPE);
  disable_signal (SIGIO, SIGIO);

  //ACE_DEBUG ((LM_DEBUG,
  //            ACE_TEXT ("FD_SETSIZE=%d ACE_FDSETSIZE=%d\n"),
  //            FD_SETSIZE,
  //            ACE_FD_SETSIZE));

  ACE_DEBUG ((LM_DEBUG,
             "s_blksize=%u r_blksize=%u win_size=%u\n",
              cfg.s_blksize(),
              cfg.r_blksize(),
              cfg.w_size()));

  ACE_SSL_Context *context = ACE_SSL_Context::instance ();
  // Note - the next two strings are naked on purpose... the arguments to
  // the ACE_SSL_Context methods are const char *, not ACE_TCHAR *.
  context->certificate ("dummy.pem", SSL_FILETYPE_PEM);
  context->private_key ("key.pem", SSL_FILETYPE_PEM);


  {
  int rc = 0;

  ProactorTask task1(cfg);

  RecvFactory r_factory;
  SendFactory s_factory;

  PSessionManager r_manager (task1, r_factory,"R_Manager");
  PSessionManager s_manager (task1, s_factory,"S_Manager");

  Acceptor  acceptor  (r_manager);
  Connector connector (s_manager);

  ACE_Time_Value time_begin = ACE_OS::gettimeofday ();
  ACE_Time_Value time_end = ACE_OS::gettimeofday ();
  ACE_Time_Value time_run;

  if (task1.start () == 0)
    {
      ACE_Time_Value timeout (cfg.timeout(), 0);
      r_manager.set_timeout (timeout);
      s_manager.set_timeout (timeout);

      if (cfg.both() != 0 || cfg.connections () == 0) // Acceptor
        {
          // Simplify, initial read with zero size
          if (acceptor.start (ACE_INET_Addr (cfg.listen_port())) == 0)
            rc = 1;
        }

      if (cfg.both() != 0 || cfg.connections () > 0) // Connector
        {
          ACE_INET_Addr addr;

          addr.set (cfg.connect_port(), cfg.connect_host());

          rc += connector.start (addr, cfg.connections ());
        }

      time_begin = ACE_OS::gettimeofday ();

      if (rc > 0)
        {
          task1.enable_event_loop();
          
          ACE_Time_Value  sleep_time (cfg.seconds());
           
          while ( sleep_time != ACE_Time_Value::zero)
            {
              ACE_Countdown_Time countdown ( & sleep_time );

              ACE_OS::sleep (sleep_time );
            }


          if (cfg.seconds () == 0)
            {
              // comment this later
              char c;
              cout << "Press any key to stop=>" << flush;
              cin.clear ();
              cin >> c;
            }
        }
Esempio n. 3
0
// *************************************************************
//   Configuration helpers
// *************************************************************
int
run (int argc, ACE_TCHAR *argv[])
{
    int rc = 0;

    ProactorTask task1(cfg);

    RecvFactory r_factory;
    SendFactory s_factory;

    PSessionManager r_manager (task1, r_factory,"R_Manager");
    PSessionManager s_manager (task1, s_factory,"S_Manager");

    Acceptor  acceptor  (r_manager);
    Connector connector (s_manager);

    ACE_Time_Value time_begin = ACE_OS::gettimeofday ();
    ACE_Time_Value time_end = ACE_OS::gettimeofday ();
    ACE_Time_Value time_run;

    if (task1.start () == 0)
    {
        task1.enable_event_loop();

        ACE_Time_Value timeout (cfg.timeout(), 0);
        r_manager.set_timeout (timeout);
        s_manager.set_timeout (timeout);

        if (cfg.both() != 0 || cfg.connections () == 0) // Acceptor
        {
            if (acceptor.start (ACE_INET_Addr (cfg.listen_port())) == 0)
                rc = 1;
        }

        if (cfg.both() != 0 || cfg.connections () > 0) // Connector
        {
            ACE_INET_Addr addr;

            addr.set (cfg.connect_port(), cfg.connect_host());

            rc += connector.start (addr, cfg.connections ());
        }
    }

    time_begin = ACE_OS::gettimeofday ();

    if (rc > 0)
    {
        //task1.enable_event_loop();
        
        ACE_Time_Value  sleep_time (cfg.seconds());
        
        while ( sleep_time != ACE_Time_Value::zero)
        {
            ACE_Countdown_Time countdown ( & sleep_time );
            ACE_OS::sleep (sleep_time );
        }

        if (cfg.seconds () == 0)
        {
            bool flgExit = false;
            for (;!flgExit;)
            {
                char c;
                cout << "\nPress Q to stop=>" << flush;
                cin.clear ();
                cin >> c;
                switch (toupper (c))
                {
                case 'Q':
                    flgExit = true;
                    break;
                case 'P':
                    cout << "\n*** Connector: PendingConnects="
                        << connector.get_ref_cnt()
                        << " Senders="
                        << s_manager.get_number_connections ()
                        << "\n*** Acceptor: PendingAccepts="
                        << acceptor.get_ref_cnt()
                        << " Receivers="
                        << r_manager.get_number_connections ();
                break;
                }//switch
            }//for
        }//if cfg.seconds
Esempio n. 4
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("W_Test"));


  if (cfg.parse_args (argc, argv) < 0)
    return -1;

  disable_signal (ACE_SIGRTMIN, ACE_SIGRTMAX);
  disable_signal (SIGPIPE, SIGPIPE);
  disable_signal (SIGIO, SIGIO);

  //ACE_DEBUG ((LM_DEBUG,
  //            ACE_TEXT ("FD_SETSIZE=%d ACE_FDSETSIZE=%d\n"),
  //            FD_SETSIZE,
  //            ACE_FD_SETSIZE));

  ACE_DEBUG ((LM_DEBUG,
             "s_blksize=%u r_blksize=%u win_size=%u\n",
              cfg.s_blksize(),
              cfg.r_blksize(),
              cfg.w_size()));


  ACE_SSL_Context *context = ACE_SSL_Context::instance ();
  // Note - the next two strings are naked on purpose... the arguments to
  // the ACE_SSL_Context methods are const char *, not ACE_TCHAR *.
  context->certificate ("dummy.pem", SSL_FILETYPE_PEM);
  context->private_key ("key.pem", SSL_FILETYPE_PEM);


  {
  int rc = 0;

  ProactorTask task1(cfg);

  RecvFactory    r_factory;
  RecvFactorySSL r_ssl_factory;

  PConnectionManager r_manager     (task1, r_factory,"R_Manager");
  PConnectionManager r_ssl_manager (task1, r_ssl_factory,"R_SSL_Manager");

  Acceptor  acceptor     (r_manager);
  Acceptor  acceptor_ssl (r_ssl_manager);

  ACE_Time_Value time_begin = ACE_OS::gettimeofday ();
  ACE_Time_Value time_end = ACE_OS::gettimeofday ();
  ACE_Time_Value time_run;

  if (task1.start () == 0)
    {
      ACE_Time_Value timeout (cfg.timeout(), 0);
      r_manager.set_timeout (timeout);

      // Simplify, initial read with zero size
      if (acceptor.start (ACE_INET_Addr (cfg.listen_port())) == 0)
        rc = 1;

      if (acceptor_ssl.start (ACE_INET_Addr (cfg.listen_port()+1)) == 0)
        rc = 1;

      time_begin = ACE_OS::gettimeofday ();

      if (rc > 0)
        {
          task1.enable_event_loop();
          
          char c;
          cout << "Press any key to stop=>" << flush;
          cin.clear ();
          cin >> c;
        }
    }
Esempio n. 5
0
// *************************************************************
//   Configuration helpers
// *************************************************************
int
run (int argc, ACE_TCHAR *argv[])
{
    int rc = 0;

    ProactorTask task1(cfg);
    if (task1.start () != 0)
    {
        task1.stop ();
        return -1;
    }
    
    task1.enable_event_loop();
    
    RecvFactory r_factory;
    SendFactory s_factory;

    PConnectionManager r_manager (task1, r_factory,"R_Manager");
    PConnectionManager s_manager (task1, s_factory,"S_Manager");

    Acceptor  acceptor  (r_manager);
    Connector connector (s_manager);

    ACE_Time_Value time_begin = ACE_OS::gettimeofday ();
    ACE_Time_Value time_end = ACE_OS::gettimeofday ();
    ACE_Time_Value time_run;

            
    ACE_Time_Value timeout (cfg.timeout(), 0);
    r_manager.set_timeout (timeout);
    s_manager.set_timeout (timeout);
    
    
    time_begin = ACE_OS::gettimeofday ();
    
    

    if (cfg.both() != 0 || cfg.connections () == 0) // Acceptor
    {
        // Simplify, initial read with zero size
        if (acceptor.start (ACE_INET_Addr (cfg.listen_port())) == 0)
            rc = 1;
    }

    if (cfg.both() != 0 || cfg.connections () > 0) // Connector
    {
        ACE_INET_Addr addr;

        addr.set (cfg.connect_port(), cfg.connect_host());

        rc += connector.start (addr, cfg.connections ());
    }
    

    if (rc > 0)
    {
        //task1.enable_event_loop();
            
        ACE_Time_Value  sleep_time (cfg.seconds());
            
        while ( sleep_time != ACE_Time_Value::zero)
        {
            ACE_Countdown_Time countdown ( & sleep_time );

            ACE_OS::sleep (sleep_time );
        }


        if (cfg.seconds () == 0)
        {
            bool flgExit = false;
            for (;!flgExit;)
            {
                char c;
                cout << "\nEnter:"
                     << "\n1 - stop  connector"
                     << "\n2 - stop  acceptor"
                     << "\n3  -stop  senders"
                     << "\n4  -stop  receivers"
                     << "\nP - statistic"
                     << "\nQ   quit=>" 
                     << flush;
                cin.clear ();
                cin >> c;
                switch (toupper (c))
                {
                case '1':
                    connector.cancel();
                    connector.wait ();
                    break;
                case '2':
                    acceptor.cancel ();
                    acceptor.wait();
                    break;
                case '3':
                    s_manager.cancel ();
                    while (!s_manager.is_safe_to_delete ())
                    {
                       task1.wait_signal ();
                    }
                    break;
                case '4':
                    r_manager.cancel ();
                    while (!r_manager.is_safe_to_delete ())
                    {
                       task1.wait_signal ();
                    }
                    break;
                case 'Q':
                    flgExit = true;
                    break;
                case 'P':
                    break;
                }//switch
                cout << "\n*** Connector: PendingConnects="
                    << connector.get_pending_count ()
                    << " Senders="
                    << s_manager.get_number_connections ()
                    << "\n*** Acceptor: PendingAccepts="
                    << acceptor.get_pending_count ()
                    << " Receivers="
                    << r_manager.get_number_connections ();
            }//for
        }//if cfg.seconds