コード例 #1
0
ファイル: ddd.c プロジェクト: digoal/postgres_cluster
void addSubgraph(Graph* graph, nodeid_t node_id, xid_t* xids, int n_xids)
{
    xid_t *last = xids + n_xids;
    Edge *e, *next, *edges = NULL;
    Node* node = findNode(&cluster, node_id);
    while (xids != last) { 
        Vertex* src = findVertex(graph, *xids++);
        xid_t xid;
        while ((xid = *xids++) != 0) { 
            Vertex* dst = findVertex(graph, xid);
            e = newEdge(graph);
            dst->nIncomingEdges += 1;
            e->dst = dst;
            e->src = src;
            e->next = edges;
            edges = e;
            l2_list_link(&src->outgoingEdges, &e->node);
        }
    }
    for (e = node->edges; e != NULL; e = next) { 
        next = e->next;
        l2_list_unlink(&e->node);
        if (--e->dst->nIncomingEdges == 0 && l2_list_is_empty(&e->dst->outgoingEdges)) {
            freeVertex(graph, e->dst);
        }
        if (e->dst != e->src && e->src->nIncomingEdges == 0 && l2_list_is_empty(&e->src->outgoingEdges)) {
            freeVertex(graph, e->src);
        }
        freeEdge(graph, e);
    }
    node->edges = edges;
}
コード例 #2
0
ファイル: bpGraphAdjList_LL.c プロジェクト: S4KH/algo-analyse
int bipartGraphFindEdge(bpGraph_t* pGraph, int srcVertId, int tarVertId, int srcPartite)
{
	vlNode_t *srcVertex;
	if (srcPartite == 1) {

		/* Finding the right vertext from list */
		srcVertex = findVertex(pGraph->vertices1, srcVertId);

		if(srcVertex!=NULL){
			/* search for edge */
			return findElement(srcVertex->edges, tarVertId);
		}
		return NOT_FOUND;
	}
	else if (srcPartite == 2) {

		/* Finding the right vertext from list */
		srcVertex = findVertex(pGraph->vertices2, srcVertId);

		if(srcVertex!=NULL){
			/* search for edge */
			return findElement(srcVertex->edges, tarVertId);
		}
		return NOT_FOUND;
	}

	return ERROR_VALUE;
} /* end of bipartGraphFindEdge() */
コード例 #3
0
void insertEdge(int u,int v)
{
	struct Vertex *locu,*locv;
	struct Edge *ptr,*tmp;

	locu = findVertex(u);
	locv = findVertex(v);

	if(locu == NULL )
	{
		printf("Start vertex not present, first insert vertex %d\n",u);
		return;
	}
	if(locv == NULL )
	{
		printf("End vertex not present, first insert vertex %d\n",v);
		return;
	}
	tmp = malloc(sizeof(struct Edge));
	tmp->destVertex = locv;
	tmp->nextEdge = NULL;

	if(locu->firstEdge == NULL)   
	{
		 locu->firstEdge = tmp;
         return;
	}
	ptr = locu->firstEdge;
	while(ptr->nextEdge!=NULL)
		ptr = ptr->nextEdge;
	ptr->nextEdge = tmp;

}/*End of insertEdge()*/
コード例 #4
0
ファイル: bpGraphAdjList_LL.c プロジェクト: S4KH/algo-analyse
int bipartGraphInsertVertex(bpGraph_t* pGraph, int vertId, int partite)
{
	if(partite ==1){
		/* Checking for vertex duplications */
		if((findVertex(pGraph->vertices1, vertId))==NULL){
			addVertex(pGraph->vertices1, vertId);
			return NEW_VERTEX;
		}
		else{
			return EXISTING_VERTEX;
		}
	}
	else if(partite == 2){
		/* Checking for vertex duplication */
		if((findVertex(pGraph->vertices2, vertId))==NULL){
			addVertex(pGraph->vertices2, vertId);
			return NEW_VERTEX;
		}
		else{
			return EXISTING_VERTEX;
		}

	}

	return ERROR_VALUE;
} /* end of bipartGraphInsertVertex() */
コード例 #5
0
/**Fills `edges` with all of the edges in the provided mesh, computes their
cost (with computeCost), then sorts them. -CJ*/
void QuadricErrorSimplification::populateEdges(STTriangleMesh* m){
  int i,j;
  STVertex *v1,*v2;
  for (i=0; i < m->mFaces.size(); i++){
    for (j=0; j<3; j++){
      v1=m->mFaces[i]->v[j];
      v2=m->mFaces[i]->v[(j+1)%3];
      Edge newEdge  = Edge(v1,v2);
      if (findEdge(this,&newEdge) == -1){
	edges.push_back(new Edge(v1,v2));
      }
    }
  }
  int i1,i2;
  STVertex w = STVertex(0,0,0,0,0);
  STMatrix4* Q1;
  STMatrix4* Q2;
  for (i=0;i<edges.size();i++){
    i1 = findVertex(m, edges[i]->vertex1);
    i2 = findVertex(m, edges[i]->vertex2);
    if (i1==-1){
      printf("Error: QuadricErrorSimplification::populateEdges could not find vertex at %f,%f,%f\n",
	     edges[i]->vertex1->pt.x,edges[i]->vertex1->pt.y,edges[i]->vertex1->pt.z);
    }
    if (i2==-1){
      printf("Error: QuadricErrorSimplification::populateEdges could not find vertex at %f,%f,%f\n",
	     edges[i]->vertex2->pt.x,edges[i]->vertex2->pt.y,edges[i]->vertex2->pt.z);
    }
    Q1 = qMatrixes[i1];
    Q2 = qMatrixes[i2];
    edges[i]->cost = computeCost(m, v1, v2, &w, Q1, Q2);
  }
}
コード例 #6
0
Graph fillEdges(Graph g){
	FILE *fp;
	int r1,r2,i;
	char c1,c2;
	Vertex *v1,*v2;
	Ball *b1,*b2;
	fp=fopen("input.txt","r");

	while(!feof(fp)){
		fscanf(fp,"%c%d %c%d\n",&c1,&r1,&c2,&r2);
		v1=findVertex(g,r1,c1);
		v2=findVertex(g,r2,c2);
		b1=(Ball*)malloc(sizeof(Ball));
		b2=(Ball*)malloc(sizeof(Ball));
		*b1=v1->ball;
		*b2=v2->ball;
		b2->next=v1->head;
		b1->next=v2->head;
		v1->head=b2;
		v2->head=b1;
		//printf("%d %d %c %u\n",v1->head->num,v1->head->radius,v1->head->colour,v1->head->next);
		//printf("%d %d %c %u\n",v2->head->num,v2->head->radius,v2->head->colour,v2->head->next);
	}
	fclose(fp);
	return g;
}
コード例 #7
0
ファイル: Graph.cpp プロジェクト: MirzoevNik/University
void Graph::addVertexToList(int u, int x)
{
	addVertex(u);
	addVertex(x);
	for (set < pairs > :: iterator i = vertices.begin(); i != vertices.end(); i++)
	{
		if ( (*i).first->getValue() == u )
		{
			bool find = false;
			for ( list <Vertex* > :: iterator j = (*i).second->begin(); j != (*i).second->end(); j++ )
			{
				if ( (*j)->getValue() == x )
					find = true;
			}
			if ( !find )
				(*i).second->push_back( findVertex(x) );
		}
		else if ( !direct && (*i).first->getValue() == x )
		{
			bool find = false;
			for ( list <Vertex* > :: iterator j = (*i).second->begin(); j != (*i).second->end(); j++ )
			{
				if ( (*j)->getValue() == u )
					find = true;
			}
			if ( !find )
				(*i).second->push_back( findVertex(u) );
		}
	}
}
コード例 #8
0
ファイル: Graph.cpp プロジェクト: bretsko/GraphAlgorithms
bool Graph::connect(const string &vert1, const string &vert2, u_int32_t weight ){

    auto v1 = findVertex(vert1);
    auto v2 = findVertex(vert2);

    if (v1 != nullptr && v2 != nullptr){
        return connect(v1, v2, weight);
    }

    return false;
}
コード例 #9
0
ファイル: Graph.cpp プロジェクト: aist2/SocialNetwork
Edge* Graph::addEdge(int id1, int id2)
{
	Vertex* pV1;
	Vertex* pV2;
	Edge* pE1 = NULL;
	Edge* pE2 = NULL;
	
	if (!directed)
	{
		//must: id1 < id2
		if(id1 > id2)
		{
			int temp = id2;
			id2 = id1;
			id1 = temp;
		}
	}
	pV1 = findVertex(id1);
	pV2 = findVertex(id2);

	if (pV1 != NULL && pV2 != NULL)
	{
		pE1 = findEdge(pV1,pV2);
	}

	if (pV1 == NULL)
	{
		pV1 = addVertex(id1);
	}

	
	if (pV2 == NULL)
	{
		pV2 = addVertex(id2);
	}
	
	if (pE1 == NULL)
	{
		pE1 = new Edge(pV1,pV2);
		//edges.push_back(pE1);
		pV1->edges.push_back(pE1);
		pV1->adj.push_back(id2);

		if (!directed)
		{
			pE2 = new Edge(pV2,pV1);
			pV2->edges.push_back(pE2);
			pV2->adj.push_back(id1);
		}
		std::string key = int_to_string(id1) + "," + int_to_string(id2);
		edgeMap[key] = pE1;
	}
	return pE1;
}
コード例 #10
0
ファイル: bpGraphAdjList_LL.c プロジェクト: S4KH/algo-analyse
int bipartGraphInsertEdge(bpGraph_t* pGraph, int srcVertId, int tarVertId, int srcPartite)
{
	vlNode_t *srcVertex, *tarVertex;
	if (srcPartite == 1) {

		/* Finding the source and target vertices */
		srcVertex = findVertex(pGraph->vertices1, srcVertId);
		tarVertex = findVertex(pGraph->vertices2, tarVertId);

		/* Check if vertices exist */
		if(srcVertex!=NULL && tarVertex!=NULL){
			if(srcVertex->edges==NULL){
				srcVertex->edges = (linkedList_t*)safeMalloc(sizeof(linkedList_t));
				srcVertex->edges->pHead=NULL;
			}

			/* Need to check for duplicates */
			if (!findElement(srcVertex->edges, tarVertId)) {
				addNode(srcVertex->edges, tarVertId);
				return NEW_EDGE;
			}
			/* else must be existing edge */
			return EXISTING_EDGE;
		}
	}
	else if (srcPartite == 2) {

		/* Finding the source and target vertices */
		srcVertex = findVertex(pGraph->vertices2, srcVertId);
		tarVertex = findVertex(pGraph->vertices1, tarVertId);

		/* Check if vertices exist */
		if(srcVertex!=NULL && tarVertex!=NULL){
			if(srcVertex->edges == NULL){
				srcVertex->edges = (linkedList_t*)safeMalloc(sizeof(linkedList_t));
			}

			/* Need to check for duplicates */
			if (!findElement(srcVertex->edges, tarVertId)) {
				addNode(srcVertex->edges, tarVertId);
				return NEW_EDGE;
			}
			/* else must be existing edge */
			return EXISTING_EDGE;
		}
	}

	return ERROR_VALUE;
} /* end of bipartGraphInsertEdge() */
コード例 #11
0
ファイル: V3TSP.cpp プロジェクト: jeras/verilator
 std::list<Vertex*> keysToVertexList(const std::vector<T_Key>& odds) {
     std::list<Vertex*> vertices;
     for(unsigned i = 0; i < odds.size(); ++i) {
         vertices.push_back(findVertex(odds.at(i)));
     }
     return vertices;
 }
