-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadCoronet.m
110 lines (89 loc) · 2.91 KB
/
readCoronet.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
clc;
clear;
close all;
%% Import data from spreadsheet
% Script for importing data from the following spreadsheet:
%
% Workbook: /home/li/Desktop/ProbabilisticModel/CORONET_CONUS_Topology.xls
% Worksheet: Nodes
%
% To extend the code for use with different selected data or a different
% spreadsheet, generate a function instead of a script.
% Auto-generated by MATLAB on 2017/04/06 09:42:43
%% Import the data
[~, ~, raw] = xlsread('/home/li/Desktop/ProbabilisticModel/CORONET_CONUS_Topology.xls','Nodes');
raw = raw(6:end,:);
stringVectors = string(raw(:,[1,2]));
stringVectors(ismissing(stringVectors)) = '';
raw = raw(:,[3,4]);
%% Create output variable
data = reshape([raw{:}],size(raw));
%% Create table
nodes = table;
%% Allocate imported array to column variable names
nodes.City = stringVectors(:,1);
nodes.State = stringVectors(:,2);
nodes.Latitude = data(:,1);
nodes.Longitude = data(:,2);
%% Clear temporary variables
clearvars data raw stringVectors;
%% Import data from spreadsheet
% Script for importing data from the following spreadsheet:
%
% Workbook: /home/li/Desktop/ProbabilisticModel/CORONET_CONUS_Topology.xls
% Worksheet: Links
%
% To extend the code for use with different selected data or a different
% spreadsheet, generate a function instead of a script.
% Auto-generated by MATLAB on 2017/04/06 10:39:06
%% Import the data
[~, ~, raw] = xlsread('/home/li/Desktop/ProbabilisticModel/CORONET_CONUS_Topology.xls','Links');
raw = raw(6:end,:);
stringVectors = string(raw(:,[1,2]));
stringVectors(ismissing(stringVectors)) = '';
raw = raw(:,3);
%% Create output variable
data = reshape([raw{:}],size(raw));
%% Create table
links = table;
%% Allocate imported array to column variable names
links.NodeA = stringVectors(:,1);
links.NodeZ = stringVectors(:,2);
links.Distancekm = data(:,1);
%% Clear temporary variables
clearvars data raw stringVectors;
%% Construct adjacent matrix, cost matrix, and topology matrix
NodeNames = cell(75, 1);
for i=1:75
NodeNames{i} = nodes.City{i};
end
networkCostMatrix = inf(75);
for i=1:size(links, 1)
src = find(contains(NodeNames, links{i, 1}));
dst = find(contains(NodeNames, links{i, 2}));
distance = ceil(links{i, 3}/100);
networkCostMatrix(src, dst) = distance;
end
for i=1:75
for j=i+1:75
if ~isinf(networkCostMatrix(i, j))
networkCostMatrix(j, i) = networkCostMatrix(i, j);
end
end
end
networkAdjacentMatrix = double(~(isinf(networkCostMatrix)));
networkTopology = zeros(sum(networkAdjacentMatrix(:)), 1);
n=1;
for i=1:75
for j=1:75
if ~isinf(networkCostMatrix(i, j))
networkTopology(n, 1) = i;
networkTopology(n, 2) = j;
networkTopology(n, 3) = networkCostMatrix(i, j);
n = n+1;
end
end
end
locations = [nodes.Latitude, nodes.Longitude];
save('CoronetTopology.mat', 'networkCostMatrix', ...
'networkAdjacentMatrix', 'networkTopology', 'locations')