Автор работы: Пользователь скрыл имя, 07 Января 2014 в 09:34, контрольная работа
Закрепление теоретических знаний по разделу "Структура и структурные свойства сети" и освоение методики и алгоритмов построения сетей связи с:
минимальной протяженностью ветвей (МПВ);
минимальной протяженностью связей (МПС);
минимальными капитальными затратами (МКЗ).
S = 0;
OVER = 0;
% while ((CorrectWay(N0) == 1) & (I < 50))
while ((OVER == 0) & (I < 50))
N_old = N0;
L_old = L;
[N, L, N0, r ,c, Number, Vmin, Ymin] = step_calc(N, L, N0);
[r, c, Number]
if(Number ~= -1)
I = I + 1
N0_chet = N0 .* (ones(ALL, ALL) - eye(ALL, ALL));
SUM = sum(sum(N0_chet .* L)) / 2;
S = S + SUM;
if (I == 2)
xlswrite('D:\var21\kur2.xls',
xlswrite('D:\var21\kur2.xls',
xlswrite('D:\var21\kur2.xls',
end
Y_ALL(1, I) = r;
Y_ALL(2, I) = c;
Y_ALL(3, I) = Number;
Y_ALL(4, I) = SUM;
else
OVER = 1;
end
end
N0
N
L
I
% plot(Y_ALL);
xlswrite('D:\var21\kur2.xls', Y_ALL','Лист1','B2');
xlswrite('D:\var21\kur2.xls', L, 'L_after', 'B2');
'end kur2'
end
function [y] = GetWays(x)
s = size(x);
N = s(1);
y = 0;
for i = 1 : N
y = y + x^i;
end
end
function [y] = CorrectWay(x)
a = GetWays(x);
y = 1;
if (HaveZero(a) == 1) y = 0; end;
end
function [Have] = HaveZero(x)
Have = 0;
s = size(x);
for i = 1 : s(1)
for j = 1 : s(2)
if (x(i,j) < 0.1)
Have = 1; end;
end
end
end
function [N, L, N0, r, c, I, Vmin, Ymin] = step_calc(N, L, N0)
[r, c, I, Vmin, Ymin] = getMin(N, L);
if (I ~= -1)
L_old = L;
L = modif(L, r, c, I);
dL = L - L_old;
[N1, N0] = BigAndZero(N, N0, r, c);
N = N0;
else
r = -1;
c = -1;
end
end
function [minR, minC, I_obh, V1, Ymin] = getMin(N, L)
s = size(N);
BIG = 10^10;
ALL = s(1);
for r = 1 : ALL
for c = 1 : ALL
if ((c~=r) & (N(r,c) > 0))
[V, I] = getOB(N, L, r, c);
Ymin(r, c) = V;
Imin(r, c) = I;
else
Ymin(r,c) = BIG;
Imin(r,c) = -1;
end
end
end
Ymin = Ymin + eye(ALL, ALL) * BIG;
M = min(Ymin); %%%получили по столбцам минимальные значения
[V, minC] = min(M);
minRow = Ymin( : , minC );
[V1, minR] = min(minRow);
I_obh = Imin(minR, minC);
end
function [L] = modif(L, r, c, i)
BIG = 10^10;
Lchange = L(r, c);
L(r, i) = L(r, i) + Lchange;
L(i, r) = L(i, r) + Lchange;
L(i, c) = L(i, c) + Lchange;
L(c, i) = L(c, i) + Lchange;
L(r, c) = BIG;
L(c, r) = BIG;
end
function [Ymin, Imin] = getOB(N, L, R, C)
s = size(N);
BIG = 10^10;
ALL = s(1);
Ymin = -1;
Imin = -1;
good = 0;
for i = 1 : ALL
N1 = N(R, i);
N2 = N(i, C);
N_Real = N(R, C);
N0 = N1 + N2;
y(i) = (N0 - N_Real) * L(R,C);
if ((N_Real == 0) | (N1 == 0) | (N2 == 0) | (R==i) | (C==i))
y(i) = BIG;
else
good = 1;
end;
end
[Ymin, Imin] = min(y);
if (good == 0) Imin = -1; end;
end
function [x, x1] = BigAndZero(x, x1, row, col)
BIG = 10^10;
x(row, col) = BIG;
x(col, row) = BIG;
x1(row, col) = 0;
x1(col, row) = 0;
end
Код для 3 задания курсовой работы:
function [ output_args ] = kur02( input_args )
%KUR02 Summary of this function goes here
% Detailed explanation goes here
tic
clear
clc
BIG = 10^4;
ALL = 8;
N = xlsread('D:\var21.xlsx');
N = triu(N) + zeros(ALL, ALL);
N = N + N';
Nsave = N;
N = N + eye(ALL) * BIG;
% N
L = xlsread('D:\var212.xlsx');
L_for_kz = L;
L = L + L';
L = L + eye(ALL) * BIG;
I = 1;
N0 = N;
S = 0;
OVER = 0;
% while ((CorrectWay(N0) == 1) & (I < 50))
% while ((OVER == 0) & (I < 50))
StartKZ = GetMoneyMatrix(L_for_kz .*N ) .* (ones(ALL, ALL) - eye(ALL, ALL));
StartMoney = sum(sum(StartKZ .* L .* N)) / 2;
Y_ALL(4, I) = StartMoney;
xlswrite('D:\var21\kur03.xls',
while ((OVER == 0) & (I < 50) & (CorrectWay(N0) == 1))
N_old = N0;
L_old = L;
[N, L, N0, r ,c, Number, Vmin, Ymin] = step_calc2(N, L, N0);
% [r, c, Number]
if(Number ~= -1)
I = I + 1;
N0_chet = N0 .* (ones(ALL, ALL) - eye(ALL, ALL));
Mo = GetMoneyMatrix(L .* N);
Mo = Mo .* (ones(ALL, ALL) - eye(ALL, ALL));
SUM = sum(sum(N0_chet .* L .*Mo)) / 2;
S = S + SUM;
if (I == 2)
xlswrite('D:\var21\kur03.xls',
xlswrite('D:\var21\kur03.xls',
xlswrite('D:\var21\kur03.xls',
end
Y_ALL(1, I) = r;
Y_ALL(2, I) = c;
Y_ALL(3, I) = Number;
Y_ALL(4, I) = SUM;
else
OVER = 1;
end
end
N0
N
L
I
plot(Y_ALL);
Mo = GetMoneyMatrix(Nsave .* L_for_kz);
xlswrite('D:\var21\kur03.xls', Mo, 'Money', 'B2');
xlswrite('D:\var21\kur03.xls', L_for_kz, 'L_for_kz', 'B2');
xlswrite('D:\var21\kur03.xls', Y_ALL','Лист1','B2');
xlswrite('D:\var21\kur03.xls', L, 'L_after', 'B2');
'end kur3'
end
function [y] = GetMoneyMatrix(x)
for i = 1 : 8
for j = 1 : 8
y(i,j) = Money(x(i,j));
if (x(i,j) == 0) y(i,j) = 0; end;
end
end
end
function [y] = GetWays(x)
s = size(x);
N = s(1);
y = 0;
for i = 1 : N
y = y + x^i;
end
end
function [y] = CorrectWay(x)
a = GetWays(x);
y = 1;
if (HaveZero(a) == 1) y = 0; end;
end
function [Have] = HaveZero(x)
Have = 0;
s = size(x);
for i = 1 : s(1)
for j = 1 : s(2)
if (x(i,j) < 0.1)
Have = 1; end;
end
end
end
function [y] = Money(x)
y = 40;
if (x>60) y = 30; end;
if (x>120) y = 25; end;
if (x>240) y = 20; end;
if (x>600) y = 18; end;
if (x>1000) y = 15; end;
if (x>1500) y = 12; end;
if (x>1500) y = 12; end;
if (x>2500) y = 10; end;
if (x>4000) y = 8; end;
if (x>10^4) y = 6; end;
end
function [N, L, N0, r, c, I, Vmin, Ymin] = step_calc2(N, L, N0)
[r, c, I, Vmin, Ymin] = getMin(N, L);
if (I ~= -1)
L_old = L;
L = modif(L, r, c, I);
dL = L - L_old;
[N1, N0] = BigAndZero(N, N0, r, c);
N = N0;
else
r = -1;
c = -1;
end
end
function [minR, minC, I_obh, V1, Ymin] = getMin(N, L)
s = size(N);
BIG = 10^10;
ALL = s(1);
for r = 1 : ALL
for c = 1 : ALL
if ((c~=r) & (N(r,c) > 0))
[V, I] = getOB(N, L, r, c);
Ymin(r, c) = V;
Imin(r, c) = I;
else
Ymin(r,c) = BIG;
Imin(r,c) = -1;
end
end
end
Ymin = Ymin + eye(ALL, ALL) * BIG;
M = min(Ymin); %%%получили по столбцам минимальные значения
[V, minC] = min(M);
minRow = Ymin( : , minC );
[V1, minR] = min(minRow);
I_obh = Imin(minR, minC);
end
function [L] = modif(L, r, c, i)
BIG = 10^10;
Lchange = L(r, c);
L(r, i) = L(r, i) + Lchange;
L(i, r) = L(i, r) + Lchange;
L(i, c) = L(i, c) + Lchange;
L(c, i) = L(c, i) + Lchange;
L(r, c) = BIG;
L(c, r) = BIG;
end
function [Ymin, Imin] = getOB(N, L, R, C)
s = size(N);
BIG = 10^10;
ALL = s(1);
Ymin = -1;
Imin = -1;
good = 0;
for i = 1 : ALL
N1 = N(R, i);
N2 = N(i, C);
N_Real = N(R, C);
N0 = N1 + N2;
L1 = L(R, i);
L2 = L(i, C);
NL1 = N1 * L1;
NL2 = N2 * L2;
Money1 = Money(NL1) * NL1 ;
Money2 = Money(NL2) * NL2;
NL3 = (N0-N_Real)*L(R,C);
Money3 = Money(NL3) * NL3;
y(i) = Money3 - (Money1 + Money2);
if ((N_Real == 0) | (N1 == 0) | (N2 == 0) | (R==i) | (C==i))
y(i) = BIG;
else
good = 1;
end;
end
[Ymin, Imin] = min(y);
if (good == 0) Imin = -1; end;
end
function [x, x1] = BigAndZero(x, x1, row, col)
BIG = 10^10;
x(row, col) = BIG;
x(col, row) = BIG;
x1(row, col) = 0;
x1(col, row) = 0;
end
function [y] = GetMoneyMatrix(x)
for i = 1 : 8
for j = 1 : 8
y(i, j) = Money(x);
end
end
end
function [y] = Money(x)
y = 40;
if (x>60) y = 30; end;
if (x>120) y = 25; end;
if (x>240) y = 20; end;
if (x>600) y = 18; end;
if (x>1000) y = 15; end;
if (x>1500) y = 12; end;
if (x>1500) y = 12; end;
if (x>2500) y = 10; end;
if (x>4000) y = 8; end;
if (x>10^4) y = 6; end;
end