155 std::ostream & outputstream,
const Stock_event & event) {
156 outputstream <<
event.event_id <<
" ";
157 for (
unsigned int i = 0; i <
event.mutually_exclusive_events.size(); i++) {
158 outputstream <<
event.mutually_exclusive_events[i] <<
" ";
160 outputstream <<
";" <<
event.text <<
";" <<
event.duration <<
" "
161 <<
event.probability_permille <<
" " <<
event.type_of_event
162 <<
" " <<
event.category <<
" ";
163 for (
const auto & modifier : event.
modifiers) {
164 outputstream << modifier.second <<
" ";
178 inputstream >>
event.event_id;
179 std::string _mutually_exclusive_events;
180 std::getline(inputstream, _mutually_exclusive_events,
';');
181 std::istringstream mutually_exclusive_events_stream(
182 _mutually_exclusive_events);
183 unsigned int temp_id;
184 while (mutually_exclusive_events_stream >> temp_id) {
185 event.mutually_exclusive_events.emplace_back(temp_id);
187 std::getline(inputstream, event.
text,
';');
188 unsigned int temp_type;
189 inputstream >>
event.duration >>
event.probability_permille >> temp_type >>
191 event.type_of_event =
static_cast<event_type>(temp_type);
213 const std::vector<Stock_event> & all_events,
unsigned int num_events);
216 const std::vector<Stock_event> & all_events);
227 const std::vector<Stock_event> & all_events);
238void print_map(
const std::map<
unsigned int, std::vector<unsigned int>> & map);
249std::vector<Stock_event>
uniq_events(std::vector<Stock_event> picked_events,
250 const std::vector<Stock_event> & all_events);
mutuallyExclusiveMap build_mutual_exclusivity_map(const std::vector< Stock_event > &all_events)
constexpr float meanMultiplier
Multiplier for mean.
const float sdMultiplier
Multiplier for standard deviation.
std::map< decltype(Stock_event::event_id), std::vector< decltype(Stock_event::event_id)> > mutuallyExclusiveMap
stock_modifiers
The attributes of a stock that Events will modify are hardcoded here.
@ upper_limit
The upper limit of the stock price percentage change.
@ standard_deviation
Amount of variation of the stock price percentage change.
@ mean
The expectation of the stock price percentage change.
@ lower_limit
The lower limit of the stock price percentage change.
void print_map(const std::map< unsigned int, std::vector< unsigned int > > &map)
Print a map to std::cout.
const float defaultUpperLimit
Default upper limit.
const float defaultLowerLimit
Default lower limit.
event_type
The type of event that will be applied to the stocks.
@ pick_random_stock
This event will apply to a randomly selected stock from all of the stocks available currently.
@ category
This event will apply to stocks within the specified category.
@ all_stocks
This event will apply to all stocks.
std::vector< Stock_event > uniq_events(std::vector< Stock_event > picked_events, const std::vector< Stock_event > &all_events)
Filter out the events that are mutually exclusive with each other, or events that are identical (exce...
Stock_event getStockSplitEvent(void)
const std::vector< Stock_event > all_stock_events
The list of all events that will be applied to the stocks.
bool assertion_check_mutual_exclusivity(void)
Check if there are mutual exclusivity violations in all_stock_events.
mutuallyExclusiveMap check_mutual_exclusivity(const std::vector< Stock_event > &all_events)
If A is mutually exclusive with B, then B is mutually exclusive with A.
constexpr float defaultMean
Default mean.
const unsigned int durationDecreaseMultiplier
Rate of decrease of duration.
const float upperLimitMultiplier
Upper limit multiplier.
std::vector< Stock_event > pick_events(const std::vector< Stock_event > &all_events, unsigned int num_events)
Pick a random event from the list of events.
void assertion_check_uniq_events(void)
const float lowerLimitMultiplier
Lower limit multiplier.
The data structure of an event that will be applied to the stocks.
event_type type_of_event
The type of event: Apply to all stocks, in one category or randomly?
bool operator==(const Stock_event &other) const
Overload the == operator to compare two Stock_event.
friend std::ostream & operator<<(std::ostream &outputstream, const Stock_event &event)
Serialize the event as std::ostream object.
friend std::istream & operator>>(std::istream &inputstream, Stock_event &event)
Deserialize the event from a std::istream object.
unsigned int probability_permille
0 to 1000, so 114 means 11.4%
unsigned int duration
Number of rounds the event will last.
std::map< stock_modifiers, double > modifiers
Stores the stock_modifiers that the event applies.
std::string text
The text that will be displayed to the player.
std::vector< unsigned int > mutually_exclusive_events
A list of event_ids that this event is mutually exclusive with.
unsigned int event_id
The id of the event.