Revision fa4a0a42

View differences:

.gitignore
8 8
*.blg
9 9
*.synctex.gz
10 10
*.toc
11
varie/
11
varie/
12
out/
13
plot/
documents/manifest/manifest.tex
88 88

  
89 89
\begin{figure}[H]
90 90
\centering
91
  \includegraphics[width=.65\linewidth]{workflow.pdf}
91
  \includegraphics[width=.55\linewidth]{workflow.pdf}
92 92
  \caption{Workflow of Experiment to allow autocorrelation analysis}
93 93
  \label{fig:workflow}
94 94
\end{figure}
......
96 96
To simulate dynamic graphs we will use the Mobility Models implemented \href{https://github.com/panisson/pymobility}{here}.
97 97

  
98 98
Supported Mobility models are:
99
\begin{multicols}{2}
99
\begin{multicols}{3}
100
\footnotesize
100 101
  \begin{itemize}
101 102
     \item Random Walk
102 103
     \item Random Waypoint
103 104
     \item Random Direction
104 105
     \item Truncated Levy Walk \cite{rhee2011levy}
105 106
     \item Gauss-Markov \cite{camp2002survey}
106
     \item Reference Point Group Mobility model \cite{hong1999group}
107
     \item Reference Point Group \cite{hong1999group}
107 108
     \item Time-variant Community \cite{hsu2007modeling}
108 109
  \end{itemize}
109 110
\end{multicols}
......
114 115

  
115 116
\section{Preliminary Demo}\label{sec:demo}
116 117

  
118
\begin{multicols}{3}
119
\footnotesize
120
  \begin{itemize}
121
  \item duration: 10000,
122
  \item  max\_velocity: 1.0,
123
  \item  max\_wait\_time: 1.0,
124
  \item  max\_x: 100,
125
  \item  max\_y: 100,
126
  \item  min\_velocity: 0.1,
127
  \item  mob\_model: RandomWayPoint,
128
  \item  mobility\_timer: 1.0,
129
  \item  nodes\_number: 50,
130
  \item  radius: 30.0
131
  \end{itemize}
132
\end{multicols}
133

  
134

  
135
\begin{figure}[H]
136
\centering
137
  \includegraphics[width=.8\linewidth]{BCACF.pdf}
138
  \caption{ACF averaged over all Nodes}
139
  \label{fig:BCACF}
140
\end{figure}
141

  
142
\subsection{How is computed the above Mean ACF}
143
For every time-instant we have a graph. For each node in the graph we have its \ac{BC} index.
144
Therefore, for each node we can compute the ACF over the time-series of \ac{BC} for that node. Given that we have 50 nodes, for any time-lag we have
145
50 ACF values. The average ACF is computed over the 50 nodes for time-lags spanning from 0 to 750. 
146
This average ACF is plotted in \cref{fig:BCACF}
147

  
117 148

  
118 149

  
119 150
\bibliographystyle{IEEEtran}
mobiExp.py
2 2
import code  # code.interact(local=dict(globals(), **locals()))
3 3
from pprint import pprint
4 4
import sys
5
import os
6
import shutil
7
import datetime
5 8
from simulator import Simulator
6 9

  
7 10
if __name__ == '__main__':
8

  
11
    
9 12
    settingsFile = ''
10 13
    sectionExp = ''
14
    outPath = ''
15
    cdir = ''
11 16
    gui = False
12
    options, remainder = getopt.getopt(sys.argv[1:], '', ['sf=', 'en=', 'gui'])
13
    mand = set(['--sf', '--en'])
17
    options, remainder = getopt.getopt(
18
        sys.argv[1:], '', ['sf=', 'en=', 'out=', 'gui'])
19
    mand = set(['--sf', '--en', '--out'])
14 20
    opts = [x[0] for x in options]
15 21
    # print 'OPTIONS   :', opts
16 22
    if (not mand.issubset(opts)):
17
        print 'Mandatory args are: --sf (settings file) --en (experiment name)'
23
        print 'Mandatory args are: --sf (settings file) --en (experiment name)'\
24
            ' --out (Output path, overwrite or create folder)'
18 25
        sys.exit(1)
19 26
    for opt, arg in options:
20 27
        if opt in ('--sf'):
21 28
            settingsFile = arg
22 29
        if opt in ('--en'):
23 30
            sectionExp = arg
31
        if opt in ('--out'):
32
            outPath = arg
33
            outPath.rstrip("/")
34
            if not os.path.exists(outPath):
35
                sys.stderr.write("Cannot find the outpath you provided!")
36
                sys.exit(1)
37
            else:
38
                start = datetime.datetime.now().strftime("%H:%M:%S_%d-%m-%Y")
39
                cdir = outPath + '/' + sectionExp + '_'+ start
40
                if os.path.exists(cdir):
41
                    shutil.rmtree(cdir)
42
                os.makedirs(cdir)
24 43
        if opt in ('--gui'):
25 44
            gui = True
26 45

  
27
    sim = Simulator(settingsFile, sectionExp, gui)
46
    sim = Simulator(settingsFile, sectionExp, cdir, gui)
28 47
    print "Simulation Parameters\n"
29 48
    pprint(sim.params)
30 49
    #code.interact(local=dict(globals(), **locals()))
settings.ini
1
[exp1]
2
duration = 100s
1
[std]
2
duration = 10000s
3 3
nodes_number = 50
4 4
max_x = 100
5 5
max_y = 100
6 6
min_velocity = 0.1
7 7
max_velocity = 1.0
8
radius = 10.0
9
# attenuationCoef = 2.3
8
radius = 30.0
10 9
mobility_timer = 1s
11
# hello = 4s
12
# housecleaning = 0.1s
13 10
mob_model = RandomWayPoint
14 11
max_wait_time = 1.0
15 12

  
16 13

  
17
[SectionOne]
18
Param1: Hello
19
Param2: World
14
[fast]
15
duration = 10000s
16
nodes_number = 50
17
max_x = 100
18
max_y = 100
19
min_velocity = 10.0
20
max_velocity = 100.0
21
radius = 30.0
22
mobility_timer = 1s
23
mob_model = RandomWayPoint
24
max_wait_time = 1.0
20 25

  
21
[SectionTwo]
22
Param1: ${SectionOne:Param1} ${SectionOne:Param2}
23 26

  
24
[SectionThree]
25
Alpha: One
26
Bravo: Two
27
Charlie: ${Alpha} Mississippi
27
[slow]
28
duration = 10000s
29
nodes_number = 50
30
max_x = 100
31
max_y = 100
32
min_velocity = 0.01
33
max_velocity = 1.0
34
radius = 30.0
35
mobility_timer = 1s
36
mob_model = RandomWayPoint
37
max_wait_time = 1.0
simulator.py
1
import warnings
1 2
import util.EventScheduler as ES
2 3
from tqdm import tqdm  # https://pypi.org/project/tqdm/#usage
3 4
from util.UnitDiskGraph import UnitDiskGraph
4 5
from util.ConfPars import ConfSettings
6
import pandas as pd
5 7

  
6 8
import random
7 9
import code  # code.interact(local=dict(globals(), **locals()))
......
9 11
import networkx as nx
10 12
import util.MyUtil as myu
11 13
from time import sleep
14
import matplotlib.pyplot as plt
15
plt.ion()
12 16

  
13 17

  
14 18
class Simulator(object):
15 19

  
16
    def __init__(self, settingsFile, sectionExp, gui):
20
    def __init__(self, settingsFile, sectionExp, outPath, gui):
17 21
        self.gui = gui
18 22
        self.sched = ES.EventScheduler()  # scheduler
19 23
        config = ConfSettings(settingsFile, sectionExp)
20 24
        self.params = config.getSimulationParameters()
21 25
        self.expName = sectionExp
22 26
        self.mob = config.configMobility(self.params)
27
        self.OP = outPath
23 28

  
24 29
    def runSimulation(self):
30
        warnings.filterwarnings("ignore", module="matplotlib")
31
        sched = self.sched
25 32
        self.sched.schedule_event(0, "move!")
26 33

  
27 34
        print "\nRunning " + self.expName + "..."
28 35
        with tqdm(total=self.params['duration']) as pbar:
29
            while(self.sched.elapsed_time() < self.params['duration']):
30
                pbar.update(self.sched.step())
31
                event = self.sched.pop_event()
36
            while(sched.elapsed_time() < self.params['duration']):
37
                pbar.update(sched.step())
38
                event = sched.pop_event()
32 39

  
33 40
                # Get new coordinates
34 41
                positions = next(self.mob)
......
37 44
                G = UnitDiskGraph(positions, self.params['radius']).getGraph()
38 45

  
39 46
                if self.gui:
40
                    self.draw(G, positions, self.params)
41
                sleep(0.01)
47
                    self.draw(G, positions)
48
                stats = ['BC', 'LC', 'DEG']
49

  
50
                self.logStatistics(G, stats, sched.processed_events())
42 51
                # schedule next DV
43 52
                jitter = [-1, 1][random.randrange(2)]*random.uniform(0, 0.866)
44
                self.sched.schedule_event(1.0 + jitter, "move!")
53
                sched.schedule_event(1.0 + jitter, "move!")
45 54

  
46 55
        return
47 56

  
48
    def draw(self, G, pos, params):
49
        myu.draw(G, pos, params['max_x'], params['max_y'])
57
    def logStatistics(self, G, whatLog, tag):
58
        tag = '%08d' % tag
59
        for stat in whatLog:
60
            if stat == 'BC':
61
                bw_centrality = nx.betweenness_centrality(
62
                    G, normalized=False,  weight='weight', endpoints=False)
63
                df = pd.DataFrame(bw_centrality.items(),
64
                                  columns=['Node', 'BC'])
65
                df.to_csv(self.OP+"/BC"+tag+".csv", sep=',',
66
                          encoding='utf-8', index=False)
67
            if stat == 'LC':
68
                load_indexes = nx.load_centrality(
69
                    G, normalized=False, weight='weight')
70
                df = pd.DataFrame(load_indexes.items(), columns=['Node', 'LC'])
71
                df.to_csv(self.OP+"/LC"+tag+".csv", sep=',',
72
                          encoding='utf-8', index=False)
73
            if stat == 'DEG':
74
                degrees = dict(G.degree())
75
                df = pd.DataFrame(degrees.items(), columns=['Node', 'DEG'])
76
                df.to_csv(self.OP+"/DEG"+tag+".csv", sep=',',
77
                          encoding='utf-8', index=False)
78

  
79
    def draw(self, G, pos):
80
        xmax = self.params['max_x']
81
        ymax = self.params['max_y']
82
        myu.draw(G, pos, xmax, ymax)
timeAnalysis.py
1
import pandas as pd
2
from pprint import pprint
3
import numpy as np
4
import glob
5
from matplotlib import pyplot
6
from statsmodels.graphics.tsaplots import plot_acf, acf
7
import sys
8
import os
9
from collections import defaultdict
10
import matplotlib.pyplot as plt
11
import code  # code.interact(local=dict(globals(), **locals()))
12

  
13
folder = sys.argv[1]
14
lags = int(sys.argv[2])
15
os.chdir(folder)
16

  
17
timeBC = defaultdict(list)
18
print "Loading data from", folder, "..."
19
for snap in sorted(glob.glob('./BC*')):
20
    # print snap
21
    df = pd.read_csv(snap, names=['Node', 'BC'], skiprows=1)
22
    for index, row in df.iterrows():
23
        timeBC[int(row.Node)].append(row.BC)
24

  
25
print "Processing data..."
26
lags2NodeACF = defaultdict(list)
27
for node in timeBC:
28
    nodeACF = acf(timeBC[node], nlags=lags)
29
    for lag in range(0, len(nodeACF)):
30
        lags2NodeACF[lag].append(nodeACF[lag])
31

  
32
#code.interact(local=dict(globals(), **locals()))
33

  
34
os.chdir("./..")
35
# Plotting
36

  
37
#lags=20
38
x = range(0, lags)
39
y = []
40
for i in x:
41
    y.append(np.mean(lags2NodeACF[i]))
42

  
43
#plt.plot(x, y, marker=".", lw="1.5")
44
#plt.stem(x, y, markerfmt=' ')
45

  
46
plt.stem(x, y, s=0.1)
47
plt.ylabel('Mean Autocorrelation')
48
plt.xlabel('Time-lags')
49
#plt.ylim(-1.0,1.0)
50
plt.xlim(0,lags)
51

  
52
#plt.title("Mean Autocorrelation X time-lag", y=1.04)
53
plt.savefig("autoCorrMean.pdf", format='pdf')
54
plt.clf()
55
print "Plot saved in", folder+".."
56
print "THE END"
57
#plot_acf(timeBC[0.0], lags=lags)
58
#pyplot.show()
util/EventScheduler.py
6 6
                self.time = 0
7 7
                self.last = 0
8 8
                self._step = 0
9
                self.counter = 0
9 10

  
10 11
        def schedule_event(self, interval, e):
11 12
                t = self.time + interval
......
17 18
                e = heapq.heappop(self.queue)
18 19
                self._step = e[0] - self.time
19 20
                self.time = e[0]
21
                self.counter += 1
20 22
                return e[1]
21 23

  
22 24
        def elapsed_time(self):
......
26 28
                return self.last
27 29

  
28 30
        def step(self):
29
            return self._step
31
            return self._step
32

  
33
        def processed_events(self):
34
            return self.counter
util/MyUtil.py
3 3
import networkx as nx 
4 4
import random as rnd
5 5
import matplotlib.pyplot as plt
6
plt.ion()
6 7
import matplotlib.colors as mcolors
7 8
import sys
8 9
import code  # code.interact(local=dict(globals(), **locals()))
......
26 27
    plt.draw()
27 28
    plt.pause(0.01)
28 29
    plt.clf()
29
    
30
    #plt.show()
30 31

  
31 32
def dictAlikes(d1, d2, perc):
32 33
	if (sorted(d1.keys()) != sorted(d2.keys())):
util/UnitDiskGraph.py
2 2

  
3 3
import networkx as nx
4 4
from scipy import spatial
5
import code # code.interact(local=dict(globals(), **locals()))
5 6

  
6 7

  
7 8
class UnitDiskGraph:
......
12 13
    def genereateGraphFromKDtree(self, points, radius):
13 14
        tree = spatial.KDTree(points)
14 15
        edges = tree.query_pairs(r=radius)
16
        edges = [e+(1.0,) for e in edges]
15 17
        G = nx.Graph()
16 18
        #pos = {k:points[k] for k in range(0,len(points))}
17
        G.add_edges_from(edges)
19
        G.add_weighted_edges_from(edges, weight='weight')
18 20
        return G
19 21

  
20 22
    def getGraph(self):

Also available in: Unified diff