MATLAB ga函数的使用方法

news2024/9/29 23:22:10

一、ga句法结构

x = ga(fitnessfcn,nvars)
x = ga(fitnessfcn,nvars,A,b)
x = ga(fitnessfcn,nvars,A,b,Aeq,beq)
x = ga(fitnessfcn,nvars,A,b,Aeq,beg,IB,UB)
x = ga(fitnessfcn,nvars,A,b,Aeq,beq,LB,UB,nonlcon)
x = ga(fitnessfcn,nvars,A,b,Aeq,beq,LB,UB,nonlcon,options)
x = ga(fitnessfcn,nvars,A,b,[],[],LB,UB,nonlcon,IntCon)
x = ga(fitnessfcn,nvars,A,b,[],[],LB,UB,nonlcon,IntCon,options)
x = ga(problem)
[x,fval] = ga(fitnessfcn,nvars,...)
[x,fval,exitflag] = ga (fitnessfcn,nvars,...)
[x,fval,exitflag,output] = ga(fitnessfcn,nvars,...)
[x,fval,exitflag,output,population] = gafitnessfcn,nvars,...)
[x,fval,exitflag,output,population,scores] = ga(fitnessfcn,nvars,...)

二、释义及解读

  • fitnessfcn 为适应度句柄函数(即:目标函数);
  • nvars 为目标函数自变量的个数;
  • options 为算法的属性设置,该属性是通过函数gaoptimset赋予的;
  • x 为经过遗传进化以后自变量最佳染色体返回值;
  • fval 为最佳染色体的适应度;
  • exitflag 为算法停止的原因;
  • output 为输出的算法结构;

  • population 为最终得到种群适应度的列向量(即当前群体,而群体里性能最好的个体,便是最优值点);

  • scores 为最终得到的种群(即:最优值点的目标函数取值);

  • A A A b b b:线性不等式约束 A ∗ x ≤ b A*x\leq b Axb 中的矩阵;
    (Note: If the problem has m linear inequality constraints and nvars variables. then A is a matrix of size m-by-nvars and b is a vector of length m. ga evaluates the matrix product A*x as if x is transposed (Ax’). )

  • A e q Aeq Aeq b e q beq beq:线性等式约束 A e q ∗ x = b e q Aeq*x=beq Aeqx=beq 中的矩阵;
    (Note: ga does not enforce linear constraints to be satisfied when the PopulationType option is ‘bitstring’ or ‘custom’.)

  • nonlcon:非线性约束,该函数返回两个输出,即:[g,h] = nonlcon(x) ,g为非线性不等式约束,所有的不等式约束均以列向量的形式存在变量g中。h为非线性等式约束,也以列向量的形式存储。非线性约束中[g,h]使用规则与我另一篇博客MATLAB fmincon函数 进阶资料(磕盐记录)一样,这里不展开叙述了。 需要注意:ga atempts to achieve g = 0 g = 0 g=0 and h = 0 h= 0 h=0. g g g and h are row vectors when there are multiple constraints. Set unused outputs to g = [ ] or h = [ ].

  • IntCon:若变量 x 中存在整数变量,则在这里设置!具体地,IntCon 是由正数整数组成的向量,取值从 1 到 nvars,IntCon 中的每个值代表决策变量 x 中相应位置的索引变量是整数变量。
    (Note: When IntCon is nonempty, Aeq and beq must be empty ([ ]), and nonlcon must return empty for ceq. For more information on integer programming, see Mixed Integer Optimizaton.)

  • options:Create options using gaoptimset. 下一章节将详细介绍 options 中关于 gaoptimset 的设置规则。


三、gaoptimset 介绍(初级)

gaoptimset 常用来设置 options 中的各个选项,其句式结构如下:

options = gaoptimset('param1',value1,'param2',value2,...)

其中, ‘Param1’、 ‘Param2’等是需要设定的参数,比如:种群规模(PopulationSize)、交叉比例(CrossoverFraction)等,value1、value2等则是Param的具体值,常用的参数名如下表:

