def get_result_lp(g, size, source, target, weight): # influence maximization - LP relaxation t_start = datetime.now() ssLp, pLp, dInf = lpIM_nobigM.optimize(S, T, size, source, target, weight) ssLp_name = map(lambda s: g.vs[s]['name'], ssLp) t_end = datetime.now() seed_prob = map(lambda i: str(ssLp_name[i]) + '_' + str(pLp[i]), xrange(len(ssLp))) write_result(netname, 'lp', dInf, seed_prob, (t_end - t_start).seconds) # influence maximization - MAX-LP dtype = [('index', 'int'), ('name', 'int'), ('prob', 'float')] vseed_prob = map(lambda i: (ssLp[i], ssLp_name[i], pLp[i]), xrange(len(ssLp))) vseed_prob_arr = np.array(vseed_prob, dtype = dtype) vseed_prob_sort = np.sort(vseed_prob_arr, order = 'prob') ssMaxlp_name = map(lambda i: vseed_prob_sort[-i-1][1], xrange(S)) ssMaxlp = map(lambda i: int(vseed_prob_sort[-i-1][0]), xrange(S)) dInf = calculate_spread(ssMaxlp, size, source, target, weight) t_end1 = datetime.now() write_result(netname, 'maxlp', dInf, ssMaxlp_name, (t_end1 - t_start).seconds)
def get_result_lp(g, size, source, target, weight): # influence maximization - LP relaxation t_start = datetime.now() ssLp, pLp, dInf = lpIM_nobigM.optimize(S, T, size, source, target, weight) ssLp_name = map(lambda s: g.vs[s]['name'], ssLp) t_end = datetime.now() seed_prob = map(lambda i: str(ssLp_name[i]) + '_' + str(pLp[i]), xrange(len(ssLp))) write_result(netname, 'lp', dInf, seed_prob, (t_end - t_start).seconds) # influence maximization - MAX-LP dtype = [('index', 'int'), ('name', 'int'), ('prob', 'float')] vseed_prob = map(lambda i: (ssLp[i], ssLp_name[i], pLp[i]), xrange(len(ssLp))) vseed_prob_arr = np.array(vseed_prob, dtype=dtype) vseed_prob_sort = np.sort(vseed_prob_arr, order='prob') ssMaxlp_name = map(lambda i: vseed_prob_sort[-i - 1][1], xrange(S)) ssMaxlp = map(lambda i: int(vseed_prob_sort[-i - 1][0]), xrange(S)) dInf = calculate_spread(ssMaxlp, size, source, target, weight) t_end1 = datetime.now() write_result(netname, 'maxlp', dInf, ssMaxlp_name, (t_end1 - t_start).seconds)
import bendersIM_nobigM import lpIM_nobigM import calculate_LT # paramters of IM S = 5 T = 10 fname = '/bkfrat-GraphML/BKFRAB.GraphML' # 'SAMPIN.GraphML' # get directed weighted network g = read_graphml.preprocess(fname) print 'g is a DAG:', g.is_dag() # influence maximization - original size, source, target, weight = len(g.vs), [e.source for e in g.es], [e.target for e in g.es], [w for w in g.es['normalized inweight']] ssCplex = cplex_tiny.optimize(S, T, size, source, target, weight) # influence maximization - original ssLp = lpIM_nobigM.optimize(S, T, size, source, target, weight) # calculate expected spread calculate_LT.run(ssCplex, S, T, size, source, target, weight) print 'seed set selected by Cplex' calculate_LT.run(ssLp, S, T, size, source, target, weight) print 'seed set selected by LP_nobigM'