예제 #1
0
void BP_dual::calcBeliefV( size_t i ) {
    Prob prod( fg().var(i).states(), 1.0 );
    diaforeach( const Neighbor &I, fg().nbV(i) )
        prod *= msgM(i,I.iter);
    _beliefs.Zb1[i] = prod.normalize();
    _beliefs.b1[i] = prod;
}
예제 #2
0
TAO::PG_Group_List_Store::PG_Group_List_Store (
  Storable_Factory & storable_factory)
  : next_group_id_ (0)
  , storable_factory_ (storable_factory)
  , loaded_from_stream_ (false)
  , last_changed_ (0)
  , stale_ (false)
{
  // Create a temporary stream simply to check if a readable
  // version already exists.
  bool stream_exists = false;
  {
    ACE_Auto_Ptr<TAO::Storable_Base> stream (
      this->create_stream ("r"));

    if (stream->exists ())
      stream_exists = true;
  }

  if (stream_exists)
    {
      File_Guard fg(*this, SFG::CREATE_WITH_FILE);
    }
  else
    {
      File_Guard fg(*this, SFG::CREATE_WITHOUT_FILE);
      this->write (fg.peer ());
    }
}
예제 #3
0
파일: Savable.cpp 프로젝트: manut/TAO
Savable::Savable (TAO::Storable_Factory & storable_factory)
  : storable_factory_(storable_factory)
  , loaded_from_stream_ (false)
{

  for (int index = 0; index < 2; ++index)
    {
      this->i_[index] = 0;
      this->ui_[index] = 0;
      this->bytes_size_[index] = 0;
      this->bytes_[index] = new char [this->bytes_size_max];
      for (int i = 0; i < this->bytes_size_max; ++i)
        {
          this->bytes_[index][i] = ACE_CHAR_MAX;
        }
    }

  ACE_Auto_Ptr<TAO::Storable_Base>
    stream (storable_factory_.create_stream("test.dat", "r"));
  if (stream->exists ())
    {
      Savable_File_Guard fg(*this, SFG::CREATE_WITH_FILE);
    }
  else
    {
      Savable_File_Guard fg(*this, SFG::CREATE_WITHOUT_FILE);
      this->write (fg.peer ());
    }
}
예제 #4
0
void BP_dual::calcNewN( size_t i, size_t _I ) {
    // calculate updated message i->I
    const Neighbor &I = fg().nbV(i)[_I];
    Prob prod( fg().var(i).states(), 1.0 );
    diaforeach( const Neighbor &J, fg().nbV(i) )
        if( J.node != I.node ) // for all J in i \ I
            prod *= msgM(i,J.iter);
    _msgs.Zn[i][_I] = prod.normalize();
    _msgs.n[i][_I] = prod;
}
예제 #5
0
void BP_dual::calcBeliefF( size_t I ) {
    Prob prod( fg().factor(I).p() );
    diaforeach( const Neighbor &j, fg().nbF(I) ) {
        IndexFor ind( fg().var(j), fg().factor(I).vars() );
        Prob n( msgN(j,j.dual) );
        for( size_t x = 0; ind.valid(); x++, ++ind )
            prod.set( x, prod[x] * n[ind] );
    }
    _beliefs.Zb2[I] = prod.normalize();
    _beliefs.b2[I] = prod;
}
예제 #6
0
파일: main.cpp 프로젝트: adiog/tbb
int main(int argc, char *argv[])
{
    try{
        tbb::tick_count mainStartTime = tbb::tick_count::now();

        // It is used for console mode for test with different number of threads and also has
        // meaning for GUI: threads.first  - use separate event/updating loop thread (>0) or not (0).
        //                  threads.second - initialization value for scheduler
        utility::thread_number_range threads( tbb::task_scheduler_init::default_num_threads );
        int num_frames = -1;
        int max_iterations = 1000000;

        // command line parsing
        utility::parse_cli_arguments(argc,argv,
            utility::cli_argument_pack()
            //"-h" option for displaying help is present implicitly
            .positional_arg(threads,"n-of-threads",utility::thread_number_range_desc)
            .positional_arg(num_frames,"n-of-frames","number of frames the example processes internally")
            .positional_arg(max_iterations,"max-of-iterations","maximum number of the fractal iterations")
            .positional_arg(grain_size,"grain-size","the grain size value")
            .arg(schedule_auto, "use-auto-partitioner", "use tbb::auto_partitioner")
            .arg(silent, "silent", "no output except elapsed time")
            .arg(single, "single", "process only one fractal")
        );

        fractal_video video;

        // video layer init
        if ( video.init_window(1024, 512) ) {
            video.calc_fps = false;
            video.threaded = threads.first > 0;
            // initialize fractal group
            fractal_group fg( video.get_drawing_memory(), threads.last, max_iterations, num_frames );
            video.set_fractal_group( fg );
            // main loop
            video.main_loop();
        }
        else if ( video.init_console() ) {
            // in console mode we always have limited number of frames
            num_frames = num_frames<0 ? 1 : num_frames;
            for(int p = threads.first;  p <= threads.last; p = threads.step(p) ) {
                if ( !silent ) printf("Threads = %d\n", p);
                fractal_group fg( video.get_drawing_memory(), p, max_iterations, num_frames );
                fg.run( !single );
            }
        }
        video.terminate();
        utility::report_elapsed_time((tbb::tick_count::now() - mainStartTime).seconds());
        return 0;
    } catch ( std::exception& e ) {
        std::cerr<<"error occurred. error text is :\"" <<e.what()<<"\"\n";
        return 1;
    }
}
예제 #7
0
void BP_dual::regenerateMessages() {
    size_t nv = fg().nrVars();
    _msgs.Zn.resize(nv);
    _msgs.Zm.resize(nv);
    _msgs.m.resize(nv);
    _msgs.n.resize(nv);
    for( size_t i = 0; i < nv; i++ ) {
        size_t nvf = fg().nbV(i).size();
        _msgs.Zn[i].resize(nvf, 1.0);
        _msgs.Zm[i].resize(nvf, 1.0);
        size_t states = fg().var(i).states();
        _msgs.n[i].resize(nvf, Prob(states));
        _msgs.m[i].resize(nvf, Prob(states));
    }
}
예제 #8
0
void
guard_die_spiked (struct anim *g)
{
  if (fg (&g->p) != SPIKES_FLOOR) {
    guard_die_properly (g);
    return;
  }

  g->oaction = g->action;
  g->action = guard_die_spiked;
  g->f.flip = (g->f.dir == RIGHT) ? ALLEGRO_FLIP_HORIZONTAL : 0;

  assert (fg (&g->p) == SPIKES_FLOOR);
  struct spikes_floor *s = spikes_floor_at_pos (&g->p);

  if (s->i != 4 || s->state != 5 || ! s->inactive) {
    s->i = 4;
    s->state = 5;
    s->inactive = true;
    register_changed_pos (&g->p);
  }

  if (g->oaction != guard_die_spiked) {
    g->splash = true;
    g->death_reason = SPIKES_DEATH;

    if (g->type == SKELETON)
      play_audio (&skeleton_audio, NULL, g->id);
    else play_audio (&spiked_audio, NULL, g->id);

    if (! g->glory_sample) {
      play_audio (&glory_audio, NULL, g->id);
      g->glory_sample = true;
    }
  }

  g->current_lives = 0;

  int dy;
  if (g->type == SKELETON) dy = +45;
  else dy = (g->f.dir == LEFT) ? +32 : +31;

  ALLEGRO_BITMAP *bitmap = get_guard_die_spiked_bitmap (g->type);
  place_frame (&g->f, &g->f, bitmap,
               &g->p, (g->f.dir == LEFT) ? +8 : +9, dy);

  g->xf.b = NULL;
}
예제 #9
0
	void FragmentTree::processFragment(const CleavageCollection& cc, MassLossWindow mlw)
	{	
		FragmentPtr fg(new Fragment(glycan_seq));
		fg->updateCleavage(cc);

		//std::string final_type = fg->getCleavageType();
		
		// Modify the MassLossWindow based on the possibility of modification sites.
		std::set<std::string> mod_types = glycan_seq->getModificationTypes();

		for(std::set<std::string>::iterator iter = mod_types.begin(); iter != mod_types.end(); iter++)
		{
			int num = (int)fg->getModificationSiteNum(*iter, 1);
			Composition temp_compo;
			if(*iter == "SO3") {
				temp_compo.add("SO3");
				int upper_num = glycan_seq->getModificationConstraint("SO3");
				if(num > upper_num)
					num = upper_num;
			} else if(*iter == "Ac") {
				temp_compo.add("CH2CO");
				int upper_num = glycan_seq->getModificationConstraint("Ac");
				if(num > upper_num)
					num = upper_num;
			}
			if(num != 0) mlw.push_back(MassLoss(temp_compo, 0, -1 * num));

		}
		
		this->processFragment(fg, mlw, 0, Satellite());
	}
예제 #10
0
파일: Savable.cpp 프로젝트: manut/TAO
void
Savable::string_set (int index, const ACE_CString &s)
{
  Savable_File_Guard fg(*this, SFG::MUTATOR);
  this->string_[index] = s;
  this->write (fg.peer ());
}
예제 #11
0
파일: cursor.cpp 프로젝트: davekilian/lwt
void Cursor::render(QPainter &p)
{
    // Do nothing if the cursor currently isn't visible
    if (m_hidden || !m_blinkVisible)
        return;

    // Find out where the cursor is
    QFont font(TERMINAL_FONT_FAMILY, TERMINAL_FONT_HEIGHT);
    font.setHintingPreference(QFont::PreferFullHinting);

    QFontMetrics fm(font);
    int w = fm.averageCharWidth(),
        h = fm.lineSpacing(),
        x = m_col * w,
        y = m_row * h - m_parent->scrollAmount();

    // Draw the cursor itself
    QBrush fg(m_parent->foregroundColorAt(m_row, m_col));
    p.fillRect(x, y + fm.descent(), w, fm.ascent() + fm.descent(), fg);
    
    // Draw the inverted character the cursor is over
    p.setFont(font);
    p.setPen(QColor(m_parent->backgroundColorAt(m_row, m_col)));

    QChar c = m_parent->history().charAt(m_row, m_col);
    p.drawText(x, y + fm.lineSpacing(), QString(c));
}
예제 #12
0
void Exec()
{
    if(strcmp(CmdBuf[CmdNum-1].args[0],"bg")==0)
         bg();
    else if(strcmp(CmdBuf[CmdNum-1].args[0],"fg")==0)
         fg();
    else if(strcmp(CmdBuf[CmdNum-1].args[0],"cd")==0)
    {
        if(chdir(CmdBuf[CmdNum-1].args[1])<0)
             printf("目录不正确!!\n");
    }
    else if(strcmp(CmdBuf[CmdNum-1].args[0],"history")==0)
         ListHis();
    else if(strcmp(CmdBuf[CmdNum-1].args[0],"jobs")==0)
         ListJob();
    else if(strcmp(CmdBuf[CmdNum-1].args[0],"exit")==0)
    {
        DelHis();
        freeJob();
        exit(0);
    }
    else if(strcmp(CmdBuf[CmdNum-1].args[0],"rm")==0)
        beforeRemove(CmdBuf[CmdNum-1].args[1]);
    else
         ExecOut();
}
예제 #13
0
        void button::draw()
        {
            color old_fg = get_foreground();
            color old_bg = get_background();

            if (down_tick)
            {
                if ((SDL_GetTicks() - down_tick) < 100)
                {
                    get_foreground() = old_bg;
                    get_background() = old_fg;
                }
                else
                {
                    down_tick = 0;
                }
            }

            textbox::draw();

            // border
            display::scoped_color fg(get_screen(), get_foreground());
            get_screen().draw_line_2d(0, 0, get_w(), 0);
            get_screen().draw_line_2d(get_w(), 0, get_w(), get_h());
            get_screen().draw_line_2d(get_w(), get_h(), 0, get_h());
            get_screen().draw_line_2d(0, get_h(), 0, 0);

            if (down_tick)
            {
                get_foreground() = old_fg;
                get_background() = old_bg;
            }
        } // button::draw()
