-
Notifications
You must be signed in to change notification settings - Fork 21
/
node.m
65 lines (62 loc) · 1.85 KB
/
node.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
classdef node
properties
name;
x;
y;
routeTable;
connectedNodes;
seqNum;
color;
pathFrom;
circle;
text;
end
methods
function obj = node(name,xin,yin)
obj.routeTable = table(1,1,1,1,1);
obj.routeTable.Properties.VariableNames = {'dest','nextHop','hopCnt','seqNum','lifeTime'};
obj.routeTable(1,:)= [];
obj.color = "black";
obj.seqNum = 1;
obj.pathFrom = [];
if nargin >= 3
obj.name = char(name);
obj.x = xin;
obj.y = yin;
else
obj.name = 'unnamed';
obj.x = 0;
obj.y = 0;
end
end
function [routeTable] = addToRouteTable(obj,dest,nextHop,hopCnt,seqNum,lifeTime)
routeTable = obj.routeTable;
oldEntries = find(routeTable.dest==dest)';
if(numel(oldEntries) > 0)
currentHopCnt = min(routeTable.hopCnt(oldEntries));
if(hopCnt >=currentHopCnt)
return
end
else
currentHopCnt = 0;
end
if(hopCnt == 0)
return
end
routeTable(oldEntries,:) = [];
routeTable = [routeTable;{dest,nextHop,hopCnt,seqNum,lifeTime}];
end
function [rtn] = updatePos(obj,x,y)
global radius range
if(x > 0 && x < range && y > 0 && y < range)
obj.x = x;
obj.y = y;
obj.circle.Position(1) = x - radius;
obj.circle.Position(2) = y - radius;
obj.text.Position(1) = x;
obj.text.Position(2) = y;
end
rtn = obj;
end
end
end