Пример #1
0
 def executeMonitorPlots (self):
     self.printSep()
     print "- Generating graph files"
     for each in self.monitorPlots:
         fileName = each + " series - Seed " + str(self.seed) + ".ps"
         plot = SimPlot ()
         pl = plot.plotLine (self.monitorPlots[each], color="blue",width=2)
         pl.postscr(fileName)
         print "Graph file created\t:\t " + fileName
Пример #2
0
	def plot(self):
		colors = iter(['red', 'green', 'blue', 'black', 'yellow', 'cyan', 'magenta'])
		plt=SimPlot()                                       # step 1
		title = '\nTime: '+str(Sim.now()) +'\n'
		plt.root.title(title)				           # step 3
		lines = []
		
		self.means.write('Time ' + str(Sim.now()) + ':\n')
		
		for name, population in Population.all_pops.items():
			if population.num_agents() == 0:
				continue
			plot_list = population.lang_plot_list()
			
			#make scatter chart of this population's language values
			color = colors.next()
			title += name + ': ' + color +';  '
			lines.append(plt.makeSymbols(plot_list,marker='dot',color=color))
			
			#calculate mean language values for this population
			sum_x = 0.0
			sum_y = 0.0
			for point in plot_list:
				sum_x += point[0]
				sum_y += point[1]
			self.means.write( '\t'+str(population.num_agents())+' '+name+'\t'+\
							str(sum_x/population.num_agents())+', '+\
							str(sum_y/population.num_agents()) + '\n' )	
		
		obj=plt.makeGraphObjects(lines)           		   # step 5
		frame=Frame(plt.root)                               # step 6
		graph=plt.makeGraphBase(frame,640,480, title=title) # step 7
		graph.pack()                                        # step 8
		graph.draw(obj)     # step 9
		graph.postscr(self.directory+'/plot'+str(self.numplots)+'.ps')
		self.numplots+=1
Пример #3
0
def PlotNetwork(numOfNodes):
	#First plot-----------------------------------------------------
	tempList = []
	plt=SimPlot()
	plt.root.title("The plot")
	objects = []
	for i in range(numOfNodes):
		tempList.append([G.NodesLocations[i][0],G.NodesLocations[i][1]])
	dots = plt.makeSymbols(tempList,color="green",size=2,marker='circle',windowsize=(1000,600))
	objects.append(dots)
	for i in range(numOfNodes):
		for j in range(i, numOfNodes):	
			src = [G.NodesLocations[i][0],G.NodesLocations[i][1]]
			dst = [G.NodesLocations[j][0],G.NodesLocations[j][1]]
			#objects.append(plt.makeLine([src,dst],splinesteps=20,color="blue",width=2))
	obj=plt.makeGraphObjects(objects)
	frame=Frame(plt.root)                               
	graph=plt.makeGraphBase(frame,1000,600, title="Network")      
	graph.pack()                                        
	graph.draw(obj)                                     
	frame.pack()
	
	#Second plot-----------------------------------------------------
	#Need to create a new root (Tk()) for every new plot
	#We use the same 'plt' object
	root1 = Tk()
	root1.title = "Panel 2"
	line = plt.makeLine([[0,0],[1,1],[2,4],[3,9]])
	obj2 = plt.makeGraphObjects([line])
	#Need to create a new frame and graph for our new root
	frame2=Frame(root1)                               
	graph2=plt.makeGraphBase(frame2,1000,600, title="Network")      
	graph2.pack()                                     
	graph2.draw(obj2)                                     
	frame2.pack()
	
	#This must be at the end
	plt.mainloop()
Пример #4
0

# Model -----------------------------------


class BankModel(Simulation):
    def run(self, aseed):
        """ PEM """
        seed(aseed)
        self.counter = Resource(1, name="Clerk", monitored=True, sim=self)
        source = Source(sim=self)
        self.activate(source, source.generate(number=20, rate=0.1), at=0.0)
        self.simulate(until=maxTime)


# Experiment data -------------------------

maxTime = 400.0  # minutes
seedVal = 393939

# Experiment -----------------------------------

mymodel = BankModel()
mymodel.run(aseed=seedVal)

# Output ---------------------------------------

plt = SimPlot()
plt.plotStep(mymodel.counter.waitMon, color="red", width=2)
plt.mainloop()
Пример #5
0
        seed(aseed)
        self.counter = Resource(1, name="Clerk", sim=self)
        self.Mon = Monitor('Time in the Bank', sim=self)
        source = Source(sim=self)
        self.activate(source, source.generate(number=20, rate=0.1), at=0.0)
        self.simulate(until=maxTime)


## Experiment data -------------------------

maxTime = 400.0  # minutes

N = 0
seedVal = 393939