예제 #14
0
파일: Savable.cpp 프로젝트: manut/TAO
void
Savable::unsigned_int_set (int index, unsigned int ui)
{
  Savable_File_Guard fg(*this, SFG::MUTATOR);
  this->ui_[index] = ui;
  this->write (fg.peer ());
}
예제 #15
0
/** Find a maximum size matching in a bipartite graph
 *  by reducing the matching problem to a max flow problem.
 *  @param[in] g is a graph
 *  @param[in,out] matchingEdge[u] is (on return) the matching edge incident
 *  to u or 0 if u is unmatched; if matchingEdge is not all 0 initially,
 *  it is assumed to represent a valid initial matching
 */
void matchb_f(const Graph& g, edge *matchingEdge) {
	// divide vertices into two independent sets
	ListPair split(g.n());
	if (!findSplit(g,split))
		Util::fatal("matchb_f: graph is not bipartite");

	// create flow graph, taking care to maintain edge numbers
	Graph_f fg(g.n()+2, g.M()+g.n(), g.n()+1, g.n()+2);
	for (edge e = g.first(); e != 0; e = g.next(e)) {
		vertex u = (split.isIn(g.left(e)) ? g.left(e) : g.right(e));
		fg.joinWith(u,g.mate(u,e),e); fg.setCapacity(e,1);
		if (e == matchingEdge[u]) fg.setFlow(e,1);
	}
	for (vertex u = split.firstIn(); u != 0; u = split.nextIn(u)) {
		edge e = fg.join(fg.src(),u); fg.setCapacity(e,1);
		if (e == matchingEdge[u]) fg.setFlow(e,1);
	}
	for (vertex u = split.firstOut(); u != 0; u = split.nextOut(u)) {
		edge e = fg.join(u,fg.snk()); 
		fg.setCapacity(e,1);
		if (e == matchingEdge[u]) fg.setFlow(e,1);
	}

	// solve flow problem
	(mflo_d(fg)); // parens added to eliminate ambiguity

	// now construct matching from flow
	for (vertex u = 1; u <= g.n(); u++) matchingEdge[u] = 0;
	for (edge e = g.first(); e != 0; e = g.next(e)) {
		vertex u = (split.isIn(g.left(e)) ? g.left(e) : g.right(e));
		if (fg.f(u,e) != 0)
			matchingEdge[u] = matchingEdge[g.mate(u,e)] = e;
	}
}
void KisGradientBenchmark::benchmarkGradient()
{
    KoColor fg(m_colorSpace);
    KoColor bg(m_colorSpace);
    fg.fromQColor(Qt::blue);
    bg.fromQColor(Qt::black);
    
    QBENCHMARK
    {
        QLinearGradient grad;
        grad.setColorAt(0, Qt::white);
        grad.setColorAt(1.0, Qt::red);
        KoAbstractGradient* kograd = KoStopGradient::fromQGradient(&grad);
        Q_ASSERT(kograd);
        KisGradientPainter fillPainter(m_device);
        //setupPainter(&fillPainter);
        fillPainter.setGradient(kograd);

        fillPainter.beginTransaction(kundo2_noi18n("Gradient Fill"));

        //fillPainter.setProgress(updater->startSubtask());
        fillPainter.setOpacity(OPACITY_OPAQUE_U8);
        // default
        fillPainter.setCompositeOp(COMPOSITE_OVER);
        fillPainter.setGradientShape(KisGradientPainter::GradientShapeBiLinear);
        fillPainter.paintGradient(QPointF(0,0), QPointF(3000,3000), KisGradientPainter::GradientRepeatNone, true, false, 0, 0, GMP_IMAGE_WIDTH,GMP_IMAGE_HEIGHT);

        fillPainter.deleteTransaction();
    }
    
    // uncomment this to see the output
    QImage out = m_device->convertToQImage(m_colorSpace->profile(),0,0,GMP_IMAGE_WIDTH,GMP_IMAGE_HEIGHT);
    out.save("fill_output.png");
}
예제 #17
0
void
guard_die_chopped (struct anim *g)
{
  if (fg (&g->p) != CHOPPER) {
    guard_die_properly (g);
    return;
  }

  g->oaction = g->action;
  g->action = guard_die_chopped;
  g->f.flip = (g->f.dir == RIGHT) ? ALLEGRO_FLIP_HORIZONTAL : 0;

  int dx, dy;

  if (g->type == SHADOW) {
    dx = (g->f.dir == LEFT) ? -8 : -7;
    dy = +47;
  } else {
    dx = (g->f.dir == LEFT) ? -10 : -13;
    dy = (g->type == SKELETON) ? +45 : +43;
  }

  ALLEGRO_BITMAP *bitmap = get_guard_die_chopped_bitmap (g->type);
  place_frame (&g->f, &g->f, bitmap, &g->p, dx, dy);

  if (g->oaction != guard_die_chopped
      && ! g->glory_sample) {
    play_audio (&glory_audio, NULL, g->id);
    g->glory_sample = true;
  }

  g->current_lives = 0;
  g->xf.b = NULL;
}
예제 #18
0
main(int argc, char* argv[]) {
	int i, reps, n, m, mss, ec1, ec2, span, floVal;
	if (argc != 8 ||
	    sscanf(argv[2],"%d",&reps) != 1 ||
	    sscanf(argv[3],"%d",&n) != 1 ||
	    sscanf(argv[4],"%d",&m) != 1 ||
	    sscanf(argv[5],"%d",&mss) != 1 ||
	    sscanf(argv[6],"%d",&ec1) != 1 ||
	    sscanf(argv[7],"%d",&ec2) != 1)
		fatal("usage: maxFloRep method reps n m mss ec1 ec2");

	Flograph fg(n,m,1,2); 
	for (i = 1; i <= reps; i++) {
		fg.rgraph(n,m,mss); fg.randCapacity(ec1,ec2);

		if (strcmp(argv[1],"maxCap") == 0)
			maxCap(fg,floVal);
		else if (strcmp(argv[1],"capScale") == 0)
			capScale(fg,floVal);
		else if (strcmp(argv[1],"shortPath") == 0)
			shortPath(fg,floVal);
		else if (strcmp(argv[1],"dinic") == 0)
			dinic(fg,floVal);
		else if (strcmp(argv[1],"dinicDtrees") == 0)
			dinicDtrees(fg,floVal);
		else if (strcmp(argv[1],"ppFifo") == 0)
			ppFifo(fg,floVal,false);
		else if (strcmp(argv[1],"ppFifoBatch") == 0)
			ppFifo(fg,floVal,true);
		else
			fatal("maxFloRep: undefined method");
	}
}
예제 #19
0
파일: fight.c 프로젝트: oitofelix/mininim
bool
is_safe_at_left (struct pos *p)
{
  enum confg t = fg (p);

  return t != WALL && t != CHOPPER && t != MIRROR;
}
예제 #20
0
파일: Savable.cpp 프로젝트: manut/TAO
void
Savable::int_set (int index, int i)
{
  Savable_File_Guard fg(*this, SFG::MUTATOR);
  this->i_[index] = i;
  this->write (fg.peer ());
}
예제 #21
0
void SettingsDialog::updateColorToolButtonColor(QToolButton* but)
{
  QString tmpl("QToolButton { background-color: %1; color: %2; }");
  QColor fg(SETTINGS->get("Color", but->text()).toString());
  QColor bg(255 - fg.red(), 255 - fg.green(), 255 - fg.blue(), 25);
  but->setStyleSheet(tmpl.arg(fg.name()).arg(bg.name()));
}
예제 #22
0
QImage TcQrencode::encodeImage(const QString& s, int bulk)
{
    QImage ret;
    QRcode* qr = QRcode_encodeString(s.toUtf8(), 1, QR_ECLEVEL_Q, QR_MODE_8, 0);
    if ( qr != NULL )
    {

        int allBulk = (qr->width) * bulk;
        ret = QImage(allBulk, allBulk, QImage::Format_Mono);
        QPainter painter(&ret);
        QColor fg("black");
        QColor bg("white");
        painter.setBrush(bg);
        painter.setPen(Qt::NoPen);
        painter.drawRect(0, 0, allBulk, allBulk);

        painter.setBrush(fg);
        for( int y=0; y<qr->width; y++ )
        {
            for( int x=0; x<qr->width; x++ )
            {
                if ( qr->data[y*qr->width+x] & 1 )
                {
                    QRectF r(x*bulk, y*bulk, bulk, bulk);
                    painter.drawRects(&r, 1);
                }
            }
        }
        QRcode_free(qr);
    }
    return ret;
}
예제 #23
0
dd::GibbsSampling::GibbsSampling(FactorGraph * const _p_fg, 
  CmdParser * const _p_cmd_parser, int n_datacopy, bool sample_evidence,
  int burn_in, bool learn_non_evidence) 
  : p_fg(_p_fg), p_cmd_parser(_p_cmd_parser), sample_evidence(sample_evidence),
    burn_in(burn_in), learn_non_evidence(learn_non_evidence) {
    // the highest node number available
    n_numa_nodes = numa_max_node(); 

    // if n_datacopy is valid, use it, otherwise, use numa_max_node
    if (n_datacopy >= 1 && n_datacopy <= n_numa_nodes + 1) {
      n_numa_nodes = n_datacopy - 1;
    }

    // max possible threads per NUMA node
    n_thread_per_numa = (sysconf(_SC_NPROCESSORS_CONF))/(n_numa_nodes+1);

    this->factorgraphs.push_back(*p_fg);

    // copy factor graphs
    for(int i=1;i<=n_numa_nodes;i++){

      numa_run_on_node(i);
      numa_set_localalloc();

      std::cout << "CREATE FG ON NODE ..." <<  i << std::endl;
      dd::FactorGraph fg(p_fg->n_var, p_fg->n_factor, p_fg->n_weight, p_fg->n_edge);
      
      fg.copy_from(p_fg);

      this->factorgraphs.push_back(fg);
    }
  };
