-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.m
94 lines (80 loc) · 4.16 KB
/
main.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
function [lp,outConf,AgentInfo, allConfigurations, agent2conf, Agent2target, AllConf, excelOut, Agent2sensor, target2sensor] = main(file)
global targetsData;
global Agent2target;
global target2TargetDistance;
tic;
% parse the input file
[ Agent2sensor,target2sensor, AgentInfo, target2Val, target2TargetDistance ] = ParseInfile( file );
Agent2target = Agent2sensor * target2sensor';
targetsData = read_excel_and_clean(file,'InMissions');
numOfTargets = size(target2sensor,1);
numOfDrones = size(AgentInfo,1);
allConfigurations = zeros(0,numOfTargets);
agent2conf = zeros(numOfDrones,0);
fprintf('Done parsing infile ');
toc;
tic;
% build the configuration per drone
for (drone = 1 : numOfDrones)
currConfs = buildConfigurationsPerDrone(zeros(numOfTargets,1), AgentInfo(drone,2),AgentInfo(drone,1),AgentInfo(drone,3) ,AgentInfo(drone,4), 1 ,0);
currConfs = unique(currConfs', 'rows');
currConfs = currConfs';
allConfigurations = [allConfigurations currConfs];
currAgent2conf = zeros(numOfDrones,size(currConfs,2));
currAgent2conf(drone,:) = ones(1,size(currConfs,2));
agent2conf = [agent2conf currAgent2conf];
fprintf('done drone %i of %i\n',drone,numOfDrones);
end
confVal = target2Val' * allConfigurations;
fprintf('the number of confs is: %d\n',size(allConfigurations,2));
b = unique(allConfigurations', 'rows');
fprintf('the number of unique confs is: %d\n',size(b,1));
fprintf('Done building Confs ');
toc;
tic;
[lp,outConf] = run_LP_Solve(allConfigurations,agent2conf,confVal,0);
fprintf('Done running lp ');
toc;
AllConf = zeros(0,4);
excelOut = zeros(0,5);
for i=1:size(outConf,2)
currConf = getRealConf(outConf(:,i),AgentInfo(i,1),AgentInfo(i,2),AgentInfo(i,3),0);
if (size(currConf,1) > 0)
AllConf = [AllConf ; (ones(size(currConf,1),1) * AgentInfo(i,4)) currConf];
% build the excel output
% best payload for the first mission
compatible = Agent2sensor(AgentInfo(i,4),:) .* target2sensor(currConf(1,1),:);
bestPayload = find(compatible==max(compatible));
excelOut = [excelOut ; AgentInfo(i,4) currConf(1,1) bestPayload currConf(1,2:3)];
for j=2:size(currConf,1)
% if there is a gap - insert a "0" mission
currFinish = excelOut(size(excelOut,1),5);
newStart = currConf(j,2);
if (currFinish < (newStart - 0.001))
excelOut = [excelOut ; AgentInfo(i,4) 0 0 currFinish newStart];
end
compatible = Agent2sensor(AgentInfo(i,4),:) .* target2sensor(currConf(j,1),:);
bestPayload = find(compatible == max(compatible));
excelOut = [excelOut ; AgentInfo(i,4) currConf(j,1) bestPayload currConf(j,2:3)];
end
end
end
col_w = 11; % Fixed column width in characters
fr_n = 2; % Number of fraction digits
% Print header
hdr_line = '| drone ID | target ID | start | end ';
fprintf('\n\nResults:\n%s\n', hdr_line)
% Print values
data_fmt = [repmat(['|%', int2str(col_w - 1), '.', int2str(fr_n), 'f '], 1, size(AllConf, 2)), '\n'];
fprintf(data_fmt, AllConf')
xlswrite(file,excelOut,'OutAssignment','A3');
%agent2targets = build_drone_targets( targets,agent2sensors,verbose);
%allConf = getAllConfigurations( numOfTargets,maxNumOfTargetInConfiguration,verbose );
%size(allConf)
%verbose && xlswrite('C:\Magneton\temp.xls',allConf','temp');
%cleanConf = cleanConfigurations( allConf,targets,BEGIN_COL,END_COL,DURATION_COL,maxNumOfTargetInConfiguration,maxFlightTime,verbose);
%verbose && xlswrite('C:\Magneton\temp.xls',cleanConf','temp2');
%confVal = targets(:,CONF_VAL_COL)' * cleanConf;
%agent2conf = build_agent2conf( cleanConf,agent2targets,verbose);
%lp = run_LP_Solve(cleanConf,agent2conf,confVal,verbose);
end