static void InitDegMap( Digraph& dg, ArcFilter& ef, IntMap& inDeg, IntMap& outDeg ) { AFGraph afg( dg, ef ); for( Digraph::NodeIt n( dg ); n != INVALID; ++n ) { inDeg[n] = countInArcs( afg, n ); outDeg[n] = countOutArcs( afg, n ); } }
void MFGraph::add_terminals() { int rightMostStart = -1; int rightMostEnd = -1; // find childless nodes for (ListDigraph::NodeIt n(mfGraph); n != INVALID; ++n) { if (countOutArcs(mfGraph, n) == 0) { childless[n] = true; if (read_map[n] && read_map[n]->start() > rightMostStart) { rightMostStart = read_map[n]->start(); rightMostEnd = rightMostStart + read_map[n]->length(); // std::cout << "rightMostEnd" << rightMostEnd << std::endl; } } } int leftMostStart = rightMostStart; // find parentless nodes for (ListDigraph::NodeIt n(mfGraph); n != INVALID; ++n) { if (countInArcs(mfGraph, n) == 0) { parentless[n] = true; if (read_map[n] && read_map[n]->start() < leftMostStart) { leftMostStart = read_map[n]->start(); } } } // now add the fake source and sink MethylRead *source_read = new MethylRead(leftMostStart - 1, 1); source = addNode("s", 0, source_read); fake[source] = true; for (ListDigraph::NodeIt n(mfGraph); n != INVALID; ++n) { if (parentless[n]) { addArc(source, n, read_map[n]->start() - source_read->start()); } } // MethylRead *sink_read = new MethylRead(rightMostStart , rightMostEnd- rightMostStart+1); MethylRead *sink_read = new MethylRead(rightMostEnd + 1 , 1); sink = addNode("t", 0, sink_read); fake[sink] = true; for (ListDigraph::NodeIt n(mfGraph); n != INVALID; ++n) { if (childless[n]) { addArc(n, sink, sink_read->start() - read_map[n]->start()); //addArc(n, sink, 1); } } }
static void FilterILTEdge( Digraph& dg, IntMap& imap, ArcFilter& ef ) { // 查找联络巷 for( Digraph::ArcIt e( dg ); e != INVALID; ++e ) { Digraph::Node u = dg.source( e ); Digraph::Node v = dg.target( e ); // 排除直接相连的分支 // 联络巷分支的始节点出度必须大于1,末节点的入度必须大于1 if( countOutArcs( dg, u ) <= 1 || countInArcs( dg, v ) <= 1 ) continue; if( imap[u]*imap[v] < 0 ) ef[e] = false; } }
static void FindILTEdges( Digraph& dg, ILT_EdgeDataMap2& datas, IntMap& cmap, EdgeArray& edges ) { for( Digraph::ArcIt e( dg ); e != INVALID; ++e ) { if( datas[e]->et == ET_VIRTUAL ) continue; Digraph::Node u = dg.source( e ); Digraph::Node v = dg.target( e ); // 排除直接相连的分支 // 联络巷分支的始节点出度必须大于1,末节点的入度必须大于1 if( countOutArcs( dg, u ) <= 1 || countInArcs( dg, v ) <= 1 ) continue; if( cmap[u]*cmap[v] < 0 ) edges.append( e ); } }
void BillOfMaterials::fromDOMElement(const QDomElement& domel) { QDomNodeList bom_node_list; // List of nodes of the BOM in the DOM document QDomNodeList bom_arc_list; // List of arcs of the BOM in the DOM document QDomNode cur_node; QHash<int, ListDigraph::Node> node_map; // <node_id, actual_node> QMap<ListDigraph::Node, int> node_itm_type_map; // <actual_node, item_type> QList<QPair<int, int> > bom_arcs; // List of pairs of node_ids QStringList bom_arcs_str; // String representation of BOM arcs int bom_id; bom_id = domel.attribute("id").toInt(); ID = bom_id; //out << "Current read BOM id: " << pboms[prod_type_id].last()->ID << endl; // Read the node descriptions cur_node = domel.firstChildElement("nodes"); bom_node_list = cur_node.childNodes(); node_map.clear(); node_itm_type_map.clear(); for (int k = 0; k < bom_node_list.size(); k++) { node_map[bom_node_list.item(k).toElement().attribute("id").toInt()] = graph.addNode(); node_itm_type_map[node_map[bom_node_list.item(k).toElement().attribute("id").toInt()]] = bom_node_list.item(k).toElement().text().toInt(); //out << "Read BOM node with id: " << bom_node_list.item(k).toElement().attribute("id").toInt() << endl; } // Read the arc descriptions cur_node = domel.firstChildElement("arcs"); bom_arc_list = cur_node.childNodes(); bom_arcs.clear(); for (int k = 0; k < bom_arc_list.size(); k++) { bom_arcs_str = bom_arc_list.item(k).toElement().text().split(","); bom_arcs.append(QPair<int, int>()); bom_arcs.last().first = bom_arcs_str[0].toInt(); bom_arcs.last().second = bom_arcs_str[1].toInt(); //out << "Read BOM arc: " << bom_arcs.last().first << "," << bom_arcs.last().second << endl; } // Create the actual BOM for (int ca = 0; ca < bom_arcs.size(); ca++) { // Add the current arc to the BOM graph graph.addArc(node_map[bom_arcs[ca].first], node_map[bom_arcs[ca].second]); } // Set the types of the items for each non-fictive node of the BOM graph for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) { itypeID[nit] = node_itm_type_map[nit]; } // Add the head and the tail head = graph.addNode(); itypeID[head] = -1; tail = graph.addNode(); itypeID[tail] = -2; // Add the arcs from the head and the tail for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) { if (nit == head) continue; if (nit == tail) continue; // If the current node has no incoming arcs then it must be connected to the head if (countInArcs(graph, nit) == 0) { graph.addArc(head, nit); } // If the current node has no outgoing arcs then it must be connected to the tail if (countOutArcs(graph, nit) == 0) { graph.addArc(nit, tail); } } setItemIDs(); }