Initial commit
This commit is contained in:
commit
66a6860316
407 changed files with 1254365 additions and 0 deletions
100
models/seq_activity_synthetic/activityHeap
Normal file
100
models/seq_activity_synthetic/activityHeap
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
1 0.0369965791702
|
||||
11 0.112361121178
|
||||
21 0.189523720741
|
||||
31 0.265329885483
|
||||
41 0.351193237305
|
||||
51 0.424329686165
|
||||
61 0.503403902054
|
||||
71 0.585793471336
|
||||
81 0.666300058365
|
||||
91 0.747553253174
|
||||
101 0.819383978844
|
||||
111 0.89609503746
|
||||
121 0.983248543739
|
||||
131 1.06522829533
|
||||
141 1.14252686501
|
||||
151 1.2261744976
|
||||
161 1.31466271877
|
||||
171 1.39959833622
|
||||
181 1.48349328041
|
||||
191 1.55498168468
|
||||
201 1.65346956253
|
||||
211 1.72339303493
|
||||
221 1.80947418213
|
||||
231 1.8966868639
|
||||
241 1.98488123417
|
||||
251 2.05820538998
|
||||
261 2.14141397476
|
||||
271 2.22942459583
|
||||
281 2.32271511555
|
||||
291 2.40576608181
|
||||
301 2.49714803696
|
||||
311 2.57033128738
|
||||
321 2.6774387598
|
||||
331 2.74941821098
|
||||
341 2.84262607098
|
||||
351 2.91811845303
|
||||
361 3.00298368931
|
||||
371 3.0906529665
|
||||
381 3.17279081345
|
||||
391 3.25203700066
|
||||
401 3.33881318569
|
||||
411 3.41099376678
|
||||
421 3.5074937582
|
||||
431 3.5903646946
|
||||
441 3.68174929619
|
||||
451 3.74438583851
|
||||
461 3.846483922
|
||||
471 3.93494508266
|
||||
481 4.00627400875
|
||||
491 4.09206953049
|
||||
501 4.17475950718
|
||||
511 4.27938659191
|
||||
521 4.35353126526
|
||||
531 4.44219696522
|
||||
541 4.53062942028
|
||||
551 4.62787718773
|
||||
561 4.72561476231
|
||||
571 4.80551929474
|
||||
581 4.88197724819
|
||||
591 4.95832087994
|
||||
601 5.0694852829
|
||||
611 5.12849938869
|
||||
621 5.22403919697
|
||||
631 5.31599895954
|
||||
641 5.41053628922
|
||||
651 5.50732691288
|
||||
661 5.5965857029
|
||||
671 5.67406601906
|
||||
681 5.75309846401
|
||||
691 5.82838673592
|
||||
701 5.92596032619
|
||||
711 6.0086879015
|
||||
721 6.10739114285
|
||||
731 6.21923859119
|
||||
741 6.27322771549
|
||||
751 6.38529527187
|
||||
761 6.47293703556
|
||||
771 6.53682727814
|
||||
781 6.65581891537
|
||||
791 6.71455945969
|
||||
801 6.80037400723
|
||||
811 6.91889183521
|
||||
821 6.9950532198
|
||||
831 7.08413529396
|
||||
841 7.18531293869
|
||||
851 7.27630629539
|
||||
861 7.3714972496
|
||||
871 7.46341562271
|
||||
881 7.52094740868
|
||||
891 7.63184168339
|
||||
901 7.72163012028
|
||||
911 7.8110522747
|
||||
921 7.91753151417
|
||||
931 8.02938401699
|
||||
941 8.07042677402
|
||||
951 8.17484688759
|
||||
961 8.30661399364
|
||||
971 8.36005790234
|
||||
981 8.45208418369
|
||||
991 8.55275297165
|
||||
100
models/seq_activity_synthetic/heap
Normal file
100
models/seq_activity_synthetic/heap
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
1 0.0434678316116
|
||||
11 0.133412909508
|
||||
21 0.225492453575
|
||||
31 0.309032678604
|
||||
41 0.409567737579
|
||||
51 0.491759061813
|
||||
61 0.576551961899
|
||||
71 0.674240875244
|
||||
81 0.760449981689
|
||||
91 0.847740340233
|
||||
101 0.925866484642
|
||||
111 1.0078962326
|
||||
121 1.11241073608
|
||||
131 1.19523248672
|
||||
141 1.27863769531
|
||||
151 1.38438062668
|
||||
161 1.459243083
|
||||
171 1.576881814
|
||||
181 1.64183933735
|
||||
191 1.7368901968
|
||||
201 1.83008029461
|
||||
211 1.92973444462
|
||||
221 1.98396217823
|
||||
231 2.09815807343
|
||||
241 2.16953516006
|
||||
251 2.26794009209
|
||||
261 2.37409491539
|
||||
271 2.44366886616
|
||||
281 2.56823003292
|
||||
291 2.63154189587
|
||||
301 2.74254205227
|
||||
311 2.81574020386
|
||||
321 2.89424221516
|
||||
331 2.9930141449
|
||||
341 3.10339314938
|
||||
351 3.14053533077
|
||||
361 3.24346318245
|
||||
371 3.29555823803
|
||||
381 3.42022402287
|
||||
391 3.5177380085
|
||||
401 3.58471620083
|
||||
411 3.68094022274
|
||||
421 3.78023655415
|
||||
431 3.84717290401
|
||||
441 3.97184329033
|
||||
451 4.026471138
|
||||
461 4.13950898647
|
||||
471 4.198691082
|
||||
481 4.31832141876
|
||||
491 4.39427080154
|
||||
501 4.49693470001
|
||||
511 4.58197011948
|
||||
521 4.66899077892
|
||||
531 4.75015947819
|
||||
541 4.87970290184
|
||||
551 4.91326961517
|
||||
561 4.99702990055
|
||||
571 5.09888746738
|
||||
581 5.19202225208
|
||||
591 5.21126952171
|
||||
601 5.38277974129
|
||||
611 5.44291319847
|
||||
621 5.53623290062
|
||||
631 5.62146866322
|
||||
641 5.67341489792
|
||||
651 5.75633661747
|
||||
661 5.84951598644
|
||||
671 5.91121139526
|
||||
681 6.06040956974
|
||||
691 6.11662962437
|
||||
701 6.16239850521
|
||||
711 6.3313498497
|
||||
721 6.36863942146
|
||||
731 6.44239268303
|
||||
741 6.55453286171
|
||||
751 6.65348696709
|
||||
761 6.68114285469
|
||||
771 6.82621030807
|
||||
781 6.89641880989
|
||||
791 6.9305552721
|
||||
801 6.99953858852
|
||||
811 7.13309621811
|
||||
821 7.2346757412
|
||||
831 7.23939731121
|
||||
841 7.43054213524
|
||||
851 7.48551328182
|
||||
861 7.46244459152
|
||||
871 7.63466565609
|
||||
881 7.61626465321
|
||||
891 7.68279607296
|
||||
901 7.86631381512
|
||||
911 7.89718620777
|
||||
921 7.96069710255
|
||||
931 8.10045251846
|
||||
941 8.19234333038
|
||||
951 8.21232898235
|
||||
961 8.32538030148
|
||||
971 8.29039082527
|
||||
981 8.34688997269
|
||||
991 8.51907470226
|
||||
21
models/seq_activity_synthetic/model.py
Normal file
21
models/seq_activity_synthetic/model.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import sys
|
||||
sys.path.append("../../src/")
|
||||
from DEVS import *
|
||||
|
||||
|
||||
class Generator(AtomicDEVS):
|
||||
def __init__(self, num, ta):
|
||||
AtomicDEVS.__init__(self, "Generator" + str(num))
|
||||
self.state = None
|
||||
self.ta = ta
|
||||
|
||||
def timeAdvance(self):
|
||||
return self.ta
|
||||
|
||||
class StaticModel(CoupledDEVS):
|
||||
def __init__(self, size, actives):
|
||||
CoupledDEVS.__init__(self, "Root")
|
||||
ta_counter = 0
|
||||
for i in range(size):
|
||||
self.addSubModel(Generator(i, 1.0 if ta_counter < actives else float('inf')))
|
||||
ta_counter += 1
|
||||
9
models/seq_activity_synthetic/plot
Normal file
9
models/seq_activity_synthetic/plot
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
reset
|
||||
set terminal postscript enhanced colour portrait size 6, 6
|
||||
set out 'seq_activity_synthetic.eps'
|
||||
set key off
|
||||
set title "Relative performance of activity heap compared to normal heap"
|
||||
set xlabel "Active models"
|
||||
set ylabel "Time taken (%)"
|
||||
set yrange [75:110]
|
||||
plot "< paste seq_activity_synthetic/activityHeap seq_activity_synthetic/heap" using 1:(100*$2/$4), 100 w l lw 5
|
||||
136
models/seq_activity_synthetic/schedulerH.py
Executable file
136
models/seq_activity_synthetic/schedulerH.py
Executable file
|
|
@ -0,0 +1,136 @@
|
|||
# -*- coding: Latin-1 -*-
|
||||
from heapq import heappush, heappop, heapify
|
||||
from logger import *
|
||||
|
||||
class SchedulerH(object):
|
||||
"""
|
||||
Scheduler class itself
|
||||
"""
|
||||
def __init__(self, models, epsilon, totalModels):
|
||||
"""
|
||||
Constructor
|
||||
|
||||
:param models: all models in the simulation
|
||||
"""
|
||||
self.heap = []
|
||||
self.id_fetch = [None] * totalModels
|
||||
for model in models:
|
||||
self.id_fetch[model.model_id] = [model.timeNext, model.model_id, True, model]
|
||||
heappush(self.heap, self.id_fetch[model.model_id])
|
||||
|
||||
self.invalids = 0
|
||||
self.maxInvalids = len(models)*2
|
||||
self.epsilon = epsilon
|
||||
|
||||
def schedule(self, model):
|
||||
"""
|
||||
Schedule a model
|
||||
|
||||
:param model: the model to schedule
|
||||
"""
|
||||
#assert debug("Scheduling " + str(model))
|
||||
# Create the entry, as we have accepted the model
|
||||
elem = [model.timeNext, model.model_id, False, model]
|
||||
try:
|
||||
self.id_fetch[model.model_id] = elem
|
||||
except IndexError:
|
||||
# A completely new model
|
||||
self.id_fetch.append(elem)
|
||||
self.maxInvalids += 2
|
||||
# Check if it requires to be scheduled
|
||||
self.id_fetch[model.model_id][2] = True
|
||||
heappush(self.heap, self.id_fetch[model.model_id])
|
||||
|
||||
def unschedule(self, model):
|
||||
"""
|
||||
Unschedule a model
|
||||
|
||||
:param model: model to unschedule
|
||||
"""
|
||||
# Update the referece still in the heap
|
||||
self.id_fetch[model.model_id][2] = False
|
||||
# Remove the reference in our id_fetch
|
||||
self.id_fetch[model.model_id] = None
|
||||
|
||||
def massReschedule(self, reschedule_set):
|
||||
"""
|
||||
Reschedule all models provided.
|
||||
Equivalent to calling unschedule(model); schedule(model) on every element in the iterable.
|
||||
|
||||
:param reschedule_set: iterable containing all models to reschedule
|
||||
"""
|
||||
#NOTE rather dirty, though a lot faster for huge models
|
||||
#assert debug("Mass rescheduling")
|
||||
inf = float('inf')
|
||||
for model in reschedule_set:
|
||||
event = self.id_fetch[model.model_id]
|
||||
if event[2]:
|
||||
if model.timeNext == event[0]:
|
||||
continue
|
||||
self.invalids += 1
|
||||
event[2] = False
|
||||
self.id_fetch[model.model_id] = [model.timeNext, model.model_id, True, model]
|
||||
heappush(self.heap, self.id_fetch[model.model_id])
|
||||
#assert debug("Optimizing heap")
|
||||
if self.invalids >= self.maxInvalids:
|
||||
#assert info("Heap compaction in progress")
|
||||
self.heap = [i for i in self.heap if i[2]]
|
||||
heapify(self.heap)
|
||||
self.invalids = 0
|
||||
#assert info("Heap compaction complete")
|
||||
|
||||
def readFirst(self):
|
||||
"""
|
||||
Returns the time of the first model that has to transition
|
||||
|
||||
:returns: timestamp of the first model
|
||||
"""
|
||||
#assert debug("Reading first element from heap")
|
||||
self.cleanFirst()
|
||||
return self.heap[0][0]
|
||||
|
||||
def cleanFirst(self):
|
||||
"""
|
||||
Clean up the invalid elements in front of the list
|
||||
"""
|
||||
#assert debug("Cleaning list")
|
||||
try:
|
||||
while not self.heap[0][2]:
|
||||
heappop(self.heap)
|
||||
self.invalids -= 1
|
||||
except IndexError:
|
||||
# Nothing left, so it as clean as can be
|
||||
#assert debug("None in list")
|
||||
pass
|
||||
|
||||
def getImminent(self, time):
|
||||
"""
|
||||
Returns a list of all models that transition at the provided time, with a specified epsilon deviation allowed.
|
||||
|
||||
:param time: timestamp to check for models
|
||||
|
||||
.. warning:: For efficiency, this method only checks the **first** elements, so trying to invoke this function with a timestamp higher than the value provided with the *readFirst* method, will **always** return an empty set.
|
||||
"""
|
||||
#assert debug("Asking all imminent models")
|
||||
immChildren = []
|
||||
t, age = time
|
||||
try:
|
||||
# Age must be exactly the same
|
||||
first = self.heap[0]
|
||||
while (abs(first[0][0] - t) < self.epsilon) and (first[0][1] == age):
|
||||
# Check if the found event is actually still active
|
||||
if(first[2]):
|
||||
# Active, so event is imminent
|
||||
immChildren.append(first[3])
|
||||
first[2] = False
|
||||
else:
|
||||
# Wasn't active, but we will have to pop this to get the next
|
||||
# So we can lower the number of invalids
|
||||
self.invalids -= 1
|
||||
|
||||
# Advance the while loop
|
||||
heappop(self.heap)
|
||||
first = self.heap[0]
|
||||
except IndexError:
|
||||
pass
|
||||
return immChildren
|
||||
38
models/seq_activity_synthetic/timer.py
Normal file
38
models/seq_activity_synthetic/timer.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import sys
|
||||
import random
|
||||
schedulers = ["sim.setSchedulerActivityHeap()", "sim.setSchedulerCustom('schedulerH', 'SchedulerH')"]
|
||||
scheds = {0: "activityHeap", 1: "heap"}
|
||||
actives = range(0, 1000, 10)
|
||||
sys.setrecursionlimit(10000)
|
||||
sys.path.append("../../src/")
|
||||
from simulator import Simulator
|
||||
import time
|
||||
iters = max(int(sys.argv[1]), 20)
|
||||
|
||||
def runFunc(param):
|
||||
schedulername, scheduler = param
|
||||
f = open("seq_activity_synthetic/" + str(scheds[schedulername]), 'w')
|
||||
for active in actives:
|
||||
from model import StaticModel
|
||||
total = 0.0
|
||||
for _ in range(iters):
|
||||
random.seed(1)
|
||||
model = StaticModel(1000, active)
|
||||
sim = Simulator(model)
|
||||
sim.setMessageCopy('none')
|
||||
exec(scheduler)
|
||||
sim.setTerminationTime(100)
|
||||
start = time.time()
|
||||
sim.simulate()
|
||||
del sim
|
||||
total += (time.time() - start)
|
||||
f.write("%s %s\n" % (active, total/iters))
|
||||
print("%s %s" % (active, total/iters))
|
||||
f.close()
|
||||
|
||||
map(runFunc, enumerate(schedulers))
|
||||
"""
|
||||
from multiprocessing import Pool
|
||||
p = Pool(3)
|
||||
p.map(runFunc, enumerate(schedulers))
|
||||
"""
|
||||
Loading…
Add table
Add a link
Reference in a new issue