Tarmoq texnologiyalari va administrlashtirish


Download 65.5 Kb.
bet2/2
Sana23.04.2023
Hajmi65.5 Kb.
#1387790
1   2
Bog'liq
dep-materiallar-varaq (1)

set
{
usul = value;
}
}
public Tarmoq_texnologiyalari (int n, int m, DataGridView dga, DataGridView dgb, DataGridView dgc, DataGridView dgg, TextBox t1,TextBox t2, TextBox t3, TextBox t4)
{
this.n = n;
this.m = m;
this.dga = dga;
this.dgb = dgb;
this.dgc = dgc;
this.dgg = dgg;
this.text1 = t1;
this.text2 = t2;
this.text3 = t3;
this.text4 = t4;
a = new double[m];
u = new double[m];
b = new double[n+1];
v = new double[n + 1];
c = new double[m, n+1];
c1 = new double[m, n + 1];
delta = new double[m, n + 1];
usul = 1;
dgg.RowCount = m;
dgg.ColumnCount = n;
x = new double[m, n+1];
dga.RowCount = m;
for (i = 0; i < m; i++)
{
dga.Rows[i].Cells[0].Value = i + 1;
}
dgb.RowCount = n;
for (i = 0; i < n; i++)
{
dgb.Rows[i].Cells[0].Value = i + 1;
}
dgc.Columns.Clear();
dgc.RowCount = m ;

dgc.ColumnCount = n ;
}
//Ma'lumotlarni o'qish
public void Read()
{
for (i = 0; i < m; i++)
{
a[i] = Convert.ToInt32(dga.Rows[i].Cells[1].Value);
u[i] = 0;
}
for (i = 0; i < n; i++)
{
b[i] = Convert.ToInt32(dgb.Rows[i].Cells[1].Value);
v[i] = 0;
}
for (i = 0; i
for (j = 0; j
{
c[i,j]= Convert.ToInt32(dgc.Rows[i].Cells[j].Value);
c1[i, j] = c[i, j];
delta[i, j] = 0;

x[i, j] = 0;
}


}
public int ochiq_model()
{
double s1 = 0, s2 = 0;
foreach (int k in a) s1 += k;
foreach (int k in b) s2 += k;
if (s1 == s2) return 2;
else if (s1 > s2)
{
b[n] = s1 - s2;
dgb.RowCount += 1;
dgb.Rows[n].Cells[1].Value = b[n];
dgb.Rows[n].Cells[0].Value = n+1;
dgc.ColumnCount += 1;
dgc.Rows[0].Cells[n ].Value = n+1;
for (i = 0; i < m; i++)
{
c[i, n] = 0;
dgc.Rows[i].Cells[n].Value = 0;
}
dgg.ColumnCount += 1;
n++;
//v[n] = 0;

ochiq_m = true;
return 1;
}
else return 0;
}

public double Shimoliy_garb()
{
i = 0; j = 0;
while (i < m || j < n)
{
if (a[i] == b[j])
{
x[i, j] = b[j];
a[i] = 0; b[j] = 0;
if (i == m - 1 && j == n - 1) goto q;
if (j != n - 1) j++;
else { for (; i < m; i++) x[i, j] = a[i]; goto q; }

if (i != m - 1) i++;
else { for (; j < n; j++) x[i, j] = b[j]; goto q; }
}

else if (a[i] > b[j])
{
x[i, j] = b[j];

a[i] -= b[j];
b[j] = 0;

if (j != n - 1) j++;
else { for (; i < m; i++) x[i, j] = a[i]; goto q; }
}

else
{
x[i, j] = a[i];
b[j] -= a[i];
a[i] = 0;
if (i != m - 1) i++;
else { for (; j < n; j++) x[i, j] = b[j]; goto q; }
}
}
q:
double s = 0;
for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
{
dgg.Rows[i].Cells[j].Value = x[i, j];
s += x[i, j] * c[i, j];
}

return s;

}
public void Min(out int i1,out int j1)
{ double min;
for (i = 0; i < m; i++)
{
if (a[i] != 0)
for (j = 0; j < n; j++)
{
if (b[j] != 0 && c1[i,j]>0)
{
min = c1[i, j];
i1 = i;
j1 = j;
goto p;
}
else if (b[j] != 0 && c1[i, j] == 0 && ochiq_m)
{
min = c1[i, j];
i1 = i;
j1 = j;
goto p;
}
else continue;
}
else continue;
}

i1 = -1;
j1 = -1;
return;
p:
for (i = 0; i < m; i++)
{
if (a[i] != 0)
for (j = 0; j < n; j++)
{
if (b[j] != 0)
{
if (min > c1[i, j] && c1[i, j] > 0)
{
min = c1[i, j];
i1 = i;
j1 = j;
}
else if ( c1[i, j] == 0 && ochiq_m)
{
min = c1[i, j];
i1 = i;
j1 = j;
}
}
else continue;
}
else continue;
}
}

public double Minimal_xarajat()
{
int k=0,l = 0;
while (k!=-1 && l!=-1)
{
Min(out k, out l);
if (k != -1 && l != -1)
{
if (a[k] == b[l])
{
x[k, l] = b[l];
a[k] = 0;
b[l] = 0;
}
else if (a[k] > b[l])
{
x[k, l] = b[l];
a[k] -= b[l];
b[l] = 0;
}
else
{
x[k, l] = a[k];
b[l] -= a[k];
a[k] = 0;
}
}
}
double s = 0;
for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
{
dgg.Rows[i].Cells[j].Value = x[i, j];
s += x[i, j] * c[i, j];
}

return s;

}
public void Set_U_V()
{
u[0] = 0;
v[0] = c[0, 0];

for (i = 0; i < u.Length; i++)
for (j = 0; j < v.Length; j++)
{
if (x[i, j] != 0)
{
if (i == 0 ) v[j] = c[i, j];
else
{
if (u[i] != 0 && v[j]==0) v[j] = c[i, j] - u[i];
if (v[j] != 0 && u[i]==0) u[i] = c[i, j] - v[j];
}

}
}
for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
if(x[i,j]==0)delta[i, j] = u[i] + v[j];

}

private bool optimal_Reja(out int i1, out int j1)
{
i1 = 0; j1 = 0;
for(i=0;i
for(j=0;j
if(x[i,j]==0)
if (delta[i, j] - c[i, j] > 0){ i1 = i; j1 = j; return false; }
i1 = 0;
j1 = 0;
return true;
}
public void Max_C_i_j(ref int i, ref int j)
{
// if(optimal_Reja(out i, out j)) return ;

double max = delta[i, j] - c[i, j];
int ii = i, jj = j;
for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
if (x[i, j] == 0)
if (delta[i, j] - c[i, j] > 0 && max< delta[i, j] - c[i, j])
{
ii = i; jj = j;
max = delta[ii, jj] - c[ii, jj];

}
i = ii; j = jj;
}
protected int Yunalish(ref int i1, ref int j1, out int i2, out int j2)
{

i2=0; j2 = 0;
if(i1>0)
{for (int i = i1; i >= 0; i--)
if (x[i, j1] != 0) { i2 = i; break; }
if (j1 < n - 1)
{
for (int j = j1; j < n; j++)
if (x[i1, j] != 0) { j2 = j; break; }
if (i2 != 0 && j2 != 0) return 1;
}
else
{
for (int j = j1; j >0 ; j--)
if (x[i1, j] != 0) { j2 = j; break; }
if (i2 != 0 && j2 != 0) return 2;
}
}
else
{
for (int i = i1; i < m; i++)
if (x[i, j1] != 0) { i2 = i; break; }
if (j1 < n - 1)
{
for (int j = j1; j < n; j++)
if (x[i1, j] != 0) { j2 = j; break; }
if (i2 != 0 && j2 != 0) return 3;
}
else
{
for (int j = j1; j > 0; j--)
if (x[i1, j] != 0) { j2 = j; break; }
if (i2 != 0 && j2 != 0) return 4;
}
return 5;

}


return 0;
}
protected void Optimallashtirish()
{ int i1, i2, j1, j2;
if (!optimal_Reja(out i, out j)) Max_C_i_j(ref i, ref j);
i1 = 1; j1 = j;
Yunalish(ref i1, ref j1, out i2, out j2);
//text1.Text = i1.ToString();
//text2.Text = j1.ToString();
//text3.Text = i2.ToString();
//text4.Text = j2.ToString();
}
public void Potensial()
{Shimoliy_garb();
Set_U_V();

for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
dgg.Rows[i].Cells[j].Value = delta[i, j];
Optimallashtirish();
//text1.Text = i.ToString();
//text2.Text = j.ToString();

double s = 0;
for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
{
dgg.Rows[i].Cells[j].Value = x[i, j];
s += x[i, j] * c[i, j];
}

//for (i = 1; i < u.Length; i++)
//{
// dgg.Rows[i].Cells[0].Value = u[i];
//}
//for (i = 0; i
//{
// dgg.Rows[0].Cells[i].Value = v[i];
//}

}
}
Transport Trans;
public Form1()
{
InitializeComponent();
}

private void BunifuTileButton1_Click(object sender, EventArgs e)
{

}

private void Panel1_Paint(object sender, PaintEventArgs e)
{

}

private void Form1_Load(object sender, EventArgs e)
{
for(int i=1;i<=20;i++)
{
comboBox1.Items.Add(i.ToString());
comboBox2.Items.Add(i.ToString());
} comboBox1.SelectedIndex = 2;
comboBox2.SelectedIndex = 4;
}

private void ComboBox1_SelectedValueChanged(object sender, EventArgs e)
{
}

private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}

private void ComboBox1_TextChanged(object sender, EventArgs e)
{


}

private void ComboBox1_SelectionChangeCommitted(object sender, EventArgs e)
{
}

private void Button1_Click(object sender, EventArgs e)
{
int m, n;
if (comboBox1.Text != "") m = Convert.ToInt32(comboBox1.Text);
else m = 1;
if (comboBox2.Text != "")n = Convert.ToInt32(comboBox2.Text);
else n= 1;
Trans = new Transport(n, m, dga, dgb, dgc,dgg,textBox1,textBox2,textBox3,textBox4);
}

private void ComboBox1_TextUpdate(object sender, EventArgs e)
{


}

private void ComboBox2_TextChanged(object sender, EventArgs e)
{
}

private void Button2_Click(object sender, EventArgs e)
{
Trans.Read();
if (Trans.ochiq_model() == 1) comboBox2.SelectedIndex += 1;
else if (Trans.ochiq_model() == 0) MessageBox.Show("Qiymatlar noto'g'ri kiritildi!!!");

if (Trans.Usul == 1) textBox1.Text = Trans.Shimoliy_garb().ToString();
else if (Trans.Usul == 2)
textBox1.Text = Trans.Minimal_xarajat().ToString();

else if (Trans.Usul == 3) Trans.Potensial();
}

private void AsdToolStripMenuItem_Click(object sender, EventArgs e)
{

}

private void ShimoliyGarbUsuliToolStripMenuItem_Click(object sender, EventArgs e)
{
Trans.Usul = 1;
}

private void MinimalXarajatlarToolStripMenuItem_Click(object sender, EventArgs e)
{
Trans.Usul = 2;
}

private void PotensialarUsuliToolStripMenuItem_Click(object sender, EventArgs e)
{
Trans.Usul = 3;
}

private void RadioButton3_CheckedChanged(object sender, EventArgs e)
{
Trans.Usul = 2;
}

private void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
Trans.Usul = 1;
}

private void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
Trans.Usul = 3;
}

private void Label1_Click(object sender, EventArgs e)
{

}
}
}


Download 65.5 Kb.

Do'stlaringiz bilan baham:
1   2




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling