Class Transformer
- All Implemented Interfaces:
Serializable
,Named
,Parented
,ProvidesBarData
,Receiver
,Resettable
,sim.engine.Steppable
,sim.portrayal.Portrayal
,sim.portrayal.Portrayal2D
If the original resource was also a countable resource, then it is converted by multiplying it by a conversion factor. For example, if we were converting dollars to euros, and one dollar was worth 1.5 euros, we might set the conversion to 1.5. If the downstream receiver accepts the offer but only partially, then the original resource is modified accordingly according to the conversion factor.
If the original resource was an Entity, then we simply offer the conversion factor. Thus one entity might be worth 1.5 euros. By default, if the original resource type is an Entity, Transformer is automatically set to take-it-or-leave-it offers. Thus if the downstream receiver must accept the offer totally. You can change this by setting take-it-or-leave-it to false; now if the downstream receiver accepts the offer only partially, the Entity is consumed regardless.
- 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
ConstructorDescriptionTransformer
(sim.engine.SimState state, CountableResource typicalProvided, Resource typicalReceived, double conversion) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Override this as you like.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).Returns the typical kind of resource the receiver can accept.boolean
Asks the Provider to make a unilateral offer of up to the given amount to the given Receiver.toString()
Methods inherited from class sim.des.Filter
getProvider, isProviding, offerReceiver, offerReceivers, process, setProvider, throwCyclicProvisions
Methods inherited from class sim.des.Middleman
getReceiverResourceRate, getRefusesOffers, getTotalReceivedResource, 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, offerReceivers, offerReceivers, provide, removeReceiver, requestEntity, selectedOfferAccepted, selectReceiver, setMakesOffers, setName, setOfferDistribution, setOfferDistribution, setOfferOrder, setOfferPolicy, setOffersAllEntities, setOffersTakeItOrLeaveIt, setParent, step, 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
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface sim.engine.Steppable
step
-
Constructor Details
-
Transformer
public Transformer(sim.engine.SimState state, CountableResource typicalProvided, Resource typicalReceived, double conversion)
-
-
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
-
provide
Description copied from class:Provider
Asks the Provider to make a unilateral offer of up to the given amount to the given Receiver. If the typical provided resource is an ENTITY, then atMost is ignored. This can be used to implement a simple pull. The Receiver does not need to be registered with the Provider. Returns true if the offer was accepted; though since the Receiver itself likely made this call, it's unlikely that this would ever return anything other than TRUE in a typical simulation.atMost must be a positive non-zero, non-NAN number.
-
getTypicalReceived
Description copied from interface:Receiver
Returns the typical kind of resource the receiver can accept. When a Receiver is also a Provider, this is very often implemented simply by calling getTypicalProvided(). If (rarely) the Receiver may receive a variety of types, such as a Composer, then this method should return null.- Specified by:
getTypicalReceived
in interfaceReceiver
- Overrides:
getTypicalReceived
in classMiddleman
-
accept
Description copied from class:Filter
Override this as you like. The default version offers to downstream Receivers whatever it is being offered here; and then calls process(...) to process the difference between the two. By default process(...) does nothing, but you could override that too. -
toString
-