Смекни!
smekni.com

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

GetOtk(L_kp_min,L_kp_max);

L_kp_dsp = Math.Pow(L_kp_otk,2);

tn_min[n]=L_kp_min; tn_max[n]=L_kp_max; tn_avg[n]=L_kp_avg;

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

{

tn_min[n-i+1]=L_kp_min-MaxPath(C_rev_min, P_rev_min, 1, i);

tn_max[n-i+1]=L_kp_max-MaxPath(C_rev_max, P_rev_max, 1, i);

tn_avg[n-i+1]=L_kp_avg-MaxPath(C_rev_avg, P_rev_avg, 1, i);

}

label4.Text="На критическом пути расположены следующие вершины: ";

label5.Text="На критическом пути расположены следующие вершины: ";

label6.Text="На критическом пути расположены следующие вершины: ";

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

{

R_min[i]=tn_min[i]-tp_min[i];

R_max[i]=tn_max[i]-tp_max[i];

R_avg[i]=tn_avg[i]-tp_avg[i];

if(R_min[i]==0)

label4.Text+=i.ToString()+" ";

if(R_max[i]==0)

label5.Text+=i.ToString()+" ";

if(R_avg[i]==0)

label6.Text+=i.ToString()+" ";

}

tpn_min = new double[n+1,n+1]; tpn_max = new double[n+1,n+1];

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

tnn_min = new double[n+1,n+1]; tnn_max = new double[n+1,n+1];

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

tpo_min = new double[n+1,n+1]; tpo_max = new double[n+1,n+1];

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

tno_min = new double[n+1,n+1]; tno_max = new double[n+1,n+1];

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

Rn_min = new double[n+1,n+1]; Rn_max = new double[n+1,n+1];

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

Rcb_min = new double[n+1,n+1]; Rcb_max = new double[n+1,n+1];

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

/*nij =

*/GetPar(C_min,tp_min,tn_min,tpn_min,tpo_min,tno_min,tnn_min,

Rn_min,Rcb_min);

ShowGrid2(dataGrid2,C_min,tpn_min, tpo_min, tnn_min, tno_min,

Rn_min, Rcb_min);

/*nij =

*/GetPar(C_max,tp_max,tn_max,tpn_max,tpo_max,tno_max,tnn_max,

Rn_max,Rcb_max);

ShowGrid2(dataGrid3,C_max,tpn_max, tpo_max, tnn_max, tno_max,

Rn_max, Rcb_max);

GetPar(C_avg,tp_avg,tn_avg,tpn_avg,tpo_avg,tno_avg,tnn_avg,

Rn_avg,Rcb_avg);

ShowGrid2(dataGrid4,C_avg,tpn_avg, tpo_avg, tnn_avg, tno_avg,

Rn_avg, Rcb_avg);

k=(int)(1+3.32*Math.Log10(n));

MainStatistics(Li,out Mx,out S2x,out Sx,out X_2);

label7.Text="Матожидание T_kp="+String.Format("{0:F2}",Mx);

label8.Text="Дисперсия T_kp = "+String.Format("{0:F2}",S2x);

label9.Text="Ср. кв. от. T_kp="+String.Format("{0:F2}",Sx);

label10.Text="Хіквадрат ="+String.Format("{0:F2}",X_2)+

", число ступеней свободы v="+v.ToString();

}

private void MainStatistics(ArrayList x,out double Mx,out double

S2x,out double Sx,out double X_2)

