creativity  v1.3.0
Agent-based model of creativity and piracy
Public Member Functions | Protected Attributes | List of all members
creativity::BookMarket Class Reference

A BookMarket is very simple: it has an exogenously determined price and can supply infinite copies of a Book at that price. More...

#include <creativity/BookMarket.hpp>

Public Member Functions

 BookMarket ()=delete
 Not default constructible.
 
 BookMarket (const Creativity &creativity, eris::SharedMember< Book > b, double price)
 Constructs a BookMarket that sells copies of the given Book with an initial price of p times the money good. More...
 
virtual price_info price (double q) const override
 Returns price info. More...
 
virtual quantity_info quantity (double p) const override
 Returns quantity info for a given payment. More...
 
virtual void setPrice (double p)
 Sets the price of copies of the book on the market for future sales. More...
 
virtual const double & price ()
 Returns the price of a single copy of the book. More...
 
virtual void added () override
 Registers this market as the book's market when added to the simulation. More...
 
virtual Reservation reserve (eris::SharedMember< eris::Agent > agent, double q, double p_max=std::numeric_limits< double >::infinity()) override
 Reserves a copy of a book, paying at most p_max for it. More...
 
eris::SharedMember< Bookbook ()
 Returns the Book sold by this market. More...
 
virtual void intraFinish () override
 Transfers all sales (less unit costs) generated in the just-ending period to the author.
 
virtual bool isPublic () const
 Returns true if this is a public market. More...
 
virtual void buy (Reservation &res) override
 We override reservation completion to transfer the payment to the author and put the book into the b_ bundle. More...
 

Protected Attributes

const Creativitycreativity_
 The creativity object pointer.
 
eris::SharedMember< Bookbook_
 The book this market object sells.
 
double price_
 The current price of the book.
 
eris::Bundle proceeds_
 Accrued income of the book (these get transferred in the interApply phase)
 

Detailed Description

A BookMarket is very simple: it has an exogenously determined price and can supply infinite copies of a Book at that price.

Constructor & Destructor Documentation

§ BookMarket()

creativity::BookMarket::BookMarket ( const Creativity creativity,
eris::SharedMember< Book b,
double  price 
)

Constructs a BookMarket that sells copies of the given Book with an initial price of p times the money good.

Books are created as needed at zero cost.

Member Function Documentation

§ added()

virtual void creativity::BookMarket::added ( )
overridevirtual

Registers this market as the book's market when added to the simulation.

Reimplemented in creativity::PublicTrackerMarket.

§ book()

eris::SharedMember<Book> creativity::BookMarket::book ( )

Returns the Book sold by this market.

§ buy()

virtual void creativity::BookMarket::buy ( Reservation &  res)
overridevirtual

We override reservation completion to transfer the payment to the author and put the book into the b_ bundle.

Todo:
this is simple: eventually it would probably be better to have a firm (perhaps created when the Book is created?) that accepts payments, mitigating this override.

§ isPublic()

virtual bool creativity::BookMarket::isPublic ( ) const
inlinevirtual

Returns true if this is a public market.

This class always returns false; public market subclasses are intended to override.

Reimplemented in creativity::PublicTrackerMarket.

§ price() [1/2]

virtual price_info creativity::BookMarket::price ( double  q) const
overridevirtual

Returns price info.

Since price is constant, and quantity should always 1, this price info is simple: it's always feasible, and total is just the price.

Parameters
qthe quantity, which must be 1.
Exceptions
std::logic_errorif the given quantity does not equal 1.0.

§ price() [2/2]

virtual const double& creativity::BookMarket::price ( )
virtual

Returns the price of a single copy of the book.

This will be the same value as any of m.price(1).total, m.price(1).marginalFirst, m.price(1).marginal.

This is guaranteed not to change during an intra-period optimization phase (and so a read lock on the market to obtain market price is not required).

§ quantity()

virtual quantity_info creativity::BookMarket::quantity ( double  p) const
overridevirtual

Returns quantity info for a given payment.

As long as the given price is at least as large as the market price, this returns a quantity_info with quantity set to 1, constrained set to false, spent set to the price, and unspent set to p minus the price.

Otherwise (if p is too low) this returns a quantity of 0, spent set to 0, constrained set to false, and unspent set to p.

§ reserve()

virtual Reservation creativity::BookMarket::reserve ( eris::SharedMember< eris::Agent >  agent,
double  q,
double  p_max = std::numeric_limits< double >::infinity() 
)
overridevirtual

Reserves a copy of a book, paying at most p_max for it.

The q argument must be 1: you can't buy anything other than 1 copy.

§ setPrice()

virtual void creativity::BookMarket::setPrice ( double  p)
virtual

Sets the price of copies of the book on the market for future sales.

The value is a multiple of creativity::MONEY.

This may not be called during an intra-optimization phase.

Inheritance diagram for creativity::BookMarket:
[legend]
Collaboration diagram for creativity::BookMarket:
[legend]

The documentation for this class was generated from the following file: