Commit ef7c769e authored by Georgios Dagkakis's avatar Georgios Dagkakis

correction so that G.Router is eliminated

parent 3a38d684
...@@ -238,7 +238,7 @@ class BatchReassembly(CoreObject): ...@@ -238,7 +238,7 @@ class BatchReassembly(CoreObject):
# if the activeEntity is in the pendingEntities list then place the subBatches there # if the activeEntity is in the pendingEntities list then place the subBatches there
if activeObjectQueue[0] in G.pendingEntities: if activeObjectQueue[0] in G.pendingEntities:
G.pendingEntities.append(batchToBeReassembled) G.pendingEntities.append(batchToBeReassembled)
if G.Router: if G.RouterList:
for entity in activeObjectQueue: for entity in activeObjectQueue:
G.pendingEntities.remove(entity) G.pendingEntities.remove(entity)
......
...@@ -108,7 +108,7 @@ class Exit(CoreObject): ...@@ -108,7 +108,7 @@ class Exit(CoreObject):
# if the entity is in the G.pendingEntities list then remove it from there # if the entity is in the G.pendingEntities list then remove it from there
from Globals import G from Globals import G
# G.pendingEntities[:]=(entity for entity in G.pendingEntities if not entity is activeEntity) # G.pendingEntities[:]=(entity for entity in G.pendingEntities if not entity is activeEntity)
if G.Router: if G.RouterList:
if activeEntity in G.pendingEntities: if activeEntity in G.pendingEntities:
G.pendingEntities.remove(activeEntity) G.pendingEntities.remove(activeEntity)
# if activeEntity in G.EntityList: # if activeEntity in G.EntityList:
......
...@@ -76,10 +76,7 @@ class G: ...@@ -76,10 +76,7 @@ class G:
outputJSONFile=None outputJSONFile=None
numberOfEntities = 0 numberOfEntities = 0
#object that routes the operators in the model
Router=None
# define the lists of each object type # define the lists of each object type
SourceList=[] SourceList=[]
MachineList=[] MachineList=[]
......
...@@ -295,7 +295,7 @@ class Job(Entity): # inherits from the Entity c ...@@ -295,7 +295,7 @@ class Job(Entity): # inherits from the Entity c
#=========================================================================== #===========================================================================
def findCandidateReceiver(self): def findCandidateReceiver(self):
from Globals import G from Globals import G
router=G.Router router=G.RouterList[0]
# initiate the local list variable available receivers # initiate the local list variable available receivers
availableReceivers=[x for x in self.candidateReceivers\ availableReceivers=[x for x in self.candidateReceivers\
if not x in router.occupiedReceivers] if not x in router.occupiedReceivers]
......
...@@ -124,7 +124,6 @@ def createObjectResourcesAndCoreObjects(): ...@@ -124,7 +124,6 @@ def createObjectResourcesAndCoreObjects():
G.OperatorManagedJobsList = [] G.OperatorManagedJobsList = []
G.OperatorPoolsList = [] G.OperatorPoolsList = []
G.BrokersList = [] G.BrokersList = []
G.Router = None
G.OperatedMachineList = [] G.OperatedMachineList = []
G.BatchScrapMachineList=[] G.BatchScrapMachineList=[]
G.OrderDecompositionList=[] G.OrderDecompositionList=[]
...@@ -592,6 +591,7 @@ def main(argv=[], input_data=None): ...@@ -592,6 +591,7 @@ def main(argv=[], input_data=None):
#create an empty list to store all the objects in #create an empty list to store all the objects in
G.ObjList=[] G.ObjList=[]
G.RouterList=[]
if input_data is None: if input_data is None:
# user passes the topology filename as first argument to the program # user passes the topology filename as first argument to the program
...@@ -618,9 +618,9 @@ def main(argv=[], input_data=None): ...@@ -618,9 +618,9 @@ def main(argv=[], input_data=None):
G.env=simpy.Environment() # initialize the environment G.env=simpy.Environment() # initialize the environment
G.maxSimTime=float(G.JSONData['general'].get('maxSimTime', '100')) # read the maxSimTime in each replication G.maxSimTime=float(G.JSONData['general'].get('maxSimTime', '100')) # read the maxSimTime in each replication
# since it may be changed for infinite ones # since it may be changed for infinite ones
if G.Router: if G.RouterList:
G.Router.isActivated=False G.RouterList[0].isActivated=False
G.Router.isInitialized=False G.RouterList[0].isInitialized=False
if G.seed: if G.seed:
G.Rnd=Random('%s%s' % (G.seed, i)) G.Rnd=Random('%s%s' % (G.seed, i))
...@@ -695,7 +695,6 @@ def main(argv=[], input_data=None): ...@@ -695,7 +695,6 @@ def main(argv=[], input_data=None):
if 0: if 0:
G.outputJSONFile=open('outputJSON.json', mode='w') G.outputJSONFile=open('outputJSON.json', mode='w')
G.outputJSONFile.write(outputJSONString) G.outputJSONFile.write(outputJSONString)
if not input_data: if not input_data:
# Output on stdout # Output on stdout
print outputJSONString print outputJSONString
......
...@@ -257,16 +257,16 @@ class Machine(CoreObject): ...@@ -257,16 +257,16 @@ class Machine(CoreObject):
if (self.operatorPool!='None'): if (self.operatorPool!='None'):
from Globals import G from Globals import G
# if there is no router # if there is no router
if not G.Router: if not G.RouterList:
# TODO if the dedicatedOperator flag is raised then create a SkilledRouter (temp) # TODO if the dedicatedOperator flag is raised then create a SkilledRouter (temp)
if self.dedicatedOperator: if self.dedicatedOperator:
self.router=SkilledRouter() self.router=SkilledRouter()
else: else:
self.router=Router() self.router=Router()
G.Router=self.router G.RouterList[0]=self.router
# otherwise set the already existing router as the machines Router # otherwise set the already existing router as the machines Router
else: else:
self.router=G.Router self.router=G.RouterList[0]
#=========================================================================== #===========================================================================
# initialise broker if needed # initialise broker if needed
#=========================================================================== #===========================================================================
...@@ -507,7 +507,7 @@ class Machine(CoreObject): ...@@ -507,7 +507,7 @@ class Machine(CoreObject):
yield self.env.process(self.release()) yield self.env.process(self.release())
from Globals import G from Globals import G
# append the entity that was stopped to the pending ones # append the entity that was stopped to the pending ones
if G.Router: if G.RouterList:
G.pendingEntities.append(self.currentEntity) G.pendingEntities.append(self.currentEntity)
#=========================================================== #===========================================================
# # request a resource after the interruption # # request a resource after the interruption
...@@ -581,8 +581,8 @@ class Machine(CoreObject): ...@@ -581,8 +581,8 @@ class Machine(CoreObject):
if self.signalGiver(): if self.signalGiver():
# XXX cleaner implementation needed # XXX cleaner implementation needed
# if there is skilled router the giver should also check # if there is skilled router the giver should also check
if G.Router: if G.RouterList:
if 'Skilled' in str(G.Router.__class__): if 'Skilled' in str(G.RouterList[0].__class__):
continue continue
break break
if self.loadOperatorAvailable in receivedEvent: if self.loadOperatorAvailable in receivedEvent:
...@@ -594,8 +594,8 @@ class Machine(CoreObject): ...@@ -594,8 +594,8 @@ class Machine(CoreObject):
if self.signalGiver(): if self.signalGiver():
# XXX cleaner implementation needed # XXX cleaner implementation needed
# if there is router that is not skilled break # if there is router that is not skilled break
if G.Router: if G.RouterList:
if not 'Skilled' in str(G.Router.__class__): if not 'Skilled' in str(G.RouterList[0].__class__):
break break
# else continue, the giver should also check # else continue, the giver should also check
continue continue
...@@ -889,7 +889,7 @@ class Machine(CoreObject): ...@@ -889,7 +889,7 @@ class Machine(CoreObject):
except IndexError: except IndexError:
pass pass
from Globals import G from Globals import G
if G.Router: if G.RouterList:
# the just processed entity is added to the list of entities # the just processed entity is added to the list of entities
# pending for the next processing # pending for the next processing
G.pendingEntities.append(activeObjectQueue[0]) G.pendingEntities.append(activeObjectQueue[0])
...@@ -1095,7 +1095,7 @@ class Machine(CoreObject): ...@@ -1095,7 +1095,7 @@ class Machine(CoreObject):
activeEntity=CoreObject.getEntity(self) # run the default method activeEntity=CoreObject.getEntity(self) # run the default method
# after the machine receives an entity, it must be removed from the pendingEntities list # after the machine receives an entity, it must be removed from the pendingEntities list
from Globals import G from Globals import G
if G.Router: if G.RouterList:
if activeEntity in G.pendingEntities: if activeEntity in G.pendingEntities:
G.pendingEntities.remove(activeEntity) G.pendingEntities.remove(activeEntity)
return activeEntity return activeEntity
...@@ -1141,7 +1141,7 @@ class Machine(CoreObject): ...@@ -1141,7 +1141,7 @@ class Machine(CoreObject):
activeEntity=entity activeEntity=entity
from Globals import G from Globals import G
router = G.Router router = G.RouterList[0]
# if the entity is in a machines who's broker waits for operator then # if the entity is in a machines who's broker waits for operator then
if self in router.pendingMachines: if self in router.pendingMachines:
activeEntity.proceed=True activeEntity.proceed=True
...@@ -1177,11 +1177,11 @@ class Machine(CoreObject): ...@@ -1177,11 +1177,11 @@ class Machine(CoreObject):
# if the Router is expecting for signal send it # if the Router is expecting for signal send it
from Globals import G from Globals import G
from SkilledOperatorRouter import SkilledRouter from SkilledOperatorRouter import SkilledRouter
if G.Router.__class__ is SkilledRouter: if G.RouterList[0].__class__ is SkilledRouter:
if G.Router.expectedFinishSignals: if G.RouterList[0].expectedFinishSignals:
if self.id in G.Router.expectedFinishSignalsDict: if self.id in G.RouterList[0].expectedFinishSignalsDict:
signal=G.Router.expectedFinishSignalsDict[self.id] signal=G.RouterList[0].expectedFinishSignalsDict[self.id]
self.sendSignal(receiver=G.Router, signal=signal) self.sendSignal(receiver=G.RouterList[0], signal=signal)
self.broker.invoke() self.broker.invoke()
self.toBeOperated = False self.toBeOperated = False
......
...@@ -66,12 +66,12 @@ class MachineManagedJob(MachineJobShop): ...@@ -66,12 +66,12 @@ class MachineManagedJob(MachineJobShop):
def createRouter(self): def createRouter(self):
#create a Router #create a Router
from Globals import G from Globals import G
if not G.Router: if not G.RouterList:
self.router=RouterManaged() self.router=RouterManaged()
G.Router=self.router G.RouterList[0]=self.router
# otherwise set the already existing router as the machines Router # otherwise set the already existing router as the machines Router
else: else:
self.router=G.Router self.router=G.RouterList[0]
#=========================================================================== #===========================================================================
# initialize broker if needed # initialize broker if needed
......
...@@ -53,13 +53,13 @@ class ManPyObject(object): ...@@ -53,13 +53,13 @@ class ManPyObject(object):
def requestAllocation(): def requestAllocation():
# TODO: signal the Router, skilled operators must be assigned to operatorPools # TODO: signal the Router, skilled operators must be assigned to operatorPools
from Globals import G from Globals import G
G.Router.allocation=True G.RouterList[0].allocation=True
G.Router.waitEndProcess=False G.RouterList[0].waitEndProcess=False
if not G.Router.invoked and G.Router.expectedSignals['isCalled']: if not G.RouterList[0].invoked and G.RouterList[0].expectedSignals['isCalled']:
G.Router.invoked=True G.RouterList[0].invoked=True
succeedTuple=(G.env,G.env.now) succeedTuple=(G.env,G.env.now)
G.Router.isCalled.succeed(succeedTuple) G.RouterList[0].isCalled.succeed(succeedTuple)
G.Router.expectedSignals['isCalled']=0 G.RouterList[0].expectedSignals['isCalled']=0
#=========================================================================== #===========================================================================
# signalRouter method # signalRouter method
...@@ -74,12 +74,12 @@ class ManPyObject(object): ...@@ -74,12 +74,12 @@ class ManPyObject(object):
if receiver.isLoadRequested(): if receiver.isLoadRequested():
try: try:
from Globals import G from Globals import G
if not G.Router.invoked and G.Router.expectedSignals['isCalled']: if not G.RouterList[0].invoked and G.RouterList[0].expectedSignals['isCalled']:
# self.printTrace(self.id, signal='router') # self.printTrace(self.id, signal='router')
G.Router.invoked=True G.RouterList[0].invoked=True
succeedTuple=(G.env,G.env.now) succeedTuple=(G.env,G.env.now)
G.Router.isCalled.succeed(succeedTuple) G.RouterList[0].isCalled.succeed(succeedTuple)
G.Router.expectedSignals['isCalled']=0 G.RouterList[0].expectedSignals['isCalled']=0
return True return True
except: except:
return False return False
......
...@@ -96,10 +96,10 @@ class Broker(ObjectInterruption): ...@@ -96,10 +96,10 @@ class Broker(ObjectInterruption):
# add the currentEntity to the pendingEntities # add the currentEntity to the pendingEntities
if not self.victim.currentEntity in G.pendingEntities: if not self.victim.currentEntity in G.pendingEntities:
G.pendingEntities.append(self.victim.currentEntity) G.pendingEntities.append(self.victim.currentEntity)
if not G.Router.invoked and G.Router.expectedSignals['isCalled']: if not G.RouterList[0].invoked and G.RouterList[0].expectedSignals['isCalled']:
self.victim.printTrace(self.victim.id, signal='router (broker)') self.victim.printTrace(self.victim.id, signal='router (broker)')
self.sendSignal(receiver=G.Router, signal=G.Router.isCalled) self.sendSignal(receiver=G.RouterList[0], signal=G.RouterList[0].isCalled)
G.Router.invoked=True G.RouterList[0].invoked=True
self.waitForOperator=True self.waitForOperator=True
self.victim.printTrace(self.victim.id, waitEvent='(resourceIsAvailable broker)') self.victim.printTrace(self.victim.id, waitEvent='(resourceIsAvailable broker)')
...@@ -118,7 +118,7 @@ class Broker(ObjectInterruption): ...@@ -118,7 +118,7 @@ class Broker(ObjectInterruption):
# else if the Router is already invoked for allocating purposes wait until a resource is allocated to the victim's operatorPool # else if the Router is already invoked for allocating purposes wait until a resource is allocated to the victim's operatorPool
# wait only if there is no current operator # wait only if there is no current operator
# XXX discuss this # XXX discuss this
elif G.Router.invoked and G.Router.allocation and not self.victim.currentOperator: elif G.RouterList[0].invoked and G.RouterList[0].allocation and not self.victim.currentOperator:
self.waitForOperator=True self.waitForOperator=True
self.victim.printTrace(self.victim.id, waitEvent='(resourceIsAvailable broker)') self.victim.printTrace(self.victim.id, waitEvent='(resourceIsAvailable broker)')
...@@ -178,10 +178,10 @@ class Broker(ObjectInterruption): ...@@ -178,10 +178,10 @@ class Broker(ObjectInterruption):
# TODO: signalling the router must be done more elegantly, router must be set as global variable # TODO: signalling the router must be done more elegantly, router must be set as global variable
# if the router is already invoked then do not signal it again # if the router is already invoked then do not signal it again
if not G.Router.invoked and G.Router.expectedSignals['isCalled']: if not G.RouterList[0].invoked and G.RouterList[0].expectedSignals['isCalled']:
self.victim.printTrace(self.victim.id, signal='router (broker)') self.victim.printTrace(self.victim.id, signal='router (broker)')
G.Router.invoked=True G.RouterList[0].invoked=True
self.sendSignal(receiver=G.Router, signal=G.Router.isCalled) self.sendSignal(receiver=G.RouterList[0], signal=G.RouterList[0].isCalled)
# TODO: signalling the router will give the chance to it to take the control, but when will it eventually receive it. # TODO: signalling the router will give the chance to it to take the control, but when will it eventually receive it.
# after signalling the broker will signal it's victim that it has finished it's processes # after signalling the broker will signal it's victim that it has finished it's processes
# TODO: this wont work for the moment. The actions that follow must be performed by all operated brokers. # TODO: this wont work for the moment. The actions that follow must be performed by all operated brokers.
......
...@@ -128,7 +128,7 @@ class Operator(ObjectResource): ...@@ -128,7 +128,7 @@ class Operator(ObjectResource):
#=========================================================================== #===========================================================================
def sortStations(self): def sortStations(self):
from Globals import G from Globals import G
router=G.Router router=G.RouterList[0]
candidateMachines=self.candidateStations candidateMachines=self.candidateStations
# for the candidateMachines # for the candidateMachines
if candidateMachines: if candidateMachines:
......
...@@ -84,7 +84,7 @@ class OperatorManagedJob(Operator): ...@@ -84,7 +84,7 @@ class OperatorManagedJob(Operator):
#=========================================================================== #===========================================================================
def findAvailableEntity(self): def findAvailableEntity(self):
from Globals import G from Globals import G
router=G.Router router=G.RouterList[0]
# if the candidateEntities and the entitiesWithOccupiedReceivers lists are identical then return None # if the candidateEntities and the entitiesWithOccupiedReceivers lists are identical then return None
if len(set(self.candidateEntities).intersection(router.entitiesWithOccupiedReceivers))==len(self.candidateEntities): if len(set(self.candidateEntities).intersection(router.entitiesWithOccupiedReceivers))==len(self.candidateEntities):
return None return None
...@@ -106,7 +106,7 @@ class OperatorManagedJob(Operator): ...@@ -106,7 +106,7 @@ class OperatorManagedJob(Operator):
#=========================================================================== #===========================================================================
def findCandidateEntity(self): def findCandidateEntity(self):
from Globals import G from Globals import G
router=G.Router router=G.RouterList[0]
# pick a candidateEntity # pick a candidateEntity
candidateEntity=self.findAvailableEntity() candidateEntity=self.findAvailableEntity()
if not candidateEntity: if not candidateEntity:
......
...@@ -105,12 +105,12 @@ class QueueManagedJob(QueueJobShop): ...@@ -105,12 +105,12 @@ class QueueManagedJob(QueueJobShop):
if receiver.identifyEntityToGet().manager.isAssignedTo()!=receiver: if receiver.identifyEntityToGet().manager.isAssignedTo()!=receiver:
try: try:
from Globals import G from Globals import G
if not G.Router.invoked and G.Router.expectedSignals['isCalled']: if not G.RouterList[0].invoked and G.RouterList[0].expectedSignals['isCalled']:
# self.printTrace(self.id, signal='router') # self.printTrace(self.id, signal='router')
G.Router.invoked=True G.RouterList[0].invoked=True
succeedTuple=(G.env, G.env.now) succeedTuple=(G.env, G.env.now)
G.Router.isCalled.succeed(succeedTuple) G.RouterList[0].isCalled.succeed(succeedTuple)
G.Router.expectedSignals['isCalled']=0 G.RouterList[0].expectedSignals['isCalled']=0
return True return True
except: except:
return False return False
......
...@@ -42,7 +42,7 @@ class SkilledRouter(Router): ...@@ -42,7 +42,7 @@ class SkilledRouter(Router):
# TODO: we should maybe define a global schedulingRule criterion that will be # TODO: we should maybe define a global schedulingRule criterion that will be
# chosen in case of multiple criteria for different Operators # chosen in case of multiple criteria for different Operators
# ======================================================================= # =======================================================================
def __init__(self,sorting=False, outputSolutions=False): def __init__(self,sorting=False, outputSolutions=True):
Router.__init__(self) Router.__init__(self)
# Flag used to notify the need for re-allocation of skilled operators to operatorPools # Flag used to notify the need for re-allocation of skilled operators to operatorPools
self.allocation=False self.allocation=False
......
...@@ -167,7 +167,7 @@ class Source(CoreObject): ...@@ -167,7 +167,7 @@ class Source(CoreObject):
from Globals import G from Globals import G
assert entity, 'cannot append None entity' assert entity, 'cannot append None entity'
activeEntity=entity activeEntity=entity
if G.Router: if G.RouterList:
# at the newly created entity to the pendingEntities # at the newly created entity to the pendingEntities
G.pendingEntities.append(activeEntity) G.pendingEntities.append(activeEntity)
......
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