-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
160 lines (121 loc) · 5.14 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using Microsoft.SolverFoundation.Services;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Рассчет_Чечкина
{
public partial class Form1 : Form
{
Splav st = new Splav();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void tabPage2_Click(object sender, EventArgs e)
{
}
private void bt_Ras_Click(object sender, EventArgs e)
{
if (
#region---
(tb_Cu1.Text == "") ||
(tb_Cu2.Text == "") ||
(tb_Sn1.Text == "") ||
(tb_Sn2.Text == "") ||
(tb_Zn1.Text == "") ||
(tb_Zn2.Text == "") ||
(tb_St1.Text == "") ||
(tb_St2.Text == ""))
#endregion---
{
Grafick.Parent = null;
MessageBox.Show("Не все поля заполнены!", "Ошибка");
return;
}
else
{
Grafick.Parent = tabControl1;
chart1.Series[0].Points.Clear();
chart1.Series[1].Points.Clear();
st.Cu1 = Double.Parse(tb_Cu1.Text);
st.Cu2 = Double.Parse(tb_Cu2.Text);
st.Sn1 = Double.Parse(tb_Sn1.Text);
st.Sn2 = Double.Parse(tb_Sn1.Text);
st.Zn1 = Double.Parse(tb_Zn1.Text);
st.Zn2 = Double.Parse(tb_Zn2.Text);
st.St1 = Double.Parse(tb_St1.Text);
st.St2 = Double.Parse(tb_St2.Text);
List<SolverRow> solverList = new List<SolverRow>();
solverList.Add(new SolverRow { xId = 1, Koef = st.Ras_Sp1 });
solverList.Add(new SolverRow { xId = 2, Koef = st.Ras_Sp2 });
SolverContext context = SolverContext.GetContext();
Model model = context.CreateModel();
Set users = new Set(Domain.Any, "users");
Parameter Koef = new Parameter(Domain.Real, "Koef", users);
Koef.SetBinding(solverList, "Koef", "xId");
model.AddParameter(Koef);
Decision choose = new Decision(Domain.RealNonnegative, "choose", users);
model.AddDecisions(choose);
model.AddGoal("goal", GoalKind.Minimize, Model.Sum(Model.ForEach(users, xId => choose[xId] * Koef[xId])));
model.AddConstraint("Ogran1", Model.Sum(Model.ForEach(users, xId => (st.Cu1* st.Ras_Sp1 + st.Cu2 * st.Ras_Sp2)*0.01 ))<=2 );
model.AddConstraint("Ogran2", Model.Sum(Model.ForEach(users, xId => (st.Sn1 * st.Ras_Sp1 + st.Sn2 * st.Ras_Sp2)*0.01)) <= 1000);
model.AddConstraint("Ogran3", Model.Sum(Model.ForEach(users, xId => (st.Zn1 * st.Ras_Sp1 + st.Zn2 * st.Ras_Sp2) * 0.01)) <=12.8 );
try
{
Solution solution = context.Solve();
Report report = solution.GetReport();
String reportStr = "";
for (int i = 0; i < solverList.Count; i++)
{
reportStr += "Значение X" + (i + 1).ToString() + ": " + choose.GetDouble(solverList[i].xId) + "\n";
}
reportStr += "\n" + report.ToString();
}
catch (Exception ex)
{
MessageBox.Show("При решении задачи оптимизации возникла исключительная ситуация.");
}
double Ras_Sp1 = Math.Round(choose.GetDouble(solverList[0].xId), 3);
double Ras_Sp2 = Math.Round(choose.GetDouble(solverList[1].xId), 3);
this.chart1.Series[0].Points.AddXY("", st.Ras_Sp1);
this.chart1.Series[1].Points.AddXY("", st.Ras_Sp2);
dataGridView1.Rows.Add(st.Ras_Sp1,st.Ras_Sp2,st.Ras_O_St);
}
}
private void Form1_Load_1(object sender, EventArgs e)
{
Grafick.Parent = null;
tb_Cu1.Text = "10";
st.Cu1 = 10d;
tb_Cu2.Text = "10";
st.Cu2 = 10d;
tb_Sn1.Text = "10";
st.Sn1 = 10d;
tb_Sn2.Text = "30";
st.Sn2 = 30d;
tb_Zn1.Text = "80";
st.Zn1 = 80d;
tb_Zn2.Text = "60";
st.Zn2 = 60d;
tb_St1.Text = "4";
st.St1 = 4d;
tb_St2.Text = "6";
st.St2 = 6d;
st.Ras_Sp1 = 10.5d;
st.Ras_Sp2 = 6.5d;
st.Ras_O_St = 81d;
tb_Kl_sp1.Text = "10.5";
tb_Kl_sp2.Text = "6.5";
tb_Ob.Text = "81";
}
}
}