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