/* mapGraphs: */ static void mapGraphs(graph_t * g, graph_t * cg, distfn dist) { node_t *n; edge_t *e; edge_t *ce; node_t *t; node_t *h; nitem *tp; nitem *hp; int delta; for (n = agfstnode(g); n; n = agnxtnode(g, n)) { tp = (nitem *) ND_alg(n); t = tp->cnode; for (e = agfstout(g, n); e; e = agnxtout(g, e)) { hp = (nitem *) ND_alg(aghead(e)); delta = dist(&tp->bb, &hp->bb); h = hp->cnode; #ifndef WITH_CGRAPH ce = agedge(cg, t, h); #else ce = agedge(cg, t, h, NULL, 1); agbindrec(ce, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE); #endif ED_weight(ce) = 1; if (ED_minlen(ce) < delta) { if (ED_minlen(ce) == 0.0) { elist_append(ce, ND_out(t)); elist_append(ce, ND_in(h)); } ED_minlen(ce) = delta; } } } }
/* dfs: * Return the number of reversed edges for this component. */ static int dfs(Agraph_t * g, Agnode_t * t, int hasCycle) { Agedge_t *e; Agedge_t *f; Agnode_t *h; ND_mark(t) = 1; ND_onstack(t) = 1; for (e = agfstout(g, t); e; e = f) { f = agnxtout(g, e); if (agtail(e) == aghead(e)) continue; h = aghead(e); if (ND_onstack(h)) { if (agisstrict(g)) { if (agedge(g, h, t, 0, 0) == 0) addRevEdge(g, e); } else { char* key = agnameof (e); if (!key || (agedge(g, h, t, key, 0) == 0)) addRevEdge(g, e); } agdelete(g, e); hasCycle = 1; } else if (ND_mark(h) == 0) hasCycle |= dfs(g, h, hasCycle); } ND_onstack(t) = 0; return hasCycle; }
/* GVEdge */ GVEdge::GVEdge(GVLayout *l, Agnode_t *src, Agnode_t *dst) : GVItem(l) { //get src regime #ifdef USE_LIBGRAPH_NOT_LIBCGRAPH this->gv_edge = agedge(this->layout->getGVGraph(), src, dst); #else this->gv_edge = agedge(this->layout->getGVGraph(), src, dst, NULL, 1); #endif }
/* clone_graph: * Create two copies of the argument graph * One is a subgraph, the other is an actual copy since we will be * adding edges to it. */ static Agraph_t* clone_graph(Agraph_t* ing, Agraph_t** xg) { Agraph_t* clone; Agraph_t* xclone; Agnode_t* n; Agnode_t* xn; Agnode_t* xh; Agedge_t* e; Agedge_t* xe; char gname[SMALLBUF]; static int id = 0; sprintf (gname, "_clone_%d", id++); clone = agsubg(ing, gname); sprintf (gname, "_clone_%d", id++); xclone = agopen(gname, ing->kind); for(n = agfstnode(ing); n; n = agnxtnode(ing, n)) { aginsert (clone, n); xn = agnode (xclone, n->name); CLONE(n) = xn; } for(n = agfstnode(ing); n; n = agnxtnode(ing, n)) { xn = CLONE(n); for(e = agfstout(ing, n); e; e = agnxtout(ing, e)) { aginsert (clone, e); xh = CLONE(e->head); xe = agedge (xclone, xn, xh); ORIGE(xe) = e; DEGREE(xn) += 1; DEGREE(xh) += 1; } } *xg = xclone; #ifdef OLD clone = agopen("clone", root->kind); for(n = agfstnode(root); n; n = agnxtnode(root, n)) { cn = agnode(clone, n->name); ND_alg(cn) = DATA(n); BCDONE(cn) = 0; } for(n = agfstnode(root); n; n = agnxtnode(root, n)) { Agnode_t *t = agnode(clone, n); for(e = agfstout(root, n); e; e = agnxtout(root, e)) { Agnode_t *h = agnode(clone, e->head->name); agedge(clone, t, h); } } #endif return clone; }
int GraphvizAdapterImpl::addEdge(int source, int target, std::string name) { Agedge_t * e = agedge(g_, nodes_[source], nodes_[target], (char*)(name.c_str()), 1); #else int GraphvizAdapterImpl::addEdge(int source, int target, std::string /* name */) { Agedge_t * e = agedge(g_, nodes_[source], nodes_[target]); #endif assert(e); ++eCount_; edges_.insert(std::pair<int, Agedge_t*>(eCount_, e)); return eCount_; }
void MERFTag::buildMatchTree(Agraph_t* G,Agnode_t* node,Agedge_t* edge,QMap<Agnode_t *,Agnode_t *>* parentNodeMap,QTreeWidgetItem* parentItem, int& id) { QStringList data; data << "Type" << formula->name; QTreeWidgetItem* newItem = new QTreeWidgetItem(parentItem,data); parentItem = newItem; char * writable = strdup(formula->name.toStdString().c_str()); if(node == NULL) { stringstream strs; strs << id; string temp_str = strs.str(); char* nodeID = strdup(temp_str.c_str()); Agnode_t * newNode = agnode(G,nodeID, 1); agset(G,const_cast<char *>("root"),nodeID); id = id+1; agset(newNode,const_cast<char *>("label"),writable); parentNodeMap->insert(newNode,NULL); node = newNode; } else { stringstream strs; strs << id; string temp_str = strs.str(); char* nodeID = strdup(temp_str.c_str()); Agnode_t * newNode = agnode(G,nodeID, 1); id = id+1; agset(newNode,const_cast<char *>("label"),writable); edge = agedge(G, node, newNode, 0, 1); parentNodeMap->insert(newNode, node); node = newNode; } match->buildMatchTree(G,node,edge,parentNodeMap,parentItem,id); }
//Edge management void GVSubGraph::addEdge(const QString &source, const QString &target) { if (hasNode(source) && hasNode(target)) { QPair<QString, QString> key(source, target); if(!_edges.contains(key)) _edges.insert(key, agedge(_graph, getNode(source), getNode(target))); } }
static graph_t *create_test_graph(void) { #define NUMNODES 5 Agnode_t *node[NUMNODES]; Agedge_t *e; Agraph_t *g; Agraph_t *sg; int j, k; char name[10]; /* Create a new graph */ g = agopen("new_graph", Agdirected,NIL(Agdisc_t *)); /* Add nodes */ for (j = 0; j < NUMNODES; j++) { sprintf(name, "%d", j); node[j] = agnode(g, name, 1); agbindrec(node[j], "Agnodeinfo_t", sizeof(Agnodeinfo_t), TRUE); //node custom data } /* Connect nodes */ for (j = 0; j < NUMNODES; j++) { for (k = j + 1; k < NUMNODES; k++) { e = agedge(g, node[j], node[k], NULL, 1); agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE); //edge custom data } } sg = agsubg (g, "cluster1", 1); agsubnode (sg, node[0], 1); return g; }
static gboolean cls_node_add_edge (ClsNode *cls_node_from, ClsNode *cls_node_to) { ClsNodeEdge *cls_edge; g_return_val_if_fail (cls_node_from->graph != NULL, FALSE); /* Check if the edge already exists */ cls_edge = g_hash_table_lookup (cls_node_from->edges_to, cls_node_to); if (cls_edge) return TRUE; cls_edge = g_new0 (ClsNodeEdge, 1); cls_edge->cls_node_from = cls_node_from; cls_edge->cls_node_to = cls_node_to; if ((cls_edge->agedge = agedge (cls_node_from->graph, cls_node_from->agnode, cls_node_to->agnode)) == NULL) { g_free (cls_edge); return FALSE; } g_hash_table_insert (cls_node_from->edges_to, cls_node_to, cls_edge); g_hash_table_insert (cls_node_to->edges_from, cls_node_from, cls_edge); return TRUE; }
static graph_t *create_test_graph(void) { #define NUMNODES 5 Agnode_t *node[NUMNODES]; Agraph_t *g; int j, k; char name[10]; /* Create a new graph */ g = agopen("new_graph", AGDIGRAPH); /* Add nodes */ for (j = 0; j < NUMNODES; j++) { sprintf(name, "%d", j); node[j] = agnode(g, name); } /* Connect nodes */ for (j = 0; j < NUMNODES; j++) { for (k = j + 1; k < NUMNODES; k++) { agedge(g, node[j], node[k]); } } return g; }
/* mapGraphs: */ static void mapGraphs(graph_t * g, graph_t * cg, distfn dist) { node_t *n; edge_t *e; edge_t *ce; node_t *t; node_t *h; nitem *tp; nitem *hp; int delta; for (n = agfstnode(g); n; n = agnxtnode(g, n)) { tp = (nitem *) ND_alg(n); t = tp->cnode; for (e = agfstout(g, n); e; e = agnxtout(g, e)) { hp = (nitem *) ND_alg(e->head); delta = dist(&tp->bb, &hp->bb); h = hp->cnode; ce = agedge(cg, t, h); ED_weight(ce) = 1; if (ED_minlen(ce) < delta) { if (ED_minlen(ce) == 0.0) { elist_append(ce, ND_out(t)); elist_append(ce, ND_in(h)); } ED_minlen(ce) = delta; } } } }
static void mapGraphs (graph_t * g, graph_t * cg, distfn dist) { node_t *n; edge_t *e; edge_t *ce; node_t *t; node_t *h; nitem *tp; nitem *hp; int delta; for (n = agfstnode (g); n; n = agnxtnode (g, n)) { for (e = agfstout (g, n); e; e = agnxtout (g, e)) { delta = dist (&tp->bb, &hp->bb); ce = agedge (cg, t, h, ((void *) 0), 1); if ((((Agedgeinfo_t *) (((Agobj_t *) (ce))->data))->minlen) < delta) { if ((((Agedgeinfo_t *) (((Agobj_t *) (ce))->data))->minlen) == 0.0) { } } } } }
Agedge_t* mkMCEdge (Agraph_t* g, Agnode_t* tail, Agnode_t* head, char* name, int type, Agedge_t* orige) { Agedge_t* tmpE = agedge(g, tail, head, name, 1); agbindrec(tmpE, "mcedgeinfo_t", sizeof(mcedgeinfo_t), TRUE); MED_type(tmpE) = type; MED_orig(tmpE) = orige; return tmpE; }
/* cloneEdge: * Make a copy of e in e's graph but using ct and ch as nodes */ static edge_t *cloneEdge(edge_t * e, node_t * ct, node_t * ch) { graph_t *g = ct->graph; edge_t *ce = agedge(g, ct, ch); agcopyattr(e, ce); return ce; }
void GVSkeletonGraph::addEdge(const QString &source, const QString &target) { setlocale(LC_NUMERIC,"en_US.UTF-8"); // Débug séparateur de décimales en version française if (hasNode(source) && hasNode(target)) { QPair<QString, QString> key(source, target); if(!_edges.contains(key)) _edges.insert(key, agedge(_graph, getNode(source), getNode(target))); } }
Agedge_t *edge(Agnode_t *t, Agnode_t *h) { // edges from/to the protonode are not permitted if (!gvc || !t || !h || (t->name[0] == '\001' && strcmp (t->name, "\001proto") == 0) || (h->name[0] == '\001' && strcmp (h->name, "\001proto") == 0)) return NULL; return agedge(t->graph, t, h); }
/* cloneEdge: * Make a copy of e in e's graph but using ct and ch as nodes */ static edge_t *cloneEdge(edge_t * e, node_t * ct, node_t * ch) { graph_t *g = agraphof(ct); edge_t *ce = agedge(g, ct, ch,NULL,1); agbindrec(ce, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE); agcopyattr(e, ce); return ce; }
Agedge_t *edge(Agnode_t *t, Agnode_t *h) { if (!gvc || !t || !h) return NULL; // edges from/to the protonode are not permitted if (AGTYPE(t) == AGRAPH || AGTYPE(h) == AGRAPH) return NULL; return agedge(agraphof(t), t, h, NULL, 1); }
static void reverse_edge(graph_t *g, edge_t *e) { edge_t *rev; rev = agfindedge(g,e->head,e->tail); if (!rev) rev = agedge(g,e->head,e->tail); merge(rev,ED_minlen(e),ED_weight(e)); agdelete(g,e); }
void GVSkeletonGraph::addEdge(const QString &source, const QString &target) { setlocale(LC_NUMERIC,"en_US.UTF-8"); if (hasNode(source) && hasNode(target)) { QPair<QString, QString> key(source, target); if(!_edges.contains(key)) _edges.insert(key, agedge(_graph, getNode(source), getNode(target))); } }
/* isEdge: * Return edge, if any, between t and h with given key. * Edge is in root graph */ Agedge_t *isEdge(Agnode_t * t, Agnode_t * h, char *key) { Agraph_t *root; if ((root = sameG(t, h, "isEdge", "tail and head node"))) { t = (Agnode_t *) agrebind(root, OBJ(t)); h = (Agnode_t *) agrebind(root, OBJ(h)); return agedge(t, h, key, 0); } else return 0; }
static void transform(Agraph_t * g) { Agnode_t *n; Agedge_t *e; char *str; Agsym_t *m_ix, *s_ix; int cnt, d; m_ix = bindedgeattr(g, "minlen"); s_ix = bindedgeattr(g, "style"); for (n = agfstnode(g); n; n = agnxtnode(g, n)) { d = myindegree(n) + myoutdegree(n); if (d == 0) { if (ChainLimit < 1) continue; if (ChainNode) { e = agedge(g, ChainNode, n, "", TRUE); agxset(e, s_ix, "invis"); ChainSize++; if (ChainSize < ChainLimit) ChainNode = n; else { ChainNode = NULL; ChainSize = 0; } } else ChainNode = n; } else if (d > 1) { if (MaxMinlen < 1) continue; cnt = 0; for (e = agfstin(g, n); e; e = agnxtin(g, e)) { if (isleaf(agtail(e))) { str = agxget(e, m_ix); if (str[0] == 0) { adjustlen(e, m_ix, (cnt % MaxMinlen) + 1); cnt++; } } } cnt = 0; for (e = agfstout(g, n); e; e = agnxtout(g, e)) { if (isleaf(e->node) || (Do_fans && ischainnode(e->node))) { str = agxget(e, m_ix); if (str[0] == 0) adjustlen(e, m_ix, (cnt % MaxMinlen) + 1); cnt++; } } } } }
static void addRevEdge(Agraph_t * g, Agedge_t * e) { Agsym_t* sym; Agedge_t* f = agedge (g, aghead(e), agtail(e), agnameof(e), 1); agcopyattr (; sym = agattr (g, AGEDGE, TAILPORT_ID, 0); if (sym) agsafeset (f, HEADPORT_ID, agxget (e, sym), ""); sym = agattr (g, AGEDGE, HEADPORT_ID, 0); if (sym) agsafeset (f, TAILPORT_ID, agxget (e, sym), ""); }
static void checkChain(graph_t * g) { node_t *t; node_t *h; edge_t *e; t = GD_nlist(g); for (h = ND_next(t); h; h = ND_next(h)) { if (!agfindedge(g, t, h)) { #ifdef WITH_CGRAPH e = agedge(g, t, h, NULL, 1); agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE); #else e = agedge(g, t, h); #endif ED_minlen(e) = 0; elist_append(e, ND_out(t)); elist_append(e, ND_in(h)); } t = h; } }
grafo escreve_grafo(FILE *output, grafo g){ if(!g || !output) return NULL; Agraph_t *ag; Agsym_t *peso; char peso_s[MAX_STRING_SIZE]; //criando a string "peso" char p_str[5]; strcpy(p_str, "peso"); //cria uma string vazia pra usar como valor default do atributo peso char default_s[1]; default_s[0] = '\0'; if(g->direcionado) ag = agopen(g->nome, Agstrictdirected, NULL); else ag= agopen(g->nome, Agstrictundirected, NULL); if(g->ponderado) peso = agattr(ag, AGEDGE, p_str, default_s); Agnode_t **nodes = malloc(g->n_vertices * sizeof(Agnode_t*)); for(unsigned int i = 0; i < g->n_vertices; i++) nodes[g->vertices[i]->id] = agnode(ag, g->vertices[i]->nome, TRUE); for(unsigned int i = 0; i < g->n_vertices; i++){ vertice v = g->vertices[i]; for(no n = primeiro_no(v->adjacencias_saida); n != NULL; n = proximo_no(n)){ adjacencia viz = conteudo(n); Agedge_t *ae = agedge(ag, nodes[v->id], nodes[viz->v_destino->id], NULL, TRUE); if(g->ponderado){ sprintf(peso_s, "%ld", viz->peso); agxset(ae, peso, peso_s); } } } free(nodes); agwrite(ag, output); agclose(ag); agfree(ag, NULL); return g; }
void ImplemGraphviz::creerListeEdges(Graphe* graph) { tableEdges.clear(); vector<Arete*> liste=graph->getListeArcs(); for(int i=0;i<liste.size();i++){ Arete* areteCour=liste[i]; Sommet* depart=areteCour->getDepart(); Sommet* arrivee=areteCour->getArrivee(); Agedge_t* agedg=agedge(G,tableNodes[depart],tableNodes[arrivee]); tableEdges.insert(areteCour,agedg); } }
static void addCutPts(Agraph_t * tree, Agraph_t * blk) { Agnode_t *n; Agnode_t *bn; Agnode_t *cn; bn = agnode(tree, agnameof(blk), 1); for (n = agfstnode(blk); n; n = agnxtnode(blk, n)) { if (Cut(n)) { cn = agnode(tree, agnameof(n), 1); agedge(tree, bn, cn, 0, 1); } } }
int main(int argc, char** argv) { Agraph_t *g; Agnode_t *n,*m; Agedge_t *e; Agsym_t *a; GVC_t *gvc; /* set up renderer context */ gvc = gvContext(); /* Accept -T and -o options like dot. * Input files are ignored in this demo. */ dotneato_initialize(gvc, argc,argv); /* Create a simple digraph */ g = agopen("g",AGDIGRAPH); n = agnode(g,"n"); m = agnode(g,"m"); e = agedge(g,n,m); /* Set an attribute - in this case one that affects the visible rendering */ if (!(a = agfindattr(g->proto->n, "color"))) a = agnodeattr(g, "color", ""); agxset(n, a->index, "red"); /* bind graph to GV context - currently must be done before layout */ gvBindContext(gvc,g); /* Compute a layout */ neato_layout(g); /* twopi_layout(g); */ /* dot_layout(g); */ /* Write the graph according to -T and -o options */ dotneato_write(gvc); /* Clean out layout data */ /* neato_cleanup(g); */ /* twopi_cleanup(g); */ /* dot_cleanup(g); */ /* Free graph structures */ agclose(g); /* Clean up output file and errors */ dotneato_terminate(gvc); return 1; }
QGVEdge *QGVScene::addEdge(QGVNode *source, QGVNode *target, const QString &label) { Agedge_t* edge = agedge(_graph->graph(), source->_node->node(), target->_node->node(), NULL, TRUE); if(edge == NULL) { qWarning()<<"Invalid egde :"<<label; return 0; } QGVEdge *item = new QGVEdge(new QGVEdgePrivate(edge), this); item->setLabel(label); addItem(item); _edges.append(item); return item; }
/* internal functions for model graph construction and maintenance */ static vpath_t *newpath(Agraph_t *model, Agnode_t *u, int low, Agnode_t *v, int high) { vpath_t *path; int i; path = NEW(vpath_t); path->v = nodearray(low, high); path->e = edgearray(low, high); for (i = low; i <= high; i++) { if ((i == low) && u) path->v[i] = u; else if ((i == high) && v) path->v[i] = v; else path->v[i] = agnode(model,0); if (i > low) path->e[i-1] = agedge(model,path->v[i-1],path->v[i]); } return path; }