Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
dream
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
dream
Commits
c3a4181b
Commit
c3a4181b
authored
Jan 15, 2014
by
Ioannis Papagiannopoulos
Committed by
Jérome Perrin
Jan 20, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new object ConditionalBuffer added
parent
9316f224
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
0 deletions
+84
-0
dream/simulation/ConditionalBuffer.py
dream/simulation/ConditionalBuffer.py
+84
-0
No files found.
dream/simulation/ConditionalBuffer.py
0 → 100644
View file @
c3a4181b
# ===========================================================================
# 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 15 Jan 2014
@author: Ioannis
'''
'''
Inherits from QueuePreemptive. Checks the condition of (a) component(s) before in can dispose of them/it
'''
from
QueuePreemptive
import
QueuePreemptive
from
SimPy.Simulation
import
now
# ===========================================================================
# the QueuePreemptive object
# ===========================================================================
class
ConditionalBuffer
(
QueuePreemptive
):
# ===========================================================================
# the __init__ function
# ===========================================================================
def
__init__
(
self
,
id
,
name
,
capacity
=
1
,
dummy
=
False
,
schedulingRule
=
"CB"
):
# run the default method, change the schedulingRule to CB
# for description, check activeQSorter function of Queue coreObject
QueuePreemptive
.
__init__
(
self
,
id
,
name
,
capacity
,
dummy
,
schedulingRule
)
# =======================================================================
# checks if the Buffer can dispose an entity.
# Returns True only to the potential receiver
# If it holds secondary components, checks first if the basicsEnded is
# True first. Otherwise, it waits until the basics are ended.
# =======================================================================
def
haveToDispose
(
self
,
callerObject
=
None
):
# get active object and its queue
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
self
.
getActiveObjectQueue
()
thecaller
=
callerObject
# if the type of the component is Secondary then assert that the basics of the same order
# are already processed before disposing them to the next object
activeEntity
=
activeObjectQueue
[
0
]
if
activeEntity
.
componentType
==
'Secondary'
:
if
not
activeEntity
.
order
.
basicsEnded
:
return
False
#if we have only one possible receiver just check if the Queue holds one or more entities
if
(
len
(
activeObject
.
next
)
==
1
or
callerObject
==
None
):
activeObject
.
receiver
=
activeObject
.
next
[
0
]
return
len
(
activeObjectQueue
)
>
0
\
and
thecaller
==
activeObject
.
receiver
#give the entity to the possible receiver that is waiting for the most time.
#plant does not do this in every occasion!
maxTimeWaiting
=
0
# loop through the object in the successor list
for
object
in
activeObject
.
next
:
if
(
object
.
canAccept
(
activeObject
)):
# if the object can accept
timeWaiting
=
now
()
-
object
.
timeLastEntityLeft
# compare the time that it has been waiting
if
(
timeWaiting
>
maxTimeWaiting
or
maxTimeWaiting
==
0
):
# with the others'
maxTimeWaiting
=
timeWaiting
self
.
receiver
=
object
# and update the receiver to the index of this object
#return True if the Queue has Entities and the caller is the receiver
return
len
(
activeObjectQueue
)
>
0
and
(
thecaller
is
self
.
receiver
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment