Router now waits for event triggered by Machine

parent 5a39d707
...@@ -25,8 +25,8 @@ Created on 8 Nov 2012 ...@@ -25,8 +25,8 @@ Created on 8 Nov 2012
Models a machine that can also have failures Models a machine that can also have failures
''' '''
from SimPy.Simulation import Process, Resource from SimPy.Simulation import Process, Resource, SimEvent
from SimPy.Simulation import activate, passivate, waituntil, now, hold, request, release from SimPy.Simulation import activate, passivate, waituntil, now, hold, request, release, waitevent
from Failure import Failure from Failure import Failure
from CoreObject import CoreObject from CoreObject import CoreObject
...@@ -136,11 +136,14 @@ class Machine(CoreObject): ...@@ -136,11 +136,14 @@ class Machine(CoreObject):
self.isPreemptive=isPreemptive self.isPreemptive=isPreemptive
self.resetOnPreemption=resetOnPreemption self.resetOnPreemption=resetOnPreemption
self.routerCycleOver=SimEvent('routerCycleOver')
# ======================================================================= # =======================================================================
# initialize the machine # initialize the machine
# ======================================================================= # =======================================================================
def initialize(self): def initialize(self):
# TODO: initialise Router for every replication
# using the Process __init__ and not the CoreObject __init__ # using the Process __init__ and not the CoreObject __init__
CoreObject.initialize(self) CoreObject.initialize(self)
# initialize the internal Queue (type Resource) of the Machine # initialize the internal Queue (type Resource) of the Machine
...@@ -216,8 +219,11 @@ class Machine(CoreObject): ...@@ -216,8 +219,11 @@ class Machine(CoreObject):
and any(type=="Load" for type in self.multOperationTypeList): and any(type=="Load" for type in self.multOperationTypeList):
# the machine informs the router that it can receive from a requesting object # the machine informs the router that it can receive from a requesting object
self.requestRouter() self.requestRouter()
self.router.startCycle.signal(self.id)
# the machine must wait until the router has decided which machine will operated by which operator # the machine must wait until the router has decided which machine will operated by which operator
# yield waitevent, self, self.routerCycleOver
yield waituntil, self, self.router.routerIsSet yield waituntil, self, self.router.routerIsSet
self.router.victim=None
# if the machine is not picked by the router the it should wait again # if the machine is not picked by the router the it should wait again
if not self.canProceedWithGetEntity: if not self.canProceedWithGetEntity:
continue continue
......
...@@ -26,9 +26,9 @@ Created on 19 Feb 2013 ...@@ -26,9 +26,9 @@ Created on 19 Feb 2013
Models an Interruption that schedules the operation of the machines by different managers Models an Interruption that schedules the operation of the machines by different managers
''' '''
from SimPy.Simulation import Process, Resource from SimPy.Simulation import Process, Resource, SimEvent
from ObjectInterruption import ObjectInterruption from ObjectInterruption import ObjectInterruption
from SimPy.Simulation import waituntil, now, hold, request, release from SimPy.Simulation import waituntil, now, hold, request, release, waitevent
# =========================================================================== # ===========================================================================
...@@ -49,6 +49,8 @@ class Router(ObjectInterruption): ...@@ -49,6 +49,8 @@ class Router(ObjectInterruption):
# list that holds all the objects that can receive # list that holds all the objects that can receive
self.pendingObjects=[] self.pendingObjects=[]
self.calledOperators=[] self.calledOperators=[]
# signal used to initiate the generator of the Router
self.startCycle=SimEvent('startCycle')
# # TODO: consider if there must be an argument set for the schedulingRules of the Router # # TODO: consider if there must be an argument set for the schedulingRules of the Router
# self.schedulingRule='' # self.schedulingRule=''
# list of the operators that may handle a machine at the current simulation time # list of the operators that may handle a machine at the current simulation time
...@@ -57,6 +59,7 @@ class Router(ObjectInterruption): ...@@ -57,6 +59,7 @@ class Router(ObjectInterruption):
self.multipleCriterionList=[] self.multipleCriterionList=[]
# TODO: find out which must be the default for the scheduling Rule # TODO: find out which must be the default for the scheduling Rule
self.schedulingRule='WT' self.schedulingRule='WT'
# TODO: create an initialise method for router to reset the attributes for every replication
# ======================================================================= # =======================================================================
# the run method # the run method
...@@ -68,15 +71,17 @@ class Router(ObjectInterruption): ...@@ -68,15 +71,17 @@ class Router(ObjectInterruption):
returns canAcceptAndIsRequested (inPositionToGet is True) returns canAcceptAndIsRequested (inPositionToGet is True)
''' '''
def run(self): def run(self):
from Globals import G from Globals import G, findObjectById
while 1: while 1:
# wait until the router is called # wait until the router is called
yield waituntil,self,self.routerIsCalled yield waitevent, self, self.startCycle
self.victim=findObjectById(self.startCycle.signalparam)
# yield waituntil,self,self.routerIsCalled
# when the router is called for the first time wait till all the entities # when the router is called for the first time wait till all the entities
# finished all their moves in stations of non-Machine-type # finished all their moves in stations of non-Machine-type
# before they can enter again a type-Machine object # before they can enter again a type-Machine object
yield waituntil, self,self.entitiesFinishedMoving yield waituntil, self,self.entitiesFinishedMoving
# update the objects to be served list (pendingObjects) # update the objects to be served list (pendingObjects)
self.pendingObjects=[object for object in G.MachineList if object.inPositionToGet] self.pendingObjects=[object for object in G.MachineList if object.inPositionToGet]
...@@ -178,6 +183,10 @@ class Router(ObjectInterruption): ...@@ -178,6 +183,10 @@ class Router(ObjectInterruption):
# assign an operator to the priorityObject # assign an operator to the priorityObject
operator.operatorAssignedTo=priorityObject operator.operatorAssignedTo=priorityObject
#=======================================================
# # TESTING
# print operator.id, 'got assigned to', priorityObject.id
#=======================================================
# and let it proceed withGetEntity # and let it proceed withGetEntity
priorityObject.canProceedWithGetEntity=True priorityObject.canProceedWithGetEntity=True
...@@ -281,6 +290,7 @@ class Router(ObjectInterruption): ...@@ -281,6 +290,7 @@ class Router(ObjectInterruption):
self.schedulingRule='WT' self.schedulingRule='WT'
# reset the call flag of the Router # reset the call flag of the Router
self.call=False self.call=False
# self.victim.routerCycleOver.signal('router has implemented its logic')
#======================================================================= #=======================================================================
# Sort pendingEntities # Sort pendingEntities
...@@ -460,26 +470,6 @@ class Router(ObjectInterruption): ...@@ -460,26 +470,6 @@ class Router(ObjectInterruption):
operator.candidateEntity=findCandidateEntity() operator.candidateEntity=findCandidateEntity()
if operator.candidateEntity: if operator.candidateEntity:
operator.candidateEntity.candidateReceiver=findCandidateReceiver() operator.candidateEntity.candidateReceiver=findCandidateReceiver()
# # initiate the local list variable available receivers
# availableReceivers=[x for x in operator.candidateEntity.candidateReceivers\
# if not x in occupiedReceivers]
# # and pick the object that is waiting for the most time
# if availableReceivers:
# # TODO: must find the receiver that waits the most
# maxTimeWaiting=0
# for object in availableReceivers:
# timeWaiting=now()-object.timeLastEntityLeft
# if(timeWaiting>maxTimeWaiting or maxTimeWaiting==0):
# maxTimeWaiting=timeWaiting
# availableReceiver=object
#
# operator.candidateEntity.candidateReceiver=availableReceiver
# occupiedReceivers.append(availableReceiver)
# # if there is no available receiver add the entity to the entitiesWithOccupiedReceivers list
# else:
# entitiesWithOccupiedReceivers.append(availableEntity)
# operator.candidateEntity.candidateReceiver=None
#======================================================================= #=======================================================================
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment