Skip to content

Commit

Permalink
new changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio-Cruciani committed Mar 4, 2023
1 parent 61ab25e commit e0cc421
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 15 deletions.
6 changes: 3 additions & 3 deletions ERAESMultiProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ def flood():


if __name__ == "__main__":
d_list = [4]
c_list = [1.5]
d_list = [3]
c_list = [3]
n_list = [512, 1024, 2048, 4096, 8192, 16384, 32768]


probs_list = [0.0,0.1, 0.5, 0.7, 0.9]
probs_list = [0.0,0.1,0.5,0.7,0.9]
outPath = "./tmp/"
for d in d_list:
for c in c_list:
Expand Down
106 changes: 106 additions & 0 deletions ERAESSprectralGapMP.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import multiprocessing
from src.Graphs.Objects.MultipleEdge import DynamicGraph
from src.StastModules.Snapshot import get_snapshot
from src.FileOperations.WriteOnFile import create_file, create_folder, write_on_file_contents
from src.StastModules.SpectralAnalysis import spectral_gap_sparse,spectral_gap

import networkx as nx
import math as mt
import logging
import pandas as pd

logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)


def worker(data, return_dict):


"""worker function"""
final_stats = []

d = data["d"]
c = data["c"]
edge_falling_rate = data["edge_falling_rate"]
# sim = data["sim"]
max_iter = data["max_iter"]
G = DynamicGraph(n, d, c,falling_probability= edge_falling_rate)
t = 0
achieved = False
repeat = True
sim = {
"simulation": data["sim"]
}
while (repeat):



G.add_phase()
G.del_phase()
spectralGapBefore = spectral_gap(G.get_G())

stats_bef = {
"spectralGapBefore": spectralGapBefore,
}
if (edge_falling_rate != 0):
G.random_fall()
spectralGapAfter = spectral_gap(G.get_G())

stats_aft = {
"spectralGapAfter": spectralGapAfter,
}
stats = get_snapshot(G, edge_falling_rate, G.get_d(), G.get_c(), t)
if t==max_iter:
repeat = False
logging.info("Spectral Gap simulation %r: TERMINATED" % data["sim"])

final_stats.append({**sim, **stats_bef, **stats_aft, **stats})

t += 1

# print(G.flooding.get_list_of_informed_ndoes())
# print(str(sim) + " represent!")
return_dict[sim['simulation']] = final_stats


if __name__ == "__main__":
d_list = [5]
c_list = [1.5]
n_list = [512, 1024, 2048, 4096, 8192, 16384, 32768]


probs_list = [0.0]
outPath = "./tmp/"
for d in d_list:
for c in c_list:
for n in n_list:
for probs in probs_list:
data = {
"d": d,
"c": c,
"edge_falling_rate": probs,
"max_iter": 100
}
name = "ERAES_d_" + str(d) + "_c_" + str(c) +"_n_"+str(n)+ "_p_" + str(probs)
outpath = create_folder(outPath, name)
logging.info("EXECUTING: %r " % name)
manager = multiprocessing.Manager()
return_dict = manager.dict()
jobs = []
for i in range(10):
data["sim"] = i
p = multiprocessing.Process(target=worker, args=(data, return_dict))
jobs.append(p)
p.start()

for proc in jobs:
proc.join()

reduced = []
for key in return_dict:
reduced.extend(return_dict[key])

df = pd.DataFrame(reduced)

df.to_csv(outpath + "results.csv")

# print(return_dict.values())
27 changes: 15 additions & 12 deletions mixedDynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,32 +147,36 @@ def check_convergence_dynamic():


if __name__ == "__main__":
d_list = [4]
c_list = [1.5]
n_list = [512, 1024, 2048, 4096, 8192, 16384, 32768, 65536]
outrate_list = [0.1]
d_list = [6]
c_list = [5]
n_list = [32768]
outrate_list = [0.5]
inrate_list = []
for n in n_list:
for q in outrate_list:
inrate_list.append(n * q)
inrate_list.append((n * q,q))

probs_list = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]
outPath = "./tmp/"
#probs_list = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]
probs_list = [0.3]

#probs_list = [0.0]

outPath = "./evraes_6/"
for d in d_list:
for c in c_list:
for inrate in inrate_list:
for outrate in outrate_list:
#for outrate in outrate_list:
for probs in probs_list:
data = {
"d": d,
"c": c,
"inrate": inrate,
"outrate": outrate,
"inrate": inrate[0],
"outrate": inrate[1],
"edge_falling_rate": probs,
"max_iter": 100
}
name = "MixedDynamic_d_" + str(d) + "_c_" + str(c) + "_inrate_" + str(
inrate) + "_outrate_" + str(outrate) + "_p_" + str(probs)
inrate[0]) + "_outrate_" + str(inrate[1]) + "_p_" + str(probs)
outpath = create_folder(outPath, name)
logging.info("EXECUTING: %r " % name)
manager = multiprocessing.Manager()
Expand All @@ -190,7 +194,6 @@ def check_convergence_dynamic():
reduced = []
for key in return_dict:
reduced.extend(return_dict[key])
print("RED ",reduced)
df = pd.DataFrame(reduced)

df.to_csv(outpath + "results.csv")
Expand Down

0 comments on commit e0cc421

Please sign in to comment.