-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_start_point_to_hiuristic_3.m
60 lines (56 loc) · 1.78 KB
/
new_start_point_to_hiuristic_3.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function [val,match]=new_start_point_to_hiuristic_3(agent2conf,all_conf,targetsData)
%%%% calculate all conf val
global allConf;
allConf = all_conf;
VAL_COL=3;
%update each conf with its value
% where c is index of conf and t index of target
for c=1:size(agent2conf,2)
conf_val=0;
for t=1:size(allConf,1)
if allConf(t,c)>0
conf_val=conf_val+(8-targetsData(t,VAL_COL));
end
end
for a=1:size(agent2conf,1)
if agent2conf(a,c)>0
agent2conf(a,c)=conf_val;
end
end
end
permutation=zeros(1,size(agent2conf,1));
%%%% find best perm
temp_agent2conf=agent2conf;
for k=1:size(temp_agent2conf,1)
[~, idx] = max(temp_agent2conf(:));
[x,y] = ind2sub(size(temp_agent2conf),idx);
permutation(k)=x;
temp_agent2conf(x,:)=0;
temp_agent2conf(:,y)=0;
end
if sum(permutation)~=sum(1:size(temp_agent2conf,1))
permutation=randperm(size(temp_agent2conf,1));
end
%%%%
agent2conf_temp=agent2conf;
match=zeros(size(agent2conf,1),1);
for a=permutation
maximum=find(agent2conf_temp(a,:)==max(agent2conf_temp(a,:)));
maximum=maximum(1);
targets_of_best_conf=allConf(:,maximum);
match(a)= maximum;%first maximum
for c=1:size(allConf,2)
if allConf(:,c)'*targets_of_best_conf>0
agent2conf_temp(:,c)=0;
end
end
end
val=calculate_assign_value(match,targetsData);
end
function [val]=calculate_assign_value(match,targetsData)
VAL_COL=3;
global allConf;
choosen_conf= allConf(:,match');
targets=sum(choosen_conf,2)>0;
val=(8-targetsData(:,VAL_COL)') * targets;
end