设定的参数名(Param名)说明默认值
CrossoverFraction交叉比例0.8
Generations算法中止的最大迭代次数100
PopulationSize种群规模20
MigrationFraction变异概率0.2
FitnessLimit当适应度函数达到设定的值时算法中止-
StallGenLimit当超过StallGenLimit代适应度函数为改善时,算法中止50

更多参数设定详见 MATLAB 官方文档,可在MATLAB命令窗口中输入 “doc gaoptimset” 查看 [2]:

或参见本博客“第六节”。

四、实例运行

实例原始网址: MATLAB利用遗传算法函数求目标函数的最优解

  1. 目标函数如下:
function f = myfit( x )
    f = (339-0.01*x(1)-0.003*x(2))*x(1)...
        + (399-0.004*x(1)-0.01*x(2))*x(2)...
        - (400000+195*x(1)+225*x(2));
    f = -f; %因为GA是寻找最小值,所以为了求这个函数的最大值,取f的相反数
end 
  1. 主函数如下:
options = gaoptimset();
options.Generations = 2000; %最大迭代数设为2000

% 当然,如果有很多参数都需要设置时,可以按照 options = gaoptimset('param1',value1,'param2',value2,...) 的形式统一设置
% options = gaoptimset('PopulationSize', 20, ...     % 种群包含个体数目
%                      'EliteCount', 10, ...          % 种群中精英个体数目
%                      'CrossoverFraction', 0.75, ... % 交叉后代比率
%                      'Generations', 500, ...        % 迭代代数
%                      'StallGenLimit', 500, ...      % 停止代数
%                      'TolFun', 1e-100, ...          % 适应度函数偏差
%                      'PlotFcns', {@gaplotbestf,  @gaplotbestindiv, @gaplotstopping}); % 绘制最优个体适应度函数与最优个体

[X,FVAL,EXITFLAG,OUTPUT] =ga(@myfit, 2 ,[], [],[],[],[],[],[],[],options)

运行结果为:

EXITFLAG 返回值为1,说明所求结果无特殊情况。

需要注意的是:如果 options.Generations 不设为 2000,采用默认迭代100轮来运行上述代码,则运行结果如下图所示:

注意到此时,EXITFLAG 返回值为0,显示信息为:Optimization terminated: maximum number of generations exceeded.

即:达到最大迭代轮数,此时的结果与最优理想结果相差甚远。由此例可知,关于最大迭代次数的设定,一定要小心,务必满足迭代次数的要求!


五、关于 exitflag 取值的说明(重要)

前文给出了 exitflag 取值的一个表格,说明了 GA 停止运行的原因 [3],这几类原因可概括为 exitflag 取值为以下三种情况:

  1. exitflag 为正值:意味着 GA 认为它做得相当好,有特定的理由停止运行
  2. exitflag = -2:无可行解,你肯定没有得到有用的答案
  3. exitflag 取其他情况时:意味着 GA 认为如果让它运行更长时间,你可能会得到更好的解决方案。 它没有在函数值中看到停止的具体原因,但它遇到了你设置的资源限制。

更详细的原因,可解释为 [3]:

  • As I know, good solution is when it converges, the change of few last iteration does not improves (exit flag 1, 3). Or when solution meets your specified value (exit flag 5).
  • And not so good solution is if it stops due to max time/iteration (exit flag 0, -4, -5), means it may not converge. It may gives better solution when you increase those limits. Or when the solution change is smaller than matlab capability (exit flag 4), this means you may need to improve your objective function.
  • Clearly bad solution is when no solution is found (exit flag -2).

六、gaoptimset 详述(进阶)

options 选项在 GA 函数中,是以结构体的形式存在,该结构体包含哪些变量呢?在第四节中介绍了几个常见的变量,我将在本节详细介绍所有变量,以及各变量的作用。

首先,在MATLAB命令窗口中输入下述命令:

gaoptimset(@ga)

