From 3371677f1a1eadb678d8f97722a9457cfeab4e0d Mon Sep 17 00:00:00 2001 From: Ciaran McCreesh <0402749m@student.gla.ac.uk> Date: Thu, 21 Jun 2012 17:11:06 +0100 Subject: [PATCH 2/2] Output in DIMACS format --- examples/graphgen/graphgen.cpp | 12 +++++++++++- 1 files changed, 11 insertions(+), 1 deletions(-) diff --git a/examples/graphgen/graphgen.cpp b/examples/graphgen/graphgen.cpp index 5f84886..f52e8fa 100644 --- a/examples/graphgen/graphgen.cpp +++ b/examples/graphgen/graphgen.cpp @@ -2,6 +2,16 @@ #include #include +template +void SaveDIMACS(const PGraph& Graph, const TStr& OutFNm, const TStr& Desc) { + FILE *F = fopen(OutFNm.CStr(), "wt"); + fprintf(F, "p edge %d %d\n", Graph->GetNodes(), Graph->GetEdges()); + for (typename PGraph::TObj::TEdgeI ei = Graph->BegEI(); ei < Graph->EndEI(); ei++) { + fprintf(F, "e %d %d\n", ei.GetSrcNId() + 1, ei.GetDstNId() + 1); + } + fclose(F); +} + int main(int argc, char* argv[]) { Env = TEnv(argc, argv, TNotify::StdNotify); Env.PrepArgs(TStr::Fmt("Graph generators. build: %s, %s. Time: %s", __TIME__, __DATE__, TExeTm::GetCurTm())); @@ -70,7 +80,7 @@ int main(int argc, char* argv[]) { DescStr = TStr::Fmt("Watts-Strogatz Small-world model. Every node links to K other nodes."); } printf("done.\n"); - TSnap::SaveEdgeList(G, OutFNm, DescStr); + SaveDIMACS(G, OutFNm, DescStr); Catch printf("\nrun time: %s (%s)\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr()); -- 1.6.5.2