コード例 #12
0
ファイル: V3TSP.cpp プロジェクト: jeras/verilator
    // For purposes of TSP, we are using non-directional graphs.
    // Map that onto the normally-directional V3Graph by creating
    // a matched pairs of opposite-directional edges to represent
    // each non-directional edge:
    void addEdge(const T_Key& from, const T_Key& to, int cost) {
        UASSERT(from != to, "Adding edge would form a loop");
        Vertex* fp = findVertex(from);
        Vertex* tp = findVertex(to);

        // No need to dedup edges.
        // The only time we may create duplicate edges is when
        // combining the MST with the perfect-matched pairs,
        // and in that case, we want to permit duplicate edges.
        unsigned edgeId = ++V3TSP::edgeIdNext;

        // Record the 'id' which identifies a single bidir edge
        // in the user field of each V3GraphEdge:
        (new V3GraphEdge(this, fp, tp, cost))->user(edgeId);
        (new V3GraphEdge(this, tp, fp, cost))->user(edgeId);
    }
void verticesGraph::BFTraversalLabel(std::string starting,int distID)
{
    std::queue<vertex *> qv;
    vertex * v1=findVertex(starting);
    vertex * v2;
    v1->visited=true;
    qv.push(v1);
    while(!qv.empty())
    {
        v2=qv.front();
        qv.pop();
        for(int m=0;m<v2->adj.size();m++)
        {
            if(v2->adj[m].v->visited==false)
            {
                v2->adj[m].v->visited=true;
                v2->district=distID;
                v2->adj[m].v->district=distID;
                qv.push(v2->adj[m].v);
            }
        }
    }

    for(int m=0;m<vertices.size();m++)
    {
        vertices[m].visited=false;
    }
}
コード例 #14
0
ファイル: hypergraph.c プロジェクト: csgrad/crin-paper
/*
 * Append unique vertexSet at end of the vertexSet list
 */
