creativity  v1.3.0
Agent-based model of creativity and piracy
Book.hpp
1 #pragma once
2 #include <eris/WrappedPositional.hpp>
3 #include <eris/good/Discrete.hpp>
4 #include <map>
5 #include <functional>
6 #include <eris/random/truncated_normal_distribution.hpp>
7 
8 namespace creativity {
9 
10 // forward-declarations
11 class Reader;
12 class BookMarket;
13 class Creativity;
14 
33 class Book final : public eris::WrappedPositional<eris::good::Discrete> {
34  public:
36  Book() = delete;
51  Book(Creativity &creativity, const eris::Position &p, eris::SharedMember<Reader> author,
52  unsigned int order, double quality);
53 
55  eris::eris_time_t age() const;
56 
60  const eris::eris_time_t& created() const;
61 
69  const eris::eris_time_t& leftPrivateMarket() const;
70 
74  const eris::eris_time_t& publicMarketCreated() const;
75 
88  unsigned int privateMarketPeriods() const;
89 
93  const unsigned int& order() const;
94 
101  void added() override;
102 
109  void setMarket(eris::SharedMember<BookMarket> market);
110 
113  void weakDepRemoved(eris::SharedMember<eris::Member>, eris::eris_id_t old) override;
114 
116  bool livingAuthor() const;
117 
122  eris::SharedMember<Reader> author() const;
123 
128  bool hasAnyMarket() const;
129 
133  bool hasPrivateMarket() const;
134 
137  bool hasPublicMarket() const;
138 
143  eris::SharedMember<BookMarket> market() const;
144 
148  double price() const;
149 
151  unsigned int lifeSales() const;
152 
154  unsigned int lifeSalesPrivate() const;
155 
157  unsigned int lifeSalesPublic() const;
158 
160  unsigned int currSales() const;
161 
165  unsigned int sales(eris::eris_time_t t) const;
166 
170  eris::eris_time_t lastSale() const;
171 
173  unsigned int lifePirated() const;
174 
176  unsigned int currPirated() const;
177 
179  unsigned int pirated(eris::eris_time_t t) const;
180 
182  double lifeRevenue() const;
183 
185  double lifeRevenuePrivate() const;
186 
188  double lifeRevenuePublic() const;
189 
199  double lifeProfitPrivate() const;
200 
202  double currRevenue() const;
203 
205  double revenue(eris::eris_time_t t) const;
206 
208  double currPrize() const;
209 
211  double prize(eris::eris_time_t t) const;
212 
214  double lifePrize() const;
215 
217  uint32_t lifeVotes() const;
219  uint32_t currVotes() const;
221  uint32_t votes(eris::eris_time_t t) const;
222 
228  unsigned int copies() const;
229 
237  unsigned int queryCopies() const;
238 
249  void recordSale(unsigned int new_sales, double new_revenue);
250 
255  void recordPiracy(unsigned int new_copies);
256 
259  void recordPrize(double prize);
260 
264  void vote(uint32_t count);
265 
272  double qualityMean() const;
273 
280  double qualityDraw();
281 
282  private:
283  Creativity &creativity_;
284  eris::eris_time_t created_ = 0, left_private_market_ = 0, public_market_created_ = 0;
285  uint32_t copies_private_total_ = 0, copies_pirated_total_ = 0, copies_public_total_ = 0,
286  votes_total_ = 0;
287  double revenue_private_total_ = 0, revenue_public_total_ = 0, prize_total_ = 0;
288  std::map<eris::eris_time_t, uint32_t> copies_sold_, copies_pirated_, votes_;
289  std::map<eris::eris_time_t, double> revenue_, prize_;
290  eris::SharedMember<Reader> author_;
291  const unsigned int order_ = 0;
292  bool market_private_ = true;
293  eris::eris_id_t market_id_ = 0;
294  eris::random::truncated_normal_distribution<double> quality_dist_;
295 };
296 
297 }
298 
bool hasAnyMarket() const
Returns true if this book is currently on the market, false if there is no associated market for this...
double currRevenue() const
Returns the revenue of this book so far in the current period.
double lifeRevenue() const
Returns the lifelong revenue (from both private and public markets) of this book. ...
double lifeRevenuePublic() const
Returns the lifelong public revenue of this book.
double qualityMean() const
Returns the mean quality level determined by the author at book creation time.
double lifePrize() const
Returns the lifetime prize money earned by the author for this book.
const eris::eris_time_t & publicMarketCreated() const
Returns the simulation period in which the book was first placed on the public market or 0 if the boo...
eris::SharedMember< Reader > author() const
Returns the author who created this Book.
Primary namespace for all Creativity library code.
Definition: config.hpp:4
void recordPiracy(unsigned int new_copies)
Increase the number of pirated copies of this book for the current period.
double lifeRevenuePrivate() const
Returns the lifelong private market revenue of this book.
uint32_t lifeVotes() const
Returns the lifetime number of votes for this book.
unsigned int currPirated() const
Returns the number of pirated copies of this book so far in the current period.
bool hasPublicMarket() const
True if the book is currently on the public market.
bool hasPrivateMarket() const
Returns true if this book&#39;s current market exists and is a private market, that is, on the market as controlled by the book&#39;s author.
eris::eris_time_t age() const
Returns the age of the book, in simulation periods.
double currPrize() const
Returns the prize money earned by the author for this book in the current period. ...
unsigned int queryCopies() const
Queries the simulation for the number of copies of this book in existence.
unsigned int sales(eris::eris_time_t t) const
Returns the number of sales in simulation period t.
unsigned int privateMarketPeriods() const
Returns the number of periods the book has been (or was) available on the private market...
unsigned int lifePirated() const
Returns the lifelong number of pirated copies of this book.
uint32_t votes(eris::eris_time_t t) const
Returns the number of votes for this book in the simulation period t
const eris::eris_time_t & created() const
Returns the simulation period in which the book became available (i.e.
bool livingAuthor() const
Returns true if this Book&#39;s author is still in the simulation, false otherwise.
unsigned int copies() const
Returns lifeSales() + lifePirated() (but atomically), reflecting the number of copies of the book tha...
unsigned int lifeSalesPublic() const
Returns the lifelong number of public market sales of this book.
void added() override
When the Book is added to the simulation it also creates an associated BookMarket object that handles...
void setMarket(eris::SharedMember< BookMarket > market)
Sets a new market for this book.
double lifeProfitPrivate() const
Calculates the lifetime profit of this book from the private market, not including initial creation c...
unsigned int currSales() const
Returns the number of sales of this book so far in the current period.
const eris::eris_time_t & leftPrivateMarket() const
Returns the first simulation period in which the book was no longer on the private market...
unsigned int lifeSales() const
Returns the lifelong number of sales (on both private and public markets) of this book...
uint32_t currVotes() const
Returns the number of votes for this book in the current period.
eris::SharedMember< BookMarket > market() const
Returns the BookMarket that sells this Book (which could be a PublicBookMarket if hasPublicMarket() i...
Class representing a particular book.
Definition: Book.hpp:33
double prize(eris::eris_time_t t) const
Returns the prize money earned by the author for this book in simulation period t ...
double revenue(eris::eris_time_t t) const
Returns the revenue earned by this book in simulation period t
void weakDepRemoved(eris::SharedMember< eris::Member >, eris::eris_id_t old) override
When the market is removed from the simulation, record it by clearing the stored market.
Central class for a creativity simulation; this class handles setting up the simulation according to ...
Definition: Creativity.hpp:22
const unsigned int & order() const
Returns the order of this book in the author&#39;s set of books.
double qualityDraw()
Draws a quality value for this book.
void vote(uint32_t count)
Called by a reader to cast one or more votes for this book, when under the public sharing with votes ...
void recordSale(unsigned int new_sales, double new_revenue)
Increase the sales and revenue of this book for the current period.
void recordPrize(double prize)
Record public money received by the author for this book.
eris::eris_time_t lastSale() const
Returns the last simulation period t in which this book had at least one sale, or 0 if this book has ...
unsigned int pirated(eris::eris_time_t t) const
Returns the number of pirated copies in simulation period t
unsigned int lifeSalesPrivate() const
Returns the lifelong number of private market sales of this book.
Book()=delete
Not default constructible.
double price() const
Returns the current market price of this book.