-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcalculateCost.m
60 lines (59 loc) · 3.06 KB
/
calculateCost.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 [totalCost] = calculateCost (sp, connections, n, noc, controllers)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
totalCost = 0; %a variable to store the total cost
% controllerLoad = zeros (2,noc); %to store the loads of individual controllers
controllerLoad = zeros (1,noc); %to store the loads of individual controllers
controllerCost = 0; %to store the total cost of the controllers
% fixedCost = 0.65; %fixed cost for the controllers
fixedCost = 6500; %fixed cost for the controllers
packets = 500; %in kilo requests per second
% controllerCapacity = 7.8e+6; %in kilo requests per second
controllerCapacity = 5000; %in kilo requests per second
% packets = randi ([200 600], 1, n); %in kilo requests per second
% controllerCapacity = 7800; %in kilo requests for second
costPerUnit = 29; %in dollars
% x = 0; %binary variable for controller
% y = 0; %binary variable for switch connection
p = 1; %index for controllers
for i = 1 : noc %for each controller
for j = 1 : n %for each node
%setting the value of x
if (p <= noc && j == controllers (1,p)) %if the controller is not counted and j is equal to the controller
x = 1; %set x to 1 to add the controller cost
p = p + 1; %increment the index
else
x = 0; %set x to 0 to keep the node out of counting
end
%setting the value of y
if ((connections (i,j) ~= 0)&&(x == 0)) %if jth node is connected to the ith controller and jth node is not counted with x
y = 1; %set y to 1 to count the node
for k = 1 : noc %for each controller
if (j == controllers (1,k)) %if jth node is a controller
y = 0; %keep the node out of counting
end
end
else
y = 0; %keep the node out of counting
end
%calculating total cost, cost of controllers, loads of individual controllers
if (x <= noc) %x must be less than the number of controllers
% controllerLoad (1,i) = controllerLoad (1,i) + (packets (1,j) * sp (i,j) * costPerUnit * y);
controllerLoad (1,i) = controllerLoad (1,i) + (packets * y);
controllerCost = controllerCost + (fixedCost *x);
% totalCost = totalCost + (fixedCost * x) + (packets (1,j) * sp (i,j) * costPerUnit * y); %calculating the total cost
totalCost = totalCost + (fixedCost * x) + (packets * sp (i,j) * y); %calculating the total cost
% totalCost = totalCost + (packets (1,j) * sp (i,j) * y); %calculating the total cost
end
end
end
% for i = 1 : noc %for each controller
% if (controllerLoad (1,i) > controllerCapacity) %if the load is more than capacity
% controllerLoad (2,i) = 0; %store 0
% else
% controllerLoad (2,i) = 1; %store 1
% end
% end
% controllerLoad
% controllerCost
end