Commit d851d9a1 authored by Georgios Dagkakis's avatar Georgios Dagkakis

MachineProbOut made as an object to solve the conceptual problem that Jerome...

MachineProbOut made as an object to solve the conceptual problem that Jerome indicated.Main script also updated to read it
parent c160fcdc
......@@ -83,6 +83,7 @@ from MouldAssemblyBuffer import MouldAssemblyBuffer
from MachineManagedJob import MachineManagedJob
from QueueManagedJob import QueueManagedJob
from ShiftScheduler import ShiftScheduler
from MachineProbOut import MachineProbOut
import ExcelHandler
import time
......@@ -164,6 +165,7 @@ def createObjects():
G.MachineManagedJobList=[]
G.QueueManagedJobList=[]
G.ModelResourceList=[]
G.MachineProbOutList=[]
# -----------------------------------------------------------------------
# loop through all the model resources
......@@ -321,6 +323,61 @@ def createObjects():
G.OperatedMachineList.append(M) # add the machine to the operatedMachines List
G.ObjList.append(M) # add machine to ObjList
elif objClass=='Dream.MachineProbOut':
id=element.get('id', 'not found')
name=element.get('name', 'not found')
processingTime=element.get('processingTime',{})
failures=element.get('failures', {})
failureDistribution=failures.get('failureDistribution', 'not found')
MTTF=float(failures.get('MTTF') or 0)
MTTR=float(failures.get('MTTR') or 0)
availability=float(failures.get('availability') or 0)
# type of operation and related times
operationType=element.get('operationType','not found')
setupTime = element.get('setupTime', None)
loadTime = element.get('loadTime', None)
preemption=element.get('preemption',{})
isPreemptive=resetOnPreemption=False
if len(preemption)>0:
isPreemptive=bool(int(preemption.get('isPreemptive') or 0))
resetOnPreemption=bool(int(preemption.get('resetOnPreemption', 0)))
if len(G.OperatorPoolsList)>0:
for operatorPool in G.OperatorPoolsList: # find the operatorPool assigned to the machine
if(id in operatorPool.coreObjectIds): # and add it to the machine's operatorPool
machineOperatorPoolList=operatorPool # there must only one operator pool assigned to the machine,
# otherwise only one of them will be taken into account
else:
machineOperatorPoolList=[] # if there is no operatorPool assigned to the machine
else: # then machineOperatorPoolList/operatorPool is a list
machineOperatorPoolList=[] # if there are no operatorsPool created then the
# then machineOperatorPoolList/operatorPool is a list
if (type(machineOperatorPoolList) is list): # if the machineOperatorPoolList is a list
# find the operators assigned to it and add them to the list
for operator in G.OperatorsList: # check which operator in the G.OperatorsList
if(id in operator.coreObjectIds): # (if any) is assigned to operate
machineOperatorPoolList.append(operator) # the machine with ID equal to id
# if there is no operator assigned then the list will be empty
r='None'
for repairman in G.RepairmanList: # check which repairman in the G.RepairmanList
if(id in repairman.coreObjectIds): # (if any) is assigned to repair
r=repairman # the machine with ID equal to id
routingOutProbabilities=element.get('routingOutProbabilities',{})
M=MachineProbOut(id, name, 1, processingTime, failureDistribution=failureDistribution,
MTTF=MTTF, MTTR=MTTR, availability=availability, #repairman=r,
operatorPool=machineOperatorPoolList, operationType=operationType,
setupTime=setupTime,
loadTime=loadTime,
repairman=r, isPreemptive=isPreemptive, resetOnPreemption=resetOnPreemption,
routingOutProbabilities=routingOutProbabilities)
M.nextIds=getSuccessorList(id) # update the nextIDs list of the machine
G.MachineList.append(M) # add machine to global MachineList
G.MachineProbOutList.append(M) # add machine to global MachineList
if M.operatorPool!="None":
G.OperatedMachineList.append(M) # add the machine to the operatedMachines List
G.ObjList.append(M) # add machine to ObjList
elif objClass=='Dream.BatchScrapMachine':
id=element.get('id', 'not found')
name=element.get('name', 'not found')
......
# ===========================================================================
# 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 8 Nov 2012
@author: George
'''
'''
Models a machine that can route Entities according to a probability. It can be merged with CoreObject in the future
'''
from RandomNumberGenerator import RandomNumberGenerator
from Machine import Machine
from SimPy.Simulation import now
# ===========================================================================
# the MachineProbOut object
# ===========================================================================
class MachineProbOut(Machine):
#initialize the id, the capacity of the resource and the distribution
def __init__(self, id, name, capacity=1, processingTime=None,
failureDistribution='No', MTTF=0, MTTR=0, availability=0, repairman='None',\
operatorPool='None',operationType='None',\
setupTime=None, loadTime=None,
isPreemptive=False, resetOnPreemption=False,
routingOutProbabilities={}):
if not processingTime:
processingTime = {'distribution': 'Fixed',
'mean': 1}
# initialize using the default method of the object
Machine.__init__(self,id=id,name=name,\
capacity=capacity,\
processingTime=processingTime,
failureDistribution=failureDistribution,MTTF=MTTF,MTTR=MTTR,\
availability=availability,
repairman=repairman)
# the following is to assert that probability input is valid
totalProb=0
for element in routingOutProbabilities:
totalProb+=routingOutProbabilities[element]
assert(totalProb==100)
self.routingOutProbabilities=routingOutProbabilities # keeps the probability input
self.routingOutRng=RandomNumberGenerator(self, 'Uniform', min=0, max=1) # a Random number generator that creates numbers
# that are uniformly distributed in (0,1)
# =======================================================================
# sets the routing in and out elements for the Object
# extend so thata staticNext is kept
# =======================================================================
def defineRouting(self, predecessorList=[], successorList=[]):
Machine.defineRouting(self, predecessorList, successorList)
self.staticNext=self.next
# =======================================================================
# actions to be carried out when the processing of an Entity ends
# extends so that a random number is generated to decide where this Entity will be routed to
# =======================================================================
def endProcessingActions(self):
activeEntity=Machine.endProcessingActions(self) # run the default method
randomNumber=self.routingOutRng.generateNumber()*100 # create a random number uniformly distributed in 0-100
probabilityLevel=0
# in this loop the next object is determined according to the random number
for object in self.staticNext:
probabilityLevel+=self.routingOutProbabilities[object.id]
if randomNumber<probabilityLevel:
self.next=[object]
self.receiver=object #TODO, I thought this line would not be needed, but it is. Check this
print now(), 'out of', randomNumber, 'selected', object.id
break
# =======================================================================
# checks if the Object can dispose an entity to the following object
# extend default so that if the caller is not in self.next it returns False
# (TODO maybe this could be added also in CoreObject)
# =======================================================================
def haveToDispose(self, callerObject=None):
if not (callerObject in self.next):
return False
return Machine.haveToDispose(self, callerObject) # run default behaviour
\ 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