Public Class Form1 Public qq As Integer Function NOD As Integer As Int

  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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
Public Class Form1
Public qq, m, n As Integer
Function NOD(a As Integer, b As Integer) As Integer 'Функция нахождения НОД, принимает целые числа
Dim t, d As Integer
a = Math.Abs(a)
b = Math.Abs(b)
If b > a Then
t = b
b = a
a = t
End If
If b <> 0 Then
If a Mod b = 0 Then
NOD = b
Else
d = a Mod b
NOD = NOD(b, d)
End If
Else
NOD = 1
End If
End Function
Function RandFunction(a As Integer, b As Integer) As Integer
Dim tt As Double
tt = Rnd()
RandFunction = Int(a * (1 - tt) + b * tt)
End Function
Function LineFunction(pt1 As ClassPoint, pt2 As ClassPoint) As ClassLine
Dim dd As Integer
Dim lin = New ClassLine With
{
._a1 = pt1._yy - pt2._yy,
._a2 = pt2._xx - pt1._xx,
._b = pt2._xx * pt1._yy - pt2._yy * pt1._xx
}
dd = NOD(NOD(lin._a1, lin._a2), lin._b)
lin._a1 /= dd
lin._a2 /= dd
lin._b /= dd
If lin._b < 0 Then
lin._a1 = -lin._a1
lin._a2 = -lin._a2
lin._b = -lin._b
End If
LineFunction = lin
End Function
Private Sub ОткрытьToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ОткрытьToolStripMenuItem.Click
Dim t, tt As String
OpenFileDialog1.Filter = "*.tex|*.tex"
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
tt = OpenFileDialog1.FileName()
t = My.Computer.FileSystem.ReadAllText(tt)
RichTextBox1.Text = t
End If
End Sub
Private Sub СохранитьToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles СохранитьToolStripMenuItem.Click
Dim t, tt As String
If qq = 1 Then
t = Preamb() + SystLin(1, m, n)
SaveFileDialog1.Filter = "LaTeX файл.tex|*.tex"
SaveFileDialog1.ShowDialog()
tt = SaveFileDialog1.FileName()
Else
t = SystLin(0, m, n)
SaveFileDialog1.Filter = "Текстовый файл (для Maple) .txt|*.txt"
SaveFileDialog1.ShowDialog()
tt = SaveFileDialog1.FileName()
End If
If tt <> Nothing Then
My.Computer.FileSystem.WriteAllText(tt, t, True)
End If
End Sub
Private Sub ОПрограммеToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ОПрограммеToolStripMenuItem.Click
MsgBox("Программа генерации заданий для графического" + Chr(13) +
Chr(10) + "решения задач линейного программирования" + Chr(13) +
Chr(10) + "Разработчик: С.П.Кайгородов", vbOK)
End Sub
Private Sub ВыйтиToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ВыйтиToolStripMenuItem.Click
End
End Sub
Private Function Preamb() 'Функция, печатающая преамбулу документ LaTeX
'вместо класса ncc можно использовать другой класс
Preamb = "\documentclass[a4paper, 12pt, oneside]{ncc}" + Chr(10) +
"\usepackage{amsmath}" + Chr(10) + "\usepackage{amssymb}" + Chr(10) +
"\usepackage{amsfonts}" + Chr(10) + "\usepackage{dsfont}" + Chr(10) +
"\usepackage{latexsym}" + Chr(10) + "\usepackage[T2A]{fontenc}" + Chr(10) +
"\usepackage[cp1251]{inputenc}" + Chr(10) + "\usepackage[russian]{babel}" + Chr(10) +
"\usepackage{graphics}" + Chr(10) + "\usepackage{floatflt}" + Chr(10) +
"\usepackage{indentfirst}" + Chr(10) +
"\textheight = 24cm\textwidth = 17.5cm\footskip = 1.2cm" + Chr(10) +
"\topmargin = -1cm\oddsidemargin = -0.5cm %\columnsep = 2cm" + Chr(10) +
"\begin{document}" + Chr(10) + Chr(13)
End Function
Private Function PointCircle(radius As Integer, phi As Double) As ClassPoint
'Генерация точки с целыми координатами на окружности с центром в начале координат с радиусом r
Dim ptC = New ClassPoint With
{
._xx = Math.Round(radius * Math.Cos(phi)),
._yy = Math.Round(radius * Math.Sin(phi))
}
PointCircle = ptC
End Function
Public Sub DialogVvod()
'Dim n, m As Integer
Do
If TextBox1.Text = "" Then
n = Val(InputBox("Введите число неравенств (больше 1 и меньше 11)", "Ввод числа неравенств системы ограничений"))
Else
n = Int(TextBox1.Text)
End If
Loop Until ((n > 1) And (n < 11))
If TextBox2.Text = "" Then
m = Val(InputBox("Введите число вариантов", "Ввод числа вариантов"))
Else
m = Int(TextBox2.Text)
End If
End Sub
Private Function SystLin(q As Integer, mm As Integer, nn As Integer) As String 'Функция, формирующая систему неравенств
Dim phi(10), phi0 As Double
Dim r, c1, c2 As Integer
Dim lin(10) As ClassLine
Dim pt(10) As ClassPoint
Dim txt, txt1 As String
Dim pt1 = New ClassPoint
Dim pt2 = New ClassPoint
m = mm
n = nn
r = 6
txt = ""
txt1 = ""
Dim pt0 As ClassPoint
For v = 1 To m
txt += Str(v) + ")\\" + Chr(10)
txt += "$$\left\{\begin{array}{rcl}" + Chr(10)
'txt1 -- Формат Maple
txt1 += "inequal({"
phi0 = (1 - Rnd()) * Math.PI / 3 + Rnd() * Math.PI / 6
pt0 = PointCircle(r, phi0)
For i = 1 To n
If n = 2 Then
pt1._xx = pt0._xx + RandFunction(1, 3)
pt1._yy = 0
pt2._xx = 0
pt2._yy = pt0._yy + RandFunction(1, 3)
lin(1) = LineFunction(pt0, pt1)
lin(2) = LineFunction(pt0, pt2)
Else
phi0 = (1 - Rnd()) * Math.PI / 3 + Rnd() * Math.PI / 6
phi(i) = (phi0 + 2 * (i - 1) * Math.PI) / n
pt(i) = PointCircle(r, phi(i))
End If
Next
For i = 1 To n
If n > 2 Then
If i < n Then
lin(i) = LineFunction(pt(i), pt(i + 1))
Else
lin(i) = LineFunction(pt(i), pt(1))
End If
Else
lin(1) = LineFunction(pt0, pt1)
lin(2) = LineFunction(pt0, pt2)
End If
If (lin(i)._a1 = 1) Then
txt += "x_1"
ElseIf (lin(i)._a1 = -1) Then
txt += "-x_1"
ElseIf (lin(i)._a1 = 0) Then
txt += ""
Else
txt = txt + lin(i)._a1.ToString() + "x_1"
End If
If (lin(i)._a2 = 1) Then
txt += "+x_2&\leqslant &" + lin(i)._b.ToString() +
"\\ " + Chr(10) + ""
ElseIf (lin(i)._a2 = -1) Then
txt += "-x_2&\leqslant &" + lin(i)._b.ToString() +
"\\ " + Chr(10) + ""
ElseIf (lin(i)._a2 < 0) Then
txt += lin(i)._a2.ToString() + "x_2 &\leqslant &" +
lin(i)._b.ToString() + "\\" + Chr(10) + ""
ElseIf (lin(i)._a2 = 0) Then
txt += "&\leqslant &" + lin(i)._b.ToString() + "\\ " + Chr(10) + ""
ElseIf ((lin(i)._a1 = 0) And (lin(i)._a2 > 0)) Then
txt += lin(i)._a2.ToString() + "x_2 &\leqslant &" +
lin(i)._b.ToString() + "\\" + Chr(10) + ""
ElseIf ((lin(i)._a1 <> 0) And (lin(i)._a2 > 0)) Then
txt += "+" + lin(i)._a2.ToString() + "x_2 &\leqslant &" +
lin(i)._b.ToString() + "\\" + Chr(10) + ""
ElseIf ((lin(i)._a1 = 0) And (lin(i)._a2 = 0)) Then
txt += ""
End If
txt1 += "(" + Str(lin(i)._a1) + ")*x1+(" + Str(lin(i)._a2) +
")*x2<=" + Str(lin(i)._b) + "," + Chr(10)
Next
txt1 += "},x1=-15..15, x2=-15..15)" + Chr(10) + Chr(13)
txt += "\end{array}\right.$$\\" + Chr(10)
If n = 2 Then
txt += "\\ x_j\geqslant 0, \\" + Chr(10)
End If
c1 = RandFunction(2, 5)
c2 = RandFunction(2, 5)
txt += "$$F=" + Str(c1) + "x_1+" + Str(c2) + "x_2\longrightarrow\max.$$\\" +
Chr(10) + Chr(13)
Next
If q = 1 Then
SystLin = txt + "\end{document}"
Else
SystLin = txt1
End If
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim t As String
DialogVvod()
qq = 1
t = Preamb() + SystLin(qq, m, n)
RichTextBox1.Text = t
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim t As String
DialogVvod()
qq = 0
t = SystLin(qq, m, n)
RichTextBox1.Text = t
End Sub
End Class