Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 6a50173
  • /
  • SplitVE.cpp
Raw File Download
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge Iframe embedding
swh:1:cnt:80086501f1dbe8c7f698f697e441cf61eb065a13
directory badge Iframe embedding
swh:1:dir:6a501733dddefc26de83fd68162cc55a3c0c8c19
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
SplitVE.cpp
#include <stdio.h>
#include <stdlib.h>
#include <ogdf/basic/Graph.h>
#include <ogdf/graphalg/Triconnectivity.h>
#include <chrono>

using namespace ogdf;

int main(int n_args, char** args)
{
    if (n_args!= 3) 
    {
       printf("\n usage: %s <input file> <output file>\n\n", args[0]);
       exit(-1);
    }

   /* read graph from file */
   FILE* fp = fopen(args[1],"r");
   int n,m;
   fscanf(fp,"%d %d",&n,&m);
   Graph G;
   node* vertex = new node[n];
   for(int i=0;i<n;i++){vertex[i]=G.newNode();} //create vertices
   for(int i=0;i<m;i++)
   {
      int x,y;
      fscanf(fp,"%d %d",&x,&y);
      G.newEdge(vertex[x-1],vertex[y-1]); //create edges
   }
   fclose(fp);


     using namespace std::chrono;
     high_resolution_clock::time_point t1 = high_resolution_clock::now();
     

   /* initialize all count(v) to 0 */
   int* count = new int[n];
   for(int i=0;i<n;i++){count[i]=0;}

   /* get the triconnected components */
   Triconnectivity tricComp(G);

   /* prepare a stack to keep track of the vertices of the polygons (since the polygons appear as sets of edges) */
   char* found = new char[n];
   for(int i=0;i<n;i++){found[i]=0;}
   int* vertexStack = new int[n];

   /* process only the polygons; a vertex forms vertex-edge cuts with all the real edges it is not incident to */
   for(int i=0; i<tricComp.m_numComp; i++)
   {
      if(tricComp.m_component[i].m_type==Triconnectivity::CompType::polygon)
      {
         int n_realEdges=0;
         int SP=0;
         for(edge e : tricComp.m_component[i].m_edges)
         {
                int x=e->source()->index();
                int y=e->target()->index();
                if(!found[x]){found[x]=1;vertexStack[SP++]=x;}
                if(!found[y]){found[y]=1;vertexStack[SP++]=y;}
                if(tricComp.m_pGC->original(e))
                {
                   n_realEdges++; 
                   count[e->source()->index()]--; count[e->target()->index()]--;
                }
         }
         for(int t=0;t<SP;t++)
         {
            int v=vertexStack[t];
            count[v]+=n_realEdges;
            found[v]=0;
         }
      }
   }

     high_resolution_clock::time_point t2 = high_resolution_clock::now();
     duration<double> time_span = duration_cast<duration<double>>(t2 - t1);

   fp = fopen(args[2],"w");
   for(int i=0;i<n;i++){fprintf(fp,"%d\n",count[i]);}
   fprintf(fp,"%lf\n",(double)time_span.count());
   fclose(fp);
 
   printf("%f\n",time_span.count());
   return 0;	
}


















back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API