-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathminEnergyRouting.m
62 lines (31 loc) · 1.14 KB
/
minEnergyRouting.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
function [ EnergyConsumption ] = minEnergyRouting( inputNode, nodes )
% Numbdr of nodes, including sink
nNodes = (length (nodes.Position))/2;
nodesPosition = ones(3, nNodes);
x = linspace (1,nNodes, nNodes);
y= x+1;
nodesPosition(1,:) = nodes.Position(x);
nodesPosition(2,:) = nodes.Position(y);
nodesPosition(3,inputNode) = 0;
EnergyConsumption = 0;
minEnergy(inputNode, nodesPosition);
function minEnergy(currentNode, nodes)
Ea=1;
for i=1:nNodes
if nodes(3,i) >0
nextNode = i;
Ea(i) = computeEnergy (currentNode , nextNode, nodes);
else
Ea(i) = inf;
end
end
[EnergyConsumptionTemp, index] = min (Ea);
EnergyConsumption = EnergyConsumption + EnergyConsumptionTemp;
nodes(3,index) = 0;
if nnz(nodes(3,:))>1
minEnergy (index, nodes);
else
a=1;
end
end
end