Failure, Operator, and ObjectResource updated

parent f1d38927
...@@ -96,19 +96,40 @@ class Failure(ObjectInterruption): ...@@ -96,19 +96,40 @@ class Failure(ObjectInterruption):
failTime=self.env.now failTime=self.env.now
if(self.repairman and self.repairman!="None"): #if the failure needs a resource to be fixed, the machine waits until the if(self.repairman and self.repairman!="None"): #if the failure needs a resource to be fixed, the machine waits until the
#resource is available #resource is available
yield self.repairman.getResource().request() # print self.env.now, self.repairman.id, 'will be requested by', self.victim.id
# update the time that the repair started # yield self.repairman.getResource().request()
timeOperationStarted=self.env.now # print self.repairman.Res.users
self.repairman.timeLastOperationStarted=self.env.now # # update the time that the repair started
# timeOperationStarted=self.env.now
# self.repairman.timeLastOperationStarted=self.env.now
with self.repairman.getResource().request() as request:
yield request
# update the time that the repair started
timeOperationStarted=self.env.now
self.repairman.timeLastOperationStarted=self.env.now
yield self.env.timeout(self.rngTTR.generateNumber()) # wait until the repairing process is over
self.victim.totalFailureTime+=self.env.now-failTime
self.reactivateVictim() # since repairing is over, the Machine is reactivated
self.victim.Up=True
self.outputTrace("is up")
self.repairman.totalWorkingTime+=self.env.now-timeOperationStarted
continue
yield self.env.timeout(self.rngTTR.generateNumber()) # wait until the repairing process is over yield self.env.timeout(self.rngTTR.generateNumber()) # wait until the repairing process is over
self.victim.totalFailureTime+=self.env.now-failTime self.victim.totalFailureTime+=self.env.now-failTime
self.reactivateVictim() # since repairing is over, the Machine is reactivated self.reactivateVictim() # since repairing is over, the Machine is reactivated
self.victim.Up=True self.victim.Up=True
self.outputTrace("is up") self.outputTrace("is up")
if(self.repairman and self.repairman!="None"): #if a resource was used, it is now released # if(self.repairman and self.repairman!="None"): #if a resource was used, it is now released
self.repairman.getResource().release() # print self.repairman.Res.users
self.repairman.totalWorkingTime+=self.env.now-timeOperationStarted # print self.env.now, self.repairman.id, 'about to be release from', self.victim.id
# self.repairman.Res.release()
# self.repairman.totalWorkingTime+=self.env.now-timeOperationStarted
# #=========================================================================== # #===========================================================================
# # interrupts the victim # # interrupts the victim
......
...@@ -24,7 +24,8 @@ Created on 18 Aug 2013 ...@@ -24,7 +24,8 @@ Created on 18 Aug 2013
''' '''
Class that acts as an abstract. It should have no instances. All the Resources should inherit from it Class that acts as an abstract. It should have no instances. All the Resources should inherit from it
''' '''
from SimPy.Simulation import Resource # from SimPy.Simulation import Resource
import simpy
# =========================================================================== # ===========================================================================
# the resource that repairs the machines # the resource that repairs the machines
...@@ -32,13 +33,15 @@ from SimPy.Simulation import Resource ...@@ -32,13 +33,15 @@ from SimPy.Simulation import Resource
class ObjectResource(object): class ObjectResource(object):
def __init__(self): def __init__(self):
from Globals import G
self.env=G.env
self.initialized = False self.initialized = False
def initialize(self): def initialize(self):
self.totalWorkingTime=0 #holds the total working time self.totalWorkingTime=0 #holds the total working time
self.totalWaitingTime=0 #holds the total waiting time self.totalWaitingTime=0 #holds the total waiting time
self.timeLastOperationStarted=0 #holds the time that the last repair was started self.timeLastOperationStarted=0 #holds the time that the last repair was started
self.Res=Resource(self.capacity) self.Res=simpy.Resource(self.env, capacity=self.capacity)
# variable that checks whether the resource is already initialized # variable that checks whether the resource is already initialized
self.initialized = True self.initialized = True
# list with the coreObjects IDs that the resource services # list with the coreObjects IDs that the resource services
...@@ -50,7 +53,7 @@ class ObjectResource(object): ...@@ -50,7 +53,7 @@ class ObjectResource(object):
# checks if the worker is available # checks if the worker is available
# ======================================================================= # =======================================================================
def checkIfResourceIsAvailable(self,callerObject=None): def checkIfResourceIsAvailable(self,callerObject=None):
return len(self.Res.activeQ)<self.capacity return len(self.Res.users)<self.capacity
# ======================================================================= # =======================================================================
# actions to be taken after the simulation ends # actions to be taken after the simulation ends
...@@ -86,7 +89,7 @@ class ObjectResource(object): ...@@ -86,7 +89,7 @@ class ObjectResource(object):
# returns the active queue of the resource # returns the active queue of the resource
# ======================================================================= # =======================================================================
def getResourceQueue(self): def getResourceQueue(self):
return self.Res.activeQ return self.Res.users
# ======================================================================= # =======================================================================
# check if the resource is already initialized # check if the resource is already initialized
......
...@@ -26,7 +26,8 @@ Created on 22 Nov 2012 ...@@ -26,7 +26,8 @@ Created on 22 Nov 2012
models an operator that operates a machine models an operator that operates a machine
''' '''
from SimPy.Simulation import Resource, now # from SimPy.Simulation import Resource, now
import simpy
import xlwt import xlwt
import scipy.stats as stat import scipy.stats as stat
from ObjectResource import ObjectResource from ObjectResource import ObjectResource
...@@ -49,7 +50,6 @@ class Operator(ObjectResource): ...@@ -49,7 +50,6 @@ class Operator(ObjectResource):
self.Working=[] # holds the percentage of working time self.Working=[] # holds the percentage of working time
# the following attributes are not used by the Repairman # the following attributes are not used by the Repairman
# self.activeCallersList=[] # the list of object that request the operator
self.schedulingRule=schedulingRule #the scheduling rule that the Queue follows self.schedulingRule=schedulingRule #the scheduling rule that the Queue follows
self.multipleCriterionList=[] #list with the criteria used to sort the Entities in the Queue self.multipleCriterionList=[] #list with the criteria used to sort the Entities in the Queue
SRlist = [schedulingRule] SRlist = [schedulingRule]
...@@ -173,9 +173,9 @@ class Operator(ObjectResource): ...@@ -173,9 +173,9 @@ class Operator(ObjectResource):
for machine in candidateMachines: for machine in candidateMachines:
machine.critical=False machine.critical=False
if machine.broker.waitForOperator: if machine.broker.waitForOperator:
machine.timeWaiting=now()-machine.broker.timeWaitForOperatorStarted machine.timeWaiting=self.env.now-machine.broker.timeWaitForOperatorStarted
else: else:
machine.timeWaiting=now()-machine.timeLastEntityLeft machine.timeWaiting=self.env.now-machine.timeLastEntityLeft
# find the stations that hold critical entities # find the stations that hold critical entities
if self in router.preemptiveOperators: if self in router.preemptiveOperators:
for entity in station.getActiveObjectQueue(): for entity in station.getActiveObjectQueue():
...@@ -297,7 +297,7 @@ class Operator(ObjectResource): ...@@ -297,7 +297,7 @@ class Operator(ObjectResource):
# if the repairman is currently working we have to count the time of this work # if the repairman is currently working we have to count the time of this work
# if len(self.getResourceQueue())>0: # if len(self.getResourceQueue())>0:
if not self.checkIfResourceIsAvailable(): if not self.checkIfResourceIsAvailable():
self.totalWorkingTime+=now()-self.timeLastOperationStarted self.totalWorkingTime+=self.env.now-self.timeLastOperationStarted
# Repairman was idle when he was not in any other state # Repairman was idle when he was not in any other state
self.totalWaitingTime=MaxSimtime-self.totalWorkingTime self.totalWaitingTime=MaxSimtime-self.totalWorkingTime
......
...@@ -26,7 +26,8 @@ Created on 14 Nov 2012 ...@@ -26,7 +26,8 @@ Created on 14 Nov 2012
models a repairman that can fix a machine when it gets failures models a repairman that can fix a machine when it gets failures
''' '''
from SimPy.Simulation import Resource, now # from SimPy.Simulation import Resource, now
import simpy
from Operator import Operator from Operator import Operator
# =========================================================================== # ===========================================================================
......
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