void Miniball<CoordAccessor>::mtf_mb (Sit n)
  {
    // Algorithm 1: mtf_mb (L_{n-1}, B), where L_{n-1} = [L.begin, n)  
    // B: the set of forced points, defining the current ball
    // S: the superset of support points computed by the algorithm
    // --------------------------------------------------------------
    // from B. Gaertner, Fast and Robust Smallest Enclosing Balls, ESA 1999,
    // http://www.inf.ethz.ch/personal/gaertner/texts/own_work/esa99_final.pdf  
  
    //   PRE: B = S  
    assert (fsize == ssize);
   
    support_end = L.begin();
    if ((fsize) == d+1) return;  
  
    // incremental construction
    for (Sit i = L.begin(); i != n;) 
      {
	// INV: (support_end - L.begin() == |S|-|B|)
	assert (std::distance (L.begin(), support_end) == ssize - fsize);
       
	Sit j = i++; 
	if (excess(*j) > nt0) 
	  if (push(*j)) {          // B := B + p_i
	    mtf_mb (j);            // mtf_mb (L_{i-1}, B + p_i)
	    pop();                 // B := B - p_i
	    mtf_move_to_front(j);  
	  }
      }
    // POST: the range [L.begin(), support_end) stores the set S\B
  }
  typename Miniball<CoordAccessor>::NT 
  Miniball<CoordAccessor>::relative_error (NT& subopt) const 
  {
    NT e, max_e = nt0;
    // compute maximum absolute excess of support points
    for (SupportPointIterator it = support_points_begin(); 
	 it != support_points_end(); ++it) {
      e = excess (*it);
      if (e < nt0) e = -e;
      if (e > max_e) {
	max_e = e; 
      }
    }
    // compute maximum excess of any point
    for (Pit i = points_begin; i != points_end; ++i)
      if ((e = excess (i)) > max_e)
	max_e = e;
   
    subopt = suboptimality();
    assert (current_sqr_r > nt0 || max_e == nt0);
    return (current_sqr_r == nt0 ? nt0 : max_e / current_sqr_r);
  }
Example #3
0
typename MatrixT::ScalarType maxflow(MatrixT const        &capacity,
                                     graphblas::IndexType  source,
                                     graphblas::IndexType  sink)
{
    using T = typename MatrixT::ScalarType;
    graphblas::IndexType rows, cols;
    capacity.get_shape(rows,cols);
    graphblas::IndexType num_nodes = rows;

    MatrixT flow(rows,cols);

    MatrixT height(1, num_nodes);
    MatrixT excess(1, num_nodes);
    MatrixT seen(1, num_nodes);

    std::vector<graphblas::IndexType> list;

    for (graphblas::IndexType i = 0; i < num_nodes; ++i)
    {
        if ((i != source) && (i != sink))
        {
            list.push_back(i);
        }
    }

    height.set_value_at(0, source, num_nodes);
    excess.set_value_at(0, source,
                        std::numeric_limits<T>::max());
    for (graphblas::IndexType i = 0; i < num_nodes; ++i)
    {
        push(capacity, flow, excess, source, i);
    }

    graphblas::IndexType  p = 0;
    while (p < (num_nodes - 2))
    {
        graphblas::IndexType u = list[p];
        T old_height = height.get_value_at(0, u);
        discharge(capacity, flow, excess, height, seen, u);
        if (height.get_value_at(0, u) > old_height)
        {
            graphblas::IndexType t = list[p];

            list.erase(list.begin() + p);
            list.insert(list.begin() + 0, t);

            p = 0;
        }
        else
        {
            p += 1;
        }
    }

    T maxflow = static_cast<T>(0);
    for (graphblas::IndexType i = 0; i < num_nodes; ++i)
    {
        maxflow += flow.get_value_at(source, i);
    }

    return maxflow;
}
Example #4
0
File: lztrie.c Project: peper/pizza
uint depthLZTrie (lztrie T, trieNode i)

   { return excess (T->pdata,i);
   }