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 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 | ///////////////////////////////////////////////////////////////////// // DESP-C++ (Discrete-Event Simulation Package) // Version 1.1, February 1998 // Jerome Darmont // LIMOS, Blaise Pascal University (Clermont-Ferrand II), France ///////////////////////////////////////////////////////////////////// // sample.cc: Flowshop sample simulation model ///////////////////////////////////////////////////////////////////// #include <stdio.h> #include "rng.h" #include "simutil.h" #include "simulc.h" #include "eventc.h" #include "simulm.h" #include <time.h> ///////////////////////////////////////////////////////////////////// // eventc.h: Event Manager methods definition // Variable with simulated systems ///////////////////////////////////////////////////////////////////// #include "stdlib.h" #include "string.h" ///////////////////////////////////////////////////////////////////// // CLASS EventManager ///////////////////////////////////////////////////////////////////// // CLASS EventManager: Constructor EventManager::EventManager(Simulation *sim,int *GetResCap,int NumOfDoctor,int NumOfOR) { simul=sim; SaveResCap = new int[GivenResCap]; SaveResCap = GetResCap; // Active resources instantiation PatientInfo_obj = new PatientInfo("Patients Information",1,simul); Secretary_obj = new Secretary("Secretary",1,simul);//1 HoldingNurse_obj = new HoldingNurse("Holding Nurse",*(GetResCap+0),simul);//12=========>range1 Pass_obj = new Pass("Pass",5,simul);//5 PatientCareSupport_obj = new PatientCareSupport("Patient Care Support",5,simul);//5 PreopRoom_obj = new PreopRoom("Pre-Operating Room",*(GetResCap+3),simul);//15=========>range4 CirclingNurse_obj = new CirclingNurse("Circling Nurse",*(GetResCap+1),simul);//20=========>range2 CirclingNurseHeart_obj = new CirclingNurseHeart("Circling Nurse (Heart)",7,simul);//7 ScrubTech_obj = new ScrubTech("Scrub Tech",13,simul);//13 ScrubTechHeart_obj = new ScrubTechHeart("Scrub Tech (Heart)",3,simul);//3 PA_obj = new PA("PA",25,simul);//25 PAHeart_obj = new PAHeart("PA (Heart)",4,simul);//4 Anesthesiologist_obj = new Anesthesiologist("Anesthesiologist",*(GetResCap+2),simul);//22 //=====>range3 ORs_obj = new ORs("OR1",1,simul); this->GetNumOfOR = NumOfOR; ORList.reserve(GetNumOfOR); for(int i=0 ; i<GetNumOfOR ; i++) { ORList.push_back(*ORs_obj); } Doctor_obj = new Doctor("Doctor",1,simul); this->GetNumOfDoctor = NumOfDoctor; DoctorList.reserve(GetNumOfDoctor); for(int i=0 ; i<GetNumOfDoctor ; i++) { DoctorList.push_back(*Doctor_obj); } RecoveryRoomLevel1_obj = new RecoveryRoomLevel1("Recovery Room Level 1",*(GetResCap+4),simul);//20 //=========>range5 RecoveryRoomLevel2_obj = new RecoveryRoomLevel2("Recovery Room Level 2",1,simul); } // CLASS EventManager: Destructor EventManager::~EventManager() { delete [] SaveResCap; // Active resources destruction delete PatientInfo_obj; delete Secretary_obj; delete HoldingNurse_obj; delete Pass_obj; delete PatientCareSupport_obj; delete PreopRoom_obj; delete CirclingNurse_obj; delete CirclingNurseHeart_obj; delete ScrubTech_obj; delete ScrubTechHeart_obj; delete PA_obj; delete PAHeart_obj; delete Anesthesiologist_obj; delete ORs_obj; delete Doctor_obj; delete RecoveryRoomLevel1_obj; delete RecoveryRoomLevel2_obj; } // CLASS EventManager: Events execution void EventManager::ExecuteEvent(int code, Client *client) { switch(code) { case 0: PatientInfo_obj->Event0(client); break; case 1: PatientInfo_obj->Event1(client); break; case 100: Secretary_obj->Event100(client); break; case 101: Secretary_obj->Event101(client); break; case 102: Secretary_obj->Event102(client); break; case 103: Pass_obj->Event103(client); break; case 104: Pass_obj->Event104(client); break; case 105: Pass_obj->Event105(client); break; case 106: PatientCareSupport_obj->Event106(client); break; case 107: PatientCareSupport_obj->Event107(client); break; case 108: PatientCareSupport_obj->Event108(client); break; case 200: PreopRoom_obj->Event200(client); break; case 204: PreopRoom_obj->Event204(client); break; case 201: HoldingNurse_obj->Event201(client); break; case 202: HoldingNurse_obj->Event202(client); break; case 203: HoldingNurse_obj->Event203(client); break; case 402: HoldingNurse_obj->Event402(client); break; case 406: HoldingNurse_obj->Event406(client); break; case 205: Anesthesiologist_obj->Event205(client); break; case 207: Anesthesiologist_obj->Event207(client); break; case 208: Anesthesiologist_obj->Event208(client); break; case 404: Anesthesiologist_obj->Event404(client); break; case 206: if(client->Heart == 1) CirclingNurseHeart_obj->Event206(client); else CirclingNurse_obj->Event206(client); break; case 310: if(client->Heart == 1) CirclingNurseHeart_obj->Event310(client); else CirclingNurse_obj->Event310(client); break; case 400: if(client->Heart == 1) CirclingNurseHeart_obj->Event400(client); else CirclingNurse_obj->Event400(client); break; case 301: if(client->Heart == 1) ScrubTechHeart_obj->Event301(client); else ScrubTech_obj->Event301(client); break; case 302: if(client->Heart == 1) ScrubTechHeart_obj->Event302(client); else ScrubTech_obj->Event302(client); break; case 308: if(client->Heart == 1) ScrubTechHeart_obj->Event308(client); else ScrubTech_obj->Event308(client); break; case 303: if(client->Heart == 1) PAHeart_obj->Event303(client); else PA_obj->Event303(client); break; case 307: if(client->Heart == 1) PAHeart_obj->Event307(client); else PA_obj->Event307(client); break; case 300: ORList[(client->PatORNum)-1].Event300(client); break; case 309: ORList[(client->PatORNum)-1].Event309(client); break; case 304: DoctorList[(client->PatDocNum)-1].Event304(client); break; case 305: DoctorList[(client->PatDocNum)-1].Event305(client); break; case 306: DoctorList[(client->PatDocNum)-1].Event306(client); break; case 401: if(client->LevelControl == 1) RecoveryRoomLevel1_obj->Event401(client); else if(client->LevelControl == 2) RecoveryRoomLevel2_obj->Event401(client); break; case 403: if(client->LevelControl == 1) RecoveryRoomLevel1_obj->Event403(client); else if(client->LevelControl == 2) RecoveryRoomLevel2_obj->Event403(client); break; case 405: if(client->LevelControl == 1) RecoveryRoomLevel1_obj->Event405(client); else if(client->LevelControl == 2) RecoveryRoomLevel2_obj->Event405(client); break; case 407: if(client->LevelControl == 1) RecoveryRoomLevel1_obj->Event407(client); else if(client->LevelControl == 2) RecoveryRoomLevel2_obj->Event407(client); break; case 408: if(client->LevelControl == 1) RecoveryRoomLevel1_obj->Event408(client); else if(client->LevelControl == 2) RecoveryRoomLevel2_obj->Event408(client); break; case 409: RecoveryRoomLevel1_obj->Event409(client); break; default: printf("Error: unknown event #%d at time %f\n",code,simul->Tnow()); } } // CLASS EventManager: Stats init for each resource void EventManager::Init() { // Active resources PatientInfo_obj->ResetStats(); Secretary_obj->ResetStats(); HoldingNurse_obj->ResetStats(); Pass_obj->ResetStats(); PatientCareSupport_obj->ResetStats(); PreopRoom_obj->ResetStats(); CirclingNurse_obj->ResetStats(); CirclingNurseHeart_obj->ResetStats(); ScrubTech_obj->ResetStats(); ScrubTechHeart_obj->ResetStats(); PA_obj->ResetStats(); PAHeart_obj->ResetStats(); Anesthesiologist_obj->ResetStats(); for(int i=0 ; i<this->GetNumOfOR ; i++) { ORList[i].ResetStats(); } for(int i=0 ; i<this->GetNumOfDoctor ; i++) { DoctorList[i].ResetStats(); } RecoveryRoomLevel1_obj->ResetStats(); RecoveryRoomLevel2_obj->ResetStats(); } // CLASS EventManager: Replications initialization void EventManager::InitRep() { // Scheduler simul->Sched()->Purge(); // Active resources PatientInfo_obj->ResetCounters(); Secretary_obj->ResetCounters(); HoldingNurse_obj->ResetCounters(); Pass_obj->ResetCounters(); PatientCareSupport_obj->ResetCounters(); PreopRoom_obj->ResetCounters(); CirclingNurse_obj->ResetCounters(); CirclingNurseHeart_obj->ResetCounters(); ScrubTech_obj->ResetCounters(); ScrubTechHeart_obj->ResetCounters(); PA_obj->ResetCounters(); PAHeart_obj->ResetCounters(); Anesthesiologist_obj->ResetCounters(); for(int i=0 ; i<this->GetNumOfOR ; i++) { ORList[i].ResetCounters(); ORList[i].PurgeQueue(); } for(int i=0 ; i<this->GetNumOfDoctor ; i++) { DoctorList[i].ResetCounters(); DoctorList[i].PurgeQueue(); } RecoveryRoomLevel1_obj->ResetCounters(); RecoveryRoomLevel2_obj->ResetCounters(); PatientInfo_obj->PurgeQueue(); Secretary_obj->PurgeQueue(); HoldingNurse_obj->PurgeQueue(); Pass_obj->PurgeQueue(); PatientCareSupport_obj->PurgeQueue(); PreopRoom_obj->PurgeQueue(); CirclingNurse_obj->PurgeQueue(); CirclingNurseHeart_obj->PurgeQueue(); ScrubTech_obj->PurgeQueue(); ScrubTechHeart_obj->PurgeQueue(); PA_obj->PurgeQueue(); PAHeart_obj->PurgeQueue(); Anesthesiologist_obj->PurgeQueue(); RecoveryRoomLevel1_obj->PurgeQueue(); RecoveryRoomLevel2_obj->PurgeQueue(); } // CLASS EventManager: Stats computation for each resource void EventManager::Stats() { // Active resources PatientInfo_obj->Stats(); Secretary_obj->Stats(); HoldingNurse_obj->Stats(); Pass_obj->Stats(); PatientCareSupport_obj->Stats(); PreopRoom_obj->Stats(); CirclingNurse_obj->Stats(); CirclingNurseHeart_obj->Stats(); ScrubTech_obj->Stats(); ScrubTechHeart_obj->Stats(); PA_obj->Stats(); PAHeart_obj->Stats(); Anesthesiologist_obj->Stats(); for(int i=0 ; i<this->GetNumOfOR ; i++) { ORList[i].Stats(); } for(int i=0 ; i<this->GetNumOfDoctor ; i++) { DoctorList[i].Stats(); } RecoveryRoomLevel1_obj->Stats(); RecoveryRoomLevel2_obj->Stats(); } // CLASS EventManager: Stats display for each resource void EventManager::DisplayStats() { //printf("\n========== SIMULATION STATISTICS ==========\n"); cout<<"\n*** Average System Total Time : "<<simul->AveTotalTime()<<"\n"; //printf("\n*** PASSIVE RESOURCES\n"); //printf("\n*** ACTIVE RESOURCES"); //cout<<"\n====================Patient Information Report :\n"; PatientInfo_obj->DisplayStats(); //cout<<"\n====================Secretary Report :\n"; Secretary_obj->DisplayStats(); //cout<<"\n====================Holding Nurse Report :\n"; HoldingNurse_obj->DisplayStats(); //cout<<"\n====================Pass Staff Report :\n"; Pass_obj->DisplayStats(); //cout<<"\n====================Patient Care Support Staff Report :\n"; PatientCareSupport_obj->DisplayStats(); //cout<<"\n====================Pre-operating Room Report :\n"; PreopRoom_obj->DisplayStats(); //cout<<"\n====================Circling Nurse Report :\n"; CirclingNurse_obj->DisplayStats(); //cout<<"\n====================Circling Nurse (Heart) Report :\n"; CirclingNurseHeart_obj->DisplayStats(); //cout<<"\n====================Scrub Tech. Report :\n"; ScrubTech_obj->DisplayStats(); //cout<<"\n====================Scrub Tech. (Heart) Report :\n"; ScrubTechHeart_obj->DisplayStats(); //cout<<"\n====================PA Report :\n"; PA_obj->DisplayStats(); //cout<<"\n====================PA (Heart) Report :\n"; PAHeart_obj->DisplayStats(); for(int i=0 ; i<this->GetNumOfOR ; i++) { //cout<<"\n====================Operating Room "<<i+1<<" Report :\n"; ORList[i].DisplayStats(); } for(int i=0 ; i<this->GetNumOfDoctor ; i++) { //cout<<"\n====================Doctor "<<i+1<<" Report :\n"; DoctorList[i].DisplayStats(); } //cout<<"\n====================Recovery Room Report :\n"; RecoveryRoomLevel1_obj->DisplayStats(); //cout<<"\n====================Recovery Room Level 2 Report :\n"; //RecoveryRoomLevel2_obj->DisplayStats(); //cout<<"\n====================Anesthesiologist Report :\n"; Anesthesiologist_obj->DisplayStats(); } void EventManager::SaveResult() { double AllORWt=0., AllDoctorWt=0.; for(int i=0 ; i<this->GetNumOfOR ; i++) { AllORWt = AllORWt + ORList[i].Mean(1); } for(int i=0 ; i<this->GetNumOfDoctor ; i++) { AllDoctorWt = AllDoctorWt + DoctorList[i].Mean(1); } ofstream WriteData; WriteData.open("Result.txt",ios::out | ios::app); WriteData<<*(SaveResCap+0)<<"\t"<<*(SaveResCap+1)<<"\t"<<*(SaveResCap+2)<<"\t"<<*(SaveResCap+3)<<"\t"<<*(SaveResCap+4)<<"\t\t" <<(HoldingNurse_obj->Mean(1))+(CirclingNurse_obj->Mean(1))+(Anesthesiologist_obj->Mean(1))+(PreopRoom_obj->Mean(1))+ (RecoveryRoomLevel1_obj->Mean(1))+(Secretary_obj->Mean(1))+(PatientCareSupport_obj->Mean(1))+ (CirclingNurseHeart_obj->Mean(1))+(ScrubTech_obj->Mean(1))+(ScrubTechHeart_obj->Mean(1))+(PA_obj->Mean(1))+ (PAHeart_obj->Mean(1))+(AllORWt)+(AllDoctorWt)<<"\t" <<simul->AveReplicAveLOS()<<"\t"<<simul->AveOverTime()<<"\t\t" <<HoldingNurse_obj->Mean(1)<<"\t"<<CirclingNurse_obj->Mean(1)<<"\t"<<Anesthesiologist_obj->Mean(1)<<"\t" <<PreopRoom_obj->Mean(1)<<"\t"<<RecoveryRoomLevel1_obj->Mean(1)<<"\t\t" <<Secretary_obj->Mean(1)<<"\t"<<PatientCareSupport_obj->Mean(1)<<"\t"<<CirclingNurseHeart_obj->Mean(1)<<"\t" <<ScrubTech_obj->Mean(1)<<"\t"<<ScrubTechHeart_obj->Mean(1)<<"\t"<<PA_obj->Mean(1)<<"\t"<<PAHeart_obj->Mean(1)<<"\t" <<AllORWt<<"\t"<<AllDoctorWt<<"\n"; //"\t\t"<<MaxORWait<<"("<<OR_BN<<")"<<"\t"<<MaxDocWait<<"\n"; WriteData.close(); } int EventManager::GetNumCustomerOut() { NumCustomerOut = RecoveryRoomLevel1_obj->GetNumberOut() + RecoveryRoomLevel2_obj->GetNumberOut(); return NumCustomerOut; } double EventManager::GetReplicSumLOS() { return RecoveryRoomLevel1_obj->SumLOS; } //============================================== Simulation procedure =================================== PatientInfo::PatientInfo(char n[], int cap, Simulation *sim):Resource(n, cap, sim) { ArrivalSchedule = new double[Sim()->NCusIn()]; ORNum = new int[Sim()->NCusIn()]; DoctorNum = new int[Sim()->NCusIn()]; SurgerySchedule = new double[Sim()->NCusIn()]; ForHeart = new bool[Sim()->NCusIn()]; Sim()->GetCusSche(ArrivalSchedule,ORNum,DoctorNum,SurgerySchedule,ForHeart); } PatientInfo::~PatientInfo() { delete [] ArrivalSchedule; delete [] ORNum; delete [] DoctorNum; delete [] SurgerySchedule; delete [] ForHeart; } void PatientInfo::Event0(Client *client) { Sim()->KillClient(client); Client *NewPatient; NewPatient = Sim()->NewClient(*(ArrivalSchedule+NumPatient),*(ORNum+NumPatient), *(DoctorNum+NumPatient),*(SurgerySchedule+NumPatient),*(ForHeart+NumPatient)); Sim()->Sched()->Schedule(1,NewPatient->PatArrivalTime,NewPatient); } void PatientInfo::Event1(Client *client) { Sim()->Sched()->Schedule(100,Sim()->Tnow(),client); NumPatient = NumPatient++; if(NumPatient<Sim()->NCusIn()) { Client *NewPatient; NewPatient = Sim()->NewClient(*(ArrivalSchedule+NumPatient),*(ORNum+NumPatient), *(DoctorNum+NumPatient),*(SurgerySchedule+NumPatient),*(ForHeart+NumPatient)); Sim()->Sched()->Schedule(1,NewPatient->PatArrivalTime,NewPatient); } } //------------------------------------------------- Secretary::Secretary(char n[], int cap, Simulation *sim):Resource(n, cap, sim){} Secretary::~Secretary(){} void Secretary::Event100(Client *client) { this->P(101,client,1); } void Secretary::Event101(Client *client) { Sim()->Sched()->Schedule(102,Sim()->Tnow()+(4./60.),client); } void Secretary::Event102(Client *client) { Sim()->Sched()->Schedule(103,Sim()->Tnow(),client); this->V(); } //------------------------------------------------- Pass::Pass(char n[], int cap, Simulation *sim):Resource(n, cap, sim){} Pass::~Pass(){} void Pass::Event103(Client *client) { this->P(104,client,1); } void Pass::Event104(Client *client) { double DecidePreadmission = Uni(0,100); if(DecidePreadmission <= 100) Sim()->Sched()->Schedule(105,Sim()->Tnow(),client); else Sim()->Sched()->Schedule(105,Sim()->Tnow()+(3./60.),client); } void Pass::Event105(Client *client) { Sim()->Sched()->Schedule(106,Sim()->Tnow(),client); this->V(); } //------------------------------------------------- PatientCareSupport::PatientCareSupport(char n[], int cap, Simulation *sim):Resource(n, cap, sim){} PatientCareSupport::~PatientCareSupport(){} void PatientCareSupport::Event106(Client *client) { this->P(107,client,1); } void PatientCareSupport::Event107(Client *client) { Sim()->Sched()->Schedule(108,Sim()->Tnow()+(5./60.),client); } void PatientCareSupport::Event108(Client *client) { Sim()->Sched()->Schedule(200,Sim()->Tnow(),client); this->V(); } //------------------------------------------------- PreopRoom::PreopRoom(char n[], int cap, Simulation *sim):Resource(n, cap, sim){} PreopRoom::~PreopRoom(){} void PreopRoom::Event200(Client *client) { this->P(201,client,1); } void PreopRoom::Event204(Client *client) { Sim()->Sched()->Schedule(205,Sim()->Tnow(),client); this->V(); } //------------------------------------------------- HoldingNurse::HoldingNurse(char n[], int cap, Simulation *sim):Resource(n, cap, sim){} HoldingNurse::~HoldingNurse(){} void HoldingNurse::Event201(Client *client) { this->P(202,client,1); } void HoldingNurse::Event202(Client *client) { Sim()->Sched()->Schedule(203,Sim()->Tnow()+(20./60.),client); } void HoldingNurse::Event203(Client *client) { Sim()->Sched()->Schedule(204,Sim()->Tnow(),client); this->V(); } void HoldingNurse::Event402(Client *client) { this->P(403,client,1); } void HoldingNurse::Event406(Client *client) { Sim()->Sched()->Schedule(407,Sim()->Tnow(),client); this->V(); } //------------------------------------------------- Anesthesiologist::Anesthesiologist(char n[], int cap, Simulation *sim):Resource(n, cap, sim){} Anesthesiologist::~Anesthesiologist(){} void Anesthesiologist::Event205(Client *client) { this->P(206,client,1); } void Anesthesiologist::Event207(Client *client) { if(Sim()->Tnow() >= client->PatSurgeryTime) Sim()->Sched()->Schedule(208,Sim()->Tnow(),client); else Sim()->Sched()->Schedule(208,client->PatSurgeryTime,client); } void Anesthesiologist::Event208(Client *client) { Sim()->Sched()->Schedule(300,Sim()->Tnow()+(0./60.),client); } void Anesthesiologist::Event404(Client *client) { Sim()->Sched()->Schedule(405,Sim()->Tnow(),client); this->V(); } //------------------------------------------------- CirclingNurse::CirclingNurse(char n[], int cap, Simulation *sim):Resource(n, cap, sim){} CirclingNurse::~CirclingNurse(){} void CirclingNurse::Event206(Client *client) { this->P(207,client,1); } void CirclingNurse::Event310(Client *client) { double InOutPercent = Uni(0,100); if(InOutPercent <= 100) client->LevelControl = 1; else client->LevelControl = 2; Sim()->Sched()->Schedule(400,Sim()->Tnow()+(3./60.),client); } void CirclingNurse::Event400(Client *client) { Sim()->Sched()->Schedule(401,Sim()->Tnow(),client); this->V(); } //------------------------------------------------- CirclingNurseHeart::CirclingNurseHeart(char n[], int cap, Simulation *sim):Resource(n, cap, sim){} CirclingNurseHeart::~CirclingNurseHeart(){} void CirclingNurseHeart::Event206(Client *client) { this->P(207,client,1); } void CirclingNurseHeart::Event310(Client *client) { double InOutPercent = Uni(0,100); if(InOutPercent <= 100) client->LevelControl = 1; else client->LevelControl = 2; Sim()->Sched()->Schedule(400,Sim()->Tnow()+(3./60.),client); } void CirclingNurseHeart::Event400(Client *client) { Sim()->Sched()->Schedule(401,Sim()->Tnow(),client); this->V(); } //------------------------------------------------- ORs::ORs(char n[], int cap, Simulation *sim):Resource(n, cap, sim){} ORs::~ORs(){} void ORs::Event300(Client *client) { this->P(301,client,1); } void ORs::Event309(Client *client) { Sim()->Sched()->Schedule(310,Sim()->Tnow(),client); this->V(); } //------------------------------------------------- ScrubTech::ScrubTech(char n[], int cap, Simulation *sim):Resource(n, cap, sim){} ScrubTech::~ScrubTech(){} void ScrubTech::Event301(Client *client) { this->P(302,client,1); } void ScrubTech::Event302(Client *client) { Sim()->Sched()->Schedule(303,Sim()->Tnow()+(10./60.),client); } void ScrubTech::Event308(Client *client) { Sim()->Sched()->Schedule(309,Sim()->Tnow(),client); this->V(); } //------------------------------------------------- ScrubTechHeart::ScrubTechHeart(char n[], int cap, Simulation *sim):Resource(n, cap, sim){} ScrubTechHeart::~ScrubTechHeart(){} void ScrubTechHeart::Event301(Client *client) { this->P(302,client,1); } void ScrubTechHeart::Event302(Client *client) { Sim()->Sched()->Schedule(303,Sim()->Tnow()+(15./60.),client); } void ScrubTechHeart::Event308(Client *client) { Sim()->Sched()->Schedule(309,Sim()->Tnow(),client); this->V(); } //------------------------------------------------- PA::PA(char n[], int cap, Simulation *sim):Resource(n, cap, sim){} PA::~PA(){} void PA::Event303(Client *client) { this->P(304,client,1); } void PA::Event307(Client *client) { Sim()->Sched()->Schedule(308,Sim()->Tnow(),client); this->V(); } //------------------------------------------------- PAHeart::PAHeart(char n[], int cap, Simulation *sim):Resource(n, cap, sim){} PAHeart::~PAHeart(){} void PAHeart::Event303(Client *client) { this->P(304,client,1); } void PAHeart::Event307(Client *client) { Sim()->Sched()->Schedule(308,Sim()->Tnow(),client); this->V(); } //------------------------------------------------- Doctor::Doctor(char n[], int cap, Simulation *sim):Resource(n, cap, sim){} Doctor::~Doctor(){} void Doctor::Event304(Client *client) { this->P(305,client,1); } void Doctor::Event305(Client *client) { double SurgeryTimeAVE[83] = {228.3076923, 250.7283951, 122.09375, 203.2142857, 37.70967742, 70.5, 39.28571429, 74.33333333, 60.5, 75.9, 86.18435754, 87.32768362, 62.53393665, 86.65198238, 82.42307692, 70.75609756, 72.6744186, 124.8695652, 42.15, 53.29411765, 68.75675676, 75.87096774, 84.53333333, 120.5254237, 90.56164384, 67.52631579, 91.75471698, 52.56756757, 107.3636364, 79.39285714, 66.78125, 152.62, 113.7446809, 201.00, 168.483871, 106.7837838, 40.14285714, 251.7083333, 99.4, 102.00, 148.4, 108.1538462, 79.68421053, 138.75, 102.9545455, 199.9117647, 91.2, 91.35245902, 82.70666667, 86.83333333, 206.6818182, 61.3125, 47.00, 92.34408602, 165.4662577, 117.9466667, 103.9411765, 180.9615385, 171.1048387, 85.41520468, 258.1494253, 68.22222222, 83.72151899, 98.5, 66.29411765, 244.7157895, 120.5, 83.04347826, 74.10638298, 62.00, 127.00, 129.7647059, 130.7810651, 107.6833333, 153.375, 122.6233766, 88.96428571, 122.4, 113.8666667, 69.96153846, 91.88235294, 89.52380952, 97.7037037}, SurgeryTimeSTD[84] = {83.58744845, 113.3818933, 56.76202586, 84.61293893, 29.96032908, 29.41787061, 7.543524502, 36.19852667, 5.972157622, 18.24655699, 47.01571075, 53.15805091, 27.27977901, 66.09933215, 42.57151449, 54.77535052, 51.29221649, 59.68135496, 12.71250938, 46.91677313, 33.45608891, 62.40071684, 65.57214155, 80.07848648, 48.33993814, 42.93095452, 44.71142758, 30.48728382, 52.21777957, 64.7995995, 47.54266971, 91.56316802, 62.610634, 78.160067, 87.86575782, 29.39022431, 26.4352935, 213.2731417, 19.0078931, 57.98275606, 136.3554179, 22.41222194, 32.00529927, 31.25566615, 40.89763909, 120.0046934, 21.70918904, 45.30793121, 28.25757525, 37.00327586, 77.96909422, 32.28745637, 87.59675184, 31.69504646, 91.5072204, 39.51497663, 37.38477654, 82.31385017, 75.2425691, 39.71260879, 102.717215, 29.24798189, 34.62507492, 115.2584053, 30.20087237, 119.9235273, 24.74873734, 33.45074841, 26.22165886, 29.35036087, 77.82198192, 76.14503383, 97.31425835, 101.6658688, 109.2710282, 94.62155076, 68.82270682, 92.33544982, 76.22323105, 61.98857086, 54.37732949, 49.07589458, 58.93325932}, alpha = 0., beta = 0., u = 0., s = 0.; u = SurgeryTimeAVE[(client->PatDocNum)-1]; s = SurgeryTimeSTD[(client->PatDocNum)-1]; alpha = (u*u) / (s*s); beta = (s*s) / u; Sim()->Sched()->Schedule(306,Sim()->Tnow()+(RandomDistribution.gamma(alpha,beta)/60.),client); //Sim()->Sched()->Schedule(306,Sim()->Tnow()+(u/60.),client); } void Doctor::Event306(Client *client) { Sim()->Sched()->Schedule(307,Sim()->Tnow(),client); this->V(); } //------------------------------------------------- RecoveryRoomLevel1::RecoveryRoomLevel1(char n[], int cap, Simulation *sim):Resource(n, cap, sim){} RecoveryRoomLevel1::~RecoveryRoomLevel1(){} void RecoveryRoomLevel1::Event401(Client *client) { this->P(402,client,1); } void RecoveryRoomLevel1::Event403(Client *client) { Sim()->Sched()->Schedule(404,Sim()->Tnow()+(2./60.),client); } void RecoveryRoomLevel1::Event405(Client *client) { Sim()->Sched()->Schedule(406,Sim()->Tnow()+(15./60.),client); } void RecoveryRoomLevel1::Event407(Client *client) { Sim()->Sched()->Schedule(408,Sim()->Tnow(),client); this->V(); } void RecoveryRoomLevel1::Event408(Client *client) { Sim()->Sched()->Schedule(409,Sim()->Tnow()+(7./60.),client); } void RecoveryRoomLevel1::Event409(Client *client) { double LOS, DepartureT, ArrivalT; //double DepartureT; DepartureT = Sim()->Tnow(); ArrivalT = client->PatArrivalTime; LOS = (DepartureT - ArrivalT); SumLOS = SumLOS + LOS; //SumLOS = SumLOS + DepartureT; Sim()->KillClient(client); } //------------------------------------------------- RecoveryRoomLevel2::RecoveryRoomLevel2(char n[], int cap, Simulation *sim):Resource(n, cap, sim){} RecoveryRoomLevel2::~RecoveryRoomLevel2(){} void RecoveryRoomLevel2::Event401(Client *client) { this->P(402,client,1); } void RecoveryRoomLevel2::Event403(Client *client) { Sim()->Sched()->Schedule(404,Sim()->Tnow()+1,client); } void RecoveryRoomLevel2::Event405(Client *client) { Sim()->Sched()->Schedule(406,Sim()->Tnow()+4,client); } void RecoveryRoomLevel2::Event407(Client *client) { Sim()->Sched()->Schedule(408,Sim()->Tnow(),client); this->V(); } void RecoveryRoomLevel2::Event408(Client *client) { Sim()->KillClient(client); } //------------------------------------------------- //==================================================================================================== SetUp::SetUp() { MaxResCap = new int[GivenResCap]; MinResCap = new int[GivenResCap]; for(int i=0 ; i<GivenResCap ; i++) { *(MinResCap+i) = 1; *(MaxResCap+i) = 1; } cout<<"\n\tMin # of holding nurses = "; cin>>*(MinResCap+0); cout<<"\tMax # of holding nurses = "; cin>>*(MaxResCap+0); //cout<<"\tMin # of pass staff = "; cin>>*(MinResCap+1); //cout<<"\tMax # of pass staff = "; cin>>*(MaxResCap+1); //cout<<"\tMin # of patient care support = "; cin>>*(MinResCap+2); //cout<<"\tMax # of patient care support = "; cin>>*(MaxResCap+2); cout<<"\n\tMin # of circling nurse = "; cin>>*(MinResCap+1); cout<<"\tMax # of circling nurse = "; cin>>*(MaxResCap+1); //cout<<"\tMin # of circling nurse for heart = "; cin>>*(MinResCap+2); //cout<<"\tMax # of circling nurse for heart = "; cin>>*(MaxResCap+2); //cout<<"\tMin # of scrub technician = "; cin>>*(MinResCap+5); //cout<<"\tMax # of scrub technician = "; cin>>*(MaxResCap+5); //cout<<"\tMin # of scrub technician for heart = "; cin>>*(MinResCap+6); //cout<<"\tMax # of scrub technician for heart = "; cin>>*(MaxResCap+6); //cout<<"\tMin # of PA = "; cin>>*(MinResCap+7); //cout<<"\tMax # of PA = "; cin>>*(MaxResCap+7); //cout<<"\tMin # of PA for heart = "; cin>>*(MinResCap+8); //cout<<"\tMax # of PA for heart = "; cin>>*(MaxResCap+8); cout<<"\n\tMin # of anesthesiologist = "; cin>>*(MinResCap+2); cout<<"\tMax # of anesthesiologist = "; cin>>*(MaxResCap+2); cout<<"\n\tMin # of pre-operating room = "; cin>>*(MinResCap+3); cout<<"\tMax # of pre-operating room = "; cin>>*(MaxResCap+3); cout<<"\n\tMin # of recovery room = "; cin>>*(MinResCap+4); cout<<"\tMax # of recovery room = "; cin>>*(MaxResCap+4); } SetUp::~SetUp() { delete [] MaxResCap; delete [] MinResCap; } //========================================== Main function =========================================== int main() { char key1, key2; int KeyNofDoc, KeyNofOR; cout<<"Start to simulate surgery process (y/n): "; cin>>key1; while(key1 == 'y') { cout<<"Reading patients' schedule data..."; double getColum1, getColum4; int getColum2, getColum3; bool getColum5; ifstream CountData("Patients Schedule.txt"); int NumPatientBeSche = 0; while(CountData>>getColum1>>getColum2>>getColum3>>getColum4>>getColum5) { NumPatientBeSche = NumPatientBeSche++; } cout<<"\nNumber of Patients are scheduled in data: "<<NumPatientBeSche; int nreplic; printf("\nSet up number of replications = "); scanf("%d",&nreplic); //cout<<"Set up number of doctors in system = "; //cin>>KeyNofDoc; KeyNofDoc = 83; //cout<<"Set up number of operating rooms in system = "; //cin>>KeyNofOR; KeyNofOR = 22; cout<<"Set up resources' capacity : "; SetUp *setup; setup = new SetUp(); cout<<"\nFinish set up and ready to run simulation (y/n): "; cin>>key2; // titles in the result txt file ofstream WriteData; WriteData.open("Result.txt",ios::out | ios::app); WriteData<<"HoldingNurses\t"<<"CirculatingNurse\t"<<"Anesthesiologist\t"<<"PreOpRoom\t"<<"RecoveryRoom\t\t" <<"SumOfAveWt\t"<<"AveOfLOS\t"<<"Ct\t\t" <<"HoldingNurseWt\t"<<"CirculatingNurseWt\t"<<"AnesthesiologistWt\t"<<"PreOpRoomWt\t"<<"RecoveryRoomWt\t\t" <<"SecretaryWt\t"<<"PCTWt\t"<<"CirculatingNurseHWt\t"<<"ScrubTechWt\t"<<"ScrubTechHWt\t"<<"PAWt\t"<<"PAHWt\t" <<"AllORWt\t"<<"AllDoctorWt\n"; WriteData.close(); time_t SimStart, SimEnd; double SimLast=0.0; if(key2 == 'y') { SimStart = time(NULL); int *GetResCap, combination=0; GetResCap = new int[GivenResCap]; for(*(GetResCap+0)=*(setup->MinResCap+0); *(GetResCap+0)<=*(setup->MaxResCap+0); *(GetResCap+0)+=1) {for(*(GetResCap+1)=*(setup->MinResCap+1); *(GetResCap+1)<=*(setup->MaxResCap+1); *(GetResCap+1)+=1) {for(*(GetResCap+2)=*(setup->MinResCap+2); *(GetResCap+2)<=*(setup->MaxResCap+2); *(GetResCap+2)+=1) {for(*(GetResCap+3)=*(setup->MinResCap+3); *(GetResCap+3)<=*(setup->MaxResCap+3); *(GetResCap+3)+=1) {for(*(GetResCap+4)=*(setup->MinResCap+4); *(GetResCap+4)<=*(setup->MaxResCap+4); *(GetResCap+4)+=1) { combination = combination++; Simulation *sim; sim = new Simulation(0,NumPatientBeSche,-1,GetResCap,KeyNofDoc,KeyNofOR); cout<<"\nSimulation: Surgery Flow is running combination "<<combination<<".....:\n\n"; sim->Run(nreplic); printf("\nSimulation: Surgery Flow end\n\n"); delete sim; // "heap" will happen when delete sim } } } } } SimEnd = time(NULL); SimLast = difftime(SimEnd,SimStart); cout<<"\nSimulation lasted: "<<SimLast<<"Sec. "; delete [] GetResCap; cout<<"\nContinue to simulate surgery process (y/n): "; cin>>key1; } } } |
Direct link: https://paste.plurk.com/show/213008