unique_distance

今天看代码的时候看见distance,不是太懂,查了写资料,就马上写下,以防忘记!
不说不懂得,只讲最快可以理解的。
**这个里面好像不能显示 >> 所以不好显示,需要输出的时候我就直接写输出两个字了,>-<

unique 将相邻相同的元素放最后面,返回–重排后元素的首地址(不懂返回值的稍后会讲)

使用方法::

int a[10] = {1,1,2,2,3,4,5};
int * s = unique(a,a+7);

vector A(a,a+7)
vector::iterator b = unique(A.begin(),A.end());

返回值::::直接代码:

int a[10] = {1,1,2,2,3,4,5};
vector A(a,a+7);
输出 unique(a,a+7)
输出 *unique(a,a+7)

//输出:
0x6ffdf4
0

distance :: 用法和他的名字一样
处理两个迭代器之间的距离

vector::iterator iter = unique(A.begin(),A.end());
输出 “ ****” distance(A.begin(),iter);

输出s:
5

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
function crowding_distance = calculate_crowding_distance(objectives, ndx) % objectives为目标函数值矩阵 % ndx为每个个体所属的帕累托前沿编号 crowding_distance = zeros(1, size(objectives, 1)); nFronts = length(unique(ndx)); for iFront = 1:nFronts frontIndices = find(ndx == iFront); nPoints = length(frontIndices); if nPoints == 1 % 如果只有一个个体,则其拥挤度为inf crowding_distance(frontIndices) = inf; else for iObjective = 1:size(objectives, 2) % 对第iObjective个目标函数进行排序,得到该维度上的排序索引 [~, sortedIndices] = sort(objectives(frontIndices, iObjective)); % 对该维度上排名最小的个体和排名最大的个体赋予最大拥挤度 crowding_distance(frontIndices(sortedIndices(1))) = inf; crowding_distance(frontIndices(sortedIndices(end))) = inf; % 计算其它个体的拥挤度 for iPoint = 2:(nPoints-1) range = objectives(frontIndices(sortedIndices(end))) - objectives(frontIndices(sortedIndices(1))); if range == 0 crowding_distance(frontIndices(sortedIndices(iPoint))) = inf; else crowding_distance(frontIndices(sortedIndices(iPoint))) = crowding_distance(frontIndices(sortedIndices(iPoint))) ... + (objectives(frontIndices(sortedIndices(iPoint+1)), iObjective) - objectives(frontIndices(sortedIndices(iPoint-1)), iObjective)) / range; end end end end end end这段代码报错:Index exceeds the number of array elements. Index must not exceed 0. 出错 calculate_crowding_distance (第 19 行) crowding_distance(frontIndices(sortedIndices(1))) = inf;该如何修改
05-24

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值