灵敏度分析C#程序代码.docx

上传人:scccc 文档编号:12047723 上传时间:2021-12-01 格式:DOCX 页数:16 大小:64.85KB
返回 下载 相关 举报
灵敏度分析C#程序代码.docx_第1页
第1页 / 共16页
灵敏度分析C#程序代码.docx_第2页
第2页 / 共16页
灵敏度分析C#程序代码.docx_第3页
第3页 / 共16页
灵敏度分析C#程序代码.docx_第4页
第4页 / 共16页
灵敏度分析C#程序代码.docx_第5页
第5页 / 共16页
点击查看更多>>
资源描述

《灵敏度分析C#程序代码.docx》由会员分享,可在线阅读,更多相关《灵敏度分析C#程序代码.docx(16页珍藏版)》请在三一文库上搜索。

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() InitializeComponent(); public bool jiansuo(double x, doub

2、le y) bool cunzai = false; ; for (int i = 0; i < y.Length; i+) if (yi = x) cunzai = true; return cunzai; public double qiumax(List<double > array) double max=-9999; for (int i = 0; i <array.Count; i+) if (arrayi > max) max = arrayi; return max; public double qiumin(List<double>

3、array) double min = 9999; for (int i = 0; i <array.Count; i+) if (arrayi < min)推荐精选 min= arrayi; return min; private void button1建立表格_Click(object sender, EventArgs e) if (dataGridView1.Columns.Count > 0 | dataGridView2.Columns.Count > 0 | dataGridView3.Columns.Count > 0 | dataGridVie

4、w4.Columns.Count > 0 | dataGridView5.Columns.Count > 0) dataGridView1.Columns.Clear(); dataGridView2.Columns.Clear(); dataGridView3.Columns.Clear(); dataGridView4.Columns.Clear(); dataGridView5.Columns.Clear(); if (dataGridView1.Rows.Count > 0 | dataGridView2.Rows.Count > 0 | dataGridVie

5、w4.Rows.Count > 0 | dataGridView5.Rows.Count > 0) dataGridView1.Rows.Clear(); dataGridView2.Rows.Clear(); dataGridView3.Rows.Clear(); dataGridView4.Rows.Clear(); dataGridView2.Rows.Clear(); int m, n; m = int.Parse(textBox1production.Text);/m=3 n = int.Parse(textBox2resource.Text);/n=3 for (int

6、 i = 1; i <= m + n; i+) dataGridView5.Columns.Add(" ", "C" + i.ToString(); for (int i = 1; i <= m + n; i+) dataGridView4.Columns.Add("", "X" + i.ToString(); dataGridView4.Rows.Add(n + 1); dataGridView3.Columns.Add(" ", "C"); dataGridV

7、iew1.Columns.Add("", "Cb");推荐精选 dataGridView1.Columns.Add("", "Xb(下标)"); dataGridView1.Columns.Add("", "B-1b"); dataGridView1.Rows.Add(n); dataGridView2.Columns.Add(" ", "C"); dataGridView2.Rows.Add(1); private void spli

8、tContainer3_SplitterMoved(object sender, SplitterEventArgs e) private void splitContainer6_Panel2_Paint(object sender, PaintEventArgs e) private void button1产品_Click(object sender, EventArgs e) double Xb = new doubledataGridView1.Rows.Count;/用于存放Xb的下标; for (int i = 0; i < dataGridView1.Rows.Count

9、; i+) if (dataGridView1.Rowsi.Cells1.Value != null) Xbi = double.Parse(dataGridView1.Rowsi.Cells1.Value.ToString(); double, A = new doubledataGridView4.Rows.Count, dataGridView4.Columns.Count;/A矩阵存放后面的 for (int i = 0; i < dataGridView4.Rows.Count; i+) for (int j = 0; j < dataGridView4.Columns.

10、Count; j+) if (dataGridView4.Rowsi.Cellsj.Value != null) Ai, j = double.Parse(dataGridView4.Rowsi.Cellsj.Value.ToString(); int pro=0; if (textBox3输入产品.Text!="") pro = int.Parse(textBox3输入产品.Text); if (pro <= 0 | pro > int.Parse(textBox1production.Text)+int.Parse (textBox2resource .Te

11、xt)推荐精选 MessageBox.Show("输入的数据必须大于0小于产品总数+资源数!,请重新输入!"); else if (jiansuo(pro, Xb) List<double> zuo = new List<double>(); List<double> you = new List<double>(); double zuomax = 0, youmin = 0; for (int j = 0; j < Xb.Length; j+) if (pro = Xbj)/pro是基变量,且第i列是非基变量 for

12、 (int i = 0; i < A.GetLength(1); i+) if (jiansuo(i+1, Xb )=false ) double shang = 0; if (Aj, i > 0) shang=AA.GetLength(0) - 1, i / Aj, i; zuo.Add(Math.Round (shang,2); /非基变量的检验数除以Cj(j就是pro)对应的变量Xj那一行 if (Aj, i < 0) shang = AA.GetLength(0) - 1, i / Aj, i; you.Add(Math.Round (shang,2); if (zu

13、o.Count > 0) zuomax = qiumax(zuo); if (you.Count > 0) youmin = qiumin(you);推荐精选 if (zuo.Count = 0 && you.Count = 0) textBox1产品结果.Text = "" if (zuo.Count > 0 && you.Count = 0) textBox1产品结果.Text = "产品" + pro + "的变化量>=" + Convert.ToString(zuomax

14、); if (zuo.Count = 0 && you.Count > 0) textBox1产品结果.Text = "产品" + pro + "的变化量<=" + Convert.ToString(youmin); if (zuo.Count > 0 && you.Count > 0) textBox1产品结果.Text = "产品" + pro + "的变化范围为 " + Convert.ToString(zuomax) + "到" +

15、 Convert.ToString(youmin); if (jiansuo(pro, Xb)=false ) int hangbiao=dataGridView4.Rows .Count-1; if (dataGridView4.Rowshangbiao.Cellspro-1.Value != null) double jieguo = -(double.Parse(dataGridView4.Rowshangbiao.Cellspro -1.Value.ToString(); textBox1产品结果.Text = "产品" + pro + "的变化量<

16、=" + Convert.ToString(jieguo); private void button资源计算_Click(object sender, EventArgs e) double B_1b = new doubledataGridView1.Rows.Count;/用于存放B-1b列; for (int i = 0; i < dataGridView1.Rows.Count; i+) /给XbB_1b赋值 if (dataGridView1.Rowsi.Cells2.Value != null) B_1bi = 推荐精选double.Parse(dataGridVi

17、ew1.Rowsi.Cells2.Value.ToString(); int Res = 0; if (textBox3输入资源.Text != "") Res = int.Parse(textBox3输入资源.Text); if (Res <= 0 | Res > int.Parse(textBox2resource.Text) MessageBox.Show("输入的数据必须大于0小于等于资源数!,请重新输入!"); else double Xnaddi = new doubledataGridView4.Rows.Count-1;/用于

18、存放Xnaddi列 for (int i = 0; i < dataGridView4.Rows.Count-1; i+) if (dataGridView4.Rowsi.Cellsint.Parse(textBox1production.Text) + Res-1.Value != null) Xnaddii = double.Parse(dataGridView4.Rowsi.Cellsint.Parse(textBox1production.Text) + Res-1.Value.ToString(); double shang = 0; List<double> zu

19、o = new List<double>(); List<double> you = new List<double>(); double zuomax = 0, youmin = 0; for (int i = 0; i < Xnaddi.Length; i+) if (Xnaddii > 0) shang = -(B_1bi) / Xnaddii; zuo.Add(Math.Round(shang, 2); /非基变量的检验数除以Cj(j就是pro)对应的变量Xj那一行 if (Xnaddii < 0) shang = -(B_1bi)

20、 / Xnaddii; you.Add(Math.Round(shang, 2); if (zuo.Count > 0) zuomax = qiumax(zuo); if (you.Count > 0)推荐精选 youmin = qiumin(you); if (zuo.Count = 0 && you.Count = 0) textBox2资源结果.Text = "" if (zuo.Count > 0 && you.Count = 0) textBox2资源结果.Text = "资源" + Res +

21、 "的变化量>=" + Convert.ToString(zuomax); if (zuo.Count = 0 && you.Count > 0) textBox2资源结果.Text = "资源" + Res + "的变化量<=" + Convert.ToString(youmin); if (zuo.Count > 0 && you.Count > 0) textBox2资源结果.Text = "资源" + Res + "的变化范围为 &qu

22、ot; + Convert.ToString(zuomax) + "到" + Convert.ToString(youmin); private void button1影子价格_Click(object sender, EventArgs e) int m; m = Convert.ToInt32(textBox1production.Text ); int n; n = Convert.ToInt32(textBox2resource.Text ); double Aend = new double dataGridView4.Columns.Count;/A矩阵存放后

23、面的 for (int j = 0; j < dataGridView4.Columns.Count; j+) if (dataGridView4.RowsdataGridView4.Rows.Count - 1.Cellsj.Value != null) Aendj = double.Parse(dataGridView4.RowsdataGridView4.Rows.Count - 1.Cellsj.Value.ToString(); int resource = 0; if (textBox1输入资源.Text != "") resource = int.Par

24、se(textBox1输入资源.Text); if (resource <= 0 | resource > n) MessageBox.Show("输入的数据必须大于0小于等于资源数!,请重新输入!"); if (resource > 0 && resource <= n) int resource111 = resource + m-1; double yinzi = Math.Abs(Aendresource111); textBox2影子价格.Text = "资源" + resource111 + 推荐精选&

25、quot;的影子价格为" + Convert.ToString(yinzi); private void textBox1影子价格_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(); dataGridView6.Columns.Clear

26、(); dataGridView6.Columns.Add(" ", "单位利润 "); for (int i = 1; i <= int.Parse(textBox2resource.Text); i+) dataGridView6.Columns.Add(" ", "消耗资源 " + i.ToString(); dataGridView6.Rows.Add(1); private void splitContainer9_Panel1_Paint(object sender, PaintEventArgs

27、 e) private void buttonCount_Click(object sender, EventArgs e) int m, n; m = int.Parse(textBox1production.Text);/m=3 n = int.Parse(textBox2resource.Text);/n=3 double A = new doublen;/A矩阵存放后面的 for (int j = 0; j < n; j+) if (dataGridView4.RowsdataGridView4.Rows.Count - 1.Cellsj+m.Value != null) Aj

28、= Math.Abs(double.Parse(dataGridView4.RowsdataGridView4.Rows.Count - 1.Cells推荐精选j+m.Value.ToString(); double XbN = new doublen+1; for (int i = 0; i < n+1; i+) if (dataGridView6.Rows0.Cellsi.Value != null) XbNi = double.Parse(dataGridView6.Rows0.Cellsi.Value.ToString(); double z = XbN0; for (int i

29、 = 0; i < n; i+) z = z- Ai * XbNi + 1; if (z > 0) textBox1.Text = "生产该商品盈利" else textBox1.Text = "生产该商品亏本" private void button2_Click(object sender, EventArgs e) int i = 0, j = 0; if (textBox6i.Text != "" && textBox5j.Text != "") i = int.Parse(te

30、xtBox6i.Text); j = int.Parse(textBox5j.Text); 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; doubl

31、e Azuihouyihang = new doubledataGridView4.Columns.Count; for (int n = 0; n < dataGridView4.Columns.Count; n+) if (dataGridView4.RowsdataGridView4.Rows.Count - 1.Cellsn.Value != null)推荐精选 Azuihouyihangn = double.Parse(dataGridView4.RowsdataGridView4.Rows.Count - 1.Cellsn.Value.ToString(); double x

32、 = Azuihouyihangint.Parse(textBox1production.Text) + i - 1; double y = Azuihouyihangj - 1; if (Math.Abs(x) > 0) i = int.Parse(textBox6i.Text); j = int.Parse(textBox5j.Text); shang = y / Math.Abs(x); textBox4Aij结果.Text = "A" + i + j + "的变化量>=" + Convert.ToString(Math.Round(s

33、hang, 2); i = int.Parse(textBox6i.Text); j = int.Parse(textBox5j.Text); else textBox4Aij结果.Text = "A" + i + j + "的变化量为" + "R" private void button1产品计算_Click(object sender, EventArgs e) double Xb = new doubledataGridView1.Rows.Count;/用于存放Xb的下标; for (int i = 0; i < dataGridView1.Rows.Count; i+) if (dataGridView1.Rowsi.Cells1.Value !=

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1