显示结果如下:

上述结果中,每一行都对应一个可设置的参数项(左侧是变量名,右侧是默认取值)

各变量名的详细解读:

  • 大括号 { } 中的值表示默认值;

  • { }* 表示当问题具有线性约束且 MutationFcn 有边界时的默认值;

  • I* 表示 ga 以不同的方式处理整数约束的选项; 此表示法不适用于 gamultiobj;

  • NM 表示该选项不适用于 GA 的多目标优化问题中(gamultiobj)。

序号OptionDescriptionValues
1ConstraintTolerance确定了非线性约束的可行性。此外,max(sqrt(eps),Constraint Tolerance) 确定了线性约束的可行性. (我理解,此参数表示约束违反的精度误差)

For an options structure, use TolCon.
Positive scalar | {1e-3}
2CreationFcn创建初始种群的函数。 指定为内置创建函数或函数句柄的名称。See Population Options.{‘gacreationuniform’}|{‘gacreationlinearfeasible’}* |‘gacreationnonlinearfeasible’ |{‘gacreationuniformint’}I* for ga | {‘gacreationsobol’}I* for gamultiobj | Custom creation function
3CrossoverFcn算法用于创建交叉子代(crossover children)的函数。 指定为内置交叉函数或函数句柄的名称。See Crossover Options.{‘crossoverscattered’} for ga, {‘crossoverintermediate’}* for gamultiobj |{‘crossoverlaplace’}I* | ‘crossoverheuristic’ |‘crossoversinglepoint’ | ‘crossovertwopoint’ | ‘crossoverarithmetic’| Custom crossover function
4CrossoverFraction交叉函数产生的下一代人口比例(不包括精英子代)Positive scalar | {0.8}
5DisplayLevel of display.‘off’ | ‘iter’ |‘diagnose’ | {‘final’}
6DistanceMeasureFcn计算个体距离度量的函数。 指定为内置距离测量函数或函数句柄的名称。 The value applies to the decision variable or design space (genotype) or to function space (phenotype). The default ‘distancecrowding’ is in function space (phenotype). For gamultiobj only. See Multiobjective Options.

For an options structure, use a function handle, not a name.
{‘distancecrowding’} means the same as {@distancecrowding,‘phenotype’} | {@distancecrowding,‘genotype’} | Custom distance function
7EliteCountNM 指定当前一代中有多少个体可以保证生存到下一代,必须是正整数。Not used in gamultiobj.Positive integer | {ceil(0.05PopulationSize)} | {0.05(default PopulationSize)} for mixed-integer problems
8FitnessLimitNM 如果适应度函数达到 FitnessLimit 的值,算法将停止。(我理解,这个函数设定不取默认的 -inf ,则最后输出的 exitflag 的取值应该是 5)Scalar | {-Inf}
9FitnessScalingFcn该函数用以缩放适应度函数值。 指定为内置缩放函数或函数句柄的名称。 Option unavailable for gamultiobj.{‘fitscalingrank’} | ‘fitscalingshiftlinear’ | ‘fitscalingprop’ | ‘fitscalingtop’ | Custom fitness scaling function
10FunctionTolerance(与表格第17项关联)翻译: 如果 MaxStallGenerations 代以后,最佳适应度函数值的平均相对变化小于或等于 FunctionTolerance,则算法停止。 如果 StallTest 为“geometricWeighted”,则当加权平均相对变化小于或等于 FunctionTolerance 时,算法将停止。原文: The algorithm stops if the average relative change in the best fitness function value over MaxStallGenerations generations is less than or equal to FunctionTolerance. If StallTest is ‘geometricWeighted’, then the algorithm stops if the weighted average relative change is less than or equal to FunctionTolerance.

For gamultiobj, the algorithm stops when the geometric average of the relative change in value of the spread over options.MaxStallGenerations generations is less than options.FunctionTolerance, and the final spread is less than the mean spread over the past options.MaxStallGenerations generations. See gamultiobj Algorithm.