{

int i, j;

double /*m2, m4,*/ x_max, x_min, h;

FileStream f = new FileStream("test.xls",FileMode.Create);

StreamWriter w = new StreamWriter(f);

int []n_ = new int[k+1];

double []p_ = new double [k+1];

double []x_cp = new double [k+1];

Mx=0; S2x=0; Sx=0;

x_max=Convert.ToDouble(x[0]);

x_min=Convert.ToDouble(x[0]);

for(i=0; i<x.Count; i++)

{

if( x_max < Convert.ToDouble(x[i]))

x_max=Convert.ToDouble(x[i]);

if( x_min > Convert.ToDouble(x[i]))

x_min=Convert.ToDouble(x[i]);

}

h=(x_max-x_min)/k;

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

{

p_[j]=0;

n_[j]=0;

x_cp[j]=x_min+h*(j-1)+h/2;

}

n_[1]=1;

for(i=0; i<x.Count; i++)

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

if ((Convert.ToDouble(x[i]) > x_min+(j-1)*h) &&

(Convert.ToDouble(x[i]) <= x_min+j*h) )

{

n_[j]++;

break;

}

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

Mx=Mx+x_cp[i]*n_[i];

Mx=Mx/x.Count;

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

S2x=S2x+Math.Pow(x_cp[i]-Mx,2)*n_[i];

S2x=S2x/(x.Count-1);

Sx=Math.Sqrt(S2x);

X_2=0;

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

{

p_[j]=h*Math.Exp(-Math.Pow(x_cp[j]-Mx,2)/(2*S2x))/(

Math.Sqrt(2*Math.PI)*Sx);

w.WriteLine(x_cp[j].ToString()+"&bsol;t"+p_[j].ToString());

X_2=X_2+Math.Pow(n_[j]-p_[j]*x.Count,2)/(p_[j]*x.Count);

}

v = k-3;

w.Close(); f.Close();

}

private void DrawGant(Graphics g,/*int n_ij,*/double [,]C,

double [,]tpn,double [,]tpo,double [,]tno,double [,]tnn)

