Class Queue
- All Implemented Interfaces:
Serializable
,Named
,Parented
,ProvidesBarData
,Receiver
,Resettable
,sim.engine.Steppable
,sim.portrayal.Portrayal
,sim.portrayal.Portrayal2D
- See Also:
-
Field Summary
Fields inherited from class sim.des.Middleman
totalReceivedResource
Fields inherited from class sim.des.Provider
entities, OFFER_ORDER_FIFO, OFFER_ORDER_LIFO, OFFER_POLICY_BACKWARD, OFFER_POLICY_FORWARD, OFFER_POLICY_RANDOM, OFFER_POLICY_ROUND_ROBIN, OFFER_POLICY_SELECT, OFFER_POLICY_SHUFFLE, resource, state, totalAcceptedOfferResource
Fields inherited from class sim.portrayal.simple.InternalPortrayal2D
portrayal
Fields inherited from class sim.portrayal.SimplePortrayal2D
TYPE_HIT_OBJECT, TYPE_SELECTED_OBJECT
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Offers a resource from a Provider to the Middleman.sim.portrayal.SimplePortrayal2D
buildDefaultPortrayal
(double scale) Builds the "base portrayal" for the object, if the image path and class haven't been set (and thus the portrayal isn't an ImagePortrayal2D).double
Returns the maximum available resources that may be aquired by the Queue.boolean
Returns whether the Queue offers items immediately upon accepting (when possible) in zero time, as opposed to when it is stepped.boolean
boolean
void
setCapacity
(double d) Set the maximum available resources that may be aquired by the Queue.void
setOffersImmediately
(boolean val) Sets whether the Queue offers items immediately upon accepting (when possible) in zero time, as opposed to when it is stepped.void
step
(sim.engine.SimState state) Upon being stepped, the Queue offers to registered receivers.toString()
Methods inherited from class sim.des.Middleman
getReceiverResourceRate, getRefusesOffers, getTotalReceivedResource, getTypicalReceived, performTransaction, reset, setRefusesOffers, throwUnequalReceivedTypeException, transact, transact
Methods inherited from class sim.des.Provider
addReceiver, clear, getAvailable, getDataBars, getDataLabels, getDataValues, getDrawState, getEntities, getEntity, getLastAcceptedOfferReceivers, getLastAcceptedOffers, getLastAcceptedOfferTime, getLastOfferTime, getMakesOffers, getName, getOfferDistribution, getOfferOrder, getOfferPolicy, getOfferResourceRate, getOffersAllEntities, getOffersTakeItOrLeaveIt, getParent, getReceivers, getState, getTotalAcceptedOfferResource, getTypicalProvided, hideDataBars, hideDataLabels, hideDataValues, hideDrawState, hideEntities, hideOfferDistribution, hideOfferOrder, hideOfferPolicy, hideOffersTakeItOrLeaveIt, hidePositiveNonNaN, hidePositiveOrZeroNonNaN, isOffering, isPositiveNonNaN, isPositiveOrZeroNonNaN, offerReceiver, offerReceiver, offerReceivers, offerReceivers, provide, provide, removeReceiver, requestEntity, selectedOfferAccepted, selectReceiver, setMakesOffers, setName, setOfferDistribution, setOfferDistribution, setOfferOrder, setOfferPolicy, setOffersAllEntities, setOffersTakeItOrLeaveIt, setParent, throwCyclicOffers, throwDoesNotProvideEntities, throwInvalidAtLeastAtMost, throwInvalidEntityNumber, throwInvalidMinMax, throwUnequalTypeException
Methods inherited from class sim.des.portrayal.DESPortrayal
buildDefaultImagePortrayal, buildPortrayal, getFillPaint, getImagePath, getStrokePaint, getStrokeWidth, getUsesGlobalImageClass, hideFillPaint, hideImagePath, hideStrokePaint, hideStrokeWidth, providePortrayal, setFillPaint, setImage, setStrokePaint, setStrokeWidth
Methods inherited from class sim.portrayal.simple.InternalPortrayal2D
draw, getInspector, getName, handleMouseEvent, hitObject, setSelected
Methods inherited from class sim.portrayal.SimplePortrayal2D
getStatus
-
Constructor Details
-
Queue
Builds a queue with the given typical resource type.
-
-
Method Details
-
buildDefaultPortrayal
public sim.portrayal.SimplePortrayal2D buildDefaultPortrayal(double scale) Description copied from class:DESPortrayal
Builds the "base portrayal" for the object, if the image path and class haven't been set (and thus the portrayal isn't an ImagePortrayal2D). The default sets to a simple gray and black quare.- Overrides:
buildDefaultPortrayal
in classDESPortrayal
-
getCapacity
public double getCapacity()Returns the maximum available resources that may be aquired by the Queue. -
hideCapacity
public boolean hideCapacity() -
setCapacity
public void setCapacity(double d) Set the maximum available resources that may be aquired by the Queue.Throws a runtime exception if the capacity is negative or NaN.
-
getOffersImmediately
public boolean getOffersImmediately()Returns whether the Queue offers items immediately upon accepting (when possible) in zero time, as opposed to when it is stepped. -
hideOffersImmediately
public boolean hideOffersImmediately() -
setOffersImmediately
public void setOffersImmediately(boolean val) Sets whether the Queue offers items immediately upon accepting (when possible) in zero time, as opposed to when it is stepped. -
accept
Description copied from class:Middleman
Offers a resource from a Provider to the Middleman. By default it does nothing: it returns FALSE, indicating that the offer is refused. You can override this as you see fit. This isn't abstract because you might wish to use a custom Middleman to conduct transactions only, rather than accepting offers.Note: if you implement this method, you probably want to check for offer cycles, invalid types, and whether the user has set the agent to refuse offers. This can be done with the following code snippet:
if (isOffering()) { throwCyclicOffers(); } if (resource.getType() != getTypicalReceived().getType()) { throwUnequalReceivedTypeException(provided); } if (getRefusesOffers()) { return false; } if (!(atLeast >= 0 invalid input: '&'invalid input: '&' atMost >= atLeast invalid input: '&'invalid input: '&' atMost > 0 invalid input: '&'invalid input: '&' atMost invalid input: '<'= resource.getAmount())) { throwInvalidAtLeastAtMost(atLeast, atMost, provided); } try { offering = true; //// DO YOUR OFFER ACCEPTANCE OR REFUSAL WORK HERE } finally { offering = false; }
Here is the general documentation for Receiver.accept():
If the resource is a COUNTABLE or UNCOUNTABLE resource of some kind, The provider may respond by removing between atLeast and atMost, inclusive, from the given amount, and returning TRUE, or returning FALSE if it refuses the offer.
If the resource is an ENTITY of some kind, The provider may respond by taking the entity and returning TRUE, or returning FALSE if it refuses the offer. atLeast and atMost may be ignored, but generally atLeast should be 0 and atMost should be 1.
May throw a RuntimeException if the resource does not match the typical resource of the receiver, or if a cycle was detected in accepting offers (A offers to B, which offers to C, which then offers to A). At present does not check that atLeast and atMost are valid.
It must be the case that 0 <= atLeast < = atMost <= resource.getAmount(), or else a RuntimeException may be thrown.
Receivers must never accept 0 of any resource. Thus if atLeast = 0, then this has a special meaning: it means that the receiver must accept > atLeast, rather than >= atLeast. Similarly, Providers should never provide atMost=0.
-
toString
-
step
public void step(sim.engine.SimState state) Upon being stepped, the Queue offers to registered receivers. You don't have to schedule the Queue at all; in which case this method would never be called.
-