For an options structure, use TolFun.
Positive scalar | {1e-6} for ga, {1e-4} for gamultiobj
11HybridFcnI* 翻译: ga 终止后继续优化的函数。 指定为名称或函数句柄。 原文: Function that continues the optimization after ga terminates. (我理解,此参数用以保留当前子代,留之用以在此子代的基础上二次优化) Alternatively, a cell array specifying the hybrid function and its options. See ga Hybrid Function. For gamultiobj, the only hybrid function is @fgoalattain. See gamultiobj Hybrid Function. When the problem has integer constraints, you cannot use a hybrid function. See When to Use a Hybrid Function.Function name or handle | ‘fminsearch’ | ‘patternsearch’ | ‘fminunc’ | ‘fmincon’ | {[]} or 1-by-2 cell array
12InitialPenaltyNM I* Initial value of the penalty parameterPositive scalar | {10}
13InitialPopulationMatrix调用遗传算法的初始Population。 最多具有 “PopulationSize ” 行 N 列,其中 N 是变量数。 您可以传递部分Population,即行数少于 PopulationSize 的总体。 在这种情况下,遗传算法使用 CreationFcn 来生成剩余的Population。See Population Options.

For an options structure, use InitialPopulation.
Matrix | {[]}
14InitialPopulationRange指定初始Population中个体的范围,该参数是一个矩阵或向量。 适用于 gacreationuniform 创建功能。ga shifts and scales the default initial range to match any finite bounds.

For an options structure, use PopInitRange.
Matrix or vector | {[-10;10]} for unbounded components, {[-1e4+1;1e4+1]} for unbounded components of integer-constrained problems, {[lb;ub]} for bounded components, with the default range modified to match one-sided bounds
15InitialScoresMatrixInitial scores used to determine fitness. 最多有“PopulationSize ”行和 Nf 列,其中 Nf 是适应度函数的数量(即:单目标的 ga 函数中为 1,多目标的 gamultiobj 函数则大于 1)。 You can pass a partial scores matrix, meaning one with fewer than PopulationSize rows. In that case, the solver fills in the scores when it evaluates the fitness functions.

For an options structure, use InitialScores.
Column vector for single objective| matrix for multiobjective | {[]}
16MaxGenerations(重要!!!) 算法停止之前的最大迭代次数。

For an options structure, use Generations.
Positive integer | {100numberOfVariables} for ga, {200numberOfVariables} for gamultiobj
17MaxStallGenerationsThe algorithm stops if the average relative change in the best fitness function value over MaxStallGenerations generations is less than or equal to FunctionTolerance. If StallTest is ‘geometricWeighted’, then the algorithm stops if the weighted average relative change is less than or equal to FunctionTolerance.

For gamultiobj, the algorithm stops when the geometric average of the relative change in value of the spread over options.MaxStallGenerations generations is less than options.FunctionTolerance, and the final spread is less than the mean spread over the past options.MaxStallGenerations generations. See gamultiobj Algorithm.

For an options structure, use StallGenLimit.
Positive integer | {50} for ga, {100} for gamultiobj
18MaxStallTimeNM 如果目标函数在 MaxStallTime 秒(通过 tic 和 toc 测量)内没有改善,则算法停止。

For an options structure, use StallTimeLimit.
Positive scalar | {Inf}
19MaxTime算法在运行 MaxTime 秒后停止(通过 tic 和 toc 测量)。 每次迭代后都会强制执行此限制,因此当迭代花费大量时间时 ga 可能会超出此限制。

For an options structure, use TimeLimit.
Positive scalar | {Inf}
20MigrationDirectionDirection of migration. See Migration Options.‘both’ | {‘forward’}
21MigrationFractionScalar from 0 through 1 specifying the fraction of individuals in each subpopulation that migrates to a different subpopulation. See Migration Options.Scalar | {0.2}
22MigrationInterval翻译: 指定了个体(individuals )在 subpopulations之间迁移之间发生的代数,该参量是正整数。原文: Positive integer specifying the number of generations that take place between migrations of individuals between subpopulations. See Migration Options.Positive integer | {20}
23MutationFcnFunction that produces mutation children. Specify as a name of a built-in mutation function or a function handle. See Mutation Options.{‘mutationgaussian’} for ga without constraints | {‘mutationadaptfeasible’}* for gamultiobj and for ga with constraints | {‘mutationpower’}I* | ‘mutationpositivebasis’ | ‘mutationuniform’ | Custom mutation function
24NonlinearConstraintAlgorithmNonlinear constraint algorithm. See Nonlinear Constraint Solver Algorithms for Genetic Algorithm. Option unchangeable for gamultiobj.

For an options structure, use NonlinConAlgorithm.
{‘auglag’} for ga, {‘penalty’} for gamultiobj
25OutputFcn翻译: ga 在每次迭代时调用的函数。 原文: Functions that ga calls at each iteration. Specify as a function handle or a cell array of function handles. See Output Function Options.

For an options structure, use OutputFcns.
Function handle or cell array of function handles | {[]}
26ParetoFractionScalar from 0 through 1 specifying the fraction of individuals to keep on the first Pareto front while the solver selects individuals from higher fronts, for gamultiobj only. See Multiobjective Options.Scalar | {0.35}
27PenaltyFactorNM I* Penalty update parameter.Positive scalar | {100}
28PlotFcnFunction that plots data computed by the algorithm. Specify as a name of a built-in plot function, a function handle, or a cell array of built-in names or function handles. See Plot Options. For an options structure, use PlotFcns.ga or gamultiobj: {[]} | ‘gaplotdistance’ | ‘gaplotgenealogy’ | ‘gaplotselection’ | ‘gaplotscorediversity’ | ‘gaplotscores’ | ‘gaplotstopping’ | ‘gaplotmaxconstr’ | Custom plot function

ga only: ‘gaplotbestf’ | ‘gaplotbestindiv’ | ‘gaplotexpectation’ | ‘gaplotrange’

gamultiobj only: ‘gaplotpareto’ | ‘gaplotparetodistance’ | ‘gaplotrankhist’ | ‘gaplotspread’
29PlotIntervalPositive integer specifying the number of generations between consecutive calls to the plot functions.Positive integer | {1}
30PopulationSize(重要!!!) Size of the population.Positive integer | {50} when numberOfVariables <= 5, {200} otherwise |{min(max(10*nvars,40),100)} for mixed-integer problems
31PopulationTypeData type of the population. Must be ‘doubleVector’ for mixed-integer problems.‘bitstring’ | ‘custom’ | {‘doubleVector’}

ga ignores all constraints when PopulationType is set to ‘bitString’ or ‘custom’. See Population Options.
32SelectionFcnFunction that selects parents of crossover and mutation children. Specify as a name of a built-in selection function or a function handle.

gamultiobj uses only ‘selectiontournament’.
{‘selectionstochunif’} for ga, {‘selectiontournament’} for gamultiobj | ‘selectionremainder’ | ‘selectionuniform’ | ‘selectionroulette’ | Custom selection function
33StallTestNM Stopping test type.‘geometricWeighted’ | {‘averageChange’}
34UseParallelCompute fitness and nonlinear constraint functions in parallel. See Vectorize and Parallel Options (User Function Evaluation) and How to Use Parallel Processing in Global Optimization Toolbox.true | {false}
35UseVectorizedSpecifies whether functions are vectorized. See Vectorize and Parallel Options (User Function Evaluation) and Vectorize the Fitness Function. For an options structure, use Vectorized with the values ‘on’ or ‘off’.true | {false}

注:上表内容为部分翻译版本,因为担心自己的翻译失真于原始文献,所以表格中会存在中英文混写的情况,完整版的英文原文参见 [2]


参考网址:

  1. Genetic Algorithm options
  2. gaoptimset
  3. exitFlag meaning in GA solver

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

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

相关文章

