2021高教社杯全国大学生数学建模竞赛C题 Python代码演示

news2024/9/20 5:14:10

目录

    • 问题一
      • 1.1 根据附件 1,对 402 家供应商的供货特征进行量化分析
        • 计算供货特征
        • 数据标准化
          • 对正向指标归一化
          • 对负向指标归一化
      • 1.2 建立反映保障企业生产重要性的数学模型
        • 熵权法
        • 熵权法-TOPSIS
        • AHP
      • 1.3 在此基础上确定 50 家最重要的供应商,并在论文中列表给出结果。
    • 问题二
      • 2.1 参考问题 1,该企业应至少选择多少家供应商供应原材料才可能满足生产的需求?
        • 遗传算法
        • 差异进化
        • 粒子群优化(PSO)

import pandas as pd
import warnings
warnings.filterwarnings("ignore")

path = '/home/shiyu/Desktop/path_acdemic/ant/数模/历年题目/2021/'
d1 = pd.read_excel((path + '附件1 近5年402家供应商的相关数据.xlsx'), sheet_name='企业的订货量(m³)')
d2 = pd.read_excel((path + '附件1 近5年402家供应商的相关数据.xlsx'), sheet_name='供应商的供货量(m³)')
d3 = pd.read_excel((path + '附件2 近5年8家转运商的相关数据.xlsx'))

问题一

1.1 根据附件 1,对 402 家供应商的供货特征进行量化分析

https://dxs.moe.gov.cn/zx/a/hd_sxjm_sxjmlw_2021qgdxssxjmjslwzs/211025/1734085.shtml
在这里插入图片描述

计算供货特征

供货次数(正向)

d2_sub = d2.iloc[:,2:]
supply_times = d2_sub.apply(lambda x: sum(x!=0), axis=1)

平均供货量(正向)

supply_quantity_mean = d2_sub.apply(lambda x: sum(x), axis=1) / supply_times

单次最大供货量(正向)

supply_max = d2_sub.apply(lambda x: max(x), axis=1)

供货稳定性(负向)

d1_sub = d1.iloc[:,2:]
d12_sub = d1_sub.subtract(d2_sub) ** 2
supply_stability = d12_sub.apply(lambda x: sum(x), axis=1) / supply_times

供货连续性

  • 间隔次数(负向)
import numpy as np

gap_times = [None] * d2_sub.shape[0]
for i in range(0,d2_sub.shape[0]):
    a = d2_sub.iloc[i,:] == 0
    gap_times[i] = (a&~np.r_[[False],a[:-1]]).sum() 
  • 平均间隔周数(负向)
gap_weeks_mean = [None] * d2_sub.shape[0]
for i in range(0,d2_sub.shape[0]):
    index = [0] + list(np.where(d2_sub.iloc[i,:] != 0)[0]) + [241]
    new = np.diff(index)
    gap_weeks_mean[i] = sum(new[np.where((new != 1) & (new != 0))])

gap_weeks_mean = gap_weeks_mean / supply_times
  • 平均连续供货周数(正向)
supply_weeks_mean = [None] * d2_sub.shape[0]
for i in range(0,d2_sub.shape[0]):
    index = np.where(d2_sub.iloc[i,:] != 0)[0]
    new = np.where(np.diff(index) == 1)[0]
    supply_weeks_mean[i] = len(new) * 2 - len(np.where(np.diff(new) == 1)[0])
    
supply_weeks_mean = supply_weeks_mean / supply_times

合理供货比例(正向)

df = pd.DataFrame(None, columns=list(d2_sub.columns),
                  index=list(d2_sub.index))

for i in range(0,d2_sub.shape[0]):
    for j in range(0,d2_sub.shape[1]):
        if d1_sub.iloc[i,j] == 0:
            df.iloc[i,j] = 0
        if (d2_sub.iloc[i,j] > d1_sub.iloc[i,j] * 0.8) and (d2_sub.iloc[i,j] < d1_sub.iloc[i,j] * 1.2):
            df.iloc[i,j] = True
        else:
            df.iloc[i,j] = False
            
supply_proportion = df.apply(lambda x: sum(x), axis=1) / supply_times
数据标准化
df = pd.DataFrame(
    {'供货次数': supply_times,
     '平均供货量': supply_quantity_mean,
     '单次最大供货量': supply_max,
     '供货稳定性': supply_stability,
     '间隔次数': gap_times,
     '平均间隔周数': gap_weeks_mean,
     '平均连续供货周数': supply_weeks_mean,
     '合理供货比例': supply_proportion
    })

df.shape
(402, 8)
对正向指标归一化
df_positive = df[['供货次数','平均供货量','单次最大供货量','平均连续供货周数','合理供货比例']]
df_positive_norm = df_positive.apply(lambda x: (x-min(x)) / (max(x)-min(x)), axis=0)
df_positive_norm.head()
供货次数平均供货量单次最大供货量平均连续供货周数合理供货比例
00.1004180.0003280.0001350.3600000.360000
10.2928870.0009720.0017850.5774650.507042
20.7949790.0231570.0104410.9738220.727749
30.1338910.0003210.0001890.6363640.363636
40.4435150.0217270.0034351.0000000.859813
对负向指标归一化
df_negative = df[['供货稳定性','间隔次数','平均间隔周数']]
df_negative_norm = df_negative.apply(lambda x: (max(x)-x) / (max(x)-min(x)), axis=0)
df_negative_norm.head()
供货稳定性间隔次数平均间隔周数
00.9999990.8090910.960863
11.0000000.5909090.987411
20.9999880.8636360.998601
30.9999930.8090910.971365
41.0000000.9454550.994567
# merge data
df_norm = pd.concat([df_positive_norm, df_negative_norm], axis=1, join='inner')

1.2 建立反映保障企业生产重要性的数学模型

  • https://www.bilibili.com/read/cv12741665/
  • https://github.com/Valdecy/pyDecision
    在这里插入图片描述
熵权法

https://www.kaggle.com/code/alpayabbaszade/entropy-topsis

首先对供货连续性下的3个二级指标进行加权

supply_continuity = df_norm[['间隔次数','平均间隔周数','平均连续供货周数']]
#Normalize Decision matrix
def norm(X):
    return X/X.sum()

supply_continuity_norm = norm(supply_continuity)
#Entropy Values
k = -(1/np.log(supply_continuity_norm.shape[0]))

def entropy(X):
    return (X*np.log(X)).sum()*k

entropy = entropy(supply_continuity_norm)

#degree of differentiation
dod = 1 - entropy
w = dod/dod.sum()
weights = w.sort_values(ascending = False)
weights
平均连续供货周数    0.594747
间隔次数        0.384353
平均间隔周数      0.020900
dtype: float64
supply_continuity_weighted = supply_continuity['间隔次数']*weights.iloc[0] + supply_continuity['平均间隔周数']*weights.iloc[1] + supply_continuity['平均连续供货周数']*weights.iloc[2]
df_norm.drop(['间隔次数','平均间隔周数','平均连续供货周数'], axis=1, inplace=True)
df_norm['供货连续性'] = supply_continuity_weighted
df_norm.head(3)
供货次数平均供货量单次最大供货量合理供货比例供货稳定性供货连续性
00.1004180.0003280.0001350.3600000.9999990.858039
10.2928870.0009720.0017850.5070421.0000000.743025
20.7949790.0231570.0104410.7277490.9999880.917813

对6个一级指标进行加权

#Normalize Decision matrix
def norm(X):
    return X/X.sum()

df_norm_new = norm(df_norm)

#Entropy Values
k = -(1/np.log(df_norm_new.shape[0]))

def entropy(X):
    return (X*np.log(X)).sum()*k

entropy = entropy(df_norm_new)

#degree of differentiation
dod = 1 - entropy
w = dod/dod.sum()
weights_entropy = w.sort_values(ascending = False)
weights_entropy
单次最大供货量    0.496440
平均供货量      0.392450
供货次数       0.091647
合理供货比例     0.016205
供货连续性      0.002825
供货稳定性      0.000433
dtype: float64
熵权法-TOPSIS
  • https://www.kaggle.com/code/alpayabbaszade/entropy-topsis
  • https://blog.csdn.net/qq_42374697/article/details/105901229
def norm(X):
    return X/np.sqrt((X**2).sum())

norm_matrix = norm(df_norm)
w_norm_matrix = norm_matrix*w

V_plus = w_norm_matrix.apply(max)
V_minus = w_norm_matrix.apply(min)

S_plus = np.sqrt(((w_norm_matrix - V_plus)**2).apply(sum, axis = 1))
S_minus = np.sqrt(((w_norm_matrix - V_minus)**2).apply(sum, axis = 1))
scores = S_minus/(S_plus + S_minus)
d2['综合得分'] = scores * 100
output = d2[['供应商ID','综合得分']]

