下载频道> 资源分类> matlab源码> 算法设计> K-最佳分配算法matlab源码程序

标题:K-最佳分配算法matlab源码程序
分享到:

所属分类: 算法设计 资源类型: 文件大小: 6.41 KB 上传时间: 2016-02-25 21:25:51 下载次数: 6 资源积分:1分 提 供 者: 源码共享 K-最佳分配算法matlab源码程序
内容:
K-最佳分配算法matlab源码程序,程序员在编程的过程中可以参考学习使用,希望对IT程序员有用,此源码程序简单易懂、方便阅读,有很好的学习价值!
function assignment_list = k_best_assign(cost_mat,k,opt_fun)
% function to find the k-best associations from an assignment cost matrix.
% See: 
%   An Algorithm for Ranking all the Assignments in Order of Increasing Cost
%   Katta G. Murty, Operations Research, Vol. 16, No. 3 (May - Jun., 1968), pp. 682-687 
%
% inputs: 
%     -cost_mat:     matrix of assignment costs, only tested square so far
%     -k:            number of ranked assignments desired
%     -opt_fun:      function handle for an assignment algorithm (munkres or
%                   JV algorithm, etc)
% outputs:
%     -assignment_list:  a (k x 2) ranked list of optimal assignments (column 1)
%                       and costs (column 2)
% NOTE: This function requires a standard assigment function for solving a
% single cost matrix.  Implementations of the Munkres and JV linear
% assigment algorithms can be found elsewhere on FEX:%                     
%
% author: v1 - EMT, 2/14/11
%
% ---------------------------------------------------------------------
% Example: 
% cost_mat = rand(50);
% k = 5;
% optfun = @munkres;      %requires 
% assignment_list = k_best_assign(cost_mat,k,opt_fun)
%
% ---------------------------------------------------------------------
 
% find initial optimal assignment
[assignment,cost] = opt_fun(cost_mat);
[col,row] = find(assignment');
nodes = {[], [],[row col], cost};
optimal_nodes = {[], [],[row col], cost};
 
%partition the optimal node
nodes_list = partition_node(nodes,cost_mat,opt_fun);
 
while (size(optimal_nodes,1) < k) 
    %find the best node among those in the node list
    costs = cell2mat(nodes_list(:,4));
    [min_cost,ind] = min(costs);
    
    %copy best node from list into optimal set
    optimal_nodes(end+1,:) = nodes_list(ind,:);
    
%     nodes_list(ind,:);  %for debug
    nodes_tmp = partition_node(nodes_list(ind,:),cost_mat,opt_fun);
    nodes_list(ind,:) = []; %remove best node from list
 
    %add new partitioned nodes to list
    nodes_list = [nodes_list; nodes_tmp]; 
%     disp('==========================================================');  %for debug
    
end
 
%format output data structure
assignment_list = cell(size(optimal_nodes,1),2);
for ii = 1:size(optimal_nodes,1)
    assignment_list{ii,1} = [optimal_nodes{ii,1}; optimal_nodes{ii,3}]; 
    assignment_list{ii,2} = optimal_nodes{ii,4};
end
 
 
 
 
 
 
 
 

文件列表(点击上边下载按钮,如果是垃圾文件请在下面评价差评或者投诉):

关键词: 算法 源码 程序

Top_arrow
回到顶部
联系方式| 版权声明| 招聘信息| 广告服务| 银行汇款| 法律顾问| 兼职技术| 付款方式| 关于我们|
网站客服网站客服 程序员兼职招聘 程序员兼职招聘
沪ICP备19040327号-3
公安备案号:沪公网安备 31011802003874号
库纳格流体控制系统(上海)有限公司 版权所有
Copyright © 1999-2014, GUSUCODE.COM, All Rights Reserved