import lpIM_nobigM import mipIM_nobigM import calculate_LT # paramters of IM S = 6 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 ssMip = mipIM_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(ssMip, S, T, size, source, target, weight) print 'seed set selected by MIP_nobigM'
S = 2 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) inweights = [] outweights = [] for v in g.vs: inweights.append([(e.source, e['normalized inweight']) for e in g.es(_target=v.index)]) outweights.append([(e.target, e['normalized inweight']) for e in g.es(_source=v.index)]) # influence maximization - benders decomposition sepflag = 0 sBenders = bendersIM_CB.optimize(S, T, sepflag, inweights, outweights) # calculate expected spread calculate_LT.run(ssCplex, S, T, size, source, target, weight) print 'seed set selected by Cplex' calculate_LT.run(sCombinatorial, S, T, size, source, target, weight) print 'seed set selected by imcomplete Benders'
# double check # sort nodes by sum(out-weight) print '*********************************************************************************************' print 'Double check through intuition (sorted out-weights)' def reverse_comp(x, y): if x[1] > y[1]: return -1 if x[1] < y[1]: return 1 return 0 node_sumw = [] for v in g.vs: node_sumw.append( (v.index, sum(g.es(_source=v.index)['normalized inweight']))) node_sumw.sort(reverse_comp) for i in xrange(5): print node_sumw[i] # calculate expected spread calculate_LT.run(ssCplex, S, T, size, source, target, weight) print 'seed set selected by Cplex' calculate_LT.run(sBenders, S, T, size, source, target, weight) print 'seed set selected by imcomplete Benders' calculate_LT.run(ssBenders, S, T, size, source, target, weight) print 'seed set selected by EXACT Benders'
def calculate_spread(ss, size, source, target, weight): # calculate expected spread return calculate_LT.run(ss, S, T, size, source, target, weight)
S = 2 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) inweights = [] outweights = [] for v in g.vs: inweights.append([(e.source, e['normalized inweight']) for e in g.es(_target = v.index)]) outweights.append([(e.target, e['normalized inweight']) for e in g.es(_source = v.index)]) # influence maximization - benders decomposition sepflag = 0 sBenders = bendersIM_CB.optimize(S, T, sepflag, inweights, outweights) # calculate expected spread calculate_LT.run(ssCplex, S, T, size, source, target, weight) print 'seed set selected by Cplex' calculate_LT.run(sCombinatorial, S, T, size, source, target, weight) print 'seed set selected by imcomplete Benders'