Пример #1
0
void PatchMgr::getEdgeCandidates(Scope &scope, Point::Type, Candidates &ret) {
   Edges edges;
   getEdges(scope, edges);
   for (Edges::iterator iter = edges.begin(); iter != edges.end(); ++iter) {
      ret.push_back(Candidate(Location::Edge(*iter), Point::EdgeDuring));
   }
}
Пример #2
0
void simplifyPFBlock(const Edges& toUnlink, const PFBlock& block, Blocks& simplifiedBlocks, Nodes& history) {
  // take a block, unlink some of the edges and
  // create smaller blocks or a simplified blocks
  // or if nothing has changed take a copy of the original block
  if (toUnlink.size() == 0) {
    // no change needed, just make a copy of block
    PFBlock newblock(block.elementIds(), block.edges(), simplifiedBlocks.size(), 's');  // will copy edges and ids
    PDebug::write("Made {}", newblock);
    auto id = newblock.id();
    simplifiedBlocks.emplace(id, std::move(newblock));
    // update history
    makeHistoryLinks(block.elementIds(), {id}, history);
  } else {
    Edges modifiedEdges;
    for (auto edge : block.edges()) {  // copying edges
      Edge e = edge.second;
      if (toUnlink.find(edge.first) != toUnlink.end()) {
        e.setLinked(false);
      }
      modifiedEdges.emplace(e.key(), e);
    }
    // create new blocks and add into simplifiedBlocks
    buildPFBlocks(block.elementIds(), modifiedEdges, 's', simplifiedBlocks, history);
  }
}
Пример #3
0
bool IsOutlineValid(const Edges& outline) {
  using std::begin;
  using std::end;
  if (outline.empty()) {
    return false;
  }
  std::vector<QPointF> points;
  auto previous = outline.back();
  for (const auto& current : outline) {
    if (AngleDistance(current, previous) == 180.0) {
      return false;
    }
    const auto point = current.Begin();
    if (!IsSameEnough(previous.End(), point)) {
      return false;
    }
    if (std::any_of(begin(points), end(points),
                    [&point](const QPointF& p) {
                      return IsSameEnough(p, point);
                    })) {
      return false;
    }
    points.push_back(point);
    previous = current;
  }
  return true;
}
Пример #4
0
/* static private */
void
PolygonizeGraph::findLabeledEdgeRings(std::vector<DirectedEdge*> &dirEdges,
		std::vector<PolygonizeDirectedEdge*> &edgeRingStarts)
{
	typedef std::vector<DirectedEdge*> Edges;

	Edges edges;

	// label the edge rings formed
	long currLabel=1;
	for(Edges::size_type i=0, n=dirEdges.size(); i<n; ++i)
	{
#ifdef GEOS_CAST_PARANOIA
		assert(dynamic_cast<PolygonizeDirectedEdge*>(dirEdges[i]));
#endif
		PolygonizeDirectedEdge *de =
			static_cast<PolygonizeDirectedEdge*>(dirEdges[i]);

		if (de->isMarked()) continue;
		if (de->getLabel() >= 0) continue;
		edgeRingStarts.push_back(de);

		findDirEdgesInRing(de, edges);
		label(edges, currLabel);
		edges.clear(); 

		++currLabel;
	}
}
Пример #5
0
void Mutation::__cleanup(Module *m)
{
  VLOG(50) << ">>>>> clean up";
  LOG_MODULE;
  for(Edges::iterator e = m->e_begin(); e != m->e_end(); e++)
  {
    if((*e)->sourceNode() == NULL || (*e)->destinationNode() == NULL) m->removeEdge(*e);
  }
  Edges toBeRemoved;
  for(Edges::iterator e = m->e_begin(); e != m->e_end(); e++)
  {
    for(Edges::iterator f = m->e_begin(); f != m->e_end(); f++)
    {
      if((*e)->sourceNode()->label() == (*f)->sourceNode()->label() &&
         (*e)->sourceNode()          != (*f)->sourceNode()          &&
         (*e)                        != (*f))
      {
        toBeRemoved.push_back(*e);
      }
    }
  }
  for(Edges::iterator e = toBeRemoved.begin(); e != toBeRemoved.end(); e++)
  {
    m->removeEdge(*e);
  }
  LOG_MODULE;
  VLOG(50) << "<<<<< clean up";
}
// @snip <sh19910711/contest:setlib/disjoints_set.cpp>
template <typename GraphType> const typename std::vector<typename GraphType::Edge> get_minimum_spanning_forest( const GraphType& G ) {
  typedef typename std::vector<typename GraphType::Edge> Edges;
  typedef typename GraphType::Edge GraphEdge;
  typedef typename GraphType::Edges GraphEdges;
  typedef std::priority_queue<GraphEdge, Edges, std::greater<GraphEdge> > PriorityQueue;
  typedef setlib::DisjointSets UnionFind;

  Edges res;
  PriorityQueue E;
  UnionFind uf(G.num_vertices);

  for ( int i = 0; i < G.num_vertices; ++ i ) {
    for ( typename GraphEdges::const_iterator it_i = G.vertex_edges[i].begin(); it_i != G.vertex_edges[i].end(); ++ it_i ) {
      const GraphEdge& e = **it_i;
      E.push(GraphEdge(e.from, e.to, e.weight));
    }
  }

  while ( ! E.empty() ) {
    GraphEdge e = E.top();
    E.pop();
    if ( ! uf.same(e.from, e.to) ) {
      res.push_back(e);
      uf.merge(e.from, e.to);
    }
  }

  return res;
}
Пример #7
0
 Edges createEdgesForFull(unsigned firstSize, unsigned secondSize)
 {
     Edges out;
     for (unsigned i = 0; i < firstSize; ++i)
         for (unsigned j = 0; j < secondSize; ++j)
             out.push_back(Edge(i, j));
     return out;
 }