## Experiment  -----------------------------

modl = BankModel()
modl.run(aseed=seedVal)

## Output ----------------------------------
Histo = modl.Mon.histogram(low=0.0, high=200.0, nbins=20)

plt = SimPlot()
plt.plotHistogram(Histo,
                  xlab='Time (min)',
                  title="Time in the Bank",
                  color="red",
                  width=2)
plt.mainloop()
Пример #6
0
    def MyXYPlot(X, Y):

        Z = zip(X, Y)
        plt = SimPlot()
        plt.plotLine(Z)
        plt.mainloop()
Пример #7
0
# Prog4.py
from SimPy.SimPlot import *
plt = SimPlot()
plt.plotBars([[0, 0], [1, 1], [2, 4], [3, 9]], color="blue", width=2)
plt.mainloop()
Пример #8
0
            edge = [ind, rod]
            self.EdgeList.append(edge)

        self.EdgeList = dict(self.EdgeList)

    def channelOn(self, chn):
        self.EdgeList[chn].color = v.color.red

    def channelOff(self, chn):
        self.EdgeList[chn].color = v.color.green


initialize()
Net = Network()
if G.vis_on: V = Vis()
for N in Net.Nodes:
    N.initCounterparts()
    N.activate()
simulate(until=G.max_time)
print 'Sim Finished, Visualising graphs...'

if not G.vis_on:
    plt = SimPlot()
    plt2 = SimPlot()
    plt2.plotLine(Net.waitQMon)
    plt.plotLine(Net.activeQMon)
    plt.mainloop()

#nx.draw(Net.graph_plan)
#plt.show()
Пример #9
0
            activate(c, c.visit())
            yield hold, self, 2


class Customer(Process):
    def visit(self):
        at = now()
        print at, self.name, "Arrived"
        yield request, self, k
        wait = now() - at
        wm.observe(wait)
        print self.name, "Waited for ", wait
        yield hold, self, 5
        yield release, self, k
        print now(), self.name, "Leaving"


initialize()
s = Source()
k = Resource(monitored=True)
wm = Monitor()
activate(s, s.generate(5), at=0)
simulate(until=100)

print wm.count(), wm.mean()

print k.waitMon
plt = SimPlot()
plt.plotBars(k.waitMon)
plt.mainloop()
                recipient = self.got[0].origin
                P = Packet(recipient, self.ID, 'ARQ')
                yield put, self, self.MacOut.macOutQueue, [P]
        

class Packet():
    def __init__(self, recipient, origin, p_type):
        self.recipient = recipient
        self.origin = origin
        self.p_type = p_type #ARQ or Data ('out')


initialize()
Network.Nodes = [NodeHead(i) for i in range(G.node_num)]
for N in Network.Nodes:
    N.initCounterparts()
    N.activate()
simulate(until=G.max_time)
print 'Sim Finished, Visualising graphs...'

plt = SimPlot()
plt2 = SimPlot()
plt2.plotLine(Network.Channels.waitMon)
plt.plotLine(Network.Channels.actMon)
plt.mainloop()

    



Пример #11
0
        self.group = grp
    def execute(self):
        yield hold, self, random.expovariate(1.0/lamb_da)
        while True: 
            for server in serverList:
                if server.name==self.group:
                    
                    yield put,self,server,1
            yield hold, self, random.expovariate(1.0/lamb_da)

initialize()

for grp in group_sizes:
    server = Level(name=grp, unitName='bandWidth', capacity='unbounded', monitored=True)
    serverList.append(server)
    for person in range(group_sizes[grp]):
        p = Person(grp)
        activate(p,p.execute())
N = Network()
activate(N,N.execute())

simulate(until=30)

plt = SimPlot()
for s in serverList:
    plt.plotLine(s.bufferMon)
plt.mainloop()
print 'done'
        
        
Пример #12
0
# Prog3.py
from SimPy.SimPlot import *
plt = SimPlot()
plt.plotStep([[0, 0], [1, 1], [2, 4], [3, 9]], color="red", width=2)
plt.mainloop()
Пример #13
0
tShopOpen = 8
tBeforeOpen = 1
tEndBake = tBeforeOpen + tShopOpen  # hours
nrDays = 100
r = random.Random(12371)
PLOTTING = True
# Experiment
waits = {}
waits["retail"] = []
waits["restaurant"] = []
for day in range(nrDays):
    bakery = model()
# Analysis/output
print("bakery")
for cType in ["retail", "restaurant"]:
    print("Average wait for {0} customers: {1:4.2f} hours".format(
        cType, (1.0 * sum(waits[cType])) / len(waits[cType])))
    print("Longest wait for {0} customers: {1:4.1f} hours".format(
        cType, max(waits[cType])))
    nrLong = len([1 for x in waits[cType] if x > 0.25])
    nrCust = len(waits[cType])
    print("Percentage of {0} customers having to wait for more than"
          " 0.25 hours: {1}".format(cType, 100 * nrLong / nrCust))

