Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions DITRAS.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from random import sample, uniform, random
import cPickle as pickle
import pickle as pickle
from math import sqrt, sin, cos, pi, asin, pow, ceil
from scipy.stats import expon
from collections import defaultdict
Expand All @@ -26,7 +26,7 @@ def timed(*argst, **kwt):
result = method(*argst, **kwt)
te = time.time()

print '\n\t\ttime: %2.2f min' % ((te-ts)/60.0)
print('\n\t\ttime: %2.2f min' % ((te-ts)/60.0))
return result

return timed
Expand Down Expand Up @@ -87,7 +87,7 @@ def compute_od_matrix(spatial_tessellation, filename='od_matrix.pkl'):
old_p = percentage
count += 1

print od_matrix.shape
print(od_matrix.shape)
pickle.dump(od_matrix, open(filename, 'wb'))

return od_matrix
Expand Down Expand Up @@ -157,7 +157,7 @@ def load_spatial_tessellation(filename='location2info_trentino', delimiter=','):
"""
spatial_tessellation = {}
f = csv.reader(open(filename), delimiter=delimiter)
f.next() # delete header
next(f) # delete header
i = 0
for line in f:
relevance = int(line[2])
Expand Down Expand Up @@ -236,7 +236,7 @@ def __preferential_return(self):
the identifier of the next location
"""
index = weighted_random_selection(self.location2visits.values())
next_location = self.location2visits.keys()[index]
next_location = list(self.location2visits)[index]
return next_location

def __preferential_exploration(self, current_location):
Expand Down Expand Up @@ -421,7 +421,7 @@ def start_simulation(self, diary_length):

## select the next state in the Markov chain
index = weighted_random_selection(self.markov_model[prev_state].values())
next_state = self.markov_model[prev_state].keys()[index]
next_state = list(self.markov_model[prev_state])[index]
V.append(next_state)

j = next_state[0]
Expand Down Expand Up @@ -562,13 +562,13 @@ def start_simulation(self, spatial_tessellation, od_matrix_file=None):

import argparse

print "----------------------------------------------"
print " DITRAS "
print " (DIary-based TRAjectory Simulator) "
print "----------------------------------------------"
print "Authors: ", __author__
print "Email: ", __contact__
print "----------------------------------------------\n"
print ("----------------------------------------------")
print (" DITRAS ")
print( " (DIary-based TRAjectory Simulator) ")
print ("----------------------------------------------")
print ("Authors: ", __author__)
print ("Email: ", __contact__)
print ("----------------------------------------------\n")

parser = argparse.ArgumentParser()
parser.add_argument('n_agents', type=int, help='number of agents to simulate')
Expand All @@ -588,7 +588,4 @@ def start_simulation(self, spatial_tessellation, od_matrix_file=None):
ditras = DITRAS(n_agents=args.n_agents, length=args.length, diary_generator=MD(filename=args.diary_generator),
trajectory_generator=dEPR(rho=0.6, gamma=0.21), filename=args.filename)

ditras.start_simulation(spatial_tessellation, od_matrix_file=args.od_matrix)



ditras.start_simulation(spatial_tessellation, od_matrix_file=args.od_matrix)