【数据聚类】基于和谐搜索实现数据集聚类附matlab代码

本文介绍了使用Matlab进行投资组合优化的一种新方法,结合了和谐搜索算法和人工蜂群算法。通过考虑半方差作为风险因素,构建有效前沿并寻找最优投资组合。实验结果显示,该混合算法在不同风险和回报水平下找到最优解的精度优于和谐搜索和遗传算法。

✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。

🍎个人主页:Matlab科研工作室

🍊个人信条:格物致知。

更多Matlab仿真内容点击👇

智能优化算法  神经网络预测 雷达通信  无线传感器

信号处理 图像处理 路径规划 元胞自动机 无人机

⛄ 内容介绍

Portfolio selection is one of the major capital allocation and budgeting issues in financial management, and a variety of models have been presented for optimal selection. Semi-variance is usually considered as a risk factor in drawing up an efficient frontier and the optimal portfolio. Since semi-variance offers a better estimation of the actual risk portfolio, it was used as a measure to approximate the risk of investment in this work. The optimal portfolio selection is one of the non-deterministic polynomial(NP)-hard problems that have not been presented in an exact algorithm, which can solve this problem in a polynomial time. Meta-heuristic algorithms are usually used to solve such problems. A novel hybrid harmony search and artificial bee colony algorithm and its application were introduced in order to draw efficient frontier portfolios. Computational results show that this algorithm is more successful than the harmony search method and genetic algorithm. In addition, it is more accurate in finding optimal solutions at all levels of risk and return.

⛄ 部分代码

 is a simple demo version implementing the basic Harmony Search      %

% algorithm for clustering problem without fine-tuning the parameters.     %

% Though this demo works very well, it is expected that this illustration  %  

% is much less efficient than the work reported in paper:                  %

% (Citation details):                                                      % 

% J. Senthilnath, Sushant Kulkarni, Raghuram, D.R., Sudhindra, M.,         %

% Omkar, S.N., Das, V. and Mani, V (2016) "A novel harmony search      %

% based approach for clustering problems", Int. J. Swarm Intelligence,     %

%  Vol. 2, No. 1, pp.66 ?86, 2016.                                           %

%%-------------------------------------------------------------------------%function [BestGen] = Harmony_Search(traindat,limits,attr)

    % Harmony search on illustrative dataset 

    % traindat----> matrix containing dataset without class labels (nxp)

    % UL ----> matrix with upper and lower limits for "p" attributes (px2)

    % HMCR---> Harmony Memory Consideration Rate [HMCR_max HMCR_min]

    % HMS----> Harmony Memory Size or population size

    % NVAR---> Number of attributes (p)

    % PAR---> Pitch Adjustment Rate [PAR_max PAR_min]

    

   global   ULB  HMS HMCR PAR_max PAR_min BW_min BW_max tem ;

   global   BestFit WorstFit BestGen BW HM fitness;

   global  counter BestIndex WorstIndex attributes;

   ULB = limits;                      

   BestGen =[];                             % Store the best fitness

   HMS = 5;                                 % Size of population

   NATTR = attr;                            % No. of attributes in datase              

   MaxIter = 5000;                          % Maximum no. of iterations

   

   HMCR_max = 0.95;      HMCR_min = 0.06;                  

   PAR_max = 0.95;       PAR_min = 0.35;                                                 

   BW_max = 0.01;        BW_min=0.1;                   

  

   % Initialize Matrices

   BW = zeros(1,NATTR);                     % Bandwidth values [1xp]            

   HM = zeros(HMS,NATTR) ;                  % Size of Harmony Memory (HMSxp)

   fitness = zeros(1,HMS);                  % Fitness of each population

   attributes = zeros(1,NATTR) ;     

   tem = zeros(2,NATTR) ;     

  HarmonySearch;

  

   % plot the final optimal cluster center

   plot(BestGen(1),BestGen(2),'k*', 'LineWidth',3) 

   legend('Agents','Agents Movement','Location','NorthEastOutside')

   xlabel('X'); ylabel('Y'); xlim([0 30]); ylim([0 35]);

   text(35,30,'* Cluster Centers', 'FontName','Times','Fontsize',12)

%    plot(BestGen(1),BestGen(2),'g*') % plot the final optimal cluster center

 % /***********************************************************************/

