Смекни!
smekni.com

Статистичне моделювання сітьового графіка побудови судна (стр. 7 из 8)

СПИСОК ВИКОРИСТАНОЇ ЛІТЕРАТУРИ

1. Ахо, Альфред, В., Хопкрофт, Джон, Ульман, Джеффи, Д. Структуры данных и алгоритмы.: Пер. с англ.:Уч. пос. – М.: Издательский дом «Вильямс», 2000. – 384 с.: ил. – Парал. тит. англ.

2. Брехов А. М., Волков В. В. Организация судостроительного производства в условиях рынка. – СПб.: Судостроение, 1992. – 224 с., ил.

3. Колде Я. К. Практикум по теории вероятностей и математической статистике: Учеб. пособие для техникумов. – М.: Высш. шк., 1991. – 157 с.: ил.

4. Полковников А.В., Корпоративная система управления проектами, Электронный офис, 1997, Октябрь

5. Полковников А.В., Линия на которой побеждают время, Электронный офис, 1997, Октябрь


Додаток А – Текст программи

usingSystem;

using System.Drawing;

using System.Drawing.Drawing2D;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

using System.IO;

using System.Diagnostics;

namespace WindowsApplication1

{

public class Form1 : System.Windows.Forms.Form

{

private const int mx=5;

private const int ht=8;

private const int zz=130;

private int n,m,k,v;

static int /*nij,*/n_ij;

private double Mx,S2x,Sx,X_2;

private double L_kp_min,L_kp_max,L_kp_avg;

private double L_kp_mat,L_kp_dsp,L_kp_otk;

private System.Windows.Forms.MainMenu mainMenu1;

private System.Windows.Forms.MenuItem menuItem1;

private System.Windows.Forms.MenuItem menuItem2;

private System.Windows.Forms.OpenFileDialog openFileDialog1;

private ArrayList codi,codj,naim,mint,maxt;

private double []tp_min; private double []tp_max; private double []tp_avg;

private double []tn_min; private double []tn_max; private double []tn_avg;

private double []R_min; private double []R_max; private double []R_avg;

private double []r_min; private double []r_max; private double []r_avg;

private double [,]tpn_min; private double [,]tpn_max;

private double [,]tpn_avg;

private double [,]tnn_min; private double [,]tnn_max;

private double [,]tnn_avg;

private double [,]tpo_min; private double [,]tpo_max;

private double [,]tpo_avg;

private double [,]tno_min; private double [,]tno_max;

private double [,]tno_avg;

private double [,]Rn_min; private double [,]Rn_max;

private double [,]Rn_avg;

private double [,]Rcb_min; private double [,]Rcb_max;

private double [,]Rcb_avg;

private double [,]C_min; private double [,]C_max; private double [,]C_avg;

private int [,]P_min; private int [,]P_max; private int [,]P_avg;

private double [,]C_rev_min; private double [,]C_rev_max;

private double [,]C_rev_avg;

private int [,]P_rev_min; private int [,]P_rev_max;

private int [,]P_rev_avg;

private System.Windows.Forms.TabControl tabControl1;

private System.Windows.Forms.TabPage tabPage1;

private System.Windows.Forms.TabPage tabPage2;

private System.Windows.Forms.TabControl tabControl2;

private System.Windows.Forms.TabPage tabPage3;

private System.Windows.Forms.TabPage tabPage4;

private System.Windows.Forms.TabPage tabPage5;

private System.Windows.Forms.TabControl tabControl3;

private System.Windows.Forms.TabPage tabPage6;

private System.Windows.Forms.TabPage tabPage7;

private System.Windows.Forms.TabPage tabPage8;

private System.Windows.Forms.TabControl tabControl4;

private System.Windows.Forms.TabPage tabPage9;

private System.Windows.Forms.TabPage tabPage10;

private System.Windows.Forms.DataGrid dataGrid1;

private System.Windows.Forms.DataGrid dataGrid2;

private System.Windows.Forms.PictureBox pictureBox1;

private System.Windows.Forms.DataGrid dataGrid3;

private System.Windows.Forms.PictureBox pictureBox2;

private System.Windows.Forms.DataGrid dataGrid4;

private System.Windows.Forms.PictureBox pictureBox3;

private System.Windows.Forms.Label label1;

private System.Windows.Forms.Label label2;

private System.Windows.Forms.Label label3;

private System.Windows.Forms.MenuItem menuItem3;

private System.Windows.Forms.MenuItem menuItem4;

private System.Windows.Forms.Label label4;

private System.Windows.Forms.Label label5;

private System.Windows.Forms.Label label6;

private System.Windows.Forms.TabPage tabPage11;

private System.Windows.Forms.Label label7;

private System.Windows.Forms.Label label8;

private System.Windows.Forms.Label label9;

private System.Windows.Forms.PictureBox pictureBox4;

private System.Windows.Forms.Label label10;

private System.Windows.Forms.Button button1;

private System.ComponentModel.Container components = null;

public Form1()

{

InitializeComponent();

}

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

[STAThread]

static void Main()

{

Application.Run(new Form1());

}

static void Read_Data(string FileName,ArrayList codi,ArrayList codj,

ArrayList naim,ArrayList mint,ArrayList maxt)

{

FileStream f = new FileStream(FileName,FileMode.Open);

StreamReader r = new StreamReader(f);

string delimStr = "\t";

char [] delimiter = delimStr.ToCharArray();

string s;

string [] split = null;

codi.Add(0);

codj.Add(0);

naim.Add(0);

mint.Add(0);

maxt.Add(0);

while((s = r.ReadLine())!= null)

{

split = s.Split(delimiter,5);

codi.Add(split[0]);

codj.Add(split[1]);

naim.Add(split[2]);

mint.Add(split[3]);

maxt.Add(split[4]);

}

r.Close();

f.Close();

}

private void ShowGrid1(DataGrid grid,ArrayList codi, ArrayList codj,

ArrayList naim, ArrayList mint, ArrayList maxt)

{

DataTable tab = new DataTable("tabl");

DataColumn c0 = new DataColumn("Кодработы i");

DataColumn c1 = new DataColumn("Кодработы j");

DataColumn c2 = new DataColumn("Наименованиеработы");

DataColumn c3 = new DataColumn("Минимальноевремя t");

DataColumn c4 = new DataColumn("Максимальноевремя t");

tab.Columns.Add(c0);

tab.Columns.Add(c1);

tab.Columns.Add(c2);

tab.Columns.Add(c3);

tab.Columns.Add(c4);

for(int i=1; i<codi.Count; i++)

{

DataRow row = tab.NewRow();

row["Кодработы i"] = codi[i];

row["Код работы j"] = codj[i];

row["Наименование работы"] = naim[i];

row["Минимальное время t"] = mint[i];

row["Максимальное время t"] = maxt[i];

tab.Rows.Add(row);

}

grid.DataSource = tab;

}

private void ShowGrid2(DataGrid grid,double [,]C, double [,]tpn,

double [,]tpo, double [,]tnn, double [,]tno, double [,]Rn, double [,]Rcb)

{

int nn = (int)Math.Sqrt(C_avg.Length)-1;

DataTable tab2 = new DataTable("tabl2");

DataColumn c0 = new DataColumn("Код i,j");

DataColumn c1 = new DataColumn("t(i,j)");

DataColumn c2 = new DataColumn("tpn(i,j)");

DataColumn c3 = new DataColumn("tpo(i,j)");

DataColumn c4 = new DataColumn("tnn(i,j)");

DataColumn c5 = new DataColumn("tno(i,j)");

DataColumn c6 = new DataColumn("Rn(i,j)");

DataColumn c7 = new DataColumn("Rcb(i,j)");

tab2.Columns.Add(c0);

tab2.Columns.Add(c1);

tab2.Columns.Add(c2);

tab2.Columns.Add(c3);

tab2.Columns.Add(c4);

tab2.Columns.Add(c5);

tab2.Columns.Add(c6);

tab2.Columns.Add(c7);

string str;

n_ij=0;

for(int i=1; i<=nn; i++)

for(int j=1; j<=nn; j++)

if(C[i,j]>=0)

{

DataRow row = tab2.NewRow();

row["Код i,j"] = i.ToString()+"-"+j.ToString();

str = String.Format("{0:F2}",C[i,j]);

row["t(i,j)"] = str;

str = String.Format("{0:F2}",tpn[i,j]);

row["tpn(i,j)"] = str;

str = String.Format("{0:F2}",tpo[i,j]);

row["tpo(i,j)"] = str;

str = String.Format("{0:F2}",tnn[i,j]);

row["tnn(i,j)"] = str;

str = String.Format("{0:F2}",tno[i,j]);

row["tno(i,j)"] = str;

str = String.Format("{0:F2}",Rn[i,j]);

row["Rn(i,j)"] = str;

str = String.Format("{0:F2}",Rcb[i,j]);

row["Rcb(i,j)"] = str;

tab2.Rows.Add(row); n_ij++;

}

grid.DataSource = tab2;

}

private void AlgorithmFloyda(double [,]C, int [,]P)

{

int i,j,k;

int nn = (int)Math.Sqrt(C.Length)-1;

double [,]A = new double[nn+1,nn+1];

for(i=1; i<=nn; i++)

for(j=1; j<=nn; j++)

{

A[i,j] = C[i,j];

P[i,j] = 0;

}

for(i=1; i<=nn; i++)

A[i,i] = 0;

for(k=1; k<=nn; k++)

for(i=1; i<=nn; i++)

for(j=1; j<=nn; j++)

if(A[i,k] + A[k,j] >A[i,j])

{

A[i,j]=A[i,k]+A[k,j];

P[i,j]=k;

}

}

private void Path(int [,]P, double [,]C, int i, int j, ref double l,

ref int sec)

{

int k;

k=P[i,j];

if(k!=0)

{

sec=k;

Path(P,C,i, k, ref l, ref sec);

l=l+C[k,j];

Path(P,C,k, j, ref l, ref sec);

}

}

private double MaxPath(double [,]C, int [,]P, int i, int j)

{

double l;int sec_v;

l=0;

sec_v=0;

Path(P,C,i, j,ref l, ref sec_v);

if(sec_v!=0) return l+C[i,sec_v];//между ними min одна вершина –

вторая

else return C[i,j];

}

private double GetMat(double tmin,double tmax,double tver)

{

double avg;

avg = (tmin+4*tver+tmax)/6;

return avg;

}

private double GetDsp(double tmin,double tmax)

{

double Ds;

Ds = 0.4*Math.Pow(tmax-tmin, 2);

return Ds;

}

private double GetOtk(double tmin,double tmax)

{

double ot;

ot = (tmax-tmin)/6;

return ot;

}

private void GetPar(double [,]C, double []tp,double []tn, double [,]tpn,

double [,]tpo, double [,]tno, double [,]tnn, double [,]Rn, double [,]Rcb)

{

for(int i=1; i<=n; i++)

for(int j=1; j<=n; j++)

if(C[i,j]>=0)

{

//ранние сроки начала и окончания работы

tpn[i,j]=tp[i]; tpo[i,j]=tpn[i,j]+C[i,j];

//поздние сроки начала и окончания работы

tno[i,j]=tn[j]; tnn[i,j]=tno[i,j]-C[i,j];

//полный резерв времени работы

Rn[i,j]=tno[i,j]-tpo[i,j];

//свободный резерв времени работы

Rcb[i,j]=tp[j]-tpo[i,j];

}

}

private double GetNorm(Random r)

{

double U1,U2,V1,V2,S,X1,Norm;

l1:

U1 = r.NextDouble();

U2 = r.NextDouble();

V1 = 2*U1-1;

V2 = 2*U2-1;

S = V1*V1+V2*V2;

if(S>=1) goto l1;

X1 = V1*Math.Sqrt(-2*Math.Log(S,Math.E)/S);

Norm = X1;

return Norm;

}

private double GetCC(Random r,double mint,double maxt,ref double Norm)

{

double C;

Norm = GetNorm(r);

C = mint+Norm*(maxt-mint);

return C;

}

private int GetMax(ArrayList codjj)

{

int Max;

Max=0;

for(int i=1; i<codi.Count; i++)

Max=Math.Max(Max,Convert.ToInt32(codjj[i]));

return Max;

}

private double GetMax(double [,]C)

{

double Max;

Max=0;

int nn = (int)Math.Sqrt(C.Length)-1;

for(int i=1; i<=nn; i++)

for(int j=1; j<=nn; j++)

if(C[i,j]>=0)

Max=Math.Max(Max,C[i,j]);

return Max;

}

private void menuItem2_Click(object sender, System.EventArgs e)

{

int i,j;

openFileDialog1.FileName="test.txt";

openFileDialog1.ShowDialog();

codi = new ArrayList();

codj = new ArrayList();

naim = new ArrayList();

mint = new ArrayList();

maxt = new ArrayList();

Read_Data(openFileDialog1.FileName,codi,codj,naim,mint,maxt);

ShowGrid1(dataGrid1,codi,codj,naim,mint,maxt);

n=GetMax(codj);

C_min = new double[n+1,n+1]; C_max = new double[n+1,n+1];

C_avg = new double[n+1,n+1];

P_min = new int[n+1,n+1]; P_max = new int[n+1,n+1];

P_avg = new int[n+1,n+1];

C_rev_min = new double[n+1,n+1]; C_rev_max = new double[n+1,n+1]; C_rev_avg = new double[n+1,n+1];

P_rev_min = new int[n+1,n+1]; P_rev_max = new int[n+1,n+1];

P_rev_avg = new int[n+1,n+1];

ArrayList Li = new ArrayList();

for(int c=0; c<zz; c++)

{

for(i=1; i<=n; i++)

for(j=1; j<=n; j++)

{

C_min[i,j]=-1000;

C_max[i,j]=-1000;

C_avg[i,j]=-1000;

}

Random r = new Random();

m=codi.Count;

double nrm=0;

for(i=1; i<m; i++)

{

C_min[Convert.ToInt32(codi[i]),

Convert.ToInt32(codj[i])]=Convert.ToDouble(mint[i]);

C_max[Convert.ToInt32(codi[i]),

Convert.ToInt32(codj[i])]=Convert.ToDouble(maxt[i]);

C_avg[Convert.ToInt32(codi[i]),

Convert.ToInt32(codj[i])]=GetCC(r,C_min[Convert.ToInt32(codi[i]),Convert.ToInt32(codj[i])],C_max[Convert.ToInt32(codi[i]),Convert.ToInt32(codj[i])],ref nrm);

}

for(i=1; i<=n; i++)

for(j=1; j<=n; j++)

{

C_rev_min[n-j+1,n-i+1]=C_min[i,j];

C_rev_max[n-j+1,n-i+1]=C_max[i,j];

C_rev_avg[n-j+1,n-i+1] = C_avg[i,j];

//GetMat(C_rev_min[n-j+1,n-i+1],C_rev_max[n-j+1,

n-i+1]);

}

AlgorithmFloyda(C_min,P_min);

AlgorithmFloyda(C_rev_min,P_rev_min);

AlgorithmFloyda(C_max,P_max);

AlgorithmFloyda(C_rev_max,P_rev_max);

AlgorithmFloyda(C_avg,P_avg);

AlgorithmFloyda(C_rev_avg,P_rev_avg);

tp_min = new double[n+1]; tp_max = new double[n+1];

tp_avg = new double[n+1];

tn_min = new double[n+1]; tn_max = new double[n+1];

tn_avg = new double[n+1];

R_min = new double[n+1]; R_max = new double[n+1];

R_avg = new double[n+1];

r_min = new double[n+1]; r_max = new double[n+1];

r_avg = new double[n+1];

tp_min[1]=0; tp_max[1]=0; tp_avg[1]=0;

for(i=2; i<=n; i++)

{

tp_min[i]=MaxPath(C_min,P_min,1,i);

tp_max[i]=MaxPath(C_max,P_max,1,i);

tp_avg[i]=MaxPath(C_avg,P_avg,1,i);

}

L_kp_min=tp_min[n]; L_kp_max=tp_max[n]; L_kp_avg = tp_avg[n];

Li.Add(L_kp_avg);

}

label1.Text = "L_kp = "+String.Format("{0:F2}",L_kp_min);

label2.Text = "L_kp = "+String.Format("{0:F2}",L_kp_max);

label3.Text = "L_kp = "+String.Format("{0:F2}",L_kp_avg);

L_kp_mat = GetMat(L_kp_min,L_kp_max,L_kp_avg); L_kp_otk =