Пример #8
0
inline bool onEdge(const Point & point, const Poly & poly, const Edges & edges, const S & eps)
{
    for(auto j = edges.begin(), jend = edges.end(); j != jend; ++j)
    {
        auto & p1 = poly[*j];
        auto & p2 = *j == 0 ? poly.back() : poly[*j - 1];
        if(onEdge(point, p1, p2, eps))
            return true;
    }
    return false;
}
Пример #9
0
void split() {
    Nodes nodes;
    Edges es;

    printf("test: bend2()\n");

    addNode(nodes,100,100,40,20);
    addNode(nodes,100,130,40,20);
    addNode(nodes,70,160,40,20);
    addNode(nodes,180,190,40,20);
    EdgePoints p1;
    addToPath(p1,nodes[0],EdgePoint::CENTRE);
    addToPath(p1,nodes[1],EdgePoint::BL);
    addToPath(p1,nodes[1],EdgePoint::TL);
    addToPath(p1,nodes[3],EdgePoint::CENTRE);
    es.push_back(new Edge(100,p1));

    EdgePoints p2;
    addToPath(p2,nodes[2],EdgePoint::CENTRE);
    addToPath(p2,nodes[3],EdgePoint::CENTRE);
    es.push_back(new Edge(50,p2));

    const size_t V = nodes.size();

    vpsc::Constraints cs;
    vpsc::Variables vs;
    getVariables(nodes,vs);
    { // scope for t, so that t gets destroyed before es

        TopologyConstraints t(vpsc::HORIZONTAL,nodes,es,vs,cs);
        writeFile(nodes,es,"split-0.svg");

        // test computeStress
        double stress=t.computeStress();
        printf("Stress=%f\n",stress);
        //assert(fabs(expectedStress-stress)<1e-4);

        valarray<double> g(V);
        cola::SparseMap h(V);
        for(unsigned i=1;i<5;i++) {
            g=0;
            h.clear();
            t.gradientProjection(g,h);
            stringstream ss;
            ss << "split-" << i << ".svg";
            writeFile(nodes,es,ss.str().c_str());
        }
    }

    for_each(nodes.begin(),nodes.end(),delete_node());
    for_each(es.begin(),es.end(),delete_object());
    for_each(cs.begin(),cs.end(),delete_object());
    for_each(vs.begin(),vs.end(),delete_object());
}
void FastMassSpring::fillJMatrix(TripletList& triplets, Edges& edges, int edge_counts)
{
  for (decltype(edges.size()) i = 0; i != edges.size(); ++i)
  {
    for (int j = 0; j < 3; ++j)
    {
      triplets.push_back(Triplet(3 * edges[i].first + j, 3 * (i + edge_counts) + j, 1));
      triplets.push_back(Triplet(3 * edges[i].second + j, 3 * (i + edge_counts) + j, -1));
    }
  }
}
Пример #11
0
BlockSplitter::BlockSplitter(const Edges& unlinkEdges, PFBlock& block, Nodes& historynodes) : m_blocks() {
  Edges modifiedEdges;
  for (auto edge : block.edges()) {  // copy edges
    Edge e = edge.second;
    if (unlinkEdges.find(edge.first) != unlinkEdges.end()) {
      e.setLinked(false);
    }
    modifiedEdges.emplace(e.key(), std::move(e));
  }

  BlockBuilder bbuilder{block.elementIds(), std::move(modifiedEdges), historynodes};
  m_blocks = bbuilder.moveBlocks();
  block.setActive(false);
}
Пример #12
0
std::vector<Path> edges_to_paths(Edges const &es, std::vector<Path> const &ps) {
    std::vector<Path> ret;
    for(unsigned i = 0; i < es.size(); i++) {
        ret.push_back(ps[es[i].ix].portion(es[i].from.time, es[i].to.time));
    }
    return ret;
}
Пример #13
0
void pes (Edges &edges)
{
  cerr << "(";
  for (int i = 0; i < edges.size(); ++i)
    pe(edges[i]);
  cerr << ")" << endl;
}
Пример #14
0
/**
 * Build a horizon that is a edge loop, 
 * each of which has one face visible and the other invisible from the specified vertex.
 */
