|
| 1 | +#include "ModelingInfinityQeueForm.h" |
| 2 | + |
| 3 | +#include <iostream> |
| 4 | +#include <cmath> |
| 5 | +#include <random> |
| 6 | +#include <time.h> |
| 7 | +#include <vector> |
| 8 | +#include <algorithm> |
| 9 | + |
| 10 | +using namespace System; |
| 11 | +using namespace System::Windows::Forms; |
| 12 | + |
| 13 | + |
| 14 | +[STAThreadAttribute] |
| 15 | +void main(array<String^>^ args) |
| 16 | +{ |
| 17 | + std::srand(time(NULL)); |
| 18 | + Application::SetCompatibleTextRenderingDefault(false); |
| 19 | + Application::EnableVisualStyles(); |
| 20 | + ModelingSystemInfiniteQueue::ModelingInfinityQeueForm form; |
| 21 | + Application::Run(% form); |
| 22 | + |
| 23 | +} |
| 24 | + |
| 25 | + |
| 26 | +System::Void ModelingSystemInfiniteQueue::ModelingInfinityQeueForm::Tb_startInteervalGetTask_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) |
| 27 | +{ |
| 28 | + if (checkInput(e)) |
| 29 | + e->Handled = true; |
| 30 | +} |
| 31 | + |
| 32 | +System::Void ModelingSystemInfiniteQueue::ModelingInfinityQeueForm::Tb_endInteervalGetTask_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) |
| 33 | +{ |
| 34 | + if (checkInput(e)) |
| 35 | + e->Handled = true; |
| 36 | +} |
| 37 | + |
| 38 | +System::Void ModelingSystemInfiniteQueue::ModelingInfinityQeueForm::Tb_probabilityGetTaskSecond_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) |
| 39 | +{ |
| 40 | + if (checkInput(e)) |
| 41 | + e->Handled = true; |
| 42 | +} |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +System::Void ModelingSystemInfiniteQueue::ModelingInfinityQeueForm::Tb_probabilityGetTaskSecondAfterFirst_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) |
| 47 | +{ |
| 48 | + if (checkInput(e)) |
| 49 | + e->Handled = true; |
| 50 | +} |
| 51 | + |
| 52 | +System::Void ModelingSystemInfiniteQueue::ModelingInfinityQeueForm::Tb_probabilityGetTaskThirdAfterFirst_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) |
| 53 | +{ |
| 54 | + if (checkInput(e)) |
| 55 | + e->Handled = true; |
| 56 | +} |
| 57 | + |
| 58 | +System::Void ModelingSystemInfiniteQueue::ModelingInfinityQeueForm::Tb_startTimeExecutionFirst_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) |
| 59 | +{ |
| 60 | + if (checkInput(e)) |
| 61 | + e->Handled = true; |
| 62 | +} |
| 63 | + |
| 64 | +System::Void ModelingSystemInfiniteQueue::ModelingInfinityQeueForm::Tb_endTimeExecutionFirst_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) |
| 65 | +{ |
| 66 | + if (checkInput(e)) |
| 67 | + e->Handled = true; |
| 68 | +} |
| 69 | + |
| 70 | +System::Void ModelingSystemInfiniteQueue::ModelingInfinityQeueForm::Tb_startTimeExecutionSecond_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) |
| 71 | +{ |
| 72 | + if (checkInput(e)) |
| 73 | + e->Handled = true; |
| 74 | +} |
| 75 | + |
| 76 | +System::Void ModelingSystemInfiniteQueue::ModelingInfinityQeueForm::Tb_endTimeExecutionSecond_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) |
| 77 | +{ |
| 78 | + if (checkInput(e)) |
| 79 | + e->Handled = true; |
| 80 | +} |
| 81 | + |
| 82 | +System::Void ModelingSystemInfiniteQueue::ModelingInfinityQeueForm::Tb_startTimeExecutionThird_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) |
| 83 | +{ |
| 84 | + if (checkInput(e)) |
| 85 | + e->Handled = true; |
| 86 | +} |
| 87 | + |
| 88 | +System::Void ModelingSystemInfiniteQueue::ModelingInfinityQeueForm::Tb_endTimeExecutionThird_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) |
| 89 | +{ |
| 90 | + if (checkInput(e)) |
| 91 | + e->Handled = true; |
| 92 | +} |
| 93 | + |
| 94 | +System::Boolean ModelingSystemInfiniteQueue::ModelingInfinityQeueForm::checkInput(System::Windows::Forms::KeyPressEventArgs^ e) |
| 95 | +{ |
| 96 | + if ((Char::IsNumber(e->KeyChar) | Char::IsPunctuation(e->KeyChar)) || e->KeyChar == (char)8) |
| 97 | + return false; |
| 98 | + else |
| 99 | + return true; |
| 100 | +} |
| 101 | + |
| 102 | + |
| 103 | +double getExponentialRandom(double const& lambda) |
| 104 | +{ |
| 105 | + double u = rand() / (RAND_MAX + 1.0); |
| 106 | + double res = int((-log(1 - u) / lambda) * 100 + 0.5) / 100.0; |
| 107 | + return res; |
| 108 | +} |
| 109 | + |
| 110 | +double getNormalRandom(double const& start, double const& end) |
| 111 | +{ |
| 112 | + std::mt19937 gen((std::random_device())()); |
| 113 | + std::normal_distribution<double> nd(start, end); |
| 114 | + double res = std::abs(int((nd(gen)) * 100 + 0.5) / 100.0); |
| 115 | + return res; |
| 116 | +} |
| 117 | + |
| 118 | +double getRandomUniform(double const& start, double const& end) |
| 119 | +{ |
| 120 | + return ((double)rand()) / RAND_MAX; |
| 121 | +} |
| 122 | + |
| 123 | + |
| 124 | + |
| 125 | +int giveNumberPC(double const& prob1, double const& prob2) |
| 126 | +{ |
| 127 | + double random = getNormalRandom(0.0, 1.0); |
| 128 | + if (random > 0 && random < prob1) |
| 129 | + return 1; |
| 130 | + else |
| 131 | + { |
| 132 | + if (random >= prob1 && random <= prob1 + prob2) |
| 133 | + return 2; |
| 134 | + else |
| 135 | + return 3; |
| 136 | + } |
| 137 | + return 0; |
| 138 | +} |
| 139 | + |
| 140 | +void completeTask(std::vector<double>& listTaskCurPC,int& timeExectuionTaskCurPC, int& totalTimeExecutionPC, int& countCompleteTask) |
| 141 | +{ |
| 142 | + totalTimeExecutionPC += timeExectuionTaskCurPC;//PC[0]; |
| 143 | + countCompleteTask++; |
| 144 | + |
| 145 | + std::reverse(listTaskCurPC.begin(), listTaskCurPC.end()); |
| 146 | + listTaskCurPC.pop_back(); |
| 147 | + if (listTaskCurPC.size() != 0) |
| 148 | + std::reverse(listTaskCurPC.begin(), listTaskCurPC.end()); |
| 149 | + timeExectuionTaskCurPC = 0; |
| 150 | +} |
| 151 | + |
| 152 | +void saveQueueIfExists(int const& countTask, int& maxQueue) |
| 153 | +{ |
| 154 | + if (countTask > 1 && maxQueue < countTask - 1) |
| 155 | + maxQueue = countTask - 1; |
| 156 | +} |
| 157 | + |
| 158 | +void calculateTimeInQueue(int const& countTask, int& timeInQueue) |
| 159 | +{ |
| 160 | + if (countTask > 1) |
| 161 | + timeInQueue++; |
| 162 | +} |
| 163 | + |
| 164 | +void checkWorkPC(std::vector<double>& listTaskCurPC, int& timeExectuionTaskCurPC, int& totalTimeExecutionPC, int& countCompleteTask, int& maxQueue, int& timeInQueue, int& timeWait) |
| 165 | +{ |
| 166 | + if (listTaskCurPC.size() != 0) |
| 167 | + { |
| 168 | + if (timeExectuionTaskCurPC >= listTaskCurPC[0]) |
| 169 | + completeTask(listTaskCurPC, timeExectuionTaskCurPC, totalTimeExecutionPC, countCompleteTask); |
| 170 | + else |
| 171 | + { |
| 172 | + timeExectuionTaskCurPC++; |
| 173 | + saveQueueIfExists(listTaskCurPC.size(), maxQueue); |
| 174 | + calculateTimeInQueue(listTaskCurPC.size(), timeInQueue); |
| 175 | + |
| 176 | + } |
| 177 | + |
| 178 | + } |
| 179 | + else |
| 180 | + timeWait++; |
| 181 | +} |
| 182 | + |
| 183 | + |
| 184 | +System::Void ModelingSystemInfiniteQueue::ModelingInfinityQeueForm::Btn_exectuion_Click(System::Object^ sender, System::EventArgs^ e) |
| 185 | +{ |
| 186 | + int countTask = Convert::ToInt32(numericUpDown1->Text); |
| 187 | + double const startInteervalGetTask = Convert::ToDouble(tb_startInteervalGetTask->Text->Replace(".", ",")); |
| 188 | + double const endInteervalGetTask = Convert::ToDouble(tb_endInteervalGetTask->Text->Replace(".", ",")); |
| 189 | + |
| 190 | + double const probabilityGetTaskFirst = Convert::ToDouble(tb_probabilityGetTaskFirst->Text->Replace(".", ",")); |
| 191 | + double const probabilityGetTaskSecond = Convert::ToDouble(tb_probabilityGetTaskSecond->Text->Replace(".", ",")); |
| 192 | + double const probabilityGetTaskThird = std::abs( 1 - (probabilityGetTaskFirst + probabilityGetTaskSecond)); |
| 193 | + |
| 194 | + double const probabilityGetTaskSecondAfterFirst = Convert::ToDouble(tb_probabilityGetTaskSecondAfterFirst->Text->Replace(".", ",")); |
| 195 | + double const probabilityGetTaskThirdAfterFirst = Convert::ToDouble(tb_probabilityGetTaskThirdAfterFirst->Text->Replace(".", ",")); |
| 196 | + |
| 197 | + //Èíòåðâàë âûïîëíåíèå 1 ÝÂÌ |
| 198 | + double const startTimeExecutionFirst = Convert::ToDouble(tb_startTimeExecutionFirst->Text->Replace(".", ",")); |
| 199 | + double const endTimeExecutionFirst = Convert::ToDouble(tb_endTimeExecutionFirst->Text->Replace(".", ",")); |
| 200 | + //Èíòåðâàë âûïîëíåíèÿ 2 ÝÂÌ |
| 201 | + double const startTimeExecutionSecond = Convert::ToDouble(tb_startTimeExecutionSecond->Text->Replace(".", ",")); |
| 202 | + double const endTimeExecutionSecond = Convert::ToDouble(tb_endTimeExecutionSecond->Text->Replace(".", ",")); |
| 203 | + //Èíòåðâàë âûïîëíåíèÿ 3 ÝÂÌ |
| 204 | + double const startTimeExecutionThird = Convert::ToDouble(tb_startTimeExecutionThird->Text->Replace(".", ",")); |
| 205 | + double const endTimeExecutionThird = Convert::ToDouble(tb_endTimeExecutionThird->Text->Replace(".", ",")); |
| 206 | + |
| 207 | + std::vector<double> timeFirstTask; //ñîäåðæèò âðåìÿ âûïîëíåíèÿ êàæäîãî çàäàíèÿ 1 ÝÂÌ |
| 208 | + std::vector<double> timeSecondTask; // ñîäåðæèò âðåìÿ âûïîëíåíèÿ êàæäîãî çàäàíèÿ 2 ÝÂÌ |
| 209 | + std::vector<double> timeThirdTask; // ñîäåðæèò âðåìÿ âûïîëíåíèÿ êàæäîãî çàäàíèÿ 3 ÝÂÌ |
| 210 | + |
| 211 | + //Îáùåå âðåìÿ âûïîëíåíèÿ è êîëè÷åñòâî 1 ÝÂÌ |
| 212 | + int totalTimeExectuionFrist = 0; |
| 213 | + int countExectionFirst = 0; |
| 214 | + //Îáùåå âðåìÿ âûïîëíåíèÿ è êîëè÷åñòâî 2 ÝÂÌ |
| 215 | + int totalTimeExecetuinSecond = 0; |
| 216 | + int countExectionSecond = 0; |
| 217 | + //Îáùåå âðåìÿ âûïîëíåíèÿ è êîëè÷åñòâî 3 ÝÂÌ |
| 218 | + int totalTimeExectuionThird = 0; |
| 219 | + int countExectionThird = 0; |
| 220 | + |
| 221 | + //îáùåå âðåìÿ ïðîñòîÿ êàæäîé ÝÂÌ |
| 222 | + int timeWaitFirst = 0; |
| 223 | + int timeWaitSecond = 0; |
| 224 | + int timeWaitThird = 0; |
| 225 | + |
| 226 | + //îáùåå âðåìÿ âûïîëíåíèÿ äëÿ êàæäîé ÝÂÌ |
| 227 | + int timeFirst = 0; |
| 228 | + int timeSecond = 0; |
| 229 | + int timeThird = 0; |
| 230 | + |
| 231 | + //îáùåå âðåìÿ î÷åðåäè â êàæäîé ÝÂÌ |
| 232 | + int timeQueueFirst = 0; |
| 233 | + int timeQueueSecond = 0; |
| 234 | + int timeQueueThird = 0; |
| 235 | + |
| 236 | + //Ìàêñèìàëüíàÿ î÷åðåäü êàæäîé ÝÂÌ |
| 237 | + int maxCountTaskQueueFirst = 0; |
| 238 | + int maxCountTaskQueueSecond = 0; |
| 239 | + int maxCountTaskQueueThird = 0; |
| 240 | + |
| 241 | + |
| 242 | + double timeBeforeNextTask = getNormalRandom(startInteervalGetTask, endInteervalGetTask); |
| 243 | + double currentTime = timeBeforeNextTask; |
| 244 | + double totalTimeWork = 0; |
| 245 | + do |
| 246 | + { |
| 247 | + if (currentTime >= timeBeforeNextTask) |
| 248 | + { |
| 249 | + if(countTask > 0) |
| 250 | + countTask--; |
| 251 | + |
| 252 | + switch (giveNumberPC(probabilityGetTaskFirst, probabilityGetTaskSecond)) |
| 253 | + { |
| 254 | + case 1: |
| 255 | + timeFirstTask.push_back(getNormalRandom(startTimeExecutionFirst, endTimeExecutionFirst)); |
| 256 | + break; |
| 257 | + case 2: |
| 258 | + timeSecondTask.push_back(getNormalRandom(startTimeExecutionSecond, endTimeExecutionSecond)); |
| 259 | + break; |
| 260 | + case 3: |
| 261 | + timeThirdTask.push_back(getNormalRandom(startTimeExecutionThird, endTimeExecutionThird)); |
| 262 | + break; |
| 263 | + default: |
| 264 | + break; |
| 265 | + } |
| 266 | + |
| 267 | + timeBeforeNextTask = getNormalRandom(startInteervalGetTask, endInteervalGetTask); |
| 268 | + currentTime = 1; |
| 269 | + } |
| 270 | + |
| 271 | + //if (timeFirstTask.size() != 0) |
| 272 | + //{ |
| 273 | + |
| 274 | + // if (timeFirst >= timeFirstTask[0]) |
| 275 | + // { |
| 276 | + // totalTimeExectuionFrist += timeFirst;//timeFirstTask[0]; |
| 277 | + // countExectionFirst++; |
| 278 | + |
| 279 | + // std::reverse(timeFirstTask.begin(), timeFirstTask.end()); |
| 280 | + // timeFirstTask.pop_back(); |
| 281 | + // if (timeFirstTask.size() != 0) |
| 282 | + // std::reverse(timeFirstTask.begin(), timeFirstTask.end()); |
| 283 | + // timeFirst = 0; |
| 284 | + // switch (giveNumberPC(probabilityGetTaskSecondAfterFirst, probabilityGetTaskThirdAfterFirst)) |
| 285 | + // { |
| 286 | + // case 1: |
| 287 | + // timeSecondTask.push_back(getNormalRandom(startTimeExecutionSecond, endTimeExecutionSecond)); |
| 288 | + // break; |
| 289 | + // case 2: |
| 290 | + // timeThirdTask.push_back(getNormalRandom(startTimeExecutionThird, endTimeExecutionThird)); |
| 291 | + // break; |
| 292 | + // default: |
| 293 | + // break; |
| 294 | + // } |
| 295 | + // } |
| 296 | + // else |
| 297 | + // { |
| 298 | + // timeFirst++; |
| 299 | + // if (timeFirstTask.size() > 1 && maxCountTaskQueueFirst < timeFirstTask.size() - 1) |
| 300 | + // maxCountTaskQueueFirst = timeFirstTask.size() - 1; |
| 301 | + // if (timeFirstTask.size() > 1) |
| 302 | + // { |
| 303 | + // timeQueueFirst++; |
| 304 | + // } |
| 305 | + // } |
| 306 | + // |
| 307 | + //} |
| 308 | + //else |
| 309 | + // timeWaitFirst++; |
| 310 | + |
| 311 | + checkWorkPC(timeFirstTask, timeFirst, totalTimeExectuionFrist, countExectionFirst, maxCountTaskQueueFirst, timeQueueFirst, timeWaitFirst); |
| 312 | + |
| 313 | + checkWorkPC(timeSecondTask, timeSecond, totalTimeExecetuinSecond, countExectionSecond, maxCountTaskQueueSecond, timeQueueSecond, timeWaitSecond); |
| 314 | + checkWorkPC(timeThirdTask, timeThird, totalTimeExectuionThird, countExectionThird, maxCountTaskQueueThird, timeQueueThird, timeWaitThird); |
| 315 | + |
| 316 | + |
| 317 | + currentTime++; |
| 318 | + totalTimeWork += currentTime; |
| 319 | + |
| 320 | + }while (countTask > 0); |
| 321 | + |
| 322 | + /*for (int i = 1; i <= countTask; i++) |
| 323 | + { |
| 324 | + double timeGetTask = getNormalRandom(startInteervalGetTask, endInteervalGetTask); |
| 325 | + if (timeBeforeNextTask > 0) |
| 326 | + timeBeforeNextTask = 0; |
| 327 | +
|
| 328 | + double timeExecutinTask = 0; |
| 329 | + switch (giveNumberPC(probabilityGetTaskFirst, probabilityGetTaskSecond)) |
| 330 | + { |
| 331 | + case 1: |
| 332 | + timeBeforeNextTask += getNormalRandom(startInteervalGetTask, endInteervalGetTask); |
| 333 | + timeExecutinTask = getNormalRandom(startTimeExecutionFirst, endTimeExecutionFirst); |
| 334 | + totatTimeExecution += timeExecutinTask; |
| 335 | + totalTimeExectuionFrist += timeExecutinTask; |
| 336 | + timeBeforeNextTask -= timeExecutinTask; |
| 337 | + if (giveNumberPCAfterFirst(probabilityGetTaskSecondAfterFirst, probabilityGetTaskThirdAfterFirst) == 2) |
| 338 | + goto second; |
| 339 | + else |
| 340 | + goto third; |
| 341 | + break; |
| 342 | + case 2: |
| 343 | + timeBeforeNextTask += getNormalRandom(startInteervalGetTask, endInteervalGetTask); |
| 344 | + second: |
| 345 | + timeExecutinTask = getNormalRandom(startTimeExecutionSecond, endTimeExecutionSecond); |
| 346 | + totatTimeExecution += timeExecutinTask; |
| 347 | + totalTimeExecetuinSecond += timeExecutinTask; |
| 348 | + timeBeforeNextTask -= timeExecutinTask; |
| 349 | + break; |
| 350 | + case 3: |
| 351 | + timeBeforeNextTask += getNormalRandom(startInteervalGetTask, endInteervalGetTask); |
| 352 | + third: |
| 353 | + timeExecutinTask = getNormalRandom(startTimeExecutionThird, endTimeExecutionThird); |
| 354 | + totatTimeExecution += timeExecutinTask; |
| 355 | + totalTimeExectuionThird += timeExecutinTask; |
| 356 | + timeBeforeNextTask -= timeExecutinTask; |
| 357 | + break; |
| 358 | + default: |
| 359 | + break; |
| 360 | + } |
| 361 | + } |
| 362 | + int countTasklInQueue = 0; |
| 363 | + while (timeBeforeNextTask < 0) |
| 364 | + { |
| 365 | + timeBeforeNextTask += getNormalRandom(startInteervalGetTask, endInteervalGetTask); |
| 366 | + countTasklInQueue++; |
| 367 | + }*/ |
| 368 | + lbl_answer->Text = "Âðåìÿ ðàáîòû : " + (static_cast<int>(totalTimeWork/60)).ToString() + " ÷. " + (static_cast<int>((int)totalTimeWork % 60)).ToString() + " ìèí."; |
| 369 | + lbl_answer1->Text = "Âðåìÿ ðàáîòû 1: " + (totalTimeExectuionFrist/60).ToString() + " ÷. " + (totalTimeExectuionFrist% 60).ToString() + " ìèí. Ìàêñ î÷åðåäü: " + maxCountTaskQueueFirst.ToString(); |
| 370 | + lbl_answer2->Text = "Âðåìÿ ðàáîòû 2: " + (totalTimeExecetuinSecond/60).ToString() + " ÷. " + (totalTimeExecetuinSecond % 60).ToString() + " ìèí.Ìàêñ î÷åðåäü: " + maxCountTaskQueueSecond.ToString(); |
| 371 | + lbl_answer3->Text = "Âðåìÿ ðàáîòû 3: " + (totalTimeExectuionThird/60).ToString() + " ÷. " + (totalTimeExectuionThird% 60).ToString() + " ìèí. Ìàêñ î÷åðåäü: " + maxCountTaskQueueThird.ToString(); |
| 372 | + lbl_answer4->Text = "Âðåìÿ â î÷åðåäè: " + ((timeQueueFirst+timeQueueSecond+timeQueueThird)/60).ToString() + " ÷. " + ((timeQueueFirst + timeQueueSecond + timeQueueThird) % 60).ToString() + " ìèí."; |
| 373 | + lbl_answer5->Text = "Âðåìÿ â ïðîñòîå: " + ((timeWaitFirst+timeWaitSecond+timeWaitThird)/ 60).ToString() + " ÷. " + ((timeWaitFirst + timeWaitSecond + timeWaitThird) % 60).ToString() + " ìèí."; |
| 374 | +} |
| 375 | + |
| 376 | +System::Void ModelingSystemInfiniteQueue::ModelingInfinityQeueForm::Tb_probabilityGetTaskFirst_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) |
| 377 | +{ |
| 378 | + if (checkInput(e)) |
| 379 | + e->Handled = true; |
| 380 | +} |
| 381 | + |
0 commit comments