Esempio n. 1
0
    double run() {
      Setup(lattice).setup();
      Solver solver(lattice);

      TimeTracker tt;
      tt.start();
      solver.run();
      tt.stop();

      return tt.elapsedSeconds();

    }
Esempio n. 2
0
// Very simple
void greedy() {

  TimeTracker tt;

  tt.start();

  // Could be optimized a LOT
  bool changed;
  do{
    changed = false;
    for(node_ptr n = lattice.begin(); n != lattice.end(); ++n) {
      if(n->gain > 0) {
	flipNode<3>(n);
	changed = true;
      }
    }
  }while(changed);

  tt.stop();

  cout << "Greedy finished in " << tt.asString() << "." << endl;
}
Esempio n. 3
0
template <int nd, typename Kernel> void run_benchmark(char mode, size_t edge_size, size_t random_seed) {

  typedef typename Indexer<nd>::index_vect index_vect;
  
  vector<dtype> X;

  ImageOptions opt;

  construct_random_bitmap<nd>(X, edge_size, opt, 10000 + random_seed);

  index_vect dimensions(edge_size); 

  // Now run it...
  TimeTracker tt;

  tt.start();
  _LatticeEnergy<nd, Kernel, dtype> le_qbp(dimensions);
  GraphCutEnergyWrapper<nd> le_gc(dimensions);

  make<nd>(&le_qbp, &le_gc, mode, opt, X, edge_size);

  tt.stop();

  cout << "Time taken in setup = " << tt.asString() << "." << endl;


  cout << "Starting LatticeEnergy version." << endl;
  tt.reset();
  tt.start();
  le_qbp.run();
  tt.stop();
  cout << "Time taken in QBP optimization = " << tt.asString() << "." << endl;

  cout << "Starting GraphCuts version." << endl;
  tt.reset();
  tt.start();
  le_gc.run();
  tt.stop();
  cout << "Time taken in GC optimization = " << tt.asString() << "." << endl;

  size_t n_pos = 0;
  size_t n_neg = 0;
  size_t fpos_mismatch_count = 0;
  size_t fneg_mismatch_count = 0;
  
  for(IndexIterator<nd> idxit(dimensions); !idxit.done(); ++idxit) {
    bool q_on  = le_qbp.on(idxit.coords());
    bool gc_on = le_gc.on(idxit.coords());

    if(!q_on && gc_on)
      ++fneg_mismatch_count;

    if(q_on && !gc_on)
      ++fpos_mismatch_count;

    ++(q_on ? n_pos : n_neg);
  }
  
  if( (fneg_mismatch_count + fpos_mismatch_count) != 0) {
    cout << "WARNING: mismatch count between QBP and GC is " 
	 << (fneg_mismatch_count + fpos_mismatch_count) 
	 << " (false negatives = " << fneg_mismatch_count
	 << ", false positives = " << fpos_mismatch_count 
	 << ", total negatives = " << n_neg
	 << ", total positives = " << n_pos
	 << ")"
	 << "!" << endl;
  } else {
    cout << "Solutions exactly match." << endl;
  }
}