{

int i,j;

Pen pn = new Pen(Color.Black);

Pen p = new Pen(Color.Black);

Pen p1 = new Pen(Color.Green,ht);

Pen p2 = new Pen(Color.Red,ht);

Font fnt = new Font("Courier New",ht);

SolidBrush sbr = new SolidBrush(Color.Black);

int dy=17;

float y0,y1,y2,x0,x1,x2,yn,xn;

x0=10; y0=10;

x1=x0; y1=y0;

double max = GetMax(tno);

double dx = max/ 10;

double sx=0;

xn=x0+(float)max*mx;

yn=m-1+dy*n_ij;

pn.EndCap = LineCap.ArrowAnchor;

g.DrawLine(pn,x0,yn,xn,yn);

g.DrawString("Работы",fnt,sbr,x0,y0-10);

//g.DrawString(max.ToString(),fnt,sbr,x0+(float)max*mx,yn);

for(i=0; i<=10; i++)

{

if(i<10)g.DrawLine(p,x0+(float)sx*mx,yn-2,

x0+(float)sx*mx,yn+2);

g.DrawString(String.Format("{0:F2}",sx),fnt,sbr,

x0+(float)sx*mx,yn);

sx+=dx;

}

g.DrawLine(pn,x0,yn,x0,y0);

g.DrawString("Время",fnt,sbr,xn+(float)dx*mx,yn);

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

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

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

{

x1=x0+(float)tpn[i,j]*mx;

x2=x1+(float)C[i,j]*mx;

y1+=dy; y2=y1;

g.DrawLine(p1,x1,y1,x2,y2);

if(tpo[i,j]!=tno[i,j])

{

x1=x2;

x2=x1+(float)(tno[i,j]-tpo[i,j])*mx;

g.DrawLine(p2,x1,y1,x2,y2);

}

g.DrawString(i.ToString()+"-

"+j.ToString(),fnt,sbr ,x2,y2-ht);

}

}

private void pictureBox1_Paint(object sender,

System.Windows.Forms.PaintEventArgs e)

{

Graphics g = e.Graphics;

DrawGant(g,/*nij,*/C_min,tpn_min,tpo_min,tno_min,tnn_min);

}

private void pictureBox2_Paint(object sender,

System.Windows.Forms.PaintEventArgs e)

{

Graphics g = e.Graphics;

DrawGant(g,/*nij,*/C_max,tpn_max,tpo_max,tno_max,tnn_max);

}

private void pictureBox3_Paint(object sender,

System.Windows.Forms.PaintEventArgs e)

{

Graphics g = e.Graphics;

DrawGant(g,/*nij,*/C_avg,tpn_avg,tpo_avg,tno_avg,tnn_avg);

}

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

{

Process.Start("test.xls");

}

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

{

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

FileStream f =new FileStream("tavg.xls",FileMode.Create);

StreamWriter w = new StreamWriter(f);

w.WriteLine("Код i,j&bsol;tt(i,j)&bsol;ttpn(i,j)&bsol;ttpo(i,j)&bsol;ttnn(i,j)&bsol;ttno(i,j)&bsol;t

Rn(i,j)&bsol;tRcb(i,j)");

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

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

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

{

w.WriteLine(i.ToString()+"-

"+j.ToString()+"&bsol;t"+C_avg[i,j]+"&bsol;t"+tpn_avg[i,j]+"&bsol;t"+

tpo_avg[i,j]+"&bsol;t"+tnn_avg[i,j]+"&bsol;t"+tno_avg[i,j]+"&bsol;t"+

Rn_avg[i,j]+"&bsol;t"+Rcb_avg[i,j]);

}

w.Close();

f.Close();

DialogResult result = MessageBox.Show(

"Просмотретьотчет?","",MessageBoxButtons.YesNo);

if(result==DialogResult.Yes)

Process.Start("tavg.xls");

}

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

{

int n = (int)Math.Sqrt(C_min.Length)-1;

FileStream f =new FileStream("tmin.xls",FileMode.Create);

StreamWriter w = new StreamWriter(f);

w.WriteLine("Код i,j&bsol;tt(i,j)&bsol;ttpn(i,j)&bsol;ttpo(i,j)&bsol;ttnn(i,j)&bsol;ttno(i,j)&bsol;t

Rn(i,j)&bsol;tRcb(i,j)");

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

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

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

{

w.WriteLine(i.ToString()+"-"+j.ToString()+"&bsol;t"+

C_min[i,j]+"&bsol;t"+tpn_min[i,j]+"&bsol;t"+tpo_min[i,j]+"&bsol;t"+

tnn_min[i,j]+"&bsol;t"+tno_min[i,j]+"&bsol;t"+Rn_min[i,j]+"&bsol;t"+Rcb_min[i,j]);

}

w.Close();

f.Close();

DialogResult result = MessageBox.Show(

"Просмотретьотчет?","",MessageBoxButtons.YesNo);

if(result==DialogResult.Yes)

Process.Start("tmin.xls");

}

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

{

int n = (int)Math.Sqrt(C_max.Length)-1;

FileStream f =new FileStream("tmax.xls",FileMode.Create);

StreamWriter w = new StreamWriter(f);

w.WriteLine("Код i,j&bsol;tt(i,j)&bsol;ttpn(i,j)&bsol;ttpo(i,j)&bsol;ttnn(i,j)&bsol;ttno(i,j)&bsol;t

Rn(i,j)&bsol;tRcb(i,j)");

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

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

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

{

w.WriteLine(i.ToString()+"-"+j.ToString()+"&bsol;t"+

C_max[i,j]+"&bsol;t"+tpn_max[i,j]+"&bsol;t"+tpo_max[i,j]+"&bsol;t"+tnn_max[i,j]+"&bsol;t"+tno_max[i,j]+"&bsol;t"+Rn_max[i,j]+"&bsol;t"+Rcb_max[i,j]);

}

w.Close();

f.Close();

DialogResult result = MessageBox.Show(

"Просмотретьотчет?","",MessageBoxButtons.YesNo);

if(result==DialogResult.Yes)

Process.Start("tmax.xls");

}

}

}