Here, I present the result of simulating the check-in process in a location-based social network. To this end, I have written a python script using SimPy, a Python-based simulation tool, the script is given below:

#!/usr/bin/env python

""" Simulate the Users visits to spatial locations in a social network

"""

from __future__ import generators # not needed for Python 2.3+

from SimPy.Simulation

import * from random

import gauss,shuffle,randint,choice,seed,random,Random,expovariateclass Generator(Process):

""" generates a set of users """

def __init__(self, maxNumberOfUsers):

Process.__init__(self)

self.name = "generator"

self.maxNumberOfUsers = maxNumberOfUsersdef execute(self):

users = []

userscopy = []

for i in range(self.maxNumberOfUsers):

j = User(i)

users.append(j)

userscopy.append(j)for user in users:

shuffle(userscopy)

numoffriends = gauss(numoffriends_mean,numoffriends_sd)

for k in range(int(numoffriends)):

if userscopy[k] != user:

user.addfriend(userscopy[k])

for user in users:

activate(user,user.execute())

yield hold,self,1.0

self.trace("WARNING generator finished -- ran out of Users")def trace(self,message):

if GTRACING: print "%7.4f \t%s"%(self.time(), message)

class User(Process):

def __init__(self,i):

Process.__init__(self)

self.i = i

self.name = "User"+`i`

self.friends = []

self.visits = []def getID(self):

return self.idef addfriend(self,friend):

self.friends.append(friend)def getvisits(self):

return self.visitsdef getfriendsvisits(self):

allvisits = []

for f in self.friends:

allvisits.extend(f.getvisits())

return allvisitsdef getrandomfriendsvisit(self,allvisits):

randomvisit = ""

if len(allvisits) == 0:

randomvisit = randint(0,maxnumvisits)

else:

self.trace("list is not empty")

randomvisit = choice(allvisits)

return randomvisitdef execute(self):

global busyStartTime,totalBusyVisits,totalBusyTime

global Nfree,busyEndTime,Jrv

self.trace("User "+`self.i`+" started")

while now()<= simulationtime:

visitedlocation = ""

Y = random()

if Y <= correlation:

allvisits = self.getfriendsvisits()

visitedlocation =

self.getrandomfriendsvisit(allvisits)

self.trace("A friend visit "+`visitedlocation`)

else:

visitedlocation = randint(0,maxnumvisits)

self.trace("A random visit "+`visitedlocation`)

visitshist[visitedlocation]+=1

self.visits.append(visitedlocation)

"""visitsrate = gauss(visitsrate_mean,visitsrate_sd)"""

visitsrate = visitsrate_mean

yield hold,self,1/visitsratedef trace(self,message):

if TRACING: print "%7.4f \t%s %s "%(now(), message , self.name)

""" Begin Main"""

simulationtime = 1000

correlation = 0.5

maxnumvisits = 1023

visitshist = []

for i in range(maxnumvisits+1):

visitshist.append(0)

numoffriends_mean = 100

numoffriends_sd = 30

maxNumberOfUsers = 10000

visitsrate_mean = 8.0

visitsrate_sd = 0.2

TRACING = 0

GTRACING =0g = Generator(maxNumberOfUsers)

activate(g,g.execute())

simulate(until=simulationtime)visitshist.sort()

print visitshist

print "Simulation ended"

In the simulation, we have six main independent (inputs); explained below as follows: (1) Number of spatial locations (NSL): it represents the total number of spatial locations that any user can visit at any time. (2) Average User Popularity (AUP): it represents the average number of friends per user (i.e., following a Gaussian distribution) for the population of all users in the social network. (3) Number of Users (NU): it represents the total number of users in the social network. (4) Average Visit Rate (AVR): it represents the average rate (i.e., following a Gaussian distribution) at which each user visits (check-ins) at any random spatial location. It is measured in number of visits per day. (5) Mobility-Friendship Correlation ratio (MFC): it is a value from 0 to 1 that determines the amount of correlation between being friends and visiting the same places. (6) Simulation time (ST): It represents the total time (i.e., number of days) over which we run the simulation.

Given the aforementioned independent variables, four dependent variables are measured: (1) Number of Visits (NV [i]): It represents the number of visits per a single spatial location. In other words, each spatial location i (i.e., such that i takes the value from 1 to Number of Spatial Locations (NSL)) has number of visits (users check-ins) NV[i]. (2) Minimum Location Visits (Min): it represents the number of visits (check-ins) in the spatial location that has the lowest number of user visits. (3) Maximum Location Visits (Max): it represents the number of visits (check-ins) in the spatial location that has the highest number of visits. (4) Location Visits Range (Range): It represents the absolute value of the dierence between the Maximum Location Visits (Max) and the Minimum Location Visits (Min).

In the simulation, three main independent variables are taken into account: (1) Average User Popularity(AUP), (2) Average Visit Rate (AV R), and (3) Mobility-Friendship Correlation ratio (MFC). Each of the three independent variables are varied, while keeping the other variables constant. We have run three main simulation experiments, measuring the eect of each independent variable as follows:

Experiment 1 (Effect of varying Average User Popularity (AUP)): In this experiment, we assign the constant values of 0.5 and 0.6667 to Mobility-Friendship Correlation ratio (MFC) and Average Visit Rate (AV R), respectively. We then measure the effect of Average User Popularity (AUP) taking the values of 140, 80, 160, 320, 640, 1280, 2560 on the Number of Visits (NV [i]) for each spatial location i such that 1 i NSL. I have also measured the effect of AUP on both Minimum Location Visits (Min) and Maximum Location Visits (Max). The following figure shows the values of both Minimum Location Visits (Min) and Maximum Location Visits (Max when varying AUP. From the gure, we can see that the Min is slightly decreasing and Max is substantially increasing. This trend is explained by the fact that the popularity of the users that visits a certain place increases the probability that the friends of this user and the friend of his friends and all the way through the social graph) will visit the same place.

Experiment 2 (Effect of varying Average Visit Rate (AVR)): In this experiment, we assign the values of 0.5 and 100 to Mobility-Friendship Correlation ratio (MFC) and Average User Popularity (AUP), respectively. Therefore, we measure the effect of Average Visit Rate (AV R) taking values of 0.5, 1.0, 2.0, 4.0, 8.0 on the same dependent variables measured in Experiment 1 (i.e., NV [i], Min, and Max). The following figure shows the values of both Minimum Location Visits (Min) and Maximum Location Visits (Max) when varying AVR. In the figure, It turns out that Min and Max are increasing approximately the same proportion which is intuitive as the total number of visits in each place increases in the same simulation time period.

Experiment 3 (Effect of varying Mobility-Friendship Correlation ratio (MFC)): In this experiment, we assign the values of 0.5 and 100 to Average Visit Rate (AV R) and Average User Popularity (AUP), receptively. Then, we measure the eect of varying Mobility-Friendship Correlation ratio (MFC) taking the values of 0.0, 0.2, 0.4, 0.8, 1.0 on the same dependent variables measured in both Experiment 1 and Experiment 2 (i.e., NV [i], Min, and Max). The following figure shows both Minimum Location Visits (Min) and Maximum Location Visits (Max) when varying MFC. The impact is quite intuitive; Max is substantially increasing when increasing MFC as some place are getting more and more attention (visits). Also, Min is slightly decreasing as some places were not initially visited by most of the users, which lead to less people interested to visit those place as their friends did not visit these places before. The results of applying this experiment show how the effect of Friendship-to-Mobility correlation could be manipulated to influence the users to visiting specific places.

## Leave a comment