1 // agmfitmain.cpp : Defines the entry point for the console application.
2
3 #include "stdafx.h"
4 #include "agm.h"
5 #include "agmfit.h"
6
7 int main(int argc, char* argv[]) {
8 Env = TEnv(argc, argv, TNotify::StdNotify);
9 Env.PrepArgs(TStr::Fmt("cpm. build: %s, %s. Time: %s", __TIME__, __DATE__, TExeTm::GetCurTm()));
10 TExeTm ExeTm;
11 Try
12 TStr OutFPrx = Env.GetIfArgPrefixStr("-o:", "", "Output file name prefix");
13 const TStr InFNm = Env.GetIfArgPrefixStr("-i:", "football.edgelist",
"Input edgelist file name. DEMO: AGM with 2 communities");
14 const TStr LabelFNm = Env.GetIfArgPrefixStr("-l:", "football.labels",
"Input file name for node names (Node ID, Node label) ");
15 const TInt RndSeed = Env.GetIfArgPrefixInt("-s:", 0, "Random seed for AGM");
16 const TFlt Epsilon = Env.GetIfArgPrefixFlt("-e:", 0,
"Edge probability between the nodes that do not share any community (default (0.0): set it to be 1 / N^2)");
17 const TInt Coms = Env.GetIfArgPrefixInt("-c:", 0, "Number of communities (0: determine it by AGM)");
18
19 PUNGraph G = TUNGraph::New();
20 TVec<TIntV> CmtyVV;
21 TIntStrH NIDNameH;
22
23 if (InFNm == "DEMO") {
24 TVec<TIntV> TrueCmtyVV;
25 TRnd AGMRnd(RndSeed);
26
27 //generate community bipartite affiliation
28 const int ABegin = 0, AEnd = 70, BBegin = 30, BEnd = 100;
29 TrueCmtyVV.Add(TIntV());
30 TrueCmtyVV.Add(TIntV());
31 for (int u = ABegin; u < AEnd; u++) {
32 TrueCmtyVV[0].Add(u);
33 }
34 for (int u = BBegin; u < BEnd; u++) {
35 TrueCmtyVV[1].Add(u);
36 }
37 G = TAGM::GenAGM(TrueCmtyVV, 0.0, 0.2, AGMRnd);
38 }
39 else if (LabelFNm.Len() > 0) {
40 G = TSnap::LoadEdgeList<PUNGraph>(InFNm);
41 TSsParser Ss(LabelFNm, ssfTabSep);
42 while (Ss.Next()) {
43 if (Ss.Len() > 0) { NIDNameH.AddDat(Ss.GetInt(0), Ss.GetFld(1)); }
44 }
45 }
46 else {
47 G = TAGMUtil::LoadEdgeListStr<PUNGraph>(InFNm, NIDNameH);
48 }
49 printf("Graph: %d Nodes %d Edges\n", G->GetNodes(), G->GetEdges());
50
51 int MaxIter = 50 * G->GetNodes() * G->GetNodes();
52 if (MaxIter < 0) { MaxIter = TInt::Mx; }
53 int NumComs = Coms;
54 if (NumComs < 2) {
55 int InitComs;
56 if (G->GetNodes() > 1000) {
57 InitComs = G->GetNodes() / 5;
58 NumComs = TAGMUtil::FindComsByAGM(G, InitComs, MaxIter, RndSeed, 1.5, Epsilon, OutFPrx);
59 } else {
60 InitComs = G->GetNodes() / 5;
61 NumComs = TAGMUtil::FindComsByAGM(G, InitComs, MaxIter, RndSeed, 1.2, Epsilon, OutFPrx);
62 }
63 }
64 TAGMFit AGMFit(G, NumComs, RndSeed);
65 if (Epsilon > 0) { AGMFit.SetPNoCom(Epsilon); }
66 AGMFit.RunMCMC(MaxIter, 10);
67 AGMFit.GetCmtyVV(CmtyVV, 0.9999);
68
69 TAGMUtil::DumpCmtyVV(OutFPrx + "cmtyvv.txt", CmtyVV, NIDNameH);
70 TAGMUtil::SaveGephi(OutFPrx + "graph.gexf", G, CmtyVV, 1.5, 1.5, NIDNameH);
71 AGMFit.PrintSummary();
72
73 Catch
74
75 printf("\nrun time: %s (%s)\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
76
77 return 0;
78 }