Source code for manpy.simulation.core.ObjectResource
# ===========================================================================# Copyright 2013 University of Limerick## This file is part of DREAM.## DREAM is free software: you can redistribute it and/or modify# it under the terms of the GNU Lesser General Public License as published by# the Free Software Foundation, either version 3 of the License, or# (at your option) any later version.## DREAM is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU Lesser General Public License for more details.## You should have received a copy of the GNU Lesser General Public License# along with DREAM. If not, see <http://www.gnu.org/licenses/>.# ==========================================================================="""Created on 18 Aug 2013@author: George"""# from SimPy.Simulation import Resourceimportsimpyfrommanpy.simulation.ManPyObjectimportManPyObject
[docs]classObjectResource(ManPyObject):""" The resource that repairs the machines Class that acts as an abstract. It should have no instances. All the Resources should inherit from it. """def__init__(self,id="",name="",**kw):ManPyObject.__init__(self,id,name)self.initialized=False# list that holds the objectInterruptions that have this element as victimself.objectInterruptions=[]# alias used for printing the traceself.alias=None# list with the coreObjects IDs that the resource servicesself.coreObjectIds=[]frommanpy.simulation.core.GlobalsimportGG.ObjectResourceList.append(self)
[docs]definitialize(self):frommanpy.simulation.core.GlobalsimportG# flag that shows if the resource is on shiftself.onShift=True# flag that shows if the resource is on breakself.onBreak=Falseself.env=G.envself.timeLastOperationStarted=(0# holds the time that the last repair was started)self.Res=simpy.Resource(self.env,capacity=self.capacity)# variable that checks whether the resource is already initializedself.initialized=True# list with the coreObjects IDs that the resource servicesself.coreObjectIds=[]# list with the coreObjects that the resource servicesself.coreObjects=[]# flag that locks the resource so that it cannot get new jobsself.isLocked=False# lists that keep the start/endShiftTimes of the victimself.endShiftTimes=[]self.startShiftTimes=[]
[docs]defcheckIfResourceIsAvailable(self,callerObject=None):"""checks if the worker is available"""# return true if the operator is idle and on shiftreturn(len(self.Res.users)<self.capacityandself.onShiftand(notself.isLocked)and(notself.onBreak))
[docs]defgetResource(self):"""returns the resource"""returnself.Res
[docs]defgetResourceQueue(self):"""returns the active queue of the resource"""returnself.Res.users
[docs]defisInitialized(self):"""check if the resource is already initialized"""returnself.initialized
[docs]defprintRoute(self):"""print the route (the different stations the resource was occupied by)"""pass