7B蓝屏INACCESSABLE BOOT DEVICE

在p2v的开发阶段&#xff0c;经常出现这个蓝屏&#xff0c;常见的原因有&#xff1a; 1. 分区表错误 潜在原因&#xff1a;p2v的qemu-img resize --shrink砍减qcow2空间时&#xff0c;实际是对磁盘尾部直接砍减&#xff0c;会使得分区表在尾部的数据丢失。 修复方法&#xf…

Socket地址

socket地址其实是一个结构体&#xff0c;封装端口号和IP等信息 。后面的 socket 相关的 api 中需要使用到这个socket地址。 客户端 -> 服务器需要知道服务器的&#xff08; IP, Port &#xff09; 一、通用 socket 地址 socket 网络编程接口中表示 socket 地址的是结构体…

【C语言刷题每日一题#牛客网BC68】——X形图案

问题描述 思路分析 首先根据输入的描述&#xff0c;多组输入需要将scanf放在循环中来实现 #include<stdio.h> int main() {int a 0;while (scanf("%d", &a) ! EOF){} } 完成了输入之后&#xff0c;再来分析输出——输出的是一个由“*”组成的对称的X形…

力扣算法-Day10

160. 相交链表 给你两个单链表的头节点 headA 和 headB &#xff0c;请你找出并返回两个单链表相交的起始节点。如果两个链表没有交点&#xff0c;返回 null 。 示例 1&#xff1a; 输入&#xff1a;intersectVal 8, listA [4,1,8,4,5], listB [5,6,1,8,4,5], skipA 2, s…

SuperMap Hi-Fi 3D SDK for Unity矢量面贴地贴模型

作者&#xff1a;kele 一、背景 SuperMap Hi-Fi 3D SDK&#xff08;2023 11i&#xff09; for Unity推出新功能&#xff1a;支持矢量面同时贴地形图层和模型图层&#xff0c;并且能实现数据点击查询属性、更改初始填充颜色、初始边框线颜色、选中填充颜色、选中边框线颜色、控…

电子科大软件系统架构设计——软件建模详细设计

文章目录 软件建模详细设计概述软件建模详细设计目标软件建模详细设计原则开闭原则里氏 (Liskov) 替换原则依赖倒置原则接口分离原则单一职责原则最少知识原则&#xff08;迪米特法则&#xff09;高内聚原则松耦合原则可重用原则 软件建模详细设计内容 UML 软件静态结构视图建模…

CSS3:绘制多边形

clip-path&#xff1a;该属性使用裁剪方式创建元素的可显示区域&#xff0c;区域内的显示&#xff0c;区域外的不显示。 构建一个三角形 <div class"mybox"></div><style>.mybox {width: 100px;height: 100px;background-color: yellow;clip-path…

Openai的openai新版本调用方式

最近大家有没有发现Openai的openai已经更新到1.6.1了,而且API的调用方式发生了巨大的变化,下面来看看openai新的调用方式吧。 欢迎关注公众号 module ‘openai’ has no attribute ChatCompletion. 提示openai的版本过低。(pip install -U openai) 1. Chat API from openai…

Spark Shell的简单使用

简介 Spark shell是一个特别适合快速开发Spark原型程序的工具&#xff0c;可以帮助我们熟悉Scala语言。即使你对Scala不熟悉&#xff0c;仍然可以使用这个工具。Spark shell使得用户可以和Spark集群交互&#xff0c;提交查询&#xff0c;这便于调试&#xff0c;也便于初学者使用…

【Java中创建对象的方式有哪些?】

✅Java中创建对象的方式有哪些&#xff1f; ✅使用New关键字✅使用反射机制✅使用clone方法✅使用反序列化✅使用方法句柄✅ 使用Unsafe分配内存 ✅使用New关键字 这是我们最常见的也是最简单的创建对象的方式&#xff0c;通过这种方式我们还可以调用任意的构造函数 (无参的和有…

Spring Boot学习随笔- 第一个Thymeleaf应用(基础语法th:,request、session作用域取值)

学习视频&#xff1a;【编程不良人】2021年SpringBoot最新最全教程 第十五章、Thymeleaf Thymeleaf是一种现代化的服务器端Java模板引擎&#xff0c;专门用于Web和独立环境。Thymeleaf在有网络和无网络的环境下皆可运行&#xff0c;即可以让美工在浏览器查看页面的静态效果&am…

数组元素反序

和前面的字符串逆向输出有异曲同工之妙 第一位和最后一位交换位置&#xff0c;然后用比大小循环 那么接下来修改一下这个程序&#xff0c;我们接下来解释一下p的概念 画图解释&#xff1a; 在最前面的 定义的时候&#xff0c;我们将p&#xff08;0&#xff09;定义在了1上&…

Ps:直方图 - 统计数据

使用扩展视图或全部通道视图时&#xff0c;直方图 Histogram的下方会显示一组实时统计数据。 提示&#xff1a; 要在直方图面板控制菜单中勾选&#xff08;默认&#xff09;“显示统计数据” Show Statistics。 源 Source --整个图像 Entire Image 默认选项。显示整个图像&am…

Spring 依赖注入概述、使用以及原理解析

前言 源码在我github的guide-spring仓库中&#xff0c;可以克隆下来 直接执行。 我们本文主要来介绍依赖注入的使用示例及其原理 依赖注入 什么是依赖注入 依赖注入&#xff08;Dependency Injection&#xff0c;简称DI&#xff09;是一种设计模式&#xff0c;它用于实现对…

【MySQL学习笔记008】多表查询

1、多表关系 概述&#xff1a;项目开发中&#xff0c;在进行数据库表结构设计时&#xff0c;会根据业务需求及业务模块之间的关系&#xff0c;分析并设计表结构&#xff0c;由于业务之间相互关联&#xff0c;所以各个表结构之间也存在着各种联系&#xff0c;基本上可分为三种&a…

在linux操作系统Centos上安装服务器相关软件

如果您的服务器没有图形界面(GUI),您可以通过命令行(终端)来安装和配置Tomcat、JDK和MySQL等软件。以下是在没有图形界面GHome的 Linux 系统上安装这些软件的基本步骤: 对于CentOS Stream 9,您可以按照以下步骤在命令行上安装Tomcat、JDK 和 MySQL 数据库: 1. 安装JD…

设计模式--迭代器模式

实验18&#xff1a;迭代器模式 本次实验属于模仿型实验&#xff0c;通过本次实验学生将掌握以下内容&#xff1a; 1、理解迭代器模式的动机&#xff0c;掌握该模式的结构&#xff1b; 2、能够利用迭代器模式解决实际问题。 [实验任务]&#xff1a;JAVA和C常见数据结构迭代…

基于遗传算法特征选择及单层感知机模型的IMDB电影评论文本分类案例

基于遗传算法特征选择及单层感知机模型的IMDB电影评论文本分类案例 1.数据载入及处理2.感知机模型建立3.模型训练4.遗传算法进行特征选择注意 5.联系我们 1.数据载入及处理 import torch import torch.nn as nn import torch.optim as optim from torch.utils.data import Dat…

线程的同步与互斥

抢票的例子 竞争过程 进程A被切走 进程B被切走 结论&#xff1a; 互斥 int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr); mutex: 指向要初始化的互斥锁的指针。attr: 用于设置互斥锁属性的指针&#xff0c;通常可以传入 NULL 以使用默认属性…

【贪心】最小生成树Kruskal算法Python实现

文章目录 [toc]问题描述最小生成树的性质证明 Kruskal算法时间复杂性Python实现 个人主页&#xff1a;丷从心 系列专栏&#xff1a;贪心算法 问题描述 设 G ( V , E ) G (V , E) G(V,E)是无向连通带权图&#xff0c; E E E中每条边 ( v , w ) (v , w) (v,w)的权为 c [ v ] …