void findHorizon (Arrangement &arr, Vertex *v, Edges &horizon)
{
	// find an edge that constitutes a part of the horizon
	Edge *e0 = NULL;
	for (int i = 0; i < v->visibleFaces.size() && e0 == NULL; ++i) {
		Edge *e = v->visibleFaces[i]->edge;
		Edge *g = e;

		do {
			if (!g->twin->face->visible(v)) {
				e0 = g;
				break;
			}

			g = g->twin->next;
		} while (g != e);
	}

	// traverse the next edges to find all the remaining parts of the horizon
	Edge *e = e0;
	do {
		horizon.push_back(e);

		e = e->twin->next;

		// find a part of the horizon again
		while (true) {
			if (!e->twin->face->visible(v)) {
				break;
			}

			e = e->next;
		}
	} while (e != e0);
}
Пример #15
0
    void dumpDotGraph()
    {
        std::ofstream file("/tmp/shiboken_graph.dot");

        file << "digraph D {\n";

        Edges::const_iterator i = m_edges.begin();
        for (; i != m_edges.end(); ++i) {
            SbkObjectType* node1 = i->first;
            const NodeList& nodeList = i->second;
            NodeList::const_iterator j = nodeList.begin();
            for (; j != nodeList.end(); ++j)
                file << '"' << (*j)->super.ht_type.tp_name << "\" -> \"" << node1->super.ht_type.tp_name << "\"\n";
        }
        file << "}\n";
    }
