This repository contains a C++ project for simulating a simple economic system involving products and consumers. The simulation models the interaction between consumers and products, allowing for the calculation of profits based on consumer purchasing decisions and product attributes.
The project simulates an economic environment where consumers purchase products based on their preferences and capital. The products have attributes like selling price, cost to produce, and quality factor. The simulation calculates profits for each product and updates consumer preferences over time.
- Product and Consumer Classes: Define the attributes and behaviors of products and consumers.
- Randomized Data Generation: Simulate realistic economic scenarios using random data generation.
- Profit Calculation: Compute profits for each product based on sales and production costs.
- Consumer Preferences: Update consumer preferences based on purchase history.
- Performance Measurement: Measure the time taken for various operations in the simulation.
- C++ compiler (e.g., GCC, Clang, MSVC)
- CMake (optional, for building the project)
git clone https://github.com/your-username/economic-simulation.git
cd economic-simulation
Using CMake:
mkdir build
cd build
cmake ..
make
Or compile directly using a C++ compiler:
g++ -o simulation main.cpp Product.cpp Consumer.cpp util.cpp
Run the simulation executable:
./simulation
The program will simulate the interactions between consumers and products, outputting the profits for each product and other relevant information.
Defined in Consumer.h
and Consumer.cpp
.
- Attributes:
capital
agent_preference_seller
agent_10y_history
- Methods:
product_score(const Product& product)
capital_change(const std::vector<double>& data)
update_agent_preference()
get_capital() const
get_agent_10y_history() const
get_agent_preference_seller() const
Defined in Product.h
and Product.cpp
.
- Attributes:
cost_to_produce
selling_price
number_produced
number_sold
seller_id
quality_factor
profit_history
- Methods:
calculate_profit() const
new_product()
get_quality_factor() const
get_seller_id() const
get_selling_price() const
get_cost_to_produce() const
get_number_produced() const
get_number_sold() const
increment_number_sold()
get_profit_history() const
Defined in util.h
and util.cpp
.
double rand_choice(const std::vector<double>& data)
double rand_in_range(double min, double max)
Defined in main.cpp
.
void buy_product_for_agent(Consumer& agent, std::vector<Product>& product_list)
void buy_product_for_agents(std::vector<Consumer>& agent_list, std::vector<Product>& product_list)
void compute_profit(const std::vector<Product>& product_list)
Contributions are welcome! Please fork this repository, create a new branch, and submit a pull request. Ensure your code follows the existing style and include comments where necessary.
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Commit your changes (
git commit -am 'Add new feature'
). - Push to the branch (
git push origin feature-branch
). - Create a new Pull Request.