if PLOTTING:
    plt = SimPlot()
    plt.plotStep(bakery.stock.bufferMon,
                 title="Number of baguettes in stock during arbitrary day",
                 color="blue")
    plt.mainloop()
Пример #14
0
# Monitorplot.py
from random import uniform
from SimPy.Simulation import *
from SimPy.Recording import *
from SimPy.SimPlot import *


class Source(Process):
    def __init__(self, monitor):
        Process.__init__(self)
        self.moni = monitor
        self.arrived = 0

    def arrivalGenerator(self):
        while True:
            yield hold, self, uniform(0, 20)
            self.arrived += 1
            self.moni.observe(self.arrived)


initialize()
moni = Monitor(name="Arrivals", ylab="nr arrived")
s = Source(moni)
activate(s, s.arrivalGenerator())
simulate(until=100)

plt = SimPlot()
plt.plotStep(moni, color='blue')
plt.mainloop()
Пример #15
0
tBakeMin = 25/60.; tBakeMax=30/60.                                #hours
tArrivals = {"retail":1.0/40,"restaurant":1.0/4}                  #hours
buy = {"retail":[1,2,3],"restaurant":[20,40,60]}                 #nr baguettes
tShopOpen = 8; tBeforeOpen = 1; tEndBake = tBeforeOpen+tShopOpen  #hours
nrDays=100
r=random.Random(12371)
PLOTTING=True
## Experiment ------------------------------
waits={}
waits["retail"]=[]; waits["restaurant"]=[]
bakMod = BakeryModel()
for day in range(nrDays):
    bakery = bakMod.run()
## Analysis/output -------------------------
print 'bakery_OO'
for cType in ["retail","restaurant"]:
    print "Average wait for %s customers: %4.2f hours"\
    %(cType,(1.0*sum(waits[cType]))/len(waits[cType]))
    print "Longest wait for %s customers: %4.1f hours"%(cType,max(waits[cType]))
    nrLong = len([1 for x in waits[cType] if x>0.25])
    nrCust = len(waits[cType])
    print "Percentage of %s customers having to wait for more than 0.25 hours: %s"\
           %(cType,100*nrLong/nrCust)    


if PLOTTING:
    plt = SimPlot()
    plt.plotStep(bakery.stock.bufferMon,
             title="Number of baguettes in stock during arbitrary day",color="blue")
    plt.mainloop()
Пример #16
0
# Prog5.py
from SimPy.SimPlot import *
plt = SimPlot()
plt.plotScatter([[0, 0], [1, 1], [2, 4], [3, 9]],
                color="green", size=2, marker='triangle')
plt.mainloop()
Пример #17
0
# Prog2.py
from SimPy.SimPlot import *
plt = SimPlot()
plt.plotLine([[0, 0], [1, 1], [2, 4], [3, 9]], title="This is prettier",
             color="red", width=2, smooth=True)
plt.mainloop()
Пример #18
0
# AdvancedAPI.py
from SimPy.SimPlot import *
plt = SimPlot()  # step 1
plt.root.title("Advanced API example")  # step 3
line = plt.makeLine([[0, 42], [1, 1], [4, 16]])  # step 4
bar = plt.makeBars([[0, 42], [1, 1], [4, 16]], color='blue')  # step 4
sym = plt.makeSymbols([[1, 1]], marker="triangle", size=3,
                      fillcolor="red")  # step 4
obj = plt.makeGraphObjects([line, bar, sym])  # step 5
frame = Frame(plt.root)  # step 6
graph = plt.makeGraphBase(frame, 500, 300, title="Line and bars")  # step 7
graph.pack()  # step 8
graph.draw(obj)  # step 9
frame.pack()  # step 10
graph.postscr()  # step 11
plt.mainloop()  # step 12
Пример #19
0
# Prog1.py
from SimPy.SimPlot import *
plt = SimPlot()
plt.plotLine([[0, 0], [1, 1], [2, 4], [3, 9]])
plt.mainloop()
Пример #20
0
 def plotLine (self,monitor):
     SimPlot().plotLine (monitor).mainloop()
Пример #21
0
        yield hold, self, tib
        yield release, self, counter

        # print "%8.4f %s: Finished    "%(now(),self.name)


## Experiment data -------------------------

maxTime = 400.0  # minutes
counter = Resource(1, name="Clerk", monitored=True)

## Model -----------------------------------