# sort by scores
output = output.sort_values('综合得分', ascending=False)
output.iloc[0:50,:].to_csv('/home/shiyu/Desktop/path_acdemic/ant/数模/历年题目/2021/output/scores_top50.csv')
output.iloc[0:50,:].head()
供应商ID综合得分
200S20187.972335
347S34857.756055
139S14052.993102
150S15144.951646
373S37441.858722
output.to_csv('/home/shiyu/Desktop/path_acdemic/ant/数模/历年题目/2021/output/scores_all.csv')
AHP
  • https://www.mindtools.com/a7y139c/the-analytic-hierarchy-process-ahp
  • https://github.com/PhilipGriffith/AHPy
df_norm.head()
供货次数平均供货量单次最大供货量合理供货比例供货稳定性供货连续性
00.1004180.0003280.0001350.3600000.9999990.858039
10.2928870.0009720.0017850.5070421.0000000.743025
20.7949790.0231570.0104410.7277490.9999880.917813
30.1338910.0003210.0001890.3636360.9999930.867852
40.4435150.0217270.0034350.8598131.0000000.965471
import ahpy
comparisons = {('供货次数', '平均供货量'): 3, ('供货次数', '单次最大供货量'): 5, ('供货次数', '合理供货比例'): 5, ('供货次数', '供货稳定性'): 5, ('供货次数', '供货连续性'): 5, 
                     ('平均供货量', '单次最大供货量'): 5, ('平均供货量', '合理供货比例'): 3, ('平均供货量', '供货稳定性'): 3, ('平均供货量', '供货连续性'): 3,
                     ('单次最大供货量', '合理供货比例'): 1/3, ('单次最大供货量', '供货稳定性'): 1/3, ('单次最大供货量', '供货连续性'): 1/3,
                     ('合理供货比例', '供货稳定性'): 1, ('合理供货比例', '供货连续性'): 1,
                     ('供货稳定性', '供货连续性'): 1}
comparisons
{('供货次数', '平均供货量'): 3,
 ('供货次数', '单次最大供货量'): 5,
 ('供货次数', '合理供货比例'): 5,
 ('供货次数', '供货稳定性'): 5,
 ('供货次数', '供货连续性'): 5,
 ('平均供货量', '单次最大供货量'): 5,
 ('平均供货量', '合理供货比例'): 3,
 ('平均供货量', '供货稳定性'): 3,
 ('平均供货量', '供货连续性'): 3,
 ('单次最大供货量', '合理供货比例'): 0.3333333333333333,
 ('单次最大供货量', '供货稳定性'): 0.3333333333333333,
 ('单次最大供货量', '供货连续性'): 0.3333333333333333,
 ('合理供货比例', '供货稳定性'): 1,
 ('合理供货比例', '供货连续性'): 1,
 ('供货稳定性', '供货连续性'): 1}
cal = ahpy.Compare(name='Drinks', comparisons=comparisons, precision=3, random_index='saaty')
cal.target_weights
{'供货次数': 0.445,
 '平均供货量': 0.232,
 '合理供货比例': 0.093,
 '供货稳定性': 0.093,
 '供货连续性': 0.093,
 '单次最大供货量': 0.044}
cal.consistency_ratio
0.032

CR < 0.1, 可认为判断矩阵的一致性可以接受

1.3 在此基础上确定 50 家最重要的供应商,并在论文中列表给出结果。

将熵权法和AHP得到的权重进行平均,得到最终的指标权重,然后加权计算各供应商的得分

weights_ahp = pd.DataFrame.from_dict(cal.target_weights, orient='index',
                       columns=['AHP权重'])
import statistics

results = pd.concat([weights_ahp, weights_entropy], axis=1)
results.columns = ['AHP权重','熵权法权重']
results['最终权重'] = results.apply(lambda x: statistics.mean(x), axis=1)
results
AHP权重熵权法权重最终权重
供货次数0.4450.0916470.268324
平均供货量0.2320.3924500.312225
合理供货比例0.0930.0162050.054603
供货稳定性0.0930.0004330.046716
供货连续性0.0930.0028250.047912
单次最大供货量0.0440.4964400.270220
d2['综合得分2'] = (df_norm['供货次数']*0.268324 + df_norm['平均供货量']*0.312225 + df_norm['合理供货比例']*0.054603 + df_norm['供货稳定性']*0.046716 + df_norm['供货连续性']*0.047912 + df_norm['单次最大供货量']*0.270220)*300
output = d2[['供应商ID','综合得分2']]

