Commit b013e446 authored by Georgios Dagkakis's avatar Georgios Dagkakis

generic class CoreObject added. All core objects inherit from it

parent a7478196
......@@ -21,8 +21,6 @@ Created on 18 Feb 2013
@author: George
'''
'''
Models an assembly object
it gathers frames and parts which are loaded to the frames
......@@ -32,9 +30,10 @@ from SimPy.Simulation import *
import xlwt
from RandomNumberGenerator import RandomNumberGenerator
import scipy.stats as stat
from CoreObject import CoreObject
#the Assembly object
class Assembly(Process):
class Assembly(CoreObject):
#initialize the object
def __init__(self, id, name, dist, time):
......@@ -181,18 +180,12 @@ class Assembly(Process):
#checks if the Assembly can dispose an entity to the following object
def haveToDispose(self):
return len(self.Res.activeQ)>0 and self.waitToDispose
#sets the routing in and out elements for the Assembly
def defineRouting(self, p, n):
self.next=n
self.previous=p
#removes an entity from the Assembly
def removeEntity(self):
self.outputTrace(self.Res.activeQ[0].name, "releases "+ self.objName)
self.Res.activeQ.pop(0)
self.waitToDispose=False
#gets an entity from the predecessor
#it may handle both Parts and Frames
......@@ -342,14 +335,4 @@ class Assembly(Process):
json['results']['waiting_ratio']['max']=self.Waiting[0]
G.outputJSON['elementList'].append(json)
#takes the array and checks if all its values are identical (returns false) or not (returns true)
#needed because if somebody runs multiple runs in deterministic case it would crash!
def checkIfArrayHasDifValues(self, array):
difValuesFlag=False
for i in range(1, len(array)):
if(array[i]!=array[1]):
difValuesFlag=True
return difValuesFlag
\ No newline at end of file
......@@ -29,9 +29,10 @@ it gathers entities and transfers them with a certain speed
from SimPy.Simulation import *
import xlwt
import scipy.stats as stat
from CoreObject import CoreObject
#The conveyer object
class Conveyer(Process):
class Conveyer(CoreObject):
def __init__(self, id, name,length,speed):
self.id=id
......@@ -223,11 +224,6 @@ class Conveyer(Process):
#only when an entity is at the end of it
else:
return False
#sets the routing in and out elements for the Conveyer
def defineRouting(self, p, n):
self.next=n
self.previous=p
#checks if the conveyer is full to count the blockage. for some reason Plant regards
#the conveyer full even when it has one place
......@@ -252,7 +248,6 @@ class Conveyer(Process):
return self.canAcceptAndIsRequested()
else:
return self.canAcceptAndIsRequested()
#actions to be taken after the simulation ends
def postProcessing(self, MaxSimtime):
......@@ -383,15 +378,6 @@ class Conveyer(Process):
json['results']['waiting_ratio']['avg']=self.Waiting[0]
json['results']['waiting_ratio']['max']=self.Waiting[0]
G.outputJSON['elementList'].append(json)
#takes the array and checks if all its values are identical (returns false) or not (returns true)
#needed because if somebody runs multiple runs in deterministic case it would crash!
def checkIfArrayHasDifValues(self, array):
difValuesFlag=False
for i in range(1, len(array)):
if(array[i]!=array[1]):
difValuesFlag=True
return difValuesFlag
#Process that handles the moves of the conveyer
class ConveyerMover(Process):
......
# ===========================================================================
# Copyright 2013 Georgios Dagkakis
#
# 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 12 Jul 2012
@author: George
'''
'''
Class that acts as an abstract. It should have no instances. All the core-objects should inherit from it
'''
from SimPy.Simulation import Process, Resource
from SimPy.Simulation import hold, now
import scipy.stats as stat
#the core object
class CoreObject(Process):
def initilize(self):
Process.__init__(self)
self.predecessorIndex=0 #holds the index of the predecessor from which the Machine will take an entity next
self.successorIndex=0 #holds the index of the successor where the Machine will dispose an entity next
self.Up=True #Boolean that shows if the machine is in failure ("Down") or not ("up")
self.currentEntity=None
self.totalBlockageTime=0 #holds the total blockage time
self.totalFailureTime=0 #holds the total failure time
self.totalWaitingTime=0 #holds the total waiting time
self.totalWorkingTime=0 #holds the total working time
self.completedJobs=0 #holds the number of completed jobs
self.timeLastEntityEnded=0 #holds the last time that an entity ended processing in the object
self.nameLastEntityEnded="" #holds the name of the last entity that ended processing in the object
self.timeLastEntityEntered=0 #holds the last time that an entity entered in the object
self.nameLastEntityEntered="" #holds the name of the last entity that entered in the object
self.timeLastFailure=0 #holds the time that the last failure of the object started
self.timeLastFailureEnded=0 #holds the time that the last failure of the object Ended
self.downTimeProcessingCurrentEntity=0 #holds the time that the machine was down while processing the current entity
self.downTimeInTryingToReleaseCurrentEntity=0 #holds the time that the object was down while trying
#to release the current entity
self.downTimeInCurrentEntity=0 #holds the total time that the object was down while holding current entity
self.timeLastEntityLeft=0 #holds the last time that an entity left the object
self.processingTimeOfCurrentEntity=0 #holds the total processing time that the current entity required
self.waitToDispose=False #shows if the object waits to dispose an entity
#the main process of the core object
#this is dummy, every object must have its own implementation
def run(self):
yield hold,self,0
#sets the routing in and out elements for the Object
def defineRouting(self, p, n):
self.next=n
self.previous=p
#removes an entity from the Object
def removeEntity(self):
self.Res.activeQ.pop(0)
#gets an entity from the predecessor that the predecessor index points to
def getEntity(self):
self.Res.activeQ=[self.previous[self.predecessorIndex].Res.activeQ[0]]+self.Res.activeQ #get the entity from the previous object
#and put it in front of the activeQ
self.previous[self.predecessorIndex].removeEntity() #remove the entity from the previous object
#actions to be taken after the simulation ends
def postProcessing(self, MaxSimtime):
pass
#outputs message to the trace.xls
def outputTrace(self, message):
pass
#outputs data to "output.xls"
def outputResultsXL(self, MaxSimtime):
pass
#outputs results to JSON File
def outputResultsJSON(self):
pass
#checks if the Object can dispose an entity to the following object
def haveToDispose(self):
return len(self.Res.activeQ)>0
#checks if the Object can accept an entity and there is an entity in some predecessor waiting for it
def canAcceptAndIsRequested(self):
pass
#checks if the Object can accept an entity
def canAccept(self):
pass
#takes the array and checks if all its values are identical (returns false) or not (returns true)
#needed because if somebody runs multiple runs in deterministic case it would crash!
def checkIfArrayHasDifValues(self, array):
difValuesFlag=False
for i in range(1, len(array)):
if(array[i]!=array[1]):
difValuesFlag=True
return difValuesFlag
\ No newline at end of file
......@@ -30,9 +30,10 @@ from SimPy.Simulation import *
import xlwt
from RandomNumberGenerator import RandomNumberGenerator
import scipy.stats as stat
from CoreObject import CoreObject
#the Dismantle object
class Dismantle(Process):
class Dismantle(CoreObject):
#initialize the object
def __init__(self, id, name, dist, time):
......
......@@ -28,9 +28,10 @@ models the exit of the model
from SimPy.Simulation import *
import xlwt
import scipy.stats as stat
from CoreObject import CoreObject
#The exit object
class Exit(Process):
class Exit(CoreObject):
def __init__(self, id, name):
Process.__init__(self)
......@@ -250,12 +251,4 @@ class Exit(Process):
json['results']['taktTime']['avg']=self.TaktTime[0]
json['results']['taktTime']['max']=self.TaktTime[0]
G.outputJSON['elementList'].append(json)
#takes the array and checks if all its values are identical (returns false) or not (returns true)
#needed because if somebody runs multiple runs in deterministic case it would crash!
def checkIfArrayHasDifValues(self, array):
difValuesFlag=False
for i in range(1, len(array)):
if(array[i]!=array[1]):
difValuesFlag=True
return difValuesFlag
\ No newline at end of file
\ No newline at end of file
......@@ -12,7 +12,7 @@
"id": "W1",
"name": "W1",
"capacity": "1",
"successorList": ["M1", "M2"]
"successorList": []
},
{
"_class": "Dream.Source",
......
......@@ -16,6 +16,7 @@
# 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 7 May 2013
......
......@@ -29,12 +29,14 @@ from SimPy.Simulation import Process, Resource
from SimPy.Simulation import activate, passivate, waituntil, now, hold
from Failure import Failure
from CoreObject import CoreObject
from RandomNumberGenerator import RandomNumberGenerator
import scipy.stats as stat
import sys
#the Machine object
class Machine(Process):
class Machine(CoreObject):
#initialize the id the capacity, of the resource and the distribution
def __init__(self, id, name, capacity, dist, time, fDist, MTTF, MTTR, availability, repairman):
......@@ -185,13 +187,7 @@ class Machine(Process):
blockageTime=totalTime-(tinMStart+failureTime)
self.totalBlockageTime+=totalTime-(tinMStart+failureTime) #the time of blockage is derived from
#the whole time in the machine
#minus the processing time and the failure time
#sets the routing in and out elements for the queue
def defineRouting(self, p, n):
self.next=n
self.previous=p
#minus the processing time and the failure time
#checks if the waitQ of the machine is empty
def checkIfWaitQEmpty(self):
return len(self.M.waitQ)==0
......@@ -259,6 +255,14 @@ class Machine(Process):
def ifCanDisposeOrHaveFailure(self):
return self.Up==False or self.next[0].canAccept() or len(self.Res.activeQ)==0 #the last part is added so that it is not removed and stack
#gotta think of it again
#removes an entity from the Machine
def removeEntity(self):
self.timeLastEntityLeft=now()
self.outputTrace("releases "+self.objName)
self.waitToDispose=False
self.Res.activeQ.pop(0)
self.downTimeInTryingToReleaseCurrentEntity=0
#checks if the Machine can dispose an entity to the following object
def haveToDispose(self):
......@@ -295,19 +299,6 @@ class Machine(Process):
flag=True
return len(self.Res.activeQ)>0 and self.waitToDispose and self.Up and flag
#removes an entity from the Machine
def removeEntity(self):
self.timeLastEntityLeft=now()
self.outputTrace("releases "+self.objName)
self.waitToDispose=False
self.Res.activeQ.pop(0)
self.downTimeInTryingToReleaseCurrentEntity=0
#gets an entity from the predecessor that the predecessor index points to
def getEntity(self):
self.Res.activeQ.append(self.previous[self.predecessorIndex].Res.activeQ[0]) #get the entity from the predecessor
self.previous[self.predecessorIndex].removeEntity()
#actions to be taken after the simulation ends
def postProcessing(self, MaxSimtime):
......@@ -497,13 +488,4 @@ class Machine(Process):
json['results']['waiting_ratio']['max']=self.Waiting[0]
G.outputJSON['elementList'].append(json)
#takes the array and checks if all its values are identical (returns false) or not (returns true)
#needed because if somebody runs multiple runs in deterministic case it would crash!
def checkIfArrayHasDifValues(self, array):
difValuesFlag=False
for i in range(1, len(array)):
if(array[i]!=array[1]):
difValuesFlag=True
return difValuesFlag
\ No newline at end of file
\ No newline at end of file
......@@ -27,10 +27,12 @@ Models a FIFO queue where entities can wait in order to get into a server
from SimPy.Simulation import *
from CoreObject import CoreObject
#import sys
#the Queue object
class Queue(Process):
class Queue(CoreObject):
def __init__(self, id, name, capacity, dummy):
Process.__init__(self)
......@@ -87,11 +89,6 @@ class Queue(Process):
#if entity just got to the dummyQ set its startTime as the current time
if self.isDummy:
self.Res.activeQ[0].startTime=now()
#sets the routing in and out elements for the queue
def defineRouting(self, p, n):
self.next=n
self.previous=p
#checks if the Q has one available place
def checkIfQHasPlace(self):
......@@ -183,20 +180,6 @@ class Queue(Process):
self.predecessorIndex=i
maxTimeWaiting=timeWaiting
return len(self.Res.activeQ)<self.capacity and isRequested
#gets an entity from the predecessor that the predecessor index points to
def getEntity(self):
self.Res.activeQ=[self.previous[self.predecessorIndex].Res.activeQ[0]]+self.Res.activeQ #get the entity from the previous object
#and put it in front of the activeQ
self.previous[self.predecessorIndex].removeEntity() #remove the entity from the previous object
#removes an entity from the Queue (this is FIFO for now)
def removeEntity(self):
self.Res.activeQ.pop(0)
#actions to be taken after the simulation ends
def postProcessing(self, MaxSimtime):
pass #no actions for the Queue
#outputs message to the trace.xls. Format is (Simulation Time | Entity Name | message)
def outputTrace(self, message):
......@@ -212,11 +195,3 @@ class Queue(Process):
G.traceIndex=0
G.sheetIndex+=1
G.traceSheet=G.traceFile.add_sheet('sheet '+str(G.sheetIndex), cell_overwrite_ok=True)
#outputs data to "output.xls"
def outputResultsXL(self, MaxSimtime):
pass
#outputs results to JSON File
def outputResultsJSON(self):
pass
\ No newline at end of file
......@@ -29,9 +29,10 @@ models the source object that generates the entities
from SimPy.Simulation import *
from Part import Part
from RandomNumberGenerator import RandomNumberGenerator
from CoreObject import CoreObject
#The Source object is a Process
class Source(Process):
class Source(CoreObject):
def __init__(self, id, name, dist, time, item):
Process.__init__(self)
self.id=id
......@@ -122,21 +123,6 @@ class Source(Process):
#sets the routing out element for the Source
def defineRouting(self, n):
self.next=n
#actions to be taken after the simulation ends
def postProcessing(self, MaxSimtime):
pass #no actions for the Source
#checks if the Source can dispose an entity to the following object
def haveToDispose(self):
#return self.waitToDispose
return len(self.Res.activeQ)>0
#removes an entity from the Source
def removeEntity(self):
self.Res.activeQ.pop(0)
#if(len(self.Res.activeQ)==0):
#self.waitToDispose=False
#outputs message to the trace.xls. Format is (Simulation Time | Entity Name | "generated")
def outputTrace(self, message):
......@@ -153,11 +139,3 @@ class Source(Process):
G.traceIndex=0
G.sheetIndex+=1
G.traceSheet=G.traceFile.add_sheet('sheet '+str(G.sheetIndex), cell_overwrite_ok=True)
#outputs data to "output.xls"
def outputResultsXL(self, MaxSimtime):
pass
#outputs results to JSON File
def outputResultsJSON(self):
pass
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