Пример #16
0
PFBlock::PFBlock(const Ids& element_ids, Edges& edges)
    : m_uniqueId(Id::makeBlockId()), m_isActive(true), m_elementIds(element_ids) {
  PFBlock::tempBlockCount += 1;

  // extract the relevant parts of the complete set of edges and store this within the block
  // note the edges will be removed from the edges unordered_map
  for (auto id1 : m_elementIds) {
    for (auto id2 : m_elementIds) {
      if (id1 >= id2) continue;
      // move the edge from one unordered map to the other
      auto e = edges.find(Edge::makeKey(id1, id2));
      if (e == edges.end()) throw std::range_error("Required Edge is missing from edges collection");
      m_edges.emplace(e->second.key(), std::move(e->second));
      edges.erase(e);
    }
  }
}
Пример #17
0
Edges edges(Path const &p, Crossings const &cr, unsigned ix) {
    Edges ret = Edges();
    EndPoint prev;
    for(unsigned i = 0; i <= cr.size(); i++) {
        double t = cr[i == cr.size() ? 0 : i].getTime(ix);
        Point pnt = p.pointAt(t);
        Point normal = p.pointAt(t+0.01) - pnt;
        normal.normalize();
        std::cout << pnt << "\n";
        EndPoint cur(pnt, normal, t);
        if(i == 0) { prev = cur; continue; }
        ret.push_back(Edge(prev, cur, ix, false));
        ret.push_back(Edge(prev, cur, ix, true));
        prev = cur;
    }
    return ret;
}
Пример #18
0
pair<Weight, Edges> minimumSpanningForest(const Graph &g) {
    int n = g.size();
    UnionFind uf(n);
    priority_queue<Edge> Q;
    REP(u, n) EACH(e, g[u]) if (u < e->dst) Q.push(*e);

    Weight total = 0;
    Edges F;
    while (F.size() < n-1 && !Q.empty()) {
        Edge e = Q.top(); Q.pop();
        if (uf.unionSet(e.src, e.dst)) {
            F.push_back(e);
            total += e.weight;
        }
    }
    return pair<Weight, Edges>(total, F);
}
Пример #19
0
int main(void) {
    ios::sync_with_stdio(false);
    int T;
    cin >> T;
    for (int _ = 0; _ < T; _++) {
        int N, K;
        cin >> N >> K;
        vector<int> cost(2*N*(N+1), 1);
        for (int i = 0; i < K; i++) {
            int t = 0;
            cin >> t;
            cost[t-1] = 0;
        }

        Graph g;
        g.push_back(Edges());
        g.push_back(Edges());
        for (int i = 1; i <= 2*N*(N+1); i++) {
            Edges point;
            point.push_back(Edge(i+1, 0, 100000, cost[i-1]));
            g[0].push_back(Edge(0, i+1, 0, -cost[i-1]));
            g.push_back(point);
        }

        int cubes = 0;
        for (int n = 1; n <= N; n++) {
            for (int y = 1; y <= N-n+1; y++) {
                for (int x = 1; x <= N-n+1; x++) {
                    Edges point;
                    int idx = g.size();
                    int top = (2*N+1)*(y-1)+x;
                    int bottom = (2*N+1)*(y+n-1)+x;
                    int left = top + N;
                    for (int t = 0; t < n; t++) {
                        point.push_back(Edge(idx, 1+top+t, 1000, 0));
                        point.push_back(Edge(idx, 1+bottom+t, 1000, 0));
                        point.push_back(Edge(idx, 1+left+t*(2*N+1), 1000, 0));
                        point.push_back(Edge(idx, 1+left+t*(2*N+1)+n, 1000, 0));
                        g[1+top+t].push_back(Edge(1+top+t, idx, 0, 0));
                        g[1+bottom+t].push_back(Edge(1+bottom+t, idx, 0, 0));
                        g[1+left+t*(2*N+1)].push_back(Edge(1+left+t*(2*N+1), idx, 0, 0));
                        g[1+left+t*(2*N+1)+n].push_back(Edge(1+left+t*(2*N+1)+n, idx, 0, 0));
                    }
                    point.push_back(Edge(idx, 1, 0, 0));
                    g.push_back(point);
                    g[1].push_back(Edge(1, idx, 1, 0));
                    cubes++;
                }
            }
        }

        P p = minimumCostFlow(g, 1, 0);
        cout << p.first << ' ' << p.second << endl;
    }
    return 0;
}
Пример #20
0
GeodesicDistance::GeodesicDistance( const Edges &edges, const VectorXf &edge_weights ) : N_( getN( edges ) ) {
	adj_list_.resize( N_ );
	for( int i=0; i<edges.size(); i++ ) {
		adj_list_[ edges[i].a ].push_back( Node( edges[i].b, edge_weights[i] ) );
		adj_list_[ edges[i].b ].push_back( Node( edges[i].a, edge_weights[i] ) );
	}
	reset();
}
Пример #21
0
    void checkAddEdge(unsigned numOfVertices, Edge toBeAdded, Edges existing, Edges missing)
    {
        g.addEdge(toBeAdded);

        ASSERT_EQ(existing.size(), g.numOfEdges());
        ASSERT_EQ(numOfVertices, g.numOfVertices());
        for (auto elem : existing) ASSERT_TRUE(g.edgeExists(elem));
        for (auto elem : missing) ASSERT_FALSE(g.edgeExists(elem));
    }
