[2023 Higher Education Society Cup] Problem analysis, mathematical model and python code implementation of automatic pricing and replenishment decision-making for vegetable commodities in Question C

[2023 Higher Education Society Cup] Automatic pricing and replenishment decision-making for vegetable commodities in Question C

insert image description here

1 question

Question C: Automatic pricing and replenishment decisions for vegetable commodities

In fresh food supermarkets, the shelf life of general vegetable products is relatively short, and the quality deteriorates with the increase of sales time. If most varieties are not sold on the same day, they cannot be resold the next day. Therefore, supermarkets usually restock every day based on the historical sales and demand of each product.

Since there are many varieties of vegetables sold in supermarkets with different origins, and the purchase and transaction time of vegetables is usually between 3:00 and 4:00 in the morning, merchants must do this without knowing exactly the specific items and purchase prices. Make replenishment decisions for each vegetable category on the day. The pricing of vegetables generally adopts the "cost-plus pricing" method. Supermarkets usually offer discounts for products that have been damaged during transportation and have deteriorated in quality. Reliable market demand analysis is particularly important for replenishment decisions and pricing decisions. From the demand side, there is often a certain correlation between the sales volume of vegetable commodities and time; from the supply side, the supply variety of vegetables is relatively abundant from April to October, and the restrictions on the sales space of supermarkets make reasonable sales Combination becomes extremely important.

Attachment 1 gives the product information of six vegetable categories distributed by a certain supermarket; Appendix 2 and Attachment 3 respectively give the sales details and details of each commodity in the supermarket from July 1, 2020 to June 30, 2023. Relevant data on wholesale prices; Appendix 4 provides recent loss rate data for each commodity. Please establish a mathematical model based on the attachment and actual situation to solve the following problems:

Question 1: There may be certain correlations between different categories or single products of vegetable commodities. Please analyze the distribution patterns and interrelationships of the sales volume of various vegetable categories and single products.

Question 2 Consider that supermarkets make replenishment plans on a category basis. Please analyze the relationship between the total sales volume of each vegetable category and cost-plus pricing, and give the forecast for each vegetable category in the next week (July 1-7, 2023). The total daily replenishment volume and pricing strategy maximize the profits of supermarkets.

Question 3 : Due to the limited sales space of vegetable products, the supermarket hopes to further develop a replenishment plan for single products, requiring the total number of single products available for sale to be controlled to 27-33, and the order quantity of each single product meets the minimum display quantity requirement of 2.5 kg. . Based on the varieties available for sale from June 24 to 30, 2023, the single product replenishment volume and pricing strategy for July 1 are given, so as to maximize the profits of supermarkets and stores while trying to meet the market demand for various types of vegetable commodities.

Question 4 In order to better make replenishment and pricing decisions for vegetable commodities, what other relevant data do supermarkets need to collect? How can these data help solve the above problems? Please give your opinions and reasons.

Attachment 1: Product information of 6 vegetable categories
Attachment 2: Detailed sales data
Attachment 3: Wholesale prices of vegetable products Attachment
4: Recent loss rates of vegetable products
Note (1) In Attachment 1, some individual product names include Numerical numbers indicate different sources of supply.
(2) The loss rate in Appendix 4 reflects the recent loss of goods and is calculated from the data of the recent inventory cycle.

2 Problem Analysis

2.1 Question 1

To analyze the sales distribution pattern of each vegetable category and single product, you can use visualization tools to display sales volume histograms and box plots to observe the sales distribution and outliers. Then, the correlation coefficient method is calculated to analyze the sales volume correlation between vegetable commodities, as well as the possible sales volume correlation between different categories or different single products.

2.2 Question 2

Linear programming problem. First, it is necessary to calculate the total sales volume of each vegetable category based on the sales flow details in Appendix 2. Specifically, for each vegetable category iii , its total sales volumeS i S_iSiIt can be obtained by summing the total sales volume of its subcategories, that is, the category code is the first 8 digits containing the category code, that is

S i = ∑ j ∈ C i s j S_i = \sum_{j \in C_i} s_j Si=jCisj

Among them, C i C_iCiIndicates vegetable category iiThe set of subclasses contained in i , sj s_jsjRepresents subclass jjThe total sales volume of j .

Next, you need to calculate the cost-plus pricing for each vegetable category. Hypothetical vegetable category iiThe cost of i isci c_ici, the bonus rate is mi m_imi, then the cost-plus pricing is
pi = (1 + mi) ci p_i = (1 + m_i) c_ipi=(1+mi)ci