vertexSet * appendUniqueVertexSet(vertexSet **head, int id)
{
  if(findVertex(*head, id) == NULL)
    return appendVertexSet(head, id);
  else
    return NULL;
}
コード例 #15
0
ファイル: hypergraph.c プロジェクト: csgrad/crin-paper
/* 
 * Returns true if the given graph is connected
 */
bool isConnected(hypergraph * h)
{
  vertexSet * container = copyVertexSets(h->vertexSets);
  
  edgeSet * head = h->edgeSets;
  
  while(head != NULL)
  {
    llnode * vertices = head->vertices;
    
    while(vertices != NULL)
    {
      vertexSet * v = findVertex(container, vertices->data);
      if(v!=NULL)
        removeVertexSet(&container, v->id);
      vertices = vertices->next;
    }
    head = head->nextEdge;
  }
  
  if(container == NULL)
    return true;
  else
    return false;
}
コード例 #16
0
ファイル: octree.cpp プロジェクト: ervanalb/ao
void Octree::finalize(Evaluator* e, uint32_t flags)
{
    // Find this Octree's level
    level = (type == BRANCH)
        ?  std::accumulate(children.begin(), children.end(), (unsigned)0,
                [](const unsigned& a, const std::unique_ptr<Octree>& b)
                    { return std::max(a, b->level);} ) + 1
        : 0;

    if (type == BRANCH)
    {
        // Grab corner values from children
        for (uint8_t i=0; i < 8; ++i)
        {
            corners[i] = children[i]->corners[i];
        }

        // Collapse branches if the COLLAPSE flag is set
        if (flags & COLLAPSE)
        {
            collapseBranch(e);
        }
    }
    else
    {
        // Always convert leafs to empty / filled cells
        collapseLeaf();
    }

    if (type == LEAF && std::isnan(vert.x))
    {
        findVertex(e);
    }
}
コード例 #17
0
vector<Vertex<FragmentInfo>*> 
AngularlyOrderedGraph::findSolution()
{
	Vertex<FragmentInfo>* v = findVertex(vertices, dest->key);
	assert(v);
	return findPath(vertices, v);
}
コード例 #18
0
ファイル: VertexGraph.cpp プロジェクト: matt-beall/Various
void VertexGraph::addEdge(int index1, int index2)
{
    // Vertex* v1 = findVertex(index1);
    // Vertex* v2 = findVertex(index2);

    Edge newEdge(findVertex(index1), findVertex(index2));

    for(int i = 0; i < vertices.size(); i++)
    {
        if(vertices[i].getIndex() == newEdge.getPreviousIndex())
        {   
            //found desired owner of edge
            vertices[i].addEdge(newEdge);
        }
    }
}
コード例 #19
0
//----------------------------------------------------------------------------
//Summary:
//		find shortest path from start vertex and to end vertex
//Parameter:
//		sourceVertex[in]: start vertex
//		destVertex[in]: end vertex
//		_shortestPath[out]: passed shortest path
//----------------------------------------------------------------------------
void CLandsideGraph::findShortestPath(const LandsideTrafficGraphVertex& sourceVertex, const LandsideTrafficGraphVertex& destVertex,LandsideTrafficGraphVertexList& _shortestPath)
{
	_shortestPath.clear();

	int sourceVertexIndex = findVertex(sourceVertex);
	int destVertexIndex = findVertex(destVertex);

	// not stored in the shortest path library, need calculate it
	boost::property_map<BoostGraph, boost::edge_weight_t>::type weightmap = boost::get(boost::edge_weight, *m_pboostGraph);
	std::vector<vertex_descriptor> parentsVertex(boost::num_vertices(*m_pboostGraph));
	std::vector<double> distanced(boost::num_vertices(*m_pboostGraph));
	boost::property_map<BoostGraph, boost::vertex_index_t>::type indexmap = boost::get(boost::vertex_index, *m_pboostGraph);

	boost::dijkstra_shortest_paths(*m_pboostGraph, sourceVertexIndex, boost::predecessor_map(&parentsVertex[0]).distance_map(&distanced[0]));

	if (parentsVertex[destVertexIndex] == destVertexIndex)
	{
		_shortestPath.push_back(GetVertex(sourceVertexIndex));
		return;
	}

	std::vector<int> indexList;
	// store the index of vertex in the shortest path
	int iIndex = destVertexIndex;
	int iNextIndex = iIndex;
	do
	{
		indexList.push_back(iIndex);
		iNextIndex = parentsVertex[iIndex];

		if (iNextIndex == iIndex)
			break;

		iIndex = iNextIndex;
	}
	while (iIndex != destVertexIndex);
	indexList.push_back(iIndex);

	//////////////////////////////////////////////////////////////////////////
	// make a path from the pathVertexList
	int pointNum = indexList.size();
	for( int i=0; i < pointNum; i++ )
	{
		_shortestPath.push_back(GetVertex(indexList[i]));
	}
	std::reverse(_shortestPath.begin(), _shortestPath.end());
}
void verticesGraph::shortestDistance(std::string starting,std::string destination)
{
    if(findVertex(starting)==NULL||findVertex(destination)==NULL)
    {
        std::cout<<"At least one vertex doesn't exist"<<std::endl;
        return;
    }

    vertex * sta=findVertex(starting);
    vertex * des=findVertex(destination);
    if(sta->district!=des->district)
    {
        std::cout<<"No path between two vertices"<<std::endl;
        return;
    }

    if(vertices[0].district==-1)
    {
        std::cout<<"Please assign vertices' districts first"<<std::endl;
        return;
    }

    vertex * startV=findVertex(starting);
    vertex * endV=Dijkstra(starting,destination);
    std::vector<vertex *> path;
    vertex * v1=endV;
    while(v1!=startV)
    {
        path.push_back(v1);
        v1=v1->previous;
    }
    std::cout<<std::endl;
    std::cout<<"Shortest distance: "<<starting<<" >>> "<<destination<<" is "<<endV->distance<<std::endl;
    std::cout<<"Path: ";
    std::cout<<startV->name;
    for(int m=path.size()-1;m>-1;m--)
    {
        std::cout<<" >>> "<<path[m]->name;
    }
    std::cout << std::endl;

    for(int m=0;m<vertices.size();m++)
    {
        vertices[m].visited=false;
    }
}
vertex * verticesGraph::Dijkstra(std::string starting,std::string destination)
{
    vertex * startV=findVertex(starting);
    vertex * endV=findVertex(destination);
    startV->visited=true;
    startV->distance=0;
    std::vector<vertex *> solved;
    solved.push_back(startV);

    int minDistance,dist;
    vertex * solvedV, *s, *parent;
    while(endV->visited==false)
    {
        minDistance=INT_MAX;
        solvedV=NULL;
        for(int m=0;m<solved.size();m++)
        {
            s=solved[m];
            for(int n=0;n<s->adj.size();n++)
            {
                if(s->adj[n].v->visited==false)
                {
                    dist=s->distance+s->adj[n].weight;
                    if(dist<minDistance)
                    {
                        solvedV=s->adj[n].v;
                        minDistance=dist;
                        parent=s;
                    }
                }
            }
        }
        solvedV->distance=minDistance;
        solvedV->previous=parent;
        solvedV->visited=true;
        solved.push_back(solvedV);
    }

    for(int m=0;m<vertices.size();m++)
    {
        vertices[m].visited=false;
    }

    return endV;
}
コード例 #22
0
ファイル: bpGraphAdjList_LL.c プロジェクト: S4KH/algo-analyse
int bipartGraphFindVertex(bpGraph_t *pGraph, int vertId, int partite)
{
	if (partite == 1) {
		if(findVertex(pGraph->vertices1, vertId)==NULL){
			return NOT_FOUND;
		}
		return FOUND;
	}
	if (partite == 2) {
		if(findVertex(pGraph->vertices2, vertId)==NULL){
			return NOT_FOUND;
		}
		return FOUND;
	}

	/* unknown partite */
	return ERROR_VALUE;
} /* end of bipartGraphFindVertex() */
コード例 #23
0
ファイル: Util.cpp プロジェクト: agudpp/CordobaZombie
/* Creates a list of triangles and allocating all the vertexs from a mesh
 * Requires:
 * 	@cont		The Vertex container where it will been put the vertexs
 * 	@mesh		The mesh to extract the triangles
 * 	@triangles	The list to be filled with the triangles
 * Returns:
 * 	true		on success
 * 	false		otherwise
 */