function objective = f(x)

    

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    % OBJECTIVE FUNCTION - Evaluation of fitness value of each solution vector

    % x receives the matrix containing the pseudo optimal cluster centres to be evaluated

    % Optimisation of Clustering Criteria by Reformulation

    % Refer Equation (4) in paper: "Optimisation of Clustering Criteria by Reformulation

    % Note: your own objective function can be written here

    % when using your own function, remember to change limits/bounds

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    

    objective = sum(pdist2(x,traindat)); 

    

end

% /***********************************************************************/

% Initialisation of Harmony Memory with random solutions between limits

        function initialize

              for i = 1:HMS

                for j = 1:NATTR

                    % Initialization of HM between upper and lower limit

                    HM(i,j) = ((ULB(j,2)-ULB(j,1))*rand(1))+ULB(j,1);   

                end

                fitness(i)= f(HM(i,:));    % evaluate fitness of each HM

              end

            % plot initial solutions for visualization 

            plot(HM(:,1),HM(:,2),'gs', 'LineWidth',1.5);

            hold on;

        end

% /***********************************************************************/

% Improvisation of Harmony Memory

        function HarmonySearch

           initialize;         % First intialize HM with random values

           counter = 0;        % Loop counter

           while counter < MaxIter

               % dynamically vary the Harmony Search parameters - PAR, HMCR, bw

               PAR=(PAR_max-PAR_min)/(MaxIter*counter)+PAR_min;

               coef=log(BW_min/BW_max)/MaxIter;

               for pp =1:NATTR

                  BW(pp)=BW_max*exp(coef*counter);

               end

               for hh = 1:NATTR

                  HMCR(hh) = HMCR_min+(((HMCR_max-HMCR_min)/MaxIter)*counter);

               end

               % improvise the solutions using parameters

               for i = 1:NATTR

                   hmcr_rnd = rand(1);

                   if hmcr_rnd <= HMCR(i)

                      index = randi([1,HMS],1);    % randomly pick one population from HM 

                      attributes(i) = HM(index,i);

                      par_rnd = rand(1); 

                      % if random number is less than PAR, tune solution

                      if par_rnd <= PAR

                         walk_rnd = rand(1);

                         temp = attributes(i);      

                         if walk_rnd<0.5 % tune i.e. add/subtract small value with 50% probabilty

                             temp = temp+rand(1)*BW(i);  

                             % check if improvised solution is within upper limit

                             if temp < ULB(i,1) 

                                attributes(i) = temp;

                             end         

                         else          

                             temp = temp-rand(1)*BW(i);

                             % check if improvised solution is within lower limit

                             if temp>ULB(i,2)

                                attributes(i) = temp;

                             end                            

                         end                     

                      end          % End of if for r2

                   else

                      % Randomisation with probability of 1-HMCR

                      attributes(i) = ((ULB(i,1)-ULB(i,2))*rand(1))+ULB(i,2);    

                   end  

               end

               value = f(attributes);         % calculate fitness of  improvised solution

               UpdateHM(value);        % Update the fitness value of the HM

               counter = counter+1;    % Increment loop counter

           end

        end

% /***********************************************************************/

% Update the Harmony Memory

        function UpdateHM( NewFit )

            % For the first iteration, find best & worst fitness solutions with index

            if(counter==0)

                [BestFit, BestIndex] = min(fitness);

                [WorstFit, WorstIndex] = max(fitness);

            end

            % for second iteration iteration onwards

               tem(1,:) = HM(WorstIndex,:);

               % replace if less than worst fitness

               if (NewFit < WorstFit)

                   % if lower than previous best fitness, update new fitness

                   % as the best fitness while discarding the worst fitness

                  if( NewFit < BestFit )

                     HM(WorstIndex,:)=attributes;

                     BestGen=attributes;

                     tem(2,:) = attributes;

                     fitness(WorstIndex)=NewFit;

                     BestIndex=WorstIndex;

                   % if only lower than worst fitness but not best fitness, then just

                   % replace worst fitness

                  else

                    HM(WorstIndex,:)=attributes;

                    tem(2,:) = attributes;

                    fitness(WorstIndex)=NewFit;

                  end

                  

                   % plot the movement of the solutions

                   pause(0.0005)  % Pause interval for tracing movements can be changed here     

                   hold on;

                   plot(tem(:,1),tem(:,2),'k:'); 

                   

                 % find the new worst solution and its index

                 [WorstFit, WorstIndex] = max(fitness);

              end % NewFit if

        end % function update

