Commit bd6cb0dc authored by Ioannis Papagiannopoulos's avatar Ioannis Papagiannopoulos Committed by Sebastien Robin

major modifications to OperatedMachine.py. OperatorPool and OperatedPoolBroker added

parent ff79aaa1
This diff is collapsed.
# ===========================================================================
# 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 27 Nov 2013
@author: Ioannis
'''
'''
Models an Interruption that handles the operating of a Station by an ObjectResource
'''
from SimPy.Simulation import Process, Resource
from ObjectInterruption import ObjectInterruption
from SimPy.Simulation import waituntil, now, hold, request, release
# ===========================================================================
# Class that handles the Operator Behavior
# ===========================================================================
class Broker(ObjectInterruption):
# =======================================================================
# according to this implementation one machine per broker is allowed
# The Broker is initiated within the Machine and considered as
# black box for the ManPy end Developer
# =======================================================================
def __init__(self, operatedMachine):
ObjectInterruption.__init__(self,operatedMachine)
self.type = "Broker"
# variable used to hand in control to the Broker
self.call=False
# variables that have to do with timing
self.timeOperationStarted = 0
self.timeLastOperationEnded = 0
self.timeWaitForOperatorStarted=0
# =======================================================================
# the run method
# =======================================================================
def run(self):
while 1:
yield waituntil,self,self.brokerIsCalled # wait until the broker is called
# ======= request a resource
if self.victim.isOperated()\
and any(type=="Load" or type=="Setup" or type=="Processing"\
for type in self.victim.multOperationTypeList):
# update the time that the station is waiting for the operator
self.timeWaitForOperatorStarted=now()
# # update the currentObject of the operatorPool
# self.victim.operatorPool.currentObject = self.victim
# wait until a resource is available
yield waituntil, self, self.victim.operatorPool.checkIfResourceIsAvailable
# set the available resource as the currentOperator
self.victim.currentOperator=self.victim.operatorPool.findAvailableOperator()
yield request,self,self.victim.operatorPool.getResource(self.victim.currentOperator)
# self.victim.totalTimeWaitingForOperator+=now()-self.timeWaitForOperatorStarted
# clear the timeWaitForOperatorStarted variable
self.timeWaitForOperatorStarted = 0
# update the time that the operation started
self.timeOperationStarted = now()
self.victim.currentOperator.timeLastOperationStarted=now()
# ======= release a resource
elif not self.victim.isOperated():
self.victim.currentOperator.totalWorkingTime+=now()-self.victim.currentOperator.timeLastOperationStarted
yield release,self,self.victim.operatorPool.getResource(self.victim.currentOperator)
# the victim current operator must be cleared after the operator is released
self.victim.currentOperator = 'None'
self.timeLastOperationEnded = now()
else:
pass
# return the control the machine.run
self.exitBroker()
# =======================================================================
# call the broker
# filter for Broker - yield waituntil brokerIsCalled
# =======================================================================
def brokerIsCalled(self):
return self.call
# =======================================================================
# the broker returns control to OperatedMachine.Run
# filter for Machine - yield request/release operator
# =======================================================================
def brokerIsSet(self):
return not self.call
# =======================================================================
# hand in the control to the Broker.run
# to be called by the machine
# =======================================================================
def invokeBroker(self):
self.call=True
# =======================================================================
# return control to the Machine.run
# =======================================================================
def exitBroker(self):
self.call=False
\ No newline at end of file
# ===========================================================================
# 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 22 Nov 2012
@author: Ioannis
'''
'''
models a Broker that organizes the dispatch of operators/repairmen
'''
from SimPy.Simulation import Resource, now
import xlwt
import scipy.stats as stat
from ObjectResource import ObjectResource
from Operator import Operator
# ===========================================================================
# the resource that handles multiple operators
# ===========================================================================
class OperatorPool(ObjectResource):
def __init__(self, id, name, capacity=1,operatorsList='None'):
self.id=id
self.objName=name
self.type="OperatorPool"
# self.Res=Resource(self.capacity)
# lists to hold statistics of multiple runs
# self.Waiting=[] # holds the percentage of waiting time
# self.Working=[] # holds the percentage of working time
# list with the coreObjects IDs that the Operators operate
self.coreObjectIds=[]
# list with the coreObjects that the Operators operate
self.coreObjects=[]
# holds the object/Machine that currently handles the operator pool
self.currentObject='None'
# check if an operatorsList is 'None'
if operatorsList=='None' or (operatorsList!='None' and len(operatorsList)==0):
# list of operators that the OperatorPool holds
self.operators = []
# the capacity of the OperatorPool in Operators
self.capacity=capacity
# populate the the operators list and initiate the operators
for index in range(self.capacity):
id='O_'+str(index)
name=self.objName+str(index)
operators.append(Operator(id,name))
# if a list of operators is given then update accordingly the self.operators variable
else:
assert type(operatorsList) is list, "operatorsList is not a List"
self.operators=operatorsList
self.capacity=len(self.operators)
# =======================================================================
# initialize the object
# =======================================================================
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 operation was started
# initialize the operators
for operator in self.operators:
operator.initialize()
# =======================================================================
# checks if there are operators available
# =======================================================================
def checkIfResourceIsAvailable(self):
# maxTimeWaiting = 0
# for operator in self.operators:
# for machine in operator.coreObjects:
# timeWaiting = now()-machine.broker.timeWaitForOperatorStarted
# if (timeWaiting>=maxTimeWaiting):
# maxTimeWaiting=timeWaiting
return any(operator.checkIfResourceIsAvailable()==True for operator in self.operators)
# =======================================================================
# find the first available operator and return it
# =======================================================================
def findAvailableOperator(self): # may need to implement different sorting of the operators
return next(x for x in self.operators if x.checkIfResourceIsAvailable())
# =======================================================================
# returns the resource
# =======================================================================
def getResource(self,operator):
# have to return the resource of the first operator available
return operator.getResource()
# =======================================================================
# returns the active queue of the resource
# needs refining
# =======================================================================
def getResourceQueue(self,operator):
return operator.getResourceQueue()
\ No newline at end of file
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