1、using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace 灵敏度分析尝试 { public partial class Form1 : Form { public Form1() {
2、 InitializeComponent(); } public bool jiansuo(double x, double[] y) { bool cunzai = false; ; for (int i = 0; i < y.Length; i++) if (y[i] == x) cunzai = true; return cunzai; }
3、 public double qiumax(List
4、double qiumin(List 5、Click(object sender, EventArgs e)
{
if (dataGridView1.Columns.Count > 0 || dataGridView2.Columns.Count > 0 || dataGridView3.Columns.Count > 0 || dataGridView4.Columns.Count > 0 || dataGridView5.Columns.Count > 0)
{
dataGridView1.Columns.Clear();
6、 dataGridView2.Columns.Clear();
dataGridView3.Columns.Clear();
dataGridView4.Columns.Clear();
dataGridView5.Columns.Clear();
}
if (dataGridView1.Rows.Count > 0 || dataGridView2.Rows.Count > 0 || dataGridVi 7、ew4.Rows.Count > 0 || dataGridView5.Rows.Count > 0)
{
dataGridView1.Rows.Clear();
dataGridView2.Rows.Clear();
dataGridView3.Rows.Clear();
dataGridView4.Rows.Clear();
dataGridView2.Rows.Clear();
8、 }
int m, n;
m = int.Parse(textBox1production.Text);//m=3
n = int.Parse(textBox2resource.Text);//n=3
for (int i = 1; i <= m + n; i++)
{
dataGridView5.Columns.Add(" ", "C" + i.ToString());
}
9、 for (int i = 1; i <= m + n; i++)
{
dataGridView4.Columns.Add("", "X" + i.ToString());
}
dataGridView4.Rows.Add(n + 1);
dataGridView3.Columns.Add(" ", "C");
dataGridView1.Columns.Add("", "Cb");
dataGridVi 10、ew1.Columns.Add("", "Xb(下标)");
dataGridView1.Columns.Add("", "B-1b");
dataGridView1.Rows.Add(n);
dataGridView2.Columns.Add(" ", "C");
dataGridView2.Rows.Add(1);
}
private void splitContainer3_SplitterMoved(object sender, SplitterE 11、ventArgs e)
{
}
private void splitContainer6_Panel2_Paint(object sender, PaintEventArgs e)
{
}
private void button1产品_Click(object sender, EventArgs e)
{
double[] Xb = new double[dataGridView1.Rows.Count];//用于存放Xb的下标 12、
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (dataGridView1.Rows[i].Cells[1].Value != null)
Xb[i] = double.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString());
}
double[,] A = new double[dataGri 13、dView4.Rows.Count, dataGridView4.Columns.Count];//A矩阵存放后面的
for (int i = 0; i < dataGridView4.Rows.Count; i++)
for (int j = 0; j < dataGridView4.Columns.Count; j++)
{
if (dataGridView4.Rows[i].Cells[j].Value != null)
14、 A[i, j] = double.Parse(dataGridView4.Rows[i].Cells[j].Value.ToString());
}
int pro=0;
if (textBox3输入产品.Text!="")
pro = int.Parse(textBox3输入产品.Text);
if (pro <= 0 || pro > int.Parse(textBox1production.Text)+int.Parse (t 15、extBox2resource .Text))
MessageBox.Show("输入的数据必须大于0小于产品总数+资源数!,请重新输入!");
else
{
if (jiansuo(pro, Xb))
{
List 16、
double zuomax = 0, youmin = 0;
for (int j = 0; j < Xb.Length; j++)
{
if (pro == Xb[j])//pro是基变量,且第i列是非基变量
{
for (int i = 0; i < A.GetLength( 17、1); i++)
{
if (jiansuo(i+1, Xb )==false )
{
double shang = 0;
if (A[j, i] > 0)
18、 {
shang=A[A.GetLength(0) - 1, i] / A[j, i];
zuo.Add(Math.Round (shang,2)); //非基变量的检验数除以Cj(j就是pro)对应的变量Xj那一行
}
if (A[ 19、j, i] < 0)
{
shang = A[A.GetLength(0) - 1, i] / A[j, i];
you.Add(Math.Round (shang,2));
}
20、}
}
}
}
if (zuo.Count > 0)
zuomax = qiumax(zuo);
if (you.Count > 0)
youmin = qiumin(you);
if (zuo.Co 21、unt == 0 && you.Count == 0)
textBox1产品结果.Text = "";
if (zuo.Count > 0 && you.Count == 0)
textBox1产品结果.Text = "产品" + pro + "的变化量>=" + Convert.ToString(zuomax);
if (zuo.Count == 0 && you.Count > 0)
22、 textBox1产品结果.Text = "产品" + pro + "的变化量<=" + Convert.ToString(youmin);
if (zuo.Count > 0 && you.Count > 0)
textBox1产品结果.Text = "产品" + pro + "的变化范围为 " + Convert.ToString(zuomax) + "到" + Convert.ToString(youmin);
}
23、 if (jiansuo(pro, Xb)==false )
{
int hangbiao=dataGridView4.Rows .Count-1;
if (dataGridView4.Rows[hangbiao].Cells[pro-1].Value != null)
{
double jieguo = -(double.Parse(dataGridView4.Rows[han 24、gbiao].Cells[pro -1].Value.ToString()));
textBox1产品结果.Text = "产品" + pro + "的变化量<=" + Convert.ToString(jieguo);
}
}
}
}
private void button资源计算_Click(object sender, EventArgs e)
{
25、 double[] B_1b = new double[dataGridView1.Rows.Count];//用于存放B-1b列;
for (int i = 0; i < dataGridView1.Rows.Count; i++) //给XbB_1b赋值
{
if (dataGridView1.Rows[i].Cells[2].Value != null)
B_1b[i] = double.Parse(d 26、ataGridView1.Rows[i].Cells[2].Value.ToString());
}
int Res = 0;
if (textBox3输入资源.Text != "")
Res = int.Parse(textBox3输入资源.Text);
if (Res <= 0 || Res > int.Parse(textBox2resource.Text))
27、 MessageBox.Show("输入的数据必须大于0小于等于资源数!,请重新输入!");
else
{
double[] Xnaddi = new double[dataGridView4.Rows.Count-1];//用于存放Xnaddi列
for (int i = 0; i < dataGridView4.Rows.Count-1; i++)
if (dataGridView4.Rows[i].Cells[i 28、nt.Parse(textBox1production.Text) + Res-1].Value != null)
Xnaddi[i] = double.Parse(dataGridView4.Rows[i].Cells[int.Parse(textBox1production.Text) + Res-1].Value.ToString());
double shang = 0;
List 29、 List 30、 zuo.Add(Math.Round(shang, 2)); //非基变量的检验数除以Cj(j就是pro)对应的变量Xj那一行
}
if (Xnaddi[i ]< 0)
{
shang = -(B_1b[i]) / Xnaddi[i];
you.Add(Math.Round(shang, 2));
} 31、
}
if (zuo.Count > 0)
zuomax = qiumax(zuo);
if (you.Count > 0)
youmin = qiumin(you);
if (zuo.Count == 0 && you.Count == 0)
textBox2资源结果.Text = "";
if 32、zuo.Count > 0 && you.Count == 0)
textBox2资源结果.Text = "资源" + Res + "的变化量>=" + Convert.ToString(zuomax);
if (zuo.Count == 0 && you.Count > 0)
textBox2资源结果.Text = "资源" + Res + "的变化量<=" + Convert.ToString(youmin);
if (zuo.Count 33、 > 0 && you.Count > 0)
textBox2资源结果.Text = "资源" + Res + "的变化范围为 " + Convert.ToString(zuomax) + "到" + Convert.ToString(youmin);
}
}
private void button1影子价格_Click(object sender, EventArgs e)
{
int m;
m = Conver 34、t.ToInt32(textBox1production.Text );
int n;
n = Convert.ToInt32(textBox2resource.Text );
double [] Aend = new double [dataGridView4.Columns.Count];//A矩阵存放后面的
for (int j = 0; j < dataGridView4.Columns.Count; j++)
if (dataGridView4.Ro 35、ws[dataGridView4.Rows.Count - 1].Cells[j].Value != null)
Aend[j] = double.Parse(dataGridView4.Rows[dataGridView4.Rows.Count - 1].Cells[j].Value.ToString());
int resource = 0;
if (textBox1输入资源.Text != "")
{
36、 resource = int.Parse(textBox1输入资源.Text);
if (resource <= 0 || resource > n)
MessageBox.Show("输入的数据必须大于0小于等于资源数!,请重新输入!");
if (resource > 0 && resource <= n)
{
37、int resource111 = resource + m-1;
double yinzi = Math.Abs(Aend[resource111]);
textBox2影子价格.Text = "资源" + resource111 + "的影子价格为" + Convert.ToString(yinzi);
}
}
}
private void text 38、Box1影子价格_TextChanged(object sender, EventArgs e)
{
}
private void buttonNewSet_Click(object sender, EventArgs e)
{
if (dataGridView6.Rows.Count > 0 || dataGridView6.Columns.Count > 0)
{
dataGridView6.Rows.Clear();
39、 dataGridView6.Columns.Clear();
}
dataGridView6.Columns.Add(" ", "单位利润 ");
for (int i = 1; i <= int.Parse(textBox2resource.Text); i++)
dataGridView6.Columns.Add(" ", "消耗资源 " + i.ToString());
dataGridView6.Rows.Add(1); 40、
}
private void splitContainer9_Panel1_Paint(object sender, PaintEventArgs e)
{
}
private void buttonCount_Click(object sender, EventArgs e)
{
int m, n;
m = int.Parse(textBox1production.Text);//m=3
n = 41、 int.Parse(textBox2resource.Text);//n=3
double[] A = new double[n];//A矩阵存放后面的
for (int j = 0; j < n; j++)
if (dataGridView4.Rows[dataGridView4.Rows.Count - 1].Cells[j+m].Value != null)
A[j] = Math.Abs(double.Parse(dataGridView4.Rows[dat 42、aGridView4.Rows.Count - 1].Cells[j+m].Value.ToString()));
double[] XbN = new double[n+1];
for (int i = 0; i < n+1; i++)
{
if (dataGridView6.Rows[0].Cells[i].Value != null)
XbN[i] = double.Parse(dataGridView6.Rows[0].Cells[i 43、].Value.ToString());
}
double z = XbN[0];
for (int i = 0; i < n; i++)
z = z- A[i] * XbN[i + 1];
if (z > 0)
textBox1.Text = "生产该商品盈利";
else
textBox1.Text = "生产该商品亏本";
}
44、 private void button2_Click(object sender, EventArgs e)
{
int i = 0, j = 0;
if (textBox6i.Text != "" && textBox5j.Text != "")
{
i = int.Parse(textBox6i.Text);
j = int.Parse(textBox5j.Text);
}
45、 if (j <= 0 || j > (int.Parse(textBox1production.Text) + int.Parse(textBox2resource.Text)) || i <= 0 || i > int.Parse(textBox2resource.Text))
MessageBox.Show("输入的产品必须大于0小于产品总数+资源数;输入的资源必须大于0小于资源数!,请输入正确的数字!");
else
{
double shang = 0; 46、
double[] Azuihouyihang = new double[dataGridView4.Columns.Count];
for (int n = 0; n < dataGridView4.Columns.Count; n++)
{
if (dataGridView4.Rows[dataGridView4.Rows.Count - 1].Cells[n].Value != null)
Azu 47、ihouyihang[n] = double.Parse(dataGridView4.Rows[dataGridView4.Rows.Count - 1].Cells[n].Value.ToString());
}
double x = Azuihouyihang[int.Parse(textBox1production.Text) + i - 1];
double y = Azuihouyihang[j - 1];
if (Math.Abs(x) > 0)
48、
{
i = int.Parse(textBox6i.Text);
j = int.Parse(textBox5j.Text);
shang = y / Math.Abs(x);
textBox4Aij结果.Text = "A" + i + j + "的变化量>=" + Convert.ToString(Math.Round(shang, 2));
i = 49、 int.Parse(textBox6i.Text);
j = int.Parse(textBox5j.Text);
}
else
textBox4Aij结果.Text = "A" + i + j + "的变化量为" + "R";
}
}
private void button1产品计算_Click(object sender, EventArgs e)
50、 {
double[] Xb = new double[dataGridView1.Rows.Count];//用于存放Xb的下标;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (dataGridView1.Rows[i].Cells[1].Value != null)
Xb[i] = double.Parse(dataGridView1.Rows[i].Cells[1].
©2010-2025 宁波自信网络信息技术有限公司 版权所有
客服电话:4009-655-100 投诉/维权电话:18658249818