int main(int argc, char* argv[]) { vector<string> reqs; //Here are the default ordering of options: reqs.push_back("input"); reqs.push_back("mapper"); reqs.push_back("comfinder"); vector<string> opts; map<string, string> popts; try { popts = OptionParser::getOpts(argc, argv, reqs, opts); } catch(exception x) { cerr << x.what() << endl; cout << "usage: " << argv[0] << OptionParser::getUsageString(reqs,opts) << endl; return 1; } Ran1Random ran; INetworkPartitioner* comfinder = 0; if( popts["comfinder"] == "Newman" ) { comfinder = new NewmanCom(); } else { comfinder = new RandAgPart(ran, popts["comfinder"]); } NetworkFactory* nf = new NetworkFactory(); Network* net; if( popts["input"] == "-") { net = nf->create(cin); } else { ifstream input( popts["input"].c_str() ); net = nf->create(input); } double p = 0; EdgeFactory ef; for(p = 0.0; p < 1.0; p += 0.01) { Network net_copy = *net; INetworkMapper* mapper = 0; if( popts["mapper"] == "EdgeRewirer" ) { mapper = new EdgeRewirer(ef, p, ran); } else if ( popts["mapper"] == "EdgeSwapper" ) { mapper = new EdgeSwapper(ef, ran, p); } mapper->map(&net_copy); vector<Network*>* part = comfinder->partition(net_copy); double q = comfinder->modularityOf(part, *net); cout << p << "\t" << q << endl; comfinder->deletePartition(part); delete mapper; } return 0; }
int main(int argc, char* argv[]) { vector<string> reqs; reqs.push_back("input"); reqs.push_back("subgraph_nodes"); reqs.push_back("out-prefix"); vector<string> opts; opts.push_back("weighted"); opts.push_back("first_is_name"); OptionParser op(reqs,opts); try { op.parse(argc, argv); } catch (exception x) { cerr << "usage: " << argv[0] << op.getUsageString() << endl; return -1; } NetworkFactory* nf; NodeFactory* node_f = new NamedNodeFactory(); bool weighted = op.getBoolOpt("weighted", false); if( weighted ) { nf = new WeightedNetworkFactory(node_f, new WeightedEdgeFactory()); } else { //Here is unweighted: nf = new NetworkFactory(node_f, new EdgeFactory()); } Network* net; if( op.getStringOpt("input", "-") == "-" ) { net = nf->create(cin); } else { ifstream input( op.getStringOpt("input","").c_str() ); net = nf->create(input); } //Subgraph ifstream sg( op.getStringOpt("subgraph_nodes","").c_str() ); bool first_is_name = op.getBoolOpt("first_is_name", false); SuperString line; int line_cnt = 0; while(getline(sg, line, '\n')) { if( line[0] == '#' ) { //This is a comment continue; } vector<SuperString> parts = line.split(" "); string name; int idx = 0; if( first_is_name ) { name = parts[0]; idx = 1; } else { stringstream ss; ss << line_cnt; name = ss.str(); } Network* sg_net; if( weighted ) { sg_net = new WeightedNetwork(); } else { sg_net = new Network(); } for(int i = idx; i < parts.size(); i++) { sg_net->add( node_f->create(parts[i]) ); } sg_net->addJoiningEdgesFrom(net); ofstream out((op.getStringOpt("out-prefix","") + name).c_str()); sg_net->printTo(out); delete sg_net; line_cnt += 1; } }