Costs and profits need to be calculated based on the wholesale price data in Appendix 3. For each vegetable categoryiii , its original versionci c_iciIt can be obtained by summing the average wholesale price of its subcategories, that is

c i = ∑ j ∈ C i w j p j ∑ j ∈ C i w j c_i = \dfrac{\sum_{j \in C_i} w_j p_j}{\sum_{j \in C_i} w_j} ci=jCiwjjCiwjpj

Among them, wj w_jwjRepresents subclass jjThe wholesale quantity of j ,pj p_jpjRepresents subclass jjThe average wholesale price of j .

Next, the loss cost of each vegetable category needs to be calculated based on the loss rate data in Appendix 4. Specifically, assuming that vegetable category iiThe loss rate of i is ri r_iri, then its loss cost li l_iliIt can be obtained by taking the weighted average of the total sales volume and wholesale price of its subcategory and multiplying it by the loss rate, that is

l i = ∑ j ∈ C i s j w j p j ∑ j ∈ C i s j w j × r i l_i = \dfrac{\sum_{j \in C_i} s_j w_j p_j}{\sum_{j \in C_i} s_j w_j} \times r_i li=jCisjwjjCisjwjpj×ri

Finally, according to the requirements of the topic, a mathematical model needs to be designed to calculate the total daily replenishment volume and pricing strategy of each vegetable category in the next week, so as to maximize the profits of the supermarket.

Please download the complete information

2.3 Question 3

Based on the model of question 2, we need to consider further formulating the replenishment plan of single products, that is, we need to limit the total number of sellable single products of each vegetable category to 27-33, and the order quantity of each single product must meet the minimum display Amount of 2.5 kg required. Convert it to an integer programming problem. The improvements mainly include two places:

(1) Add constraints to limit the total number of items available for sale in each vegetable category to no more than 33. At the same time, except for the last day, the number of items that need to be replenished every day does not exceed 33.

(2) Split the original optimization problem into 7-day sub-problems, and solve the optimal daily replenishment volume and selling price under the premise of satisfying the first step of constraints.

The mathematical model is as follows:

Please download the complete information

The first constraint limits the total daily replenishment volume of each vegetable category to not exceed its maximum daily replenishment volume.
The second constraint limits the number of categories that need to be replenished every day to no more than 33, except for the last day.
The third constraint restricts the last day without replenishment.
The fourth constraint restricts the replenishment quantity and selling price to be integers.

2.4 Question 4

Commodity transactions are a matter between buyers and sellers. By collecting as much data as possible from buyers and sellers, we can achieve customized sales plans for customers and rationalized sales plans for sellers.

(1) Customer information: purchasing preferences and consumer demographic information, such as age, gender, occupation, monthly income, etc., to analyze market demand and formulate sales mix and pricing strategies suitable for different consumer groups.

(2) Product information: the origin, purchase time, purchase batch and other information of the product, and analyze the purchase price, purchase cost and product quality in different seasons.

3 python code

3.1 Question 1

Read data

import pandas as pd
import numpy as np
import warnings
import matplotlib.pyplot as plt 
import seaborn as sns 
import scipy.stats as st
%matplotlib  inline
warnings.filterwarnings("ignore")
plt.rcParams['font.sans-serif'] = 'SimSun' # 换成自己环境下的中文字体,比如'SimHei'
plt.style.use('seaborn-darkgrid')
sns.set(style = 'darkgrid')

# 使用分类编码和单品编码进行合并
item_info = pd.read_excel('data/附件1.xlsx')
item_info = item_info.fillna(method='ffill')
item_info['单品编码'] = item_info['单品编码'].astype('str')
item_info['分类编码'] = item_info['分类编码'].astype('str')
item_info['分类-单品编码'] = item_info['分类编码'] + '-' + item_info['单品编码']

# 计算出每个商品的销售总量、销售总额等信息
sales_details = pd.read_excel('data/附件2.xlsx')
sales_details['单品编码'] = sales_details['单品编码'].astype('str')
sales_details = sales_details[['销售日期', '单品编码', '销量(千克)', '销售单价(元/千克)']]
sales_details['销售额(元)'] = sales_details['销量(千克)'] * sales_details['销售单价(元/千克)']
sales_by_item = sales_details.groupby('单品编码').agg({
    
    '销量(千克)': 'sum', '销售额(元)': 'sum'}).reset_index()