Пример #22
0
pair<Weight, Edges> minimumSpanningTree(const Graph &g, int r = 0) {
    int n = g.size();
    Edges T;
    Weight total = 0;

    vector<bool> visited(n);
    priority_queue<Edge> Q;
    Q.push( Edge(-1, r, 0) );
    while (!Q.empty()) {
        Edge e = Q.top(); Q.pop();
        if (visited[e.dst]) continue;
        T.push_back(e);
        total += e.weight;
        visited[e.dst] = true;
        EACH(f, g[e.dst]) if (!visited[f->dst]) Q.push(*f);
    }
    return pair<Weight, Edges>(total, T);
}
Пример #23
0
void IEdgesExtractor::purgeBoundaryVertices(VerticesMap& map_vertex, Edges & satEdges, float maxRho, float minRho){
	VerticesMap::iterator it = map_vertex.begin();
	int i = 0;
	Vertex * from = 0;
	Vertex * to = 0;
	while(it != map_vertex.end()){

		//not too close
		if(((Vertex*)it->second)->norm() > (minRho+epsilon)){
			if(((Vertex*)it->second)->norm() >= (maxRho - epsilon)){
				//erased
				if(from == 0){
					from = it->second;
				}else{
					to = it->second;
				}
				map_vertex.erase(it++);
			}else{
				//ok
				if(to != 0){ //have a saturated edge of at least 2 points
					Edge * e = new Edge(0);
					e->setVertexFrom(*from);
					e->setVertexTo(*to);
					satEdges.push_back(e);
					to = 0;
				}
				from = 0;
				++it;
			}
		}else{
			map_vertex.erase(it++);
		}
		i++;
	}
	if(to != 0){ //have a saturated edge of at least 2 points
		Edge * e = new Edge(0);
		e->setVertexFrom(*from);
		e->setVertexTo(*to);
		satEdges.push_back(e);
		to = 0;
	}

}
Edges ReadEdgesFromDIMACSFile(const char* filename) {
  Edges edges;
  ifstream in(filename);
  assert(in.is_open());
  string buf;
  getline(in, buf);
  int n, m;
  sscanf(buf.c_str(), "%d %d", &n, &m);
  edges.reserve(2 * m);
  for (int i = 0; i < n; ++i) {
    getline(in, buf);
    istringstream parser(buf);
    int neighbor;
    while (parser >> neighbor) {
      edges.push_back(make_pair(i, neighbor - 1));
    }
  }
  return edges;
}
Пример #25
0
int main(int argc, char *argv[]) {
  typedef std::pair<int, int> Edge;
  typedef std::vector<Edge> Edges;
  Edges edges;
  Edge edge;
  edge = std::make_pair(0, 1);
  edges.push_back(edge);

  std::cout << edge.first << " ---- " << edge.second << std::endl;
  edge = std::make_pair(1, 0);
  edges.push_back(edge);

  std::cout << edge.first << " ---- " << edge.second << std::endl;
  for(Edges::iterator it = edges.begin(); it != edges.end(); it++) {
    std::cout << (*it).first << " --- " << (*it).second << std::endl;
  }

  return 0;
}
Пример #26
0
void MST(const Graph &g) {
	int n = g.size();
	UnionFind uf(n);
	priority_queue<Edge> Q;
	REP(u,n) EACH(e,g[u])  Q.push(*e);

	Weight total = 0;
	Edges cycleEdges;
	while (!Q.empty()) {
		Edge e = Q.top(); Q.pop();
		if(!uf.unionSet(e.src,e.dst)){
			cycleEdges.push_back(e);
		}
	}
	int i;
	for(i = 0; i < cycleEdges.size(); i++){
	    Edge e = cycleEdges[i];
	    cout << e.weight << ((i==cycleEdges.size()-1)? "\n" : " ");
	}
	if(!i) cout << "forest\n";
}
Пример #27
0
/**
 * Delete all the visible faces and edges except the horizon.
 */
