Commit 8a9dd26a authored by Georgios Dagkakis's avatar Georgios Dagkakis

CapacityObjects moved from simulation folder

parent 94d13812
# ===========================================================================
# 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 5 June 2013
@author: George
'''
'''
entity that requires specific capacity from a station
'''
from Entity import Entity
# ===========================================================================
# The CapacityEntity object
# ===========================================================================
class CapacityEntity(Entity):
type="CapacityEntity"
def __init__(self, id=None, name=None, capacityProjectId=None, requiredCapacity=10, priority=0, dueDate=0,
orderDate=0, currentStation=None, isCritical=False, **kw):
Entity.__init__(self, id, name, priority, dueDate, orderDate, isCritical, currentStation=currentStation)
self.capacityProjectId=capacityProjectId # the project id hat the capacity Entity is part of
self.capacityProject=None # the project that the capacity Entity is part of. It is defined in initialize
self.requiredCapacity=requiredCapacity # the capacity that the capacity entity requires from the following station
self.shouldMove=False
from Globals import G
G.CapacityEntityList.append(self)
def initialize(self):
Entity.initialize(self)
self.shouldMove=False
from Globals import G
# find the project that the capacity entity is part of
for project in G.CapacityProjectList:
if project.id==self.capacityProjectId:
self.capacityProject=project
break
\ 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 5 June 2013
@author: George
'''
'''
a project that requires specific capacity from each station
'''
from Entity import Entity
# ===========================================================================
# The CapacityEntityProject object
# ===========================================================================
class CapacityProject(Entity):
type="CapacityProject"
def __init__(self, id=None, name=None, capacityRequirementDict={}, earliestStartDict={}, dueDate=0,
assemblySpaceRequirement=0, **kw):
Entity.__init__(self, id, name, dueDate=dueDate)
# a dict that shows the required capacity from every station
self.capacityRequirementDict=capacityRequirementDict
# a dict that shows the earliest start in every station
self.earliestStartDict=earliestStartDict
# the assembly space the project requires
self.assemblySpaceRequirement=assemblySpaceRequirement
from Globals import G
G.CapacityProjectList.append(self)
def initialize(self):
self.projectSchedule=[] # a list of dicts to keep the schedule
self.alreadyWorkedDict={} # a dict that hold what has been processed at every station
for stationId in self.capacityRequirementDict:
self.alreadyWorkedDict[stationId]=0
# =======================================================================
# outputs results to JSON File
# =======================================================================
def outputResultsJSON(self):
from Globals import G
json = {'_class': 'Dream.%s' % (self.__class__.__name__),
'id': self.id,
'family': 'Job',
'results': {}}
if (G.numberOfReplications == 1):
# if we had just one replication output the results as numbers
json['results']['schedule']=self.projectSchedule
G.outputJSON['elementList'].append(json)
# ===========================================================================
# 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 5 June 2013
@author: George
'''
'''
a station that can process a specified capacity in every time period
'''
from Queue import Queue
import simpy
# ===========================================================================
# the CapacityStation object
# ===========================================================================
class CapacityStation(Queue):
family='CapacityStation'
#===========================================================================
# the __init__ method of the CapacityStation
#===========================================================================
def __init__(self, id, name, capacity=float("inf"), intervalCapacity=[], schedulingRule="FIFO", gatherWipStat=False,
sharedResources={}, **kw):
Queue.__init__(self, id, name, capacity=capacity)
# a list that holds the capacity (manhours) that is available in each interval
self.intervalCapacity=intervalCapacity
# a list that holds the capacity (manhours) that is available in each interval for the remaining time
self.remainingIntervalCapacity=list(self.intervalCapacity)
# blocks the entry of the capacity station, so that it can be manipulated to accept only in certain moments of simulation time
self.isLocked=True
# dict that holds information if station shares workpower with some other station
self.sharedResources=sharedResources
def initialize(self):
Queue.initialize(self)
# if the station shares resources and the capacity is not defined in this
# then read it from some other of the sharing stations
if not self.intervalCapacity and self.sharedResources:
for stationId in self.sharedResources.get('stationIds',[]):
import Globals
station=Globals.findObjectById(stationId)
if station.intervalCapacity:
self.intervalCapacity=station.intervalCapacity
break
# initialize variables
self.remainingIntervalCapacity=list(self.intervalCapacity)
self.isLocked=True
self.utilisationDict=[] # a list of dicts for the utilization results
self.detailedWorkPlan=[] # a list of dicts to keep detailed data
from Globals import G
G.CapacityStationList.append(self)
def canAccept(self, callerObject=None):
if self.isLocked:
return False
return Queue.canAccept(self)
# =======================================================================
# outputs results to JSON File
# =======================================================================
def outputResultsJSON(self):
from Globals import G
json = {'_class': 'Dream.%s' % self.__class__.__name__,
'id': self.id,
'family': self.family,
'results': {}}
if (G.numberOfReplications == 1):
# if we had just one replication output the results as numbers
json['results']['capacityUsed']=self.utilisationDict
meanUtilization=0
for entry in self.utilisationDict:
meanUtilization+=entry['utilization']/float(len(self.utilisationDict))
json['results']['meanUtilization']=meanUtilization
json['results']['detailedWorkPlan']=self.detailedWorkPlan
G.outputJSON['elementList'].append(json)
\ 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 6 June 2013
@author: George
'''
'''
the buffer of the capacity station. Only change from queue that it can be blocked.
'''
import simpy
from Queue import Queue
# ===========================================================================
# the Queue object
# ===========================================================================
class CapacityStationBuffer(Queue):
#===========================================================================
# the __init__ method of the CapacityStationBuffer
#===========================================================================
def __init__(self, id, name, requireFullProject =False, capacity=float("inf"), isDummy=False,
schedulingRule="FIFO", gatherWipStat=False,**kw):
Queue.__init__(self, id, name, capacity=capacity)
self.isLocked=True
self.requireFullProject=requireFullProject # flag that shows if here the whole project is assembled
from Globals import G
G.CapacityStationBufferList.append(self)
def initialize(self):
Queue.initialize(self)
self.isLocked=True
def canAccept(self, callerObject=None):
if self.isLocked:
return False
return Queue.canAccept(self)
def haveToDispose(self, callerObject=None):
activeObjectQ=self.getActiveObjectQueue()
if len(activeObjectQ)==0:
return False
if not activeObjectQ[0].shouldMove:
return False
# put the entities that should move in front
def sortEntities(self):
activeObjectQ=self.getActiveObjectQueue()
activeObjectQ.sort(key=lambda x: x.shouldMove, reverse=True)
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 6 June 2013
@author: George
'''
'''
the exit of the capacity station. Only change from buffer that it can be blocked.
'''
from Exit import Exit
import simpy
# ===========================================================================
# the CapacityStationExit object
# ===========================================================================
class CapacityStationExit(Exit):
#===========================================================================
# the __init__ method of the CapacityStationExit
#===========================================================================
def __init__(self, id, name=None, nextCapacityStationBufferId=None,**kw):
Exit.__init__(self, id, name)
self.isLocked=True
self.nextCapacityStationBufferId=nextCapacityStationBufferId # the id of the next station. If it is None it
# means it is the end of the system.
self.nextCapacityStationBuffer=None # the next buffer. If it is None it
from Globals import G
G.CapacityStationExitList.append(self)
# means it is the end of the system.
def initialize(self):
Exit.initialize(self)
self.isLocked=True
# list that contains the entities that are just obtained so that they can be
# moved to the next buffer
self.currentlyObtainedEntities=[]
# find the next buffer
if self.nextCapacityStationBufferId:
from Globals import G
# find the project that the capacity entity is part of
for capacityStationBuffer in G.CapacityStationBufferList:
if capacityStationBuffer.id==self.nextCapacityStationBufferId:
self.nextCapacityStationBuffer=capacityStationBuffer
break
def canAccept(self, callerObject=None):
if self.isLocked:
return False
return Exit.canAccept(self)
# =======================================================================
# outputs results to JSON File
# =======================================================================
def outputResultsJSON(self):
# output results only for the last exit
if not self.nextCapacityStationBuffer:
Exit.outputResultsJSON(self)
# extend so that it updates alreadyWorkedDict of the project
def getEntity(self):
activeEntity=Exit.getEntity(self)
alreadyWorkedDict=activeEntity.capacityProject.alreadyWorkedDict
stationId=self.giver.id
alreadyWorkedDict[stationId]+=activeEntity.requiredCapacity
\ 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