# 计算出每个商品的平均批发价格、总批发额等信息
wholesale_price = pd.read_excel('data/附件3.xlsx')
wholesale_price
wholesale_price['单品编码'] = wholesale_price['单品编码'].astype('str')
wholesale_by_item = wholesale_price.groupby('单品编码').agg({
    
    '批发价格(元/千克)': 'mean'}).reset_index()
wholesale_by_item.columns = ['单品编码', '平均批发价格(元/千克)']
wholesale_by_item['总批发额(元)'] = wholesale_by_item['平均批发价格(元/千克)'] * sales_by_item['销量(千克)']


# 与商品信息合并,得到每个商品的损耗率
loss_rate = pd.read_excel('data/附件4.xlsx')
loss_rate
loss_rate['小分类编码'] = loss_rate['小分类编码'].astype('str')
item_info['单品编码'] = item_info['单品编码'].astype('str')
item_loss_rate = pd.merge(item_info, loss_rate, left_on='分类编码', right_on='小分类编码', how='left')

(1) Analyze the sales volume distribution rules of each vegetable category and single product, and use histograms and box plots to display the sales volume distribution.

# 统计根茎类不同单品的销售量
sales_by_item = sales_details.merge(item_info, on='单品编码', how='left')
sales_by_item = sales_by_item.groupby(['分类名称', '单品名称']).agg({
    
    '销量(千克)': 'sum'}).reset_index()

# 绘制直方图展示销售量分布情况
sales_by_item[sales_by_item['分类名称'] == '根茎类'].sort_values('销量(千克)', ascending=False).plot(kind='bar', x='单品名称', y='销量(千克)',
                                                                                             figsize=(10, 6))
plt.title('根茎类销售量直方图')
plt.xlabel('单品名称')
plt.ylabel('销量(千克)')
plt.show()

# 绘制箱线图展示销售量分布情况
sales_by_item.boxplot(column='销量(千克)', by='分类名称', figsize=(10, 6))
plt.title('各品类销售量箱线图')
plt.xlabel('品类名称')
plt.ylabel('销量(千克)')
plt.show()

insert image description here
insert image description here

(2) Analyze the sales volume correlation between vegetable commodities, and use the correlation coefficient matrix and heat map to analyze the sales volume correlation between different vegetable commodities.

# 将销售流水明细和商品信息合并,得到分类-单品编码和销售量的对应关系
sales_by_category = sales_details.merge(item_info, on='单品编码', how='left')
# 只取了20个进行可视化分析
sales_by_category = sales_by_category[0:20]
sales_matrix = sales_by_category.pivot(columns='分类-单品编码', values='销量(千克)')
corr_matrix = sales_matrix.corr()

plt.figure(figsize=(10, 8))
plt.imshow(corr_matrix, cmap=plt.cm.Reds_r)
plt.xticks(range(len(corr_matrix.columns)), corr_matrix.columns, rotation=90)
plt.yticks(range(len(corr_matrix.columns)), corr_matrix.columns)
plt.colorbar()
plt.title('销售量相关系数热力图')
plt.savefig('3.png',dpi=300)
plt.show()

(3) Analyze the possible sales volume correlations between different categories or different single products, and use scatter diagrams to show the possible sales volume correlations between different categories or different single products.

# 将销售流水明细和商品信息合并,得到分类名称和销售量的对应关系
sales_by_category = sales_details.merge(item_info, on='单品编码', how='left')
sales_by_category = sales_by_category.groupby('分类名称').agg({
    
    '销量(千克)': 'sum'}).reset_index()

# 绘制散点图展示不同品类之间的销售量关联情况
categories = list(set(item_info['分类名称']))
fig, ax = plt.subplots(figsize=(10, 6))
for c in categories:
    if c != '其他':
        ax.scatter(sales_by_category[sales_by_category['分类名称'] == c]['销量(千克)'], 
                   sales_by_category[sales_by_category['分类名称'] == c].index,
                   label=c)
plt.legend()
plt.ylabel('分类名称')
plt.xlabel('销售量(千克)')
plt.title('不同品类间销售量关联情况')
plt.show()

insert image description here

3.2 Questions 2 and 3

insert image description here

Guess you like

Origin blog.csdn.net/weixin_43935696/article/details/132752966