# sort by scores
output = output.sort_values('综合得分2', ascending=False)
output.iloc[0:50,:].to_csv('/home/shiyu/Desktop/path_acdemic/ant/数模/历年题目/2021/output/scores_top50_AHP&Entropy.csv')
# 对排名前10的供应商可视化
df = output.iloc[0:10,:]
df = df.sort_values(by='综合得分2')
df
供应商ID综合得分2
307S308160.745089
329S330164.460643
107S108174.260128
360S361174.874852
373S374175.082953
228S229179.242563
139S140196.710758
150S151197.078972
200S201199.599719
347S348200.332317
# Horizontal lollipop plot
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

# Linux show Chinese characters *** important
plt.rcParams['font.family'] = 'WenQuanYi Micro Hei' 
plt.rcParams['figure.dpi'] = 300
plt.rcParams['savefig.dpi'] = 300

my_range=range(1,11)
plt.hlines(y=my_range, xmin=0, xmax=df['综合得分2'], color='skyblue')
plt.plot(df['综合得分2'], my_range, "o")
 
# Add titles and axis names
plt.yticks(my_range, df['供应商ID'])
plt.title("综合得分前10的供应商")
plt.xlabel('供应商综合得分')
plt.ylabel('供应商ID')

# Show the plot
plt.show()

在这里插入图片描述

问题二

Pyhon中智能算法的模块:

https://scikit-opt.github.io/scikit-opt/#/en/README

Python中优化的模块

https://docs.scipy.org/doc/scipy/tutorial/optimize.html

formular editor:

https://editor.codecogs.com/

2.1 参考问题 1,该企业应至少选择多少家供应商供应原材料才可能满足生产的需求?

在这里插入图片描述
在这里插入图片描述

平均损失率
α \alpha α

loss_rate = sum(d3.iloc[:,1:].apply(lambda x: sum(x) / sum(x!=0), axis=0)) / 240
loss_rate
1.3063532832341274

供货量 x ^ i , t \widehat{x}_{i,t} x i,t

supply_quantity_mean[:6]
0     1.960000
1     3.845070
2    68.785340
3     1.939394
4    64.598131
5     2.307692
dtype: float64

供应商得分 s i s_{i} si

scores = pd.read_csv('/home/shiyu/Desktop/path_acdemic/ant/数模/历年题目/2021/output/scores_all.csv')
scores = scores.iloc[:,1:]
index_A = np.where(d2['材料分类'] == 'A')[0]
index_B = np.where(d2['材料分类'] == 'B')[0]
index_C = np.where(d2['材料分类'] == 'C')[0]
import numpy as np

def func(y):
    # input y is a list with 402 dims
    # set y as int
    y = np.around(np.array(y))
    res = sum(y) / sum(y * scores['综合得分'])
    return res
constraint_eq = [
    lambda y: sum((np.around(np.array(y))[index_A] 
                   * supply_quantity_mean[index_A] 
                   * (1-loss_rate/100)) / 0.6) 
    + sum((np.around(np.array(y))[index_B] 
                    * supply_quantity_mean[index_B] 
                    * (1-loss_rate/100)) / 0.66) 
    + sum((np.around(np.array(y))[index_C] 
           * supply_quantity_mean[index_C] 
           * (1-loss_rate/100)) / 0.72) - 2.82 * 10**4
]
遗传算法
from sko.GA import GA
y_len = 402

ga = GA(func=func, n_dim=y_len, size_pop=50, 
        max_iter=800, prob_mut=0.001, 
        lb=[0]*y_len, ub=[1]*y_len, precision=1,
        constraint_eq=constraint_eq)
best_y_ga = ga.run()
suppliers_index_ga = np.where(best_y_ga[0] == 1)[0].tolist()
suppliers_ga = d2.iloc[suppliers_index_ga,0:2]
print('选择的供应商数量:', suppliers_ga.shape[0])
选择的供应商数量: 210
差异进化
from sko.DE import DE
y_len = 402
de = DE(func=func, n_dim=y_len, size_pop=50, max_iter=800, 
        lb=[0]*y_len, ub=[1]*y_len,
        constraint_eq=constraint_eq)

