Failure, Operator, and ObjectResource updated

parent f1d38927
......@@ -96,19 +96,40 @@ class Failure(ObjectInterruption):
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
#resource is available
yield self.repairman.getResource().request()
# update the time that the repair started
timeOperationStarted=self.env.now
self.repairman.timeLastOperationStarted=self.env.now
# print self.env.now, self.repairman.id, 'will be requested by', self.victim.id
# yield self.repairman.getResource().request()
# print self.repairman.Res.users
# # 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
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")
if(self.repairman and self.repairman!="None"): #if a resource was used, it is now released
self.repairman.getResource().release()
self.repairman.totalWorkingTime+=self.env.now-timeOperationStarted
# if(self.repairman and self.repairman!="None"): #if a resource was used, it is now released
# print self.repairman.Res.users
# 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
......
......@@ -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
'''
from SimPy.Simulation import Resource
# from SimPy.Simulation import Resource
import simpy
# ===========================================================================
# the resource that repairs the machines
......@@ -32,13 +33,15 @@ from SimPy.Simulation import Resource
class ObjectResource(object):
def __init__(self):
from Globals import G
self.env=G.env
self.initialized = False
def initialize(self):
self.totalWorkingTime=0 #holds the total working time
self.totalWaitingTime=0 #holds the total waiting time
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
self.initialized = True
# list with the coreObjects IDs that the resource services
......@@ -50,7 +53,7 @@ class ObjectResource(object):
# checks if the worker is available
# =======================================================================
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
......@@ -86,7 +89,7 @@ class ObjectResource(object):
# returns the active queue of the resource
# =======================================================================
def getResourceQueue(self):
return self.Res.activeQ
return self.Res.users
# =======================================================================
# check if the resource is already initialized
......
......@@ -26,7 +26,8 @@ Created on 22 Nov 2012
models an operator that operates a machine
'''
from SimPy.Simulation import Resource, now
# from SimPy.Simulation import Resource, now
import simpy
import xlwt
import scipy.stats as stat
from ObjectResource import ObjectResource
......@@ -49,7 +50,6 @@ class Operator(ObjectResource):
self.Working=[] # holds the percentage of working time
# 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.multipleCriterionList=[] #list with the criteria used to sort the Entities in the Queue
SRlist = [schedulingRule]
......@@ -173,9 +173,9 @@ class Operator(ObjectResource):
for machine in candidateMachines:
machine.critical=False
if machine.broker.waitForOperator:
machine.timeWaiting=now()-machine.broker.timeWaitForOperatorStarted
machine.timeWaiting=self.env.now-machine.broker.timeWaitForOperatorStarted
else:
machine.timeWaiting=now()-machine.timeLastEntityLeft
machine.timeWaiting=self.env.now-machine.timeLastEntityLeft
# find the stations that hold critical entities
if self in router.preemptiveOperators:
for entity in station.getActiveObjectQueue():
......@@ -297,7 +297,7 @@ class Operator(ObjectResource):
# if the repairman is currently working we have to count the time of this work
# if len(self.getResourceQueue())>0:
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
self.totalWaitingTime=MaxSimtime-self.totalWorkingTime
......
......@@ -26,7 +26,8 @@ Created on 14 Nov 2012
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
# ===========================================================================
......
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