Exemplo n.º 1
0
static void output_finalized_vertices_for_sorting (
    vertex_list & finalized_vertices,
    vertex_db & vertices,ExtSort* es)
{
    vertex_list::iterator v_ptr = finalized_vertices.begin ();
    while (v_ptr != finalized_vertices.end ())
    {
        vertex_db::iterator v = vertices.find (*v_ptr);
        assert (v != vertices.end ()); // Do not comment out this line

        ///

        Vertex_info* temp = new Vertex_info();
        temp->vid = v->first;
        temp->vi  = v->second;
#ifndef NDEBUG
        std::cout << "\ninserting: "<< temp->vid << " :" << temp->vi.coords[0] << "," << temp->vi.coords[1] << temp->vi.coords[2];
#endif

        es->insert(temp);

//        v->second.output_in_binary (*v_ptr, YOUR_STREAM_HERE);
        vertices.erase (v);
        v_ptr++;
    }
    finalized_vertices.clear ();
}
Exemplo n.º 2
0
polygon::polygon (const vertex_list& vert){
   DEBUGF ('c', this);
   vertex_list v;
   GLfloat xavg = 0;
   GLfloat yavg = 0;
   for(size_t i = 0; i < vert.size(); i++){
      xavg += vert[i].xpos; yavg += vert[i].ypos;
   }
   xavg /= vert.size(); yavg /= vert.size();
   for(size_t i = 0; i < vert.size(); i++)
      v.push_back({vert[i].xpos - xavg, vert[i].ypos - yavg});
   vertices = v;
}
Exemplo n.º 3
0
static void output_finalized_vertices_for_sorting (
    vertex_list & finalized_vertices,
    dias::vertex_db & vertices,
    dias::ExtSort* es)
{
    vertex_list::iterator v_ptr = finalized_vertices.begin ();
    while (v_ptr != finalized_vertices.end ())
    {
        dias::vertex_db::iterator v = vertices.find (*v_ptr);
        assert (v != vertices.end ()); // Do not comment out this line

        dias::Vertex_info* temp = new dias::Vertex_info();
        temp->vid = v->first;
        temp->vi  = v->second;

        es->insert(temp);

        vertices.erase (v);
        v_ptr++;
    }
    finalized_vertices.clear ();
}
Exemplo n.º 4
0
std::vector<double> dissimilarity_subsets_sp(
  const adjacency_array<vid_t>& adj,
  const vertex_list& s, const redwalk::MatrixUS& sp)
{
  const idx_t nv = adj.vcount();
  const idx_t ns = s.size();

  //to check if a vertex is a target
  std::vector<bool> is_targ(nv, false);
  for(idx_t i = 0; i < ns; i++)
    is_targ[s[i]] = true;

  //Set up triplet list for sparse matrix
  typedef Eigen::Triplet<redwalk::flt_t> Triplet;
  std::vector<Triplet> tripletList;
  tripletList.reserve(nv + 2 * adj.ecount()); //TODO: reserve exact or close to

  //Build the tripletlist
  for(idx_t i = 0; i < nv; i++)
  {
    tripletList.push_back(Triplet(i, i, redwalk::ONE_F));
    if(!is_targ[i])
    {
      redwalk::flt_t val = redwalk::NEG_ONE_F / (redwalk::flt_t)adj.degree(i);
      NeighborhoodList<vid_t> nbrs = adj[i];
      NeighborhoodList<vid_t>::iterator nitr;
      for(nitr = nbrs.begin(); nitr != nbrs.end(); nitr++)
        tripletList.push_back(Triplet(i,*nitr,val));
    }
  }

  //set up the random walk normalized laplacian
  Eigen::SparseMatrix<redwalk::flt_t> L(nv, nv);
  L.setFromTriplets(tripletList.begin(), tripletList.end());
  L.makeCompressed();

  //free the triplets
  std::vector<Triplet>().swap(tripletList);

  //factor the RWNL
  Eigen::SparseLU<Eigen::SparseMatrix<redwalk::flt_t, Eigen::ColMajor>,
                  Eigen::COLAMDOrdering<int> > solver;
  solver.analyzePattern(L);
  solver.factorize(L);

  //setup b
  redwalk::MatrixF b(nv, ns);
  b.fill(0);
  for(idx_t i = 0; i < ns; i++)
    b.row(s[i]) = sp.col(i).cast<redwalk::flt_t>();

  //Solve
  const redwalk::MatrixF x = solver.solve(b);

  //Free b
  b.resize(0,0);

  //Free L
  Eigen::SparseMatrix<redwalk::flt_t, Eigen::ColMajor>().swap(L);

  //Allocate D - what will become a "dist"
  //number of entries in contiguous symmetric matrix with no diagonal
  std::vector<double> D((ns * ns - ns) >> 1, 0.0);

  idx_t idx = 0;
  redwalk::flt_t mspi, mspj;
  for(idx_t i = 0; i < (ns-1); i++)
  {
    vid_t ti = s[i];
    idx_t degi = adj.degree(ti);
    NeighborhoodList<vid_t> nbrsi = adj[ti];
    for(idx_t j = i+1; j < ns; j++)
    {
      vid_t tj = s[j];
      idx_t degj = adj.degree(tj);
      NeighborhoodList<vid_t> nbrsj = adj[tj];
      mspi = 0; mspj = 0;
      for(idx_t n = 0; n < degi; n++)
        mspi += x(nbrsi[n],j);
      mspi /= degi;
      for(idx_t n = 0; n < degj; n++)
        mspj += x(nbrsj[n],i);
      mspj /= degj;
      D[idx] = (mspi < mspj) ? mspi : mspj;
      idx++;
    }
  }

  return D;
}
Exemplo n.º 5
0
	static inline void remove_vertex(vertex_list & l, vertex v)
	{
		l.erase(std::remove(std::begin(l), std::end(l), v), std::end(l));
	}
Exemplo n.º 6
0
	/// Appends the spcified vertex to the list, only if it is not already
	/// in the list.
	static inline void push_back_unique(vertex_list & l, vertex v)
	{
		if (!contains(l, v))
			l.push_back(v);
	}