bool Util::getTrianglesFromMesh(PolyStructsContainer<sm::Vertex *> &cont,
		PolyStructsContainer<Triangle *> &triangles,
		Ogre::MeshPtr mesh)
{
	ASSERT(!mesh.isNull());

	if(!cont.isEmpty()){
		debug("Warning: Not an empty container\n");
	}

	if(!triangles.isEmpty()){
		debug("Warning, triangles is not empty\n");
		ASSERT(false);
	}

	size_t vertex_count,index_count;
	Ogre::Vector3* vertices = 0;
	long unsigned* indices = 0;

	getMeshInformation(mesh.get(),vertex_count,vertices,index_count,indices);

	// TODO: hacer esta funcion mas rapida, estamos buscando para cada vector
	// el vertice asociado. Es lento

	// here we will map Ogre::Vector3[i] -> Vertex*
	std::vector<sm::Vertex *> vertexMap;
	vertexMap.resize(vertex_count);

	// fills the map of vertexs
	sm::Vertex *v = 0;
	for(size_t i = 0; i < vertex_count; ++i){
		v = findVertex(cont.getObjs(), vertices[i]);
		if(!v){
			// create a new vertex and put it in the container
			v = new sm::Vertex(vertices[i].x, vertices[i].z);
			cont.addObj(v);
		}

		// associate the vec to the vertex
		vertexMap[i] = v;
	}

	// now we have to create the triangles
	for(size_t i = 0; i < index_count; i += 3){
		triangles.addObj(new Triangle(vertexMap[indices[i]],
				vertexMap[indices[i+1]],
				vertexMap[indices[i+2]]));
	}

	delete []vertices;
	delete []indices;

	return true;
}
コード例 #24
0
ファイル: bpGraphAdjList_LL.c プロジェクト: S4KH/algo-analyse
int bipartGraphDeleteEdge(bpGraph_t* pGraph,  int srcVertId, int tarVertId, int srcPartite)
{
	vlNode_t *srcVertex;
	int errorStatus;

	if (srcPartite == 1) {

		/* Find the vertex that is connected*/
		srcVertex = findVertex(pGraph->vertices1, srcVertId);

		if(srcVertex!=NULL){
			/* delete linked list node */
			errorStatus = deleteNode(srcVertex->edges, tarVertId);

			if (errorStatus > 0) {
				return FOUND;
			}
		}
		/* edge/vertex not in graph */
		return NOT_FOUND;

	}
	else if (srcPartite == 2) {

		/* Find the vertex that is connected*/
		srcVertex = findVertex(pGraph->vertices2, srcVertId);

		if(srcVertex!=NULL){
			/* delete linked list node */
			errorStatus = deleteNode(srcVertex->edges, tarVertId);

			if (errorStatus>0) {
				return FOUND;
			}
		}
		/* edge/vertex not in graph */
		return NOT_FOUND;
	}

	return ERROR_VALUE;
} /** end of bipartGraphDeleteEdge() */
コード例 #25
0
ファイル: VertexGraph.cpp プロジェクト: matt-beall/Various
void VertexGraph::printGraph()
{
    for(int i = 0; i < vertices.size() ; i++)
    {
        std::cout << "NEW VERT" << std::endl;
        vertices[i].printChildren();
        std::cout << "NumChildren: " << vertices[i].numChildren() << std::endl;
    }

    Vertex* vert2 = findVertex(2);
    std::cout << "NumPtr: " <<  vert2->numChildren() << std::endl;
}
コード例 #26
0
Graph maxStream(VertexType source, VertexType sink, Graph G)
{
    Index S = findVertex(source, G);
    Index E = findVertex(sink, G);
    if(G->TheCells[S].Info != Legitimate || G->TheCells[E].Info != Legitimate)
    {
        fprintf(stderr, "vertex %s or %s does not exist", source, sink);
        return NULL;
    }
    /*准备好残余图和流图*/
    Graph Gr = intializeGraph(G->vertex);
    Gr = copyGraph(Gr, G);
    Graph Gf = intializeGraph(G->vertex);
    copyVertex(Gf, G);


    maxStream(S, E, Gf, Gr);
    DestroyGraph(Gr);

    return Gf;
}
コード例 #27
0
ファイル: main.cpp プロジェクト: mahedi0244/Graphics_Project3
void mouse (int button, int state, int x, int y){
    
    if (drawn == false){
        switch(button){
            case GLUT_LEFT_BUTTON:
                if (state == GLUT_DOWN){
                    v = n++;
                    vert[v][0] = x;
                    vert[v][1] = height - 1 - y;
                    rubberbanding = true;
                    glutPostRedisplay();
                    
                }
                
                else
                    rubberbanding = false;
                break;
                
            case GLUT_RIGHT_BUTTON:
                if (state == GLUT_DOWN && (v = findVertex(x, height-1-y)) != -1){
                    if (glutGetModifiers() == GLUT_ACTIVE_CTRL){
                        for (int i = v; i < n-1; i++){
                            vert[i][0] = vert[i+1][0];
                            vert[i][1] = vert[i+1][1];
                        }
                        n--;
                    }
                    else{
                        vert[v][0] = x;
                        vert[v][1] = height - 1 - y;
                        rubberbanding = true;
                        
                    }
                    glutPostRedisplay();
                }
                else
                    rubberbanding = false;
                break;
        }
    }
    if (drawn == true){
        switch(button){
            case GLUT_LEFT_BUTTON:
                if (state == GLUT_DOWN){
                    t = k++;
                    test_points[t][0] = x;
                    test_points[t][1] = height - 1 - y;
                    glutPostRedisplay();
                }
                break;
        }
    }
}
void verticesGraph::addService(std::string name,std::string serV,std::string type, int cost){
    service newServ;

    vertex *temp = findVertex(name);
    if (temp != NULL){
        newServ.name = serV;
        newServ.cost = cost;
        newServ.type = type;
        temp->services.push_back(newServ);
    }else{
        std::cout << "This vertex does not exist." << std::endl;
    }
}
コード例 #29
0
void 
AngularlyOrderedGraph::Initialize(vector<Vertex<FragmentInfo>*>& v, 
								  vector<ContourEQW>& contours, 
								  FragmentInfo& start,
								  FragmentInfo& end)
{
	for(int i=0; i<vertices.size(); ++i)
	{
		delete vertices[i];
	}
	vertices.clear();

	for(int i=0; i<v.size(); ++i)
	{
		Vertex<FragmentInfo>* u = new Vertex<FragmentInfo>(v[i]->key);
		*u = *(v[i]);
		vertices.push_back(u);
	}

	vertices = orderVertices(vertices, contours, click);
	source = findVertex(vertices, start);
	assert(source);
	dest = findVertex(vertices, end);
	assert(dest);
	if(GetOrientation(start, end, click, contours)==false)
	{
		swap(source, dest);
	}

	vertices = arrangeVertices(vertices, source);

	for(int i=0; i<vertices.size(); ++i)
	{
		vertices[i]->Reset();
	}
	source->d = 0;
	iter = 1;
}
コード例 #30
0
ファイル: hypergraph.c プロジェクト: csgrad/crin-paper
/*
 * Generate an induced subgraph of G
 * - Starts with the edge specified by N
 * - Selects all the vertices which are associated with the edge
 * - Determines which edges should be part of the graph based on 
 * - which vertices have been selected and which edges connect them
 * - returns the new graph which is an induced subgraph of G (hopefully)
 */