def model(SEED=393939):
    seed(SEED)

    initialize()
    source = Source()
    activate(source, source.generate(number=20, rate=0.1), at=0.0)
    simulate(until=maxTime)


## Experiment -----------------------------------

model()

plt = SimPlot()
plt.plotStep(counter.waitMon, color="red", width=2)
plt.mainloop()
Пример #22
0
                #print self.ID, 'got ARQ, putting in ScreenResponse'
                yield put, self, self.Computer.ScreenResponse, self.got
                #print self.ID, 'put in screenResponse SUCCESS'
            elif self.got[0].p_type == 'out':
                #print self.ID, 'got DATA, putting ARQ in macOutQueue'
                recipient = self.got[0].origin
                P = Packet(recipient, self.ID, 'ARQ')
                yield put, self, self.MacOut.macOutQueue, [P]
                #print self.ID, 'put in macOutQueue SUCCESS'


class Packet():
    def __init__(self, recipient, origin, p_type):
        self.recipient = recipient
        self.origin = origin
        self.p_type = p_type


initialize()
Network.Nodes = [NodeHead(i) for i in range(G.node_num)]
for N in Network.Nodes:
    N.initCounterparts()
    N.activate()
simulate(until=G.max_time)
print 'Sim Finished, Visualising graphs...'

plt = SimPlot()
#plt.plotLine(Network.Channels.waitMon)
plt.plotLine(Network.Channels.actMon)
plt.mainloop()
        self.EdgeList[chn].color=v.color.red
    def channelOff(self,chn):
        self.EdgeList[chn].color=v.color.green


initialize()
Net = Network()
if G.vis_on: V = Vis()
for N in Net.Nodes:
    N.initCounterparts()
    N.activate()
simulate(until=G.max_time)
print 'Sim Finished, Visualising graphs...'

if not G.vis_on:
    plt = SimPlot()
    plt2 = SimPlot()
    plt2.plotLine(Net.waitQMon)
    plt.plotLine(Net.activeQMon)
    plt.mainloop()

#nx.draw(Net.graph_plan)
#plt.show()



    



Пример #24
0
maxTime = 400.0   # minutes                                     
                                
N = 0

## Model  ----------------------------------

class BankModel(Simulation):
    def run(self):
        self.initialize()
        self.counter = Resource(1,name="Clerk",sim=self)                           
        self.Mon = Monitor('Time in the Bank',sim=self)
        source = Source(sim=self)                                                         
        self.activate(source,
             source.generate(number=20,rate=0.1),at=0.0)    
        self.simulate(until=maxTime)                                      

## Experiment  -----------------------------

seed(393939)
modl=BankModel()
modl.run()

## Output ----------------------------------
Histo = modl.Mon.histogram(low=0.0,high=200.0,nbins=20)             

plt = SimPlot()                                                  
plt.plotHistogram(Histo,xlab='Time (min)',                       
                  title="Time in the Bank",
                  color="red",width=2)                         
plt.mainloop()                                                 
    ###########################################################
    # Analysis and Output

    print "Normalizing data..."
    normalizedData = {}
    for lang in Parameters.languages:
        data = []
        lastDatum = None
        for datum in lang.population.bufferMon:
            if lastDatum and datum[0] > lastDatum[0]:
                data.append(lastDatum)
            lastDatum = datum
        normalizedData[lang] = data

    colors = iter(["red", "green", "blue", "black", "yellow", "cyan", "magenta"])
    plt = SimPlot()  # step 1
    plt.root.title("Language Population Levels")  # step 3
    lines = []
    print "Language Colors:"
    for lang in Parameters.languages:
        color = colors.next()
        print "\t%s: %s" % (lang, color)
        lines.append(plt.makeLine(normalizedData[lang], color=color))
    #       lines.append(plt.makeLine(lang.population.bufferMon, color=color))

    obj = plt.makeGraphObjects(lines)  # step 5
    frame = Frame(plt.root)  # step 6
    graph = plt.makeGraphBase(frame, 640, 480, title="Population Levels", xtitle="Time", ytitle="Speakers")  # step 7
    graph.pack()  # step 8
    graph.draw(obj)  # step 9
    frame.pack()  # step 10
Пример #26
0
# Experiment data -------------------------

maxTime = 400.0  # minutes
counter = Resource(1, name="Clerk", monitored=True)

# Model -----------------------------------


def model(SEED=393939):  # 3
    seed(SEED)
    initialize()
    source = Source()
    activate(
        source,  # 4
        source.generate(number=20, rate=0.1),
        at=0.0)
    simulate(until=maxTime)  # 5


# Experiment -----------------------------------

model()

plt = SimPlot()  # 6
plt.plotStep(
    counter.waitMon,  # 7
    color="red",
    width=2)  # 8
plt.mainloop()  # 9