2 #include <eris/Good.hpp> 3 #include <eris/noncopyable.hpp> 4 #include "creativity/CreativitySettings.hpp" 5 #include "creativity/state/Storage.hpp" 28 std::shared_ptr<eris::Simulation>
sim;
31 eris::SharedMember<eris::Good>
money;
52 template <
class T,
typename... Args>
54 auto new_storage = state::Storage::create<T>(set_, std::forward<Args>(args)...);
56 auto &old_storage = spair.first;
58 for (
const auto &state : *old_storage) {
59 new_storage->push_back(state);
62 new_storage->flush(
false);
66 spair.first = new_storage;
76 template <
class T,
typename... Args>
77 void read(Args&&... args) {
78 if (setup_sim_)
throw std::logic_error(
"Creativity: attempt to read() after calling setup()");
79 storage().first = state::Storage::create<T>(set_, std::forward<Args>(args)...);
223 std::pair<std::vector<eris::SharedMember<Book>>&, std::unique_lock<std::mutex>>
newBooks();
232 std::pair<std::shared_ptr<state::Storage>&, std::unique_lock<std::mutex>>
storage();
244 template <
typename Iter,
typename =
typename std::enable_if<std::is_arithmetic<
245 typename std::iterator_traits<Iter>::value_type>::value>::type>
249 for (; it != end; ++it) {
261 template <
typename Container,
typename =
typename std::enable_if<std::is_arithmetic<
262 typename Container::value_type>::value>::type>
285 bool setup_sim_{
false};
288 bool setup_read_{
false};
298 std::vector<eris::SharedMember<Book>> new_books_;
303 std::list<unsigned int> mkt_books_;
308 std::shared_ptr<state::Storage> storage_;
311 std::mutex storage_mutex_, new_books_mutex_;
double meanInitialQuality() const
Returns the mean quality of books created with initial parameter distributions.
bool publicSharingActive() const
Returns true if public sharing is an enabled policy response and it is active in the simulation (i...
Primary namespace for all Creativity library code.
Definition: config.hpp:4
void write(Args &&... args)
Creates a new Storage object with any type of StorageBackend class.
Definition: Creativity.hpp:53
bool policyActive() const
Returns true if a policy response exists yet in the simulation.
static double boundaryFromDensity(uint32_t readers, uint32_t dimensions, double density)
Static method that calculates a boundary given a number of readers, dimensions, and a desired density...
static double evalPolynomial(double x, Iter it, Iter end)
Evaluates a polynomial at the value x.
Definition: Creativity.hpp:246
const CreativitySettings & parameters
Simulation parameters that are used to configure the simulation when calling setup().
Definition: Creativity.hpp:36
eris::SharedMember< eris::Good > money
The money good. Will be empty until setup() is called.
Definition: Creativity.hpp:31
bool piracy() const
Returns true if piracy exists yet in the simulation.
void checkParameters()
Checks .parameters to make sure that all configured values are valid, throwing an exception if any in...
double policyTaxes() const
Returns the per-user policies taxes currently in effect.
bool publicVotingActive() const
Returns true if public sharing with voting is an enabled policy response and it is active in the simu...
double densityFromBoundary() const
Returns the value of densityFromBoundary called with the current readers, dimensions, and boundary settings.
Creativity()=default
Default constructor.
unsigned long market_books
Stores the number of on-market books.
Definition: Creativity.hpp:270
double market_books_avg
Stores the average number of on-market books over the past creation_time + 1 periods.
Definition: Creativity.hpp:275
bool catchPiratesActive() const
Returns true if getting caught for piracy is a configured policy response and it is active in the sim...
Central class for a creativity simulation; this class handles setting up the simulation according to ...
Definition: Creativity.hpp:22
double priorWeight() const
Returns the prior multiplier currently in effect.
std::shared_ptr< eris::Simulation > sim
The simulation object.
Definition: Creativity.hpp:28
std::pair< std::vector< eris::SharedMember< Book > > &, std::unique_lock< std::mutex > > newBooks()
Establishes a lock on the new books storage and returns a pair consisting of the new books reference ...
void run()
Runs one iteration of the simulation.
static double evalPolynomial(double x, const Container &cont)
Evaluates a polynomial at the value x.
Definition: Creativity.hpp:263
Simulation parameters that are used to configure the simulation when calling setup().
Definition: CreativitySettings.hpp:10
double disposableIncome() const
Returns the level of exogenous, disposable income, i.e.
void createPiracyNetwork()
Sets up the piracy network.
void read(Args &&... args)
Opens a creativity simulation storage source for reading via storage().
Definition: Creativity.hpp:77
void setup()
Creates the Simulation object and adds the configured number of readers plus some base members (such ...
std::pair< std::shared_ptr< state::Storage > &, std::unique_lock< std::mutex > > storage()
Establishes a lock on the storage object and returns a pair consisting of the storage object and the ...