auction

suspend fun KSLProcessBuilder.auction(cfp: CallForProposals, deadline: Double, selectBest: (List<Bid>) -> Bid? = ::lowestBidByName): Bid?(source)

Runs a Contract-Net negotiation over the available vehicles and returns the winning bid.

A real auction, not a distance rule wearing an auction's clothes. The dispatcher broadcasts the call and each vehicle answers with whatever its own BidPolicyIfc makes of it, so two fleets with the same layout and different bidding rules reach different awards. A vehicle may decline, and declining is silence rather than a message -- a dispatcher receiving an "I decline" would have to tell it apart from a bid.

The deadline consumes simulated time, and that is the point of expressing an auction as something a policy does rather than as a rule it evaluates. Negotiation is not free; a model that charges for it is more faithful than one that awards instantaneously, and the cost is visible in the loads' waiting time rather than hidden in an assumption.

A deadline of zero is well defined and is not a trap. contractNet collects the proposals that reached it before the deadline elapsed, and a bid is computed by a non-suspending mailbox handler that answers inside the broadcast itself -- so at zero every vehicle has still bid. That safety rests on BidPolicyIfc.bid not being a suspending function, which the type system enforces rather than a convention: a bidding rule that consumed simulated time could not be written, so a zero deadline cannot silently start collecting nothing.

Ties are broken by vehicle name, not by position in the fleet. Elsewhere in this subsystem declaration order is the tiebreaker, and here it would be wrong: an auction treats its bidders as symmetric except for what they offer, so two vehicles quoting the same number should get the same answer however the fleet happened to be declared. Name is stable under reordering, total, and explicable to a modeller looking at a result they did not expect. A supplied selectBest takes on that responsibility for itself.

Return

the best bid by selectBest, or null when every vehicle declined

Parameters

cfp

what the vehicles are being asked to bid on

deadline

how long to wait for proposals, in simulated time. Zero is instantaneous.