best_y_de = de.run()
y_de = np.around(best_y_de[0])
suppliers_index_de = np.where(y_de == 1)[0].tolist()
suppliers_de = d2.iloc[suppliers_index_de,0:2]
print('选择的供应商数量:', suppliers_de.shape[0])
选择的供应商数量: 184
粒子群优化(PSO)
from sko.PSO import PSO
y_len = 402
pso = PSO(func=func, n_dim=y_len, pop=40, max_iter=150, 
          lb=[0]*y_len, ub=[1]*y_len, 
          constraint_eq=constraint_eq)
best_y_pso = pso.run()
y_pso = np.around(best_y_pso[0])
suppliers_index_pso = np.where(y_pso == 1)[0].tolist()
suppliers_pso = d2.iloc[suppliers_index_pso,0:2]
print('选择的供应商数量:', suppliers_pso.shape[0])
选择的供应商数量: 152
import matplotlib.pyplot as plt
# Linux show Chinese characters *** important
plt.rcParams['font.family'] = 'WenQuanYi Micro Hei' 
plt.rcParams['figure.dpi'] = 300
plt.rcParams['savefig.dpi'] = 300

plt.plot(pso.gbest_y_hist)
plt.title("目标函数的迭代过程")
plt.xlabel('迭代次数')
plt.ylabel('目标函数值')
plt.show()

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2140701.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

软件工程毕业设计开题汇总

文章目录 &#x1f6a9; 1 前言1.1 选题注意事项1.1.1 难度怎么把控&#xff1f;1.1.2 题目名称怎么取&#xff1f; 1.2 开题选题推荐1.2.1 起因1.2.2 核心- 如何避坑(重中之重)1.2.3 怎么办呢&#xff1f; &#x1f6a9;2 选题概览&#x1f6a9; 3 项目概览题目1 : 大数据电商…

几个常见的非初等函数

在多个激励共同作用下,其响应恒等于每个激励单独引起的响应之和。这种现象称为线性现象。线性性质使得对这类现象的数学描述大为简化,它是线性系统理论的基础。 本篇博客将简单介绍以下几个常用的非初等函数。 rect 矩形函数(Rectangular Function)sinc 函数(Sinc Function)三…

“树”据结构:并查集从入门到AC

“树”据结构&#xff1a;并查集 前言算法设计代码示例优化相关文章 前言 在一组数据中&#xff0c;数据被分为了不同的集合&#xff0c;那么其中的集合往往可以用树形来表示。而区分集合&#xff0c;与查找集合的元素&#xff0c;就会成为核心的问题。并查集主要就是解决这类…

模特妙善:一位多才多艺的短视频达人,绽放新光彩

模特妙善&#xff0c;在当今多元化的网络时代&#xff0c;短视频已成为人们生活中不可或缺的一部分。而在这一领域中&#xff0c;有一位以其独特魅力和多才多艺而备受瞩目的达人&#xff0c;她就是妙善&#xff0c;本名高艳芳。 模特妙善&#xff0c;出生于山西省的著名景点——…

一款免费的AI搜索工具,提升您的搜索效率!

开搜AI是一款面向大众的、直达答案的AI搜索引擎&#xff0c;它能够为用户问题提供直接、精准的答案&#xff0c;并自动总结重点、生成大纲、思维导图并下载。 开搜AI功能特点 精准结果呈现&#xff1a;开搜AI能够直接呈现精准结果&#xff0c;省去用户翻阅多个的繁琐过程。信…

MyBatis 增删改查【后端 17】

MyBatis 增删改查 引言 MyBatis 是一个优秀的持久层框架&#xff0c;它支持定制化 SQL、存储过程以及高级映射。MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集。MyBatis 可以使用简单的 XML 或注解用于配置和原始映射&#xff0c;将接口和 Java 的 POJOs (…

Adding Placement Constraints

步骤2&#xff1a;添加放置约束 探索一些设计层次结构&#xff0c;并开始放置逻辑元素以创建物理 约束。 1.从Flow Navigator中&#xff0c;选择Open Synthetic Design。综合设计可能 如果您直接进入此步骤&#xff0c;则已经打开。 合成网表打开&#xff0c;显示设备窗口。 2.…

Note091203_Outlook邮件撤回操作

Note091203_Outlook邮件撤回操作 如图所示&#xff1a; step1: 打开outlook step2&#xff1a; 点击已发送邮件&#xff0c;选中目标撤回邮件双击打开&#xff1b; step3&#xff1a; 点击图中2框所示&#xff0c;可看见撤回操作&#xff1b; 以上

Linux常用命令以及操作技巧

