1С-КОЛЬЦО
ПРОГРАММА
1C-КОЛЬЦО
1. ОБЩЕЕ
2. АЛГОРИТМ
3. ВЫВОД
4. СКАЧИВАНИЕ
1. ОБЩЕЕ
В статье «Исследование кольцевой сети» - Сборник трудов ЦНИИС, № 3, 1975 г.
Исследована кольцевая сеть.
Скачать статью.
https://disk.yandex.ru/d/Gwy_lP4zFUupzA
Имеется n – станций. Одна центральная станция и n-1 оконечных станций.
Каждая станция связана с двумя другими станциями.
Выход из строя двух и более линий связи приводит к потере связи части оконечных станций с центральной станцией.
То есть.
Задан единичный цикл графа:
n – вершин, n – рёбер.
Вершина № 1 называется центром.
Исследовано.
С заданной вероятностью ребра исключаются. При исключении двух и более ребер часть вершин теряет путь к центру.
В статье дано без доказательств выражение для расчёта
В программе 1C-КОЛЬЦО вычисляется моделированием математическое ожидание числа вершин, не имеющих пути к центру.
2. АЛГОРИТМ
Три уровня - цикла.
Первый уровень.
Выбор вероятности исключения ребра из графа.
Переменная цикла – x.
Вероятность от 0,02 до 1 c шагом – 0,02.
Второй уровень.
Сбор статистики.
Повторение цикла третьего уровня.
Переменная цикла – j.
Третий уровень.
Четыре шага.
Шаг 1.
Обход ребер графа по возрастанию номера ребер.
Помечаются удаляемые ребра.
Шаг 2.
Отмечается первое помеченное ребро -r.
Отмечается последнее помеченное ребро – t.
Шаг 3.
Число вершин, отрезанных от центра при t>0.
d:= r-t.
3. ВЫВОД
Результат - массив S1[1..3,1..w].
S1 [2, z] – математическое ожидание числа вершин, отрезанных от центра.
S1 [5, z] – вероятность исключения ребра
Кроме того, вывод информации с контрольных точек для понимания работы программы.
По программе Ф-КОЛЬЦО проведены точные расчёты математического ожидания число отрезанных вершин.
Результаты моделирования совпадают с точностью менее одного процента.
4. СКАЧИВАНИЕ
Программа С-КОЛЬЦО на Дельфи 7.
Распечатка программы – Дельфи 7.
Скачать программу
https://disk.yandex.ru/d/B9rbp_6y5AEtvQ
Приложение 1
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button5: TButton;
Label1: TLabel;
StringGrid2: TStringGrid;
StringGrid3: TStringGrid;
StringGrid4: TStringGrid;
Button4: TButton;
Edit1: TEdit;
Edit2: TEdit;
Label4: TLabel;
Edit3: TEdit;
Label2: TLabel;
Label3: TLabel;
Label7: TLabel;
Label6: TLabel;
Edit4: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Const
n=3;// ÷Число вершин
p =20000; //сбор статистики
w=50; // задание вероятности удаления ребер
x1=22; //
p1 = 1; //
x2 = 22;//
p2 = 2 ;//
x3=23; //
p3 = 1; //
x4 = 23;//
p4 = 2 ;//
yy=2;
Контрольные точки
var
Tick: Cardinal;
s:array [1..7,1..n] of integer;//
s1 : array [1..7,1..w] of real; //
s2 : array [1..7,1..w] of integer; //
s3 : array [1..7,1..w] of integer; //
h, i, j, q, e, r, t, d, d1, x,u, e1,e2,e3,e4,e5: integer;//
v, a,b ,a1, b1, i0, i1,i2,i3,i4, i5,i6, i7,i8, i9, j1,j2,j3 , r1,t1 : integer;//
f,f1 : variant;//
ff, gg, pp : integer;//
c,z,z1 : real;//
C1 : variant;//
c2 : variant;//
procedure TForm1.Button1Click(Sender: TObject);
// îêàíòîâêà
begin
for q:=1 to n //íóìåðàöèÿ ïî ãîðèçîíòàëè â òàáë ¹1 ,
do StringGrid1.Cells[q,0]:=IntToStr(q);
for q:=1 to 5 // íóìåðàöèÿ ïî âåðòèêàëè â òàáë ¹1 ,
do StringGrid1.Cells[0,q]:=IntToStr(q);
for q:=1 to w //íóìåðàöèÿ ïî ãîðèçîíòàëè â òàáë ¹2,
do StringGrid2.Cells[q,0]:=IntToStr(q);
for q:=1 to 5 // íóìåðàöèÿ ïî âåðòèêàëè â òàáë ¹2 ,
do StringGrid2.Cells[0,q]:=IntToStr(q);
// ðåçåðâ
for q:=1 to w //íóìåðàöèÿ ïî ãîðèçîíòàëè â òàáë ¹4,
do StringGrid4.Cells[q,0]:=IntToStr(q);
for q:=1 to 7 // íóìåðàöèÿ ïî âåðòèêàëè â òàáë ¹4 ,
do StringGrid4.Cells[0,q]:=IntToStr(q);
// ðåçåðâ
for q:=1 to n //íóìåðàöèÿ ïî ãîðèçîíòàëè â òàáë ¹4,
do StringGrid3.Cells[q,0]:=IntToStr(q);
for q:=1 to 5 // íóìåðàöèÿ ïî âåðòèêàëè â òàáë ¹4 ,
do StringGrid3.Cells[0,q]:=IntToStr(q);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
for x:=1 to w do // âûáîð âåðîÿòíîñòè èñêëþ÷åíèÿ ðåáåð
begin //x
d:=0; c:=0; c1 :=0; e1:=0; r:=0; t:=0; e3:=0;
C1:= 2*X/100;
S1[5,x] := c1;
for i3 := 1 to w do begin
s[1,x] :=0;
end;
for j:= 1 to p do //ïîâòîð äëÿ ñòàòèñòèêè
begin
d:=0; c:=0; c1 :=0; e1:=0; r:=0; t:=0; e3:=0;
for i5 :=1 to w do
s[1,i5] :=0;
for i0:=1 to n do begin
begin
h:= random (100)+1;
if (2*x) >=h then
begin
s[1,i0] :=1;
s1[3,x] := s1[3,x] +1;
if ((x=x1) and (j = p1) ) then
s3[1,i0] := s[1,i0] ;
if ((x=x2) and (j = p2) ) then
s3[2,i0] := s[1,i0];
if ((x=x3) and (j = p3) ) then
s3[3,i0] := s[1,i0] ;
if ((x=x4) and (j = p4) ) then
s3[4,i0] := s[1,i0] ;
end;
end;
///
Form1.Caption:=IntToStr(GetTickCount-Tick);
for i1:=1 to n do
if s[1,i1] =1 then
begin r:=i1; break
end ;
if j = yy then s2[1,x] := r;
if r<n then
for i2:=r+1 to n do
if (s[1,i2] =1) then
begin t:=i2; end;
if j = yy then s2[2,x] := t;
///
end;
if ((t>0) and (r>0)) and (t>r) then
begin
d:= t-r;
s2[3,x] :=d;
s1[1,x] := d + s1[1,x];
t:=0; r:=0;
end ;
end;
end;
for i:=1 to w do begin
s1[2,i] := s1[1,i]/p;
s1[4,i] := s1[3,i]/p;
end;
for a:=1 to n do
StringGrid3.Cells[a,1]:= IntToStr(s3[1,a]) ;
for b:=1 to n do
StringGrid3.Cells[b,2]:= IntToStr(s3[2,b]) ;
for a1:=1 to n do
StringGrid3.Cells[a1,3]:= IntToStr(s3[3,a1]) ;
for b1:=1 to n do
StringGrid3.Cells[b1,4]:= IntToStr(s3[4,b1]) ;
for i0:=1 to w do begin
StringGrid2.Cells[i0,1]:= FormatFloat('0.000',s1[1,i0]) ;
StringGrid2.Cells[i0,2]:= FormatFloat('0.00000',s1[2,i0]) ;
StringGrid2.Cells[i0,3]:= FormatFloat('0.000',s1[3,i0]) ;
StringGrid2.Cells[i0,4]:= FormatFloat('0.00000',s1[4,i0]) ;
StringGrid2.Cells[i0,5]:= FormatFloat('0.000',s1[5,i0]) ;
end;
for i0:=1 to w do begin
StringGrid4.Cells[i0,1]:= IntToStr(s2[1,i0]) ;
StringGrid4.Cells[i0,2]:= IntToStr(s2[2,i0]) ;
StringGrid4.Cells[i0,3]:= IntToStr(s2[3,i0]) ;
end;
Edit1.Text := 'd='+'---' +IntToStr(d) +' ' +
't='+'---' +IntToStr(t) +' ' +
'r='+'---' +IntToStr(r) +' ' +
'f='+'--- ' +IntToStr(f) +' ' +
'f1='+'--- ' +IntToStr(f1) +' ' +
'c='+'---' + FormatFloat('0.00',c) +' ' +
's[1,1]='+'---' + IntToStr(s[1,1])+' ' +
's[1,2]='+'---' + IntToStr(s[1,2]) +' ' +
's[1,3]='+'---' + IntToStr(s[1,3]) +' ' +
's1[,1]='+'---' + FormatFloat('0.00',s1[1,1]) +' ' +
's1[1,w]='+'---' + FormatFloat('0.00',s1[1,w])
+' ' +
's[2,1]='+'---' + FormatFloat('0.00',s[2,1]) ;
Edit2.Text :=
'e3='+'---'+IntToStr(e3)+' ' +
'c2='+'---'+FormatFloat('0.00',c2) +' ' +
't1='+'---' +IntToStr(t1) +' ' +
'r1='+'---' +IntToStr(r1)+' ' +
'd1='+'---' +IntToStr(d1) +' ' +
'x='+'---' +IntToStr(x) +' ' +
'j='+'---' +IntToStr(j)+' ' +
'z='+'---' +FormatFloat('0.000',z) +' ' +
'z1='+'---' + FormatFloat('0.000',z1)
+' ' +
's1[2,40]='+'---' + FormatFloat('0.000',s1[2,40]) ;
Edit4.Text := 'n='+'---'+IntToStr(n)+' ' +
'p='+'---' +IntToStr(p) +' ' +
'w='+'---'+IntToStr(w) +' ' +
'x1='+'---' +IntToStr(x1) +' ' +
'p1='+'---'+IntToStr(p1) +' ' +
'x2='+'---' +IntToStr(x2) +' ' +
'p2='+'---'+IntToStr(p2) +' ' +
'z='+'---'+FormatFloat('0.0000',z)
+' ' +
'ff='+'---'+IntToStr(ff) +' ' +
'gg='+'---' +IntToStr(gg) +' ' +
'pp='+'---' +IntToStr(pp);
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
end;
///////// ///////////////////////////////////////////////////////
procedure TForm1.Button5Click(Sender: TObject);
begin
close
end;
initialization
randomize;
end.