예제 #24
0
bool FilmGrain::toolOperations()
{
    if (!loadToDImg())
    {
        return false;
    }

    FilmGrainContainer prm;
    prm.grainSize               = settings()["grainSize"].toInt();
    prm.photoDistribution       = settings()["photoDistribution"].toBool();
    prm.addLuminanceNoise       = settings()["addLuminanceNoise"].toBool();
    prm.lumaIntensity           = settings()["lumaIntensity"].toInt();
    prm.lumaShadows             = settings()["lumaShadows"].toInt();
    prm.lumaMidtones            = settings()["lumaMidtones"].toInt();
    prm.lumaHighlights          = settings()["lumaHighlights"].toInt();
    prm.addChrominanceBlueNoise = settings()["addChrominanceBlueNoise"].toBool();
    prm.chromaBlueIntensity     = settings()["chromaBlueIntensity"].toInt();
    prm.chromaBlueShadows       = settings()["chromaBlueShadows"].toInt();
    prm.chromaBlueMidtones      = settings()["chromaBlueMidtones"].toInt();
    prm.chromaBlueHighlights    = settings()["chromaBlueHighlights"].toInt();
    prm.addChrominanceRedNoise  = settings()["addChrominanceRedNoise"].toBool();
    prm.chromaRedIntensity      = settings()["chromaRedIntensity"].toInt();
    prm.chromaRedShadows        = settings()["chromaRedShadows"].toInt();
    prm.chromaRedMidtones       = settings()["chromaRedMidtones"].toInt();
    prm.chromaRedHighlights     = settings()["chromaRedHighlights"].toInt();

    FilmGrainFilter fg(&image(), 0L, prm);
    applyFilter(&fg);

    return savefromDImg();
}
예제 #25
0
void
compute_opener_floors (void)
{
    size_t i;

    for (i = 0; i < opener_floor_nmemb;) {
        struct opener_floor *o = &opener_floor[i];
        if (fg (&o->p) == OPENER_FLOOR) {
            i++;
            continue;
        }
        remove_opener_floor (o);
    }

    for (i = 0; i < opener_floor_nmemb; i++) {
        struct opener_floor *o = &opener_floor[i];
        if (o->pressed && ! o->broken) {
            if (! o->noise) {
                alert_guards (&o->p);
                play_audio (&opener_floor_audio, &o->p, -1);
                o->noise = true;
            }
            open_door (o->p.l, o->event, o->priority, false);
        } else o->noise = false;
    }
}
예제 #26
0
파일: Color.cpp 프로젝트: SEJeff/task
Color::operator std::string () const
{
  std::string description;
#ifdef FEATURE_COLOR
  if (_value & _COLOR_BOLD) description += "bold";

  if (_value & _COLOR_UNDERLINE)
    description += std::string (description.length () ? " " : "") + "underline";

  if (_value & _COLOR_INVERSE)
    description += std::string (description.length () ? " " : "") + "inverse";

  if (_value & _COLOR_HASFG)
    description += std::string (description.length () ? " " : "") + fg ();

  if (_value & _COLOR_HASBG)
  {
    description += std::string (description.length () ? " " : "") + "on";

    if (_value & _COLOR_BRIGHT)
      description += std::string (description.length () ? " " : "") + "bright";

    description += " " + bg ();
  }
#endif

  return description;
}
예제 #27
0
/** Find a maximum size matching in a bipartite graph
 *  by reducing the matching problem to a max flow problem.
 *  @param g1 is an undirected graph
 *  @param match is a list in which the result is returned
 */