&#x1f30f;个人博客主页&#xff1a;意疏-CSDN博客 希望文章能够给到初学的你一些启发&#xff5e; 如果觉得文章对你有帮助的话&#xff0c;点赞 关注 收藏支持一下笔者吧&#xff5e; 阅读指南&#xff1a; 开篇说明帮助命令常见的七个linux操作终端实用的技巧跟文件目录…

Leetcode—740. 删除并获得点数【中等】(unordered_map+set+sort)

2024每日刷题&#xff08;162&#xff09; Leetcode—740. 删除并获得点数 算法思想 实现代码 class Solution { public:int deleteAndEarn(vector<int>& nums) {unordered_map<int, int> freq;set<int> st;sort(nums.begin(), nums.end());int n num…

c++234继承

#include<iostream> using namespace std;//public 修饰的成员便俩个和方法都能使用 //protected&#xff1a;类的内部 在继承的子类中可使用 class Parents { public:int a;//名字 protected:int b;//密码 private:int c;//情人public:void printT(){cout << &quo…

关于wp网站出现的问题

问题1 问题1&#xff1a;如果出现这个界面的问题 说明是根目录的index.php编码出了问题&#xff0c;用备份的源文件退换一下即可。 问题2 问题2&#xff1a;如果出现页面错位现象&#xff0c;可能是某个WP插件引起的问题&#xff0c;这里需要逐步排查插件&#xff0c;或者你刚…

论文内容分类与检测系统源码分享

论文内容分类与检测检测系统源码分享 [一条龙教学YOLOV8标注好的数据集一键训练_70全套改进创新点发刊_Web前端展示] 1.研究背景与意义 项目参考AAAI Association for the Advancement of Artificial Intelligence 项目来源AACV Association for the Advancement of Comput…

【二叉树进阶】二叉搜索树

目录 1. 二叉搜索树概念 2. 二叉搜索树的实现 2.1 创建二叉搜索树节点 2.2 创建实现二叉搜索树 2.3 二叉搜索树的查找 2.4 二叉搜索树的插入 2.5 二叉搜索树的删除 2.6 中序遍历 2.7 完整代码加测试 3. 二叉搜索树的应用 3.1 K模型&#xff1a; 3.2 KV模型&#xf…

【C++】入门基础(下)

Hi&#xff01;很高兴见到你~ 目录 7、引用 7.3 引用的使用&#xff08;实例&#xff09; 7.4 const引用 【第一分点】 【第二分点1】 【第二分点2】 7.5 指针和引用的关系&#xff08;面试点&#xff09; 8、inline 9、nullptr Relaxing Time&#xff01; ———…

asp.net core调用wps实现word转pdf的方法

1&#xff0c;首先安装wps&#xff0c;从官网下载安装包 2&#xff0c;创建.net core控制项目 添加com引用&#xff0c;搜索wps 准备一个word文档&#xff0c;名字叫001.docx&#xff0c;随便编写一些文字内容 3&#xff0c;word转pdf 编写代码 namespace WPSStu01 {inter…

MYSQL数据库基础篇——DDL

DDL&#xff1a;DDL是数据定义语言&#xff0c;用来定义数据库对象。 一.DDL操作数据库 1.查询 ①查询所有数据库 输入&#xff1b; 得到结果&#xff1a; ②查询当前数据库 输入&#xff1b; 例如执行下面语句&#xff1a; 2.创建 输入 然后展示数据库即可得到结果&…

Linux学习之路 - 线程概念补充理解

前面介绍了线程的基本概念&#xff0c;下面介绍一下线程在内核中的存在方式。 在OS中&#xff0c;存在着大量的线程&#xff0c;为了管理这些线程&#xff0c;我们必然需要用结构体对其进行描述&#xff0c;然后再组织起来管理。但是在linux中&#xff0c;实际上是不存在线程这…

QT 事件 Event 应用

文章目录 一、事件处理过程1. QT 事件应用介绍2. 事件分发过程 二、重写事件案例1. 鼠标事件2. 自定义按钮事件 一、事件处理过程 1. QT 事件应用介绍 众所周知Qt是一个基于C的框架&#xff0c;主要用来开发带窗口的应用程序&#xff08;不带窗口的也行&#xff0c;但不是主流…

【C++】 —— string的使用

前言 string类虽然不在STL的容器中&#xff0c;但string类十分重要&#xff0c;string类是对字符串的存储和相关操作。 basic_string std::basic_string类是C的一个模版类&#xff0c;它支持多种字符类型。 char &#xff1a;用于表示一个字节的字符&#xff0c;使用ASCII编码。…