Skip to content

Commit 9aadb56

Browse files
#TDP - 1 Modeling work machine
Add solution author solution: Povilika310121
1 parent 76de799 commit 9aadb56

File tree

6 files changed

+888
-0
lines changed

6 files changed

+888
-0
lines changed
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
#include "ModelingWorkForm.h"
2+
#include <iostream>
3+
#include <cmath>
4+
#include <random>
5+
#include <time.h>
6+
7+
using namespace System;
8+
using namespace System::Windows::Forms;
9+
10+
11+
[STAThreadAttribute]
12+
void main(array<String^>^ args)
13+
{
14+
std::srand(time(NULL));
15+
Application::SetCompatibleTextRenderingDefault(false);
16+
Application::EnableVisualStyles();
17+
ModelingWorkMachineWithBreakdowns::ModelingWorkForm form;
18+
Application::Run(% form);
19+
20+
}
21+
22+
double getTimeBefoeNextTask(double const& lambda)
23+
{
24+
double u = rand() / (RAND_MAX + 1.0);
25+
double res = int((-log(1 - u) / lambda) * 100 + 0.5) / 100.0;
26+
return res;
27+
}
28+
29+
double getTimeBeforeBreakdownMachine(double const& timeBreakDown_M_X, double const& timeBreakdown_StandartDeviation)
30+
{
31+
std::mt19937 gen((std::random_device())());
32+
std::normal_distribution<double> nd(timeBreakDown_M_X, timeBreakdown_StandartDeviation);
33+
double res = int((nd(gen)) * 100 + 0.5) / 100.0;
34+
return res;
35+
}
36+
37+
double getRandomUniform(double const& start,double const& end)
38+
{
39+
return ((double)rand()) / RAND_MAX;
40+
}
41+
42+
double getDebugMachine(double const& timeExectuionInterval1, double const& timeExectuionInterval2)
43+
{
44+
double res = int((getRandomUniform(timeExectuionInterval1, timeExectuionInterval2)) * 100 + 0.5) / 100.0;
45+
return res;
46+
}
47+
48+
double getTimeExecutionTask(double const& timeExectuionM_X,double const& timeExectuionStandartDeviation)
49+
{
50+
double res = int((getRandomUniform(timeExectuionM_X, timeExectuionStandartDeviation)) * 100 + 0.5) / 100.0;
51+
return res;
52+
}
53+
54+
double getTimeRepair(double const& timeTroubleshootinFrom,double const& timeTroubleshootinTo)
55+
{
56+
double res = int((getRandomUniform(timeTroubleshootinFrom, timeTroubleshootinTo)) * 100 + 0.5) / 100.0;
57+
return res;
58+
}
59+
60+
System::Void ModelingWorkMachineWithBreakdowns::ModelingWorkForm::Btn_execution_Click(System::Object^ sender, System::EventArgs^ e)
61+
{
62+
int countDetails = Convert::ToInt32(numericUpDown1->Text);
63+
int allDetails = countDetails;
64+
double const timeExectuionInterval1 = Convert::ToDouble(tb_TimeExecutionInterval1->Text->Replace(".",",")); //íàëàäêà ñòàíêà
65+
double const timeExectuionInterval2 = Convert::ToDouble(tb_TimeExecutionInterval2->Text->Replace(".", ","));
66+
double const timeExectuionM_X = Convert::ToDouble(tb_TimeExecutionM_X->Text->Replace(".", ",")); // âðåìÿ âûï çàäàíèÿ
67+
double const timeExectuionStandartDeviation = Convert::ToDouble(tb_TimeExecutionStandartDeviation->Text->Replace(".", ","));
68+
69+
double const timeBreakDown_M_X = Convert::ToDouble(tb_breakdownM_X->Text->Replace(".", ",")); // ìåæäó ïîëîìêàìè èíòåðâàë
70+
double const timeBreakdown_StandartDeviation = Convert::ToDouble(tb_breakdownStandartDeviation->Text->Replace(".", ","));
71+
72+
double const timeTroubleshootinFrom = Convert::ToDouble(tb_troubleshootingFrom->Text->Replace(".", ",")); // âðåìÿ óñòðàíåíèÿ îò
73+
double const timeTroubleshootinTo = Convert::ToDouble(tb_troubleshootingTo->Text->Replace(".", ","));
74+
75+
double timeBeforeNextTask = getTimeBefoeNextTask(1.0); //âðåìÿ äî ñëåäóþùåãî çàäàíèÿ
76+
double timeToBreakdownMachine = getTimeBeforeBreakdownMachine(timeBreakDown_M_X, timeBreakdown_StandartDeviation); // âðåìÿ äî ïîëîìêè
77+
78+
double totalTimeWorkMachine = 0;
79+
int brokenDetails = 0;
80+
double totalTimeRepair = 0;
81+
while (countDetails > 0)
82+
{
83+
if (timeBeforeNextTask > 0)
84+
{
85+
totalTimeWorkMachine += timeBeforeNextTask;
86+
timeBeforeNextTask = 0;
87+
}
88+
89+
double setMachine = getDebugMachine(timeExectuionInterval1, timeExectuionInterval2);
90+
double timeExectuionTask = getTimeExecutionTask(timeExectuionM_X, timeExectuionStandartDeviation);
91+
double timeDebugExection_oneTask = setMachine + timeExectuionTask;
92+
93+
if (timeDebugExection_oneTask < timeToBreakdownMachine)
94+
{
95+
timeBeforeNextTask += getTimeBefoeNextTask(1.0);
96+
totalTimeWorkMachine += timeDebugExection_oneTask;
97+
timeToBreakdownMachine -= timeDebugExection_oneTask;
98+
countDetails--;
99+
}
100+
else
101+
{
102+
brokenDetails++;
103+
totalTimeWorkMachine += timeToBreakdownMachine;
104+
timeBeforeNextTask -= timeToBreakdownMachine;
105+
double repairTime = getTimeRepair(timeTroubleshootinFrom, timeTroubleshootinTo);
106+
//cout repairTime
107+
totalTimeWorkMachine += repairTime;
108+
timeBeforeNextTask -= repairTime;
109+
timeToBreakdownMachine = getTimeBeforeBreakdownMachine(timeBreakDown_M_X, timeBreakdown_StandartDeviation);
110+
totalTimeRepair += repairTime;
111+
112+
}
113+
}
114+
int countDetailInQueue = 0;
115+
while (timeBeforeNextTask < 0)
116+
{
117+
timeBeforeNextTask += getTimeBefoeNextTask(1.0);
118+
countDetailInQueue++;
119+
}
120+
121+
lbl_countTask->Text = "Êîëè÷åñòâî äåòàëåé: " + allDetails.ToString();
122+
lbl_CountBreakdown->Text = "Êîëè÷åñòâî ïîëîìîê: " + brokenDetails.ToString();
123+
lbl_TimeWork->Text = "Âðåìÿ ðàáîòû: " + (static_cast<int>(totalTimeWorkMachine)).ToString() +" ÷. " + (static_cast<int>((int)totalTimeWorkMachine % 1 * 60)).ToString() +" ìèí.";
124+
lbl_DetailInQueue->Text = "Äåòàëåé â î÷åðåäè: " + countDetailInQueue.ToString();
125+
lbl_TotalTimeRepair->Text = "Îáùåå âðåìÿ ðåìîíòà: " + (static_cast<int>(totalTimeRepair)).ToString() + " ÷. " + (static_cast<int>((int)totalTimeRepair % 1 * 60)).ToString() + " ìèí.";
126+
//return brokenDetails,totalTimeWorkMachine, totalTimeWorkMachine/allDetails,countDetailInQueue,
127+
}
128+
129+
System::Void ModelingWorkMachineWithBreakdowns::ModelingWorkForm::Tb_TimeExecutionInterval1_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e)
130+
{
131+
if (checkInput(e)== true)
132+
e->Handled = true;
133+
}
134+
135+
System::Void ModelingWorkMachineWithBreakdowns::ModelingWorkForm::Tb_TimeExecutionInterval2_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e)
136+
{
137+
if (checkInput(e))
138+
e->Handled = true;
139+
}
140+
141+
System::Void ModelingWorkMachineWithBreakdowns::ModelingWorkForm::Tb_TimeExecutionM_X_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e)
142+
{
143+
if (checkInput(e))
144+
e->Handled = true;
145+
}
146+
147+
System::Void ModelingWorkMachineWithBreakdowns::ModelingWorkForm::Tb_TimeExecutionStandartDeviation_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e)
148+
{
149+
if (checkInput(e))
150+
e->Handled = true;
151+
}
152+
153+
System::Void ModelingWorkMachineWithBreakdowns::ModelingWorkForm::Tb_breakdownM_X_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e)
154+
{
155+
if (checkInput(e))
156+
e->Handled = true;
157+
}
158+
159+
System::Void ModelingWorkMachineWithBreakdowns::ModelingWorkForm::Tb_breakdownStandartDeviation_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e)
160+
{
161+
if (checkInput(e))
162+
e->Handled = true;
163+
}
164+
165+
System::Void ModelingWorkMachineWithBreakdowns::ModelingWorkForm::Tb_troubleshootingFrom_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e)
166+
{
167+
if (checkInput(e))
168+
e->Handled = true;
169+
}
170+
171+
System::Void ModelingWorkMachineWithBreakdowns::ModelingWorkForm::Tb_troubleshootingTo_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e)
172+
{
173+
if (checkInput(e))
174+
e->Handled = true;
175+
}
176+
177+
System::Boolean ModelingWorkMachineWithBreakdowns::ModelingWorkForm::checkInput(System::Windows::Forms::KeyPressEventArgs^ e)
178+
{
179+
if ((Char::IsNumber(e->KeyChar) | Char::IsPunctuation(e->KeyChar)) || e->KeyChar == (char)8)
180+
return false;
181+
else
182+
return true;
183+
}
184+
185+

0 commit comments

Comments
 (0)