void flowMatch(Graph& g, Glist<edge>& match) {
	// divide vertices into two independent sets
	ListPair split(g.n());
	if (!findSplit(g,split))
		Util::fatal("flowMatch: graph is not bipartite");

	// create flow graph, taking care to maintain edge numbers
	Flograph fg(g.n()+2, g.M()+g.n(), g.n()+1, g.n()+2);
	for (edge e = g.first(); e != 0; e = g.next(e)) {
		vertex u = (split.isIn(g.left(e)) ? g.left(e) : g.right(e));
		fg.joinWith(u,g.mate(u,e),e); fg.setCapacity(e,1);
	}
	for (vertex u = split.firstIn(); u != 0; u = split.nextIn(u)) {
		edge e = fg.join(fg.src(),u); fg.setCapacity(e,1);
	}
	for (vertex u = split.firstOut(); u != 0; u = split.nextOut(u)) {
		edge e = fg.join(u,fg.snk()); fg.setCapacity(e,1);
	}

	// solve flow problem
	(dinic(fg)); // parens added to eliminate ambiguity

	// now construct matching from flow
	match.clear();
	for (edge e = g.first(); e != 0; e = g.next(e)) {
		vertex u = (split.isIn(g.left(e)) ? g.left(e) : g.right(e));
		if (fg.f(u,e) != 0) match.addLast(e);
	}
}
예제 #28
0
void QRWidget::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    QRcode *qrcode = QRcode_encodeString(data.constData(), 1, QR_ECLEVEL_L, QR_MODE_8, 1);
    if (qrcode != NULL) {
        QColor fg(Qt::black);
        QColor bg(Qt::white);
        painter.setBrush(bg);
        painter.setPen(Qt::NoPen);
        const double w = width();
        const double h = height();
        painter.drawRect(0, 0, w, h);
        painter.setBrush(fg);
        const int s = qrcode->width > 0 ? qrcode->width : 1;
        const double aspect = w / h;
        const double scale = ((aspect > 1.0) ? h : w) / s;
        for(int y = 0; y < s; y++){
            const int yy = y * s;
            for(int x = 0; x < s; x++){
                const int xx = yy + x;
                const unsigned char b = qrcode->data[xx];
                if(b &0x01){
                    const double rx1 = x * scale, ry1 = y * scale;
                    QRectF r(rx1, ry1, scale, scale);
                    painter.drawRects(&r,1);
                }
            }
        }
        QRcode_free(qrcode);
    }
    else {
        qWarning() << tr("Generating QR code failed.");
    }
}
예제 #29
0
void CodeEditor::onPrefsChanged( const QString &name ){

    QString t( name );

    Prefs *prefs=Prefs::prefs();

    if( t=="" || t=="backgroundColor" || t=="fontFamily" || t=="fontSize" || t=="tabSize" || t=="smoothFonts" ){

        QColor bg=prefs->getColor( "backgroundColor" );
        QColor fg( 255-bg.red(),255-bg.green(),255-bg.blue() );

        QPalette p=palette();
        p.setColor( QPalette::Base,bg );
        p.setColor( QPalette::Text,fg );
        setPalette( p );

        QFont font;
        font.setFamily( prefs->getString( "fontFamily" ) );
        font.setPixelSize( prefs->getInt( "fontSize" ) );

        if( prefs->getBool( "smoothFonts" ) ){
            font.setStyleStrategy( QFont::PreferAntialias );
        }else{
            font.setStyleStrategy( QFont::NoAntialias );
        }

        setFont( font );

        QFontMetrics fm( font );
        setTabStopWidth( fm.width( 'X' )* prefs->getInt( "tabSize" ) );
    }
}
예제 #30
0
PortableGroup::ObjectGroupId
TAO::PG_Group_List_Store::get_next_group_id ()
{
  File_Guard fg(*this, SFG::ACCESSOR);
  PortableGroup::ObjectGroupId next_id = this->next_group_id_;
  ++this->next_group_id_;
  this->write (fg.peer ());
  return next_id;
}