void deleteVisibleCone(Arrangement &arr, Vertex *v)
{
	// clear the visited flag of all the edges
	for (int i = 0; i < arr.edges.size(); ++i) {
		arr.edges[i]->flag = false;
	}

	Edges toBeRemovedEdges;

	for (int i = 0; i < v->visibleFaces.size(); ++i) {
		Edge *e = v->visibleFaces[i]->edge;

		Edge *g = e;
		do {
			if (!g->flag && !g->twin->flag) {
				g->flag = true;

				if (g->twin->face->visible(v)) {
					toBeRemovedEdges.push_back(g);
				}
			}

			g = g->twin->next;
		} while (g != e);
	}

	// delete all the edges to be removed
	for (int i = 0; i < toBeRemovedEdges.size(); ++i) {
		arr.removeEdge(toBeRemovedEdges[i]);
	}

	// delete all the faces to be removed
	while (v->visibleFaces.size() > 0) {
		arr.removeFace(v->visibleFaces[0]);
	}

	v->visibleFaces.clear();
}
Пример #28
0
Edges Graph::find_min_span() {
	Edges min_span;
	sort_edges();
	for (int i = 0; i < edges.size(); i++) {
		int f = edges[i].f;
		int t = edges[i].t;
		if (!joined(f, t)) {
			join(f, t);
			min_span.push_back(edges[i]);
			if (sets[f].size() == num_vert) break;
		}
	}
	return min_span;
}
Пример #29
0
 SbkObjectType* identifyType(void** cptr, SbkObjectType* type, SbkObjectType* baseType) const
 {
     Edges::const_iterator edgesIt = m_edges.find(type);
     if (edgesIt != m_edges.end()) {
         const NodeList& adjNodes = m_edges.find(type)->second;
         NodeList::const_iterator i = adjNodes.begin();
         for (; i != adjNodes.end(); ++i) {
             SbkObjectType* newType = identifyType(cptr, *i, baseType);
             if (newType)
                 return newType;
         }
     }
     void* typeFound = ((type->d && type->d->type_discovery) ? type->d->type_discovery(*cptr, baseType) : 0);
     if (typeFound) {
         // This "typeFound != type" is needed for backwards compatibility with old modules using a newer version of
         // libshiboken because old versions of type_discovery function used to return a SbkObjectType* instead of
         // a possible variation of the C++ instance pointer (*cptr).
         if (typeFound != type)
             *cptr = typeFound;
         return type;
     } else {
         return 0;
     }
 }
Пример #30
0
std::vector<Edges> cells(cairo_t */*cr*/, std::vector<Path> const &ps) {
    CrossingSet crs = crossings_among(ps);
    Edges es = edges(ps, crs);
    std::vector<Edges> ret = std::vector<Edges>();

    while(!es.empty()) {
        std::cout << "hello!\n";
        Edge start = es.front();
        Path p = Path();
        Edge cur = start;
        bool rev = false;
        Edges cell = Edges();
        do {
            std::cout << rev << " " << cur.from.time << ", " << cur.to.time << "\n";
            double a = 0;
            Edge was = cur;
            EndPoint curpnt = rev ? cur.from : cur.to;
            Point norm = rev ? -curpnt.norm : curpnt.norm;
            //Point to = curpnt.point + norm *20;
            
            //std::cout << norm;
            for(unsigned i = 0; i < es.size(); i++) {
                if(es[i] == was || es[i].cw != start.cw) continue;
                if((!are_near(curpnt.time, es[i].from.time)) &&
				    are_near(curpnt.point, es[i].from.point, 0.1)) {
                    double v = ang(norm, es[i].from.norm);
                    //draw_line_seg(cr, curpnt.point, to);
                    //draw_line_seg(cr, to, es[i].from.point + es[i].from.norm*30); 
                    //std::cout << v << "\n";
                    if(start.cw ? v < a : v > a ) {
                        a = v;
                        cur = es[i];
                        rev = false;
                    }
                }
                if((!are_near(curpnt.time, es[i].to.time)) &&
				    are_near(curpnt.point, es[i].to.point, 0.1)) {
                    double v = ang(norm, -es[i].to.norm);
                    if(start.cw ? v < a : v > a) {
                        a = v;
                        cur = es[i];
                        rev = true; 
                    }
                }
            }
            cell.push_back(cur);
            remove(es, cur);
			if(cur == was) break;
        } while(!(cur == start));
		if(are_near(start.to.point, rev ? cur.from.point : cur.to.point)) {
			ret.push_back(cell);
		}
    }
    return ret;
}