コード例 #1
0
        void AlgorithmMAXIMALMATCHING::FindMaximalMatching(Graph& G, EdgeSet& Matching, VertexSet& MatchedVertices)
        {
            for(EdgeIterator e = G.BeginEdges(); e != G.EndEdges(); e++)
            {
                VertexSet Incident = (*e)->CollectIncidentVertices(1,1,1);
                if(SetHelper::IntersectionEmpty(MatchedVertices,Incident))
                {
                    Matching.insert(*e);
                    SetHelper::DestructiveUnion(MatchedVertices, Incident);
                }
            }

        }
コード例 #2
0
        void ExportFilterRGML::Export(Graph& G, ostream& os, VertexColoring& vertexcoloring,
                                      EdgeColoring& edgecoloring, float dpi, float edgewidth, float vertexradius)
        {
            StringTranslatorXML Translator;

            os << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
            os << "<!-- www.Open-Graphtheory.org -->\n\n";

            os << "<rdf:RDF\n"
               << "  xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"
               << "  xmlns=\"http://purl.org/puninj/2001/05/rgml-schema#\"\n"
               << "  xmlns:rgml=\"http://purl.org/puninj/2001/05/rgml-schema#\"\n"
               << ">\n\n";

            os << "  <Graph rdf:ID=\"graph\" rgml:directed=\"false\">\n";

            /// declare vertices
            os << "    <nodes>\n";
            os << "      <rdf:Bag>\n";
            for(VertexIterator v = G.BeginVertices(); v != G.EndVertices(); v++)
                os << "        <rdf:li rdf:resource=\"#n" << (*v)->GetID() << "\"/>\n";
            os << "      </rdf:Bag>\n";
            os << "    </nodes>\n\n";

            /// declare edges and arcs
            os << "    <edges>\n";
            os << "      <rdf:Bag>\n";
            for(EdgeIterator e = G.BeginEdges(); e != G.EndEdges(); e++)
                os << "        <rdf:li rdf:resource=\"#e" << (*e)->GetID() << "\"/>\n";
            os << "      </rdf:Bag>\n";
            os << "    </edges>\n";

            os << "  </Graph>\n\n";

            /// write vertices
            for(VertexIterator v = G.BeginVertices(); v != G.EndVertices(); v++)
                os << "  <Node rdf:ID=\"n" << (*v)->GetID() << "\" rgml:label=\"" << Translator.Translate((*v)->GetLabel()) << "\"/>\n";

            /// write edges
            for(EdgeIterator ei = G.BeginEdges(); ei != G.EndEdges(); ei++)
            {
                Edge* e = *ei;
                if(e->IsHyperedge())
                    continue;
                os << "\n  <Edge rdf:ID=\"e" << e->GetID() << "\" directed=\"" << (e->IsEdge()?"false":"true") << "\""
                   << " rgml:label=\"" << Translator.Translate(e->GetLabel()) << "\">\n";
                os << "    <source rdf:resource=\"#n" << e->From()->GetID() << "\"/>\n";
                os << "    <target rdf:resource=\"#n" << e->To()->GetID() << "\"/>\n";
                os << "  </Edge>\n";
            }

            /// write hyperedges
            for(EdgeIterator ei = G.BeginEdges(); ei != G.EndEdges(); ei++)
            {
                Edge *e = *ei;
                if(!e->IsHyperedge())
                    continue;
                os << "\n  <Edge rdf:ID=\"e" << e->GetID() << "\""
                   << " rgml:label=\"" << Translator.Translate(e->GetLabel()) << "\">\n";
                os << "    <nodes>\n";
                os << "      <rdf:Seq>\n";
                for(VertexEdgeConnectionIterator conn = e->BeginConnections(); conn != e->EndConnections(); conn++)
                    os << "        <rdf:li rdf:resource=\"#n" << (*conn)->GetVertex()->GetID() << "\"/>\n";
                os << "      </rdf:Seq>\n";
                os << "    </nodes>\n";
                os << "  </Edge>\n";
            }

            os << "\n</rdf:RDF>\n";
        }