Compare commits
3 Commits
5f052f8d98
...
58efb6fec8
Author | SHA1 | Date | |
---|---|---|---|
58efb6fec8 | |||
88737d8f4c | |||
0c30e880cc |
@ -29,7 +29,6 @@ func RunAuction(g BidderGenerator) (float64, Bidder) {
|
|||||||
return prevBid, highBidder
|
return prevBid, highBidder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RunAuctionVerbosely simulates a single-bid second-price auction with no
|
* RunAuctionVerbosely simulates a single-bid second-price auction with no
|
||||||
* reserve price between all bidders emitted by the provided generator,
|
* reserve price between all bidders emitted by the provided generator,
|
||||||
@ -39,7 +38,7 @@ func RunAuction(g BidderGenerator) (float64, Bidder) {
|
|||||||
* Use CappedBidderGenerator to limit the size of the auction and therefore
|
* Use CappedBidderGenerator to limit the size of the auction and therefore
|
||||||
* the number of bidders on the list.
|
* the number of bidders on the list.
|
||||||
*/
|
*/
|
||||||
func RunAuctionVerbosely(g BidderGenerator) float64, []Bidder {
|
func RunAuctionVerbosely(g BidderGenerator) (float64, []Bidder) {
|
||||||
var bidders []Bidder
|
var bidders []Bidder
|
||||||
for b, ok := g.Generate(); ok; b, ok = g.Generate() {
|
for b, ok := g.Generate(); ok; b, ok = g.Generate() {
|
||||||
bidders = append(bidders, b)
|
bidders = append(bidders, b)
|
||||||
|
@ -5,25 +5,25 @@ package auctionsim
|
|||||||
* not threadsafe. It is a pure value type.
|
* not threadsafe. It is a pure value type.
|
||||||
*/
|
*/
|
||||||
type Bidder struct {
|
type Bidder struct {
|
||||||
/**
|
/**
|
||||||
* Value stores the real value of the item being auctioned, to this bidder.
|
* Value stores the real value of the item being auctioned, to this bidder.
|
||||||
* If the bidder won the auction at this price, they would make exactly
|
* If the bidder won the auction at this price, they would make exactly
|
||||||
* zero effective profit. It is the "rational bid" in a perfectly efficient
|
* zero effective profit. It is the "rational bid" in a perfectly efficient
|
||||||
* marketplace.
|
* marketplace.
|
||||||
*
|
*
|
||||||
* A bidder that wants some nonzero profit has a lower value on the item by
|
* A bidder that wants some nonzero profit has a lower value on the item by
|
||||||
* the amount of profit they want -- that "minimum payoff" represents an
|
* the amount of profit they want -- that "minimum payoff" represents an
|
||||||
* unspecified cost for the time and effort of doing the project at all.
|
* unspecified cost for the time and effort of doing the project at all.
|
||||||
* Other costs for getting value out of the object also decrease its value.
|
* Other costs for getting value out of the object also decrease its value.
|
||||||
*
|
*
|
||||||
* For example, a city to which hosting an F1 race is worth five billion
|
* For example, a city to which hosting an F1 race is worth five billion
|
||||||
* dollars, but would spend three and a half billion dollars setting up for
|
* dollars, but would spend three and a half billion dollars setting up for
|
||||||
* it, one billion dollars running it, and lose one billion dollars of tax
|
* it, one billion dollars running it, and lose one billion dollars of tax
|
||||||
* revenue due to business disruption during setup and during the event,
|
* revenue due to business disruption during setup and during the event,
|
||||||
* correctly values the race for negative five hundred million dollars. As
|
* correctly values the race for negative five hundred million dollars. As
|
||||||
* demonstrated by this example, a value can be negative.
|
* demonstrated by this example, a value can be negative.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Value float64
|
Value float64
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,8 +57,9 @@ type Bidder struct {
|
|||||||
/**
|
/**
|
||||||
* ValueBelief returns how much the bidder *thinks* the item is worth to them.
|
* ValueBelief returns how much the bidder *thinks* the item is worth to them.
|
||||||
* The actual value to them is b.Value.
|
* The actual value to them is b.Value.
|
||||||
|
*/
|
||||||
func (b Bidder) ValueBelief() float64 {
|
func (b Bidder) ValueBelief() float64 {
|
||||||
return b.Value + b.Irrationality;
|
return b.Value + b.Irrationality
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -79,7 +80,7 @@ func (b Bidder) BidCeiling() float64 {
|
|||||||
* than their calculated ceiling if they had the money to do so, but they don't.
|
* than their calculated ceiling if they had the money to do so, but they don't.
|
||||||
*/
|
*/
|
||||||
func (b Bidder) CashCapped() bool {
|
func (b Bidder) CashCapped() bool {
|
||||||
return b.ValueBelief() > b.Cash;
|
return b.ValueBelief() > b.Cash
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,9 +10,9 @@ import (
|
|||||||
*/
|
*/
|
||||||
func NormalestDistribution() *NormalDistribution {
|
func NormalestDistribution() *NormalDistribution {
|
||||||
return &NormalDistribution{
|
return &NormalDistribution{
|
||||||
Rand: rand.New(rand.NewSource(int64(rand.Uint64()))),
|
Rand: rand.New(rand.NewSource(int64(rand.Uint64()))),
|
||||||
StdDev: 1,
|
StdDev: 1,
|
||||||
Mean: 0,
|
Mean: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,8 +24,8 @@ func NormalestDistribution() *NormalDistribution {
|
|||||||
func NormalestBidderGenerator() BidderGenerator {
|
func NormalestBidderGenerator() BidderGenerator {
|
||||||
d := NormalestDistribution()
|
d := NormalestDistribution()
|
||||||
return &BiddersFromDistributions{
|
return &BiddersFromDistributions{
|
||||||
Values: d,
|
Values: d,
|
||||||
Irrationalities: d,
|
Irrationalities: d,
|
||||||
Bankrolls: ConstDistribution(math.Inf(1)),
|
Bankrolls: ConstDistribution(math.Inf(1)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ type Distribution interface {
|
|||||||
* Draw returns the next float64 from the distribution and true, or
|
* Draw returns the next float64 from the distribution and true, or
|
||||||
* zero and false if the distribution is exhausted or otherwise unusable.
|
* zero and false if the distribution is exhausted or otherwise unusable.
|
||||||
*/
|
*/
|
||||||
Draw() float64, bool
|
Draw() (float64, bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,7 +23,7 @@ type BidderGenerator interface {
|
|||||||
* Generate returns the next Bidder and true, or a zero Bidder and false if
|
* Generate returns the next Bidder and true, or a zero Bidder and false if
|
||||||
* the generator is exhausted or otherwise unusable.
|
* the generator is exhausted or otherwise unusable.
|
||||||
*/
|
*/
|
||||||
Generate() Bidder, bool
|
Generate() (Bidder, bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,9 +31,9 @@ type BidderGenerator interface {
|
|||||||
* irrationality levels, and cash on hand from the provided distributions.
|
* irrationality levels, and cash on hand from the provided distributions.
|
||||||
*/
|
*/
|
||||||
type BiddersFromDistributions struct {
|
type BiddersFromDistributions struct {
|
||||||
Values Distribution
|
Values Distribution
|
||||||
Irrationalities Distribution
|
Irrationalities Distribution
|
||||||
Bankrolls Distribution
|
Bankrolls Distribution
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,10 +53,10 @@ func (b *BiddersFromDistributions) Generate() (Bidder, bool) {
|
|||||||
return Bidder{}, false
|
return Bidder{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
return Bidder {
|
return Bidder{
|
||||||
Value: value,
|
Value: value,
|
||||||
Irrationality: irrationality,
|
Irrationality: irrationality,
|
||||||
Cash: cash,
|
Cash: cash,
|
||||||
}, true
|
}, true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,16 +67,16 @@ func (b *BiddersFromDistributions) Generate() (Bidder, bool) {
|
|||||||
* (since rand.Rand is not threadsafe).
|
* (since rand.Rand is not threadsafe).
|
||||||
*/
|
*/
|
||||||
type NormalDistribution struct {
|
type NormalDistribution struct {
|
||||||
Rand *rand.Rand
|
Rand *rand.Rand
|
||||||
StdDev float64
|
StdDev float64
|
||||||
Mean float64
|
Mean float64
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draw implements Distribution.
|
* Draw implements Distribution.
|
||||||
*/
|
*/
|
||||||
func (n *NormalDistribution) Draw() (float64, bool) {
|
func (n *NormalDistribution) Draw() (float64, bool) {
|
||||||
return n.Rand.NormFloat64() * n.StdDev + n.Mean, true
|
return n.Rand.NormFloat64()*n.StdDev + n.Mean, true
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -88,7 +88,7 @@ type ConstDistribution float64
|
|||||||
* Draw implements Distribution.
|
* Draw implements Distribution.
|
||||||
*/
|
*/
|
||||||
func (c ConstDistribution) Draw() (float64, bool) {
|
func (c ConstDistribution) Draw() (float64, bool) {
|
||||||
return (float64)c, true
|
return float64(c), true
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,7 +96,7 @@ func (c ConstDistribution) Draw() (float64, bool) {
|
|||||||
* then stops returning values.
|
* then stops returning values.
|
||||||
*/
|
*/
|
||||||
type CappedDistribution struct {
|
type CappedDistribution struct {
|
||||||
D Distribution
|
D Distribution
|
||||||
Lim int64
|
Lim int64
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ func (c *CappedDistribution) Draw() (float64, bool) {
|
|||||||
* BidderGenerator, then stops returning values.
|
* BidderGenerator, then stops returning values.
|
||||||
*/
|
*/
|
||||||
type CappedBidderGenerator struct {
|
type CappedBidderGenerator struct {
|
||||||
G BidderGenerator
|
G BidderGenerator
|
||||||
Lim int64
|
Lim int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user