hypergraph * generateInducedSubgraph(hypergraph *G, edgeSet *N)
{
  hypergraph * tmp = newHyperGraph();
  vertexSet * tmp_vertex = NULL;
  edgeSet * tmp_edge=NULL;
  
  if(N!=NULL)
  {
    //add the vertices to the new graph
    llnode * vertices = N->vertices;
    while(vertices != NULL)
    {
      //Add the vertex into the vertexSet of the new graph
      tmp_vertex = appendUniqueVertexSet(&tmp->vertexSets, vertices->data);
      //advance to next vertex
      vertices = vertices->next;
    }
    
    edgeSet * E = G->edgeSets;
    
    while(E!=NULL)
    {
      bool bad_edge = false;
      llnode * tmp_list = E->vertices;
      //traverse the vertice list of the edge looking for vertices
      //which are not in the induced subgraph
      while(tmp_list != NULL)
      {
        //found a bad egdge
        if(findVertex(tmp->vertexSets, tmp_list->data)==NULL)
        {
          bad_edge = true;
        }
        tmp_list = tmp_list->next;
      }
      //if no bad edges are found we are safe to add the edge to
      //the induced subgraph
      if(!bad_edge)
      {
        tmp_edge = appendUniqueEdgeSet(&tmp->edgeSets, E->id);
        tmp_edge->vertices = copyList(E->vertices);
        addEdgetoVertices(tmp_edge, tmp->vertexSets);
      }
      E = E->nextEdge;
    }
  }
  else
    printf("Error creating induced graph because N is NULL\n");
  return tmp;
}