toc;

end      % end of function

⛄ 运行结果

⛄ 参考文献

[1]戈国华, 肖海波, 张敏. 基于FCM的数据聚类分析及Matlab实现[J]. 福建电脑, 2007(4):2.

[2] Seyedhosseini, S. M. , et al. "A novel hybrid algorithm based on a harmony search and artificial bee colony for solving a portfolio optimization problem using a mean-semi variance approach." Journal of Central South University (2016).​

❤️ 关注我领取海量matlab电子书和数学建模资料

❤️部分理论引用网络文献,若有侵权联系博主删除

<think>我们正在讨论的是多目标优化算法在项目调度问题中的应用。用户之前已经了解了NSGA-II算法,现在想阅读一篇关于多目标教学学习元启发式算法(Multi-objective Teaching-Learning-Based Optimization, MTLBO)解决多技能项目调度问题(Multi-Skilled Project Scheduling Problem, MSPSP)的论文。 论文题目:'Multi-objective teaching-learning-based meta-heuristic algorithms to solve multi-skilled project scheduling problem' 我们需要做的是: 1. 理解多技能项目调度问题(MSPSP)的基本概念。 2. 理解教学学习优化算法(TLBO)的基本原理。 3. 如何将TLBO扩展为多目标优化算法(MTLBO)? 4. 如何应用MTLBO解决MSPSP? 由于论文的具体内容我们无法直接获取,但根据题目和领域知识,我们可以进行以下分析: ### 1. 多技能项目调度问题(MSPSP) 在MSPSP中,项目由一系列任务组成,每个任务需要特定的技能,并且任务之间有先后顺序约束(如网络图中所示)。同时,项目拥有一组人力资源,每个人员掌握多种技能,但每种技能的水平可能不同。目标是在满足任务技能需求和顺序约束的前提下,优化多个目标,例如: - 最小化项目总工期(makespan) - 最小化人力资源成本 - 最大化资源利用率 - 平衡工作负载 引用[1]提到智能制造调度涉及优化生产计划以实现效率最大化,这与MSPSP有相似之处。 ### 2. 教学学习优化算法(TLBO) TLBO是一种基于种群的元启发式算法,模拟了教室中的教学过程。它分为两个阶段: - **教学阶段(Teacher Phase)**:教师(当前最优解)向学生(种群中的个体)传授知识,提高班级(种群)的平均水平。 - **学习阶段(Learner Phase)**:学生之间通过互动学习来提高自己的知识水平。 基本TLBO步骤: 1. 初始化:随机生成一组学生(种群)。 2. 教学阶段:对于每个学生,根据教师和当前平均水平的差值进行更新: $$X_{new} = X_{old} + r \times (Teacher - T_F \times Mean)$$ 其中,$r$是[0,1]之间的随机数,$T_F$是教学因子(通常为1或2),$Mean$是当前种群的平均值。 3. 学习阶段:随机选择另一个学生,进行互动学习: $$X_{new} = \begin{cases} X_{old} + r \times (X_{partner} - X_{old}), & \text{if } f(X_{partner}) \text{ is better than } f(X_{old}) \\ X_{old} + r \times (X_{old} - X_{partner}), & \text{otherwise} \end{cases}$$ 4. 选择:如果新解优于旧解,则替换。 5. 重复直到满足终止条件。 ### 3. 多目标教学学习优化算法(MTLBO) 将TLBO扩展到多目标,需要引入多目标优化的机制,例如: - **非支配排序**:似于NSGA-II,将种群分为多个非支配层级。 - **拥挤距离**:保持解集的多样性。 - **精英策略**:保留优秀个体。 因此,MTLBO可能会结合TLBO的更新机制和NSGA-II的选择机制。具体步骤可能如下: 1. 初始化种群。 2. 计算每个个体的多个目标函数值。 3. 进行非支配排序并计算拥挤距离。 4. 选择教师:通常选择非支配排序中第一层级的个体作为候选,然后根据拥挤距离或其他指标(如超体积贡献)选择一个教师。 5. 教学阶段:用教师引导种群更新,生成新种群。 6. 学习阶段:学生之间相互学习,进一步更新。 7. 合并父代和子代种群,进行非支配排序和拥挤距离计算,选择下一代种群(精英保留)。 8. 重复步骤4-7直到终止条件满足。 ### 4. 应用MTLBO解决MSPSP 关键点是如何将调度问题编码为算法中的个体,以及如何设计目标函数。 - **编码**:通常使用活动列表(Activity List)来表示解,即一个任务序列,然后通过序列解码得到调度方案(例如,使用串行调度方案SSS或并行调度方案PSS)。同时,还需要考虑资源分配(即每个任务分配给哪个人员),因此编码可能包含两部分:任务序列和资源分配方案。 - **解码**:根据任务序列和资源分配,考虑任务的持续时间、前置约束和资源的可用性(包括技能匹配),计算每个任务的开始时间和结束时间,从而得到整个项目的调度。 - **目标函数**:通常至少包括两个目标:最小化项目工期和最小化总成本(或资源使用)。例如: $$f_1 = \text{makespan}$$ $$f_2 = \sum_{k \in \text{resources}} c_k \times \text{total working time of resource } k$$ 其中,$c_k$是资源$k$的单位时间成本。 - **约束处理**:任务的前后顺序约束、资源技能匹配约束、资源可用时间约束等。违反约束的解需要被惩罚或通过修复机制处理。 ### 阅读论文的建议 1. **摘要和引言**:了解论文的主要贡献和MTLBO算法的创新点。 2. **问题定义**:理解MSPSP的数学模型,包括变量、约束和目标函数。 3. **算法设计**:重点关注如何将TLBO扩展到多目标,如何处理调度问题的编码和解码,以及如何结合非支配排序和拥挤距离。 4. **实验部分**:看作者使用了哪些测试实例,与哪些算法进行比较,以及评价指标(如超体积、间距等)。 5. **结论**:总结算法的优势和局限性。 引用[2]中提到了项目阶段评审的目的(决定是否进入下一阶段),这提醒我们在项目调度中里程碑评审的重要性,但论文中可能不涉及。 引用[3]提到“早期部署单个组件可以同时提供更高的商业价值和更好的架构质量”,这可能启发我们在调度中考虑分阶段交付或部分交付的价值,但论文聚焦于完整项目调度。 ### 如何学习使用MTLBO解决MSPSP? 1. **编程实现**:根据论文描述的算法步骤实现MTLBO,并应用于MSPSP实例。 2. **使用现有框架**:如果论文提供了代码,可以直接使用;或者利用多目标优化框架(如Platypus、jMetal等)实现MTLBO。 3. **测试与验证**:使用标准测试实例(如PSPLIB)验证算法性能。 ### 注意事项 - 由于是多目标问题,最终输出是一组Pareto最优解,决策者需要根据实际情况选择最终调度方案。 - 参数调整:教学因子$T_F$、种群大小、迭代次数等参数可能需要调整。 ### 总结 阅读该论文需要掌握多目标优化和项目调度的基础知识。MTLBO结合了TLBO的高效收敛和NSGA-II的多样性保持机制,适用于解决复杂的MSPSP。通过论文可以学习到如何设计多目标元启发式算法以及如何解决实际调度问题。 §§相关问题§§ 1. 多技能项目调度问题(MSPSP)与经典项目调度问题(如RCPSP)有什么区别? 2. 教学学习优化算法(TLBO)相比其他元启发式算法(如遗传算法、粒子群算法)有什么优势? 3. 在MTLBO中,如何选择教师(特别是多目标情况下)? 4. 如何评估多目标优化算法在MSPSP上的性能? </think>### 多技能项目调度问题(MSPSP)与多目标教学学习算法解析 针对论文《Multi-objective teaching-learning-based meta-heuristic algorithms to solve multi-skilled project scheduling problem》的核心内容,结合多目标优化和项目调度领域知识,解析如下: --- #### 1. **多技能项目调度问题(MSPSP)** MSPSP是经典项目调度问题(RCPSP)的扩展,其核心挑战在于: - **任务约束**:任务需特定技能组合,且存在时序依赖(如网络图中的前置关系)[^2]。 - **资源约束**:人力资源具备多技能,但技能水平存在差异(如初级/高级工程师)。 - **多目标冲突**:需同时优化工期、成本、资源利用率等目标。例如: $$ \begin{cases} \text{minimize} & \text{makespan} \ (T) \\ \text{minimize} & \text{total cost} \ (C) \\ \text{maximize} & \text{resource utilization} \ (U) \end{cases} $$ 智能制造调度中的似问题表明,其复杂性源于资源分配与任务调度的强耦合性[^1]。 --- #### 2. **教学学习优化算法(TLBO)的基本原理** TLBO模拟课堂中“教师教学”和“学生互学”的过程: - **教学阶段**:教师(当前最优解)提升班级平均水平: $$X_{i,\text{new}} = X_{i,\text{old}} + r \cdot \left( X_{\text{teacher}} - T_F \cdot X_{\text{mean}} \right)$$ 其中 $T_F$ 为教学因子(通常取1或2),$r$ 为随机数。 - **学习阶段**:学生 $i$ 随机选择同伴 $j$ 交流: $$X_{i,\text{new}} = \begin{cases} X_{i,\text{old}} + r \cdot (X_j - X_i) & \text{if } f(X_j) \text{ better} \\ X_{i,\text{old}} + r \cdot (X_i - X_j) & \text{otherwise} \end{cases}$$ TLBO无需调参且收敛快,但需扩展为多目标版本(MTLBO)以处理MSPSP[^3]。 --- #### 3. **多目标MTLBO算法设计** 论文的核心创新是将TLBO与多目标优化机制融合: - **非支配排序与精英保留** 似NSGA-II,合并父代与子代种群后进行非支配排序,保留Pareto前沿解。 - **教师选择策略** 教师从第一非支配层中选取,优先选择拥挤距离大的解以保持多样性。 - **技能匹配的解码机制** - **编码**:解向量 =(任务序列 + 资源分配矩阵)。 - **解码**:根据任务技能需求动态分配资源,确保技能匹配(如任务需“编程+测试”技能时,仅分配同时具备两者的人员)[^1]。 - **目标函数设计** $$f_1 = \sum_{k=1}^{K} \max(\text{end time of tasks using resource } k) \quad \text{(工期)}$$ $$f_2 = \sum_{k=1}^{K} c_k \cdot (\text{total working time of resource } k) \quad \text{(成本)}$$ 其中 $c_k$ 是资源单位时间成本。 --- #### 4. **算法实现关键步骤** 伪代码框架如下(需结合论文细节补充): ```python import numpy as np from deap import base, creator # 多目标定义(工期+成本最小化) creator.create("FitnessMulti", base.Fitness, weights=(-1.0, -1.0)) creator.create("Individual", list, fitness=creator.FitnessMulti) def MTLBO_MSPSP(): # 1. 种群初始化(随机生成任务序列和资源分配) population = initialize_population() for gen in range(max_generations): # 2. 教学阶段:更新解 teacher = select_teacher(population) # 从Pareto前沿选教师 for ind in population: ind_new = ind + r * (teacher - TF * mean_population) if dominates(ind_new, ind): ind = ind_new # 保留更优解 # 3. 学习阶段:随机配对互学 for i in range(len(population)): j = random.choice(population) if fitness(j) better than fitness(i): i_new = i + r * (j - i) else: i_new = i + r * (i - j) repair(i_new) # 修复违反约束的解(如时序冲突) # 4. 非支配排序与精英保留 combined_pop = population + offspring fronts = non_dominated_sort(combined_pop) population = select_by_crowding(fronts, pop_size) return pareto_front ``` --- #### 5. **工程应用与优势** - **调度优化场景**: 适用于研发项目管理、智能制造排程等需平衡工期与资源的场景[^1][^3]。 - **对比NSGA-II的优势**: MTLBO参数少、收敛快,教学机制可加速高质量解的生成,尤其适合MSPSP的高维离散空间搜索。 - **实践建议**: 1. 使用标准数据集(如PSPLIB)验证算法性能; 2. 引入局部搜索(如变邻域搜索)增强开采能力; 3. 添加动态事件处理(如人员请假)提升实用性[^3]。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

matlab科研助手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值