-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbigolfile.cpp
executable file
·859 lines (751 loc) · 18.3 KB
/
bigolfile.cpp
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
//#ifndef _PEDIDO_H_
//#define _PEDIDO_H_
#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
#include <stdlib.h>
////#include <ctime.h>
//#include "fila.h"
using namespace std;
class Pedido
{
public:
int num; //numero do pedido
int qtdPizza; //uma certa quantidade de pizzas (sorteada entre 1 e 3),
int qtdPasteis; //uma certa quantidade de pasteis (sorteada entre 1 e 5) e o
int iTempo; //instante de tempo que chegou
int procTempo;
int getNum(); //retorna numero de controle
int getQtdPizza(); //retorna quantidade de pizzas
void setQtdPizza(int aux); //adiciona pizzas
int getProcTempo()
{
return procTempo;
}
void setProcTempo(int aux)
{
procTempo = aux;
}
int getQtdPasteis(); //retorna quantidade de pasteis
void setQtdPasteis(int aux); //adiciona pasteis
int getITempo();
Pedido();
~Pedido();
Pedido(float tempo, int numP);
};
//#endif
//#include "pedido.h"
Pedido::Pedido()
{
//cout << "Pedido Construtor s/p" << endl;
num = -1;
qtdPizza = -1;
qtdPasteis = -1;
iTempo = -1;
}
Pedido::~Pedido()
{
}
Pedido::Pedido(float tempo, int numP)
{
// cout << "Pedido Construtor c/p" << endl;
qtdPasteis = rand() % 3 + 1;
qtdPizza = rand() % 5 + 1;
iTempo = tempo;
num = numP;
}
int Pedido::getITempo()
{
return iTempo;
}
int Pedido::getNum()
{
return num;
}
int Pedido::getQtdPizza()
{
return qtdPizza;
}
void Pedido::setQtdPizza(int aux)
{
qtdPizza = aux;
}
int Pedido::getQtdPasteis()
{
return qtdPasteis;
}
void Pedido::setQtdPasteis(int aux)
{
qtdPasteis = aux;
}
//#ifndef _NODOFILA_H_
//#define _NODOFILA_H_
//#include <iostream>
//#include "pedido.h"
using namespace std;
class Pedido;
class NodoFila
{
public:
Pedido *Dados;
NodoFila *prox;
void setDados(Pedido *aux);
Pedido *getDados();
void setProx(NodoFila *aux);
NodoFila *getProx();
};
//#endif
//#include "nodoFila.h"
void NodoFila::setDados(Pedido *aux)
{
Dados = aux;
}
Pedido *NodoFila::getDados()
{
return Dados;
}
void NodoFila::setProx(NodoFila *aux)
{
prox = aux;
}
NodoFila *NodoFila::getProx()
{
return prox;
}
//#ifndef _FILA_H_
//#define _FILA_H_
//#include <iostream>
//#include "nodoFila.h"
//#include "pedido.h"
class Pedido;
class NodoFila;
using namespace std;
class Fila
{
public:
NodoFila *inicio, *fim;
int tam;
Fila();
~Fila();
void adiciona(Pedido *aux);
Pedido *retira();
int tamanho();
bool vazia();
};
//#endif
//#include "fila.h"
Fila::Fila()
{
tam = 0;
inicio = NULL;
fim = NULL;
}
Fila::~Fila()
{
}
void Fila::adiciona(Pedido *aux)
{
//cout << "Fila Adiciona" << endl;
NodoFila *temp;
temp = new NodoFila;
temp->setDados(aux);
temp->setProx(NULL);
if (fim == NULL)
{
fim = temp;
inicio = temp;
}
else
{
fim->setProx(temp);
fim = temp;
}
tam++;
}
Pedido *Fila::retira()
{
// cout << "Fila Retira" << endl;
NodoFila *temp;
temp = new NodoFila;
if (inicio == NULL)
{
//cout << "Fila Vazia" << endl;
return NULL;
}
else
{
temp = inicio;
inicio = inicio->getProx();
if (inicio == NULL)
{
fim = NULL;
}
tam--;
return temp->getDados();
}
}
int Fila::tamanho()
{
return tam;
}
bool Fila::vazia()
{
if (inicio == NULL)
{
return true;
}
else
return false;
}
//#ifndef _MONT_H_
//#define _MONT_H_
//#include <iostream>
//#include "fila.h"
//#include "pedido.h"
class Mont
{
public:
bool disponivel; //conferir se a montagem esta disponivel
bool pronto;
int tRest; //tempo restante da montagem tempo total - (tempo atual - tempo chegada)
int tAtual;
int t; //tempo total de montagem
Pedido *Atual;
int getTRest(float tempo); //retorna tempo restante de montagem
void setTempoAt(int aux);
bool getDisp();
void setDisp(bool aux);
bool getPronto();
void pedido(Pedido *P, float tempo);
Pedido *getPedido();
Mont();
~Mont();
};
//#endif
//#include "mont.h"
Mont::Mont()
{
disponivel = true;
tRest = -1;
tAtual = -1;
Atual = NULL;
t = -1;
pronto = false;
}
Mont::~Mont()
{
}
int Mont::getTRest(float tempo)
{
tRest = Atual->getProcTempo() - tempo + t;
return tRest;
} //retorna tempo restante de montagem
void Mont::setTempoAt(int aux)
{
tAtual = aux;
}
bool Mont::getDisp()
{
return disponivel;
}
void Mont::pedido(Pedido *P, float tempo)
{
//cout << "Mont pedido" << endl;
Atual = P;
t = Atual->getQtdPasteis() * 1 + Atual->getQtdPizza() * 3;
disponivel = false;
Atual->setProcTempo(tempo);
}
Pedido *Mont::getPedido()
{
return Atual;
}
bool Mont::getPronto()
{
if (getTRest(tAtual) <= 0)
{
return pronto = true;
}
else
return pronto = false;
}
void Mont::setDisp(bool aux)
{
disponivel = aux;
}
//#ifndef _COZIM_H_
//#define _COZIM_H_
//#include <iostream>
//#include "fila.h"
//#include "pedido.h"
//#include "mont.h"
using namespace std;
class Cozim
{
public:
bool disponivel; //conferir se o forno esta disponivel / vazio
bool pronto;
int tAtual;
int tRest; //tempo restante do cozimento tempo total - (tempo atual - tempo chegada)
int t; //tempo total de cozimento
Pedido *Atual;
bool getDisp();
void setDisp(bool aux);
void setTempoAt(int aux);
int getTRest(float tempo); //retorna tempo restante de cozimento
void pedido(Pedido *P, float tempo);
Pedido *getPedido();
bool getPronto();
Cozim();
~Cozim();
};
//#endif
//#include "cozim.h"
Cozim::Cozim()
{
disponivel = true;
tRest = -1;
tAtual = -1;
Atual = NULL;
t = -1;
pronto = false;
}
Cozim::~Cozim()
{
}
int Cozim::getTRest(float tempo)
{
tRest = Atual->getProcTempo() - tempo + t;
return tRest;
} //retorna tempo restante de montagem
void Cozim::setTempoAt(int aux)
{
tAtual = aux;
}
bool Cozim::getDisp()
{
return disponivel;
}
void Cozim::pedido(Pedido *P, float tempo)
{
//cout << "Cozim pedido" << endl;
Atual = P;
t = Atual->getQtdPasteis() * 2 + Atual->getQtdPizza() * 4;
disponivel = false;
Atual->setProcTempo(tempo);
}
Pedido *Cozim::getPedido()
{
return Atual;
}
bool Cozim::getPronto()
{
if (getTRest(tAtual) <= 0)
{
return pronto = true;
}
else
return pronto = false;
}
void Cozim::setDisp(bool aux)
{
disponivel = aux;
}
//#ifndef _EMPAC_H_
//#define _EMPAC_H_
//#include <iostream>
//#include "fila.h"
//#include "pedido.h"
//#include "mont.h"
//#include "cozim.h"
using namespace std;
class Empac
{
public:
bool disponivel; //conferir se o empacotamento esta disponivel
bool pronto;
int tRest; //tempo restante do empacotamento tempo total - (tempo atual - tempo chegada)
int tAtual;
int t; //tempo total de empacotamento
Pedido *Atual;
int getTRest(float tempo); //retorna tempo restante de empacotamento
void setTempoAt(int aux);
bool getDisp();
void setDisp(bool aux);
Pedido *getPedido();
void pedido(Pedido *P, float tempo);
Empac();
~Empac();
bool getPronto();
};
//#endif
//#include "empac.h"
Empac::Empac()
{
disponivel = true;
tRest = -1;
tAtual = -1;
Atual = NULL;
t = -1;
pronto = false;
}
Empac::~Empac()
{
}
int Empac::getTRest(float tempo)
{
tRest = Atual->getITempo() - tempo + t;
return tRest;
} //retorna tempo restante de montagem
void Empac::setTempoAt(int aux)
{
tAtual = aux;
}
bool Empac::getDisp()
{
return disponivel;
}
void Empac::pedido(Pedido *P, float tempo)
{
// cout << "Cozim pedido" << endl;
Atual = P;
t = Atual->getQtdPasteis() * 1 + Atual->getQtdPizza() * 1;
disponivel = false;
Atual->setProcTempo(tempo);
}
Pedido *Empac::getPedido()
{
return Atual;
}
bool Empac::getPronto()
{
if (getTRest(tAtual) <= 0)
{
return pronto = true;
}
else
return pronto = false;
}
void Empac::setDisp(bool aux)
{
disponivel = aux;
}
//#include <iostream>
//#include <sstream>
//#include <string>
//#include <cstdlib>
//#include <stdlib.h>
//#include "fila.h"
//#include "pedido.h"
//#include "cozim.h"
//#include "mont.h"
//#include "empac.h"
using namespace std;
int main()
{
Fila M; //Fila de pedidos antes de entrar no montador
Fila F; // Fila de pedidos antes de entrar no forno
Fila E; //Fila de pedidos antes de entrar no empacotador
Pedido *P, *aux;
Mont M1, M2, M3; // 3 montadores
Cozim F1, F2, F3; //3 fornos
Empac E1, E2, E3; //3 empacotadores
int control, numP;
float tempo, entregues, tempoMedio, aux1;
tempoMedio = 0;
numP = 0; //numero do pedido
tempo = 0;
aux1 = 0; //auxiliar para o calculo da media de tempo
entregues = 0;
control = 0;
while (cin.get() != 'q')
{
control = rand() % 100 + 1;
if (control > 80)
{
numP++;
P = new Pedido(tempo, numP); //novo pedido
M.adiciona(P); // adiciona o pedido a fila
}
M1.setTempoAt(tempo); //adiciona o tempo atual a cada processo
M2.setTempoAt(tempo);
M3.setTempoAt(tempo);
F1.setTempoAt(tempo);
F2.setTempoAt(tempo);
F3.setTempoAt(tempo);
E1.setTempoAt(tempo);
E2.setTempoAt(tempo);
E3.setTempoAt(tempo);
if (M1.getDisp() == true) // verifica se cada processo esta disponivel para consultar se a fila tem itens,
{
if (M.vazia() != true)
{
aux = M.retira(); //se houver, retira o primeiro elemento
if (aux != NULL)
{
M1.pedido(aux, tempo);
}
}
}
if (M2.getDisp() == true)
{
if (M.vazia() != true)
{
aux = M.retira();
if (aux != NULL)
{
M2.pedido(aux, tempo);
}
}
}
if (M3.getDisp() == true)
{
if (M.vazia() != true)
{
aux = M.retira();
if (aux != NULL)
{
M3.pedido(aux, tempo);
}
}
}
//montador pronto
if (M1.getDisp() == false)
{ // verifica se nao esta disponivel, ou seja, em processo
if (M1.getPronto() == true) // verifica se esta pronto, se o processo esta pronto
{
aux = M1.getPedido();
if (aux != NULL)
{
F.adiciona(aux); // passa para a proxima fila
M1.setDisp(true);
} // libera o processo
}
}
if (M2.getDisp() == false)
{
if (M2.getPronto() == true)
{
aux = M2.getPedido();
if (aux != NULL)
{
F.adiciona(aux);
M2.setDisp(true);
}
}
}
if (M3.getDisp() == false)
{
if (M3.getPronto() == true)
{
aux = M3.getPedido();
if (aux != NULL)
{
F.adiciona(aux);
M3.setDisp(true);
}
}
}
//
if (F1.getDisp() == true)
{
if (F.vazia() != true)
{
aux = F.retira();
if (aux != NULL)
{
F1.pedido(aux, tempo);
}
}
}
if (F2.getDisp() == true)
{
if (F.vazia() != true)
{
aux = F.retira();
if (aux != NULL)
{
F2.pedido(aux, tempo);
}
}
}
if (F3.getDisp() == true)
{
if (F.vazia() != true)
{
aux = F.retira();
if (aux != NULL)
{
F3.pedido(aux, tempo);
}
}
}
//forno pronto
if (F1.getDisp() == false)
{
if (F1.getPronto() == true)
{
aux = F1.getPedido();
if (aux != NULL)
{
E.adiciona(aux);
F1.setDisp(true);
}
}
}
if (F2.getDisp() == false)
{
if (F2.getPronto() == true)
{
aux = F2.getPedido();
if (aux != NULL)
{
E.adiciona(aux);
F2.setDisp(true);
}
}
}
if (F3.getDisp() == false)
{
if (F3.getPronto() == true)
{
aux = F3.getPedido();
if (aux != NULL)
{
E.adiciona(aux);
F3.setDisp(true);
}
}
}
//
if (E1.getDisp() == true)
{
if (E.vazia() != true)
{
aux = E.retira();
if (aux != NULL)
{
E1.pedido(aux, tempo);
}
}
}
if (E2.getDisp() == true)
{
if (E.vazia() != true)
{
aux = E.retira();
if (aux != NULL)
{
E2.pedido(aux, tempo);
}
}
}
if (E3.getDisp() == true)
{
if (E.vazia() != true)
{
aux = E.retira();
if (aux != NULL)
{
E3.pedido(aux, tempo);
}
}
}
system("clear");
cout << "Status das listas" << endl;
cout << "Quantidades de pedidos na fila de Montagem: " << M.tamanho() << endl;
if (M1.getDisp() == false)
cout << "Montador 1 falta " << M1.getTRest(tempo) << " instantes para finalizar o pedido " << M1.getPedido()->num << endl;
else
cout << "Montador 1 vazio" << endl;
if (M2.getDisp() == false)
cout << "Montador 2 falta " << M2.getTRest(tempo) << " instantes para finalizar o pedido " << M2.getPedido()->num << endl;
else
cout << "Montador 2 vazio" << endl;
if (M3.getDisp() == false)
cout << "Montador 3 falta " << M3.getTRest(tempo) << " instantes para finalizar o pedido " << M3.getPedido()->num << endl;
else
cout << "Montador 3 vazio" << endl;
cout << "Quantidades de pedidos na fila de Cozimento: " << F.tamanho() << endl;
if (F1.getDisp() == false)
cout << "Forno 1 falta " << F1.getTRest(tempo) << " instantes para finalizar o pedido " << F1.getPedido()->num << endl;
else
cout << "Forno 1 vazio" << endl;
if (F2.getDisp() == false)
cout << "Forno 2 falta " << F2.getTRest(tempo) << " instantes para finalizar o pedido " << F2.getPedido()->num << endl;
else
cout << "Forno 2 vazio" << endl;
if (F3.getDisp() == false)
cout << "Forno 3 falta " << F3.getTRest(tempo) << " instantes para finalizar o pedido " << F3.getPedido()->num << endl;
else
cout << "Forno 3 vazio" << endl;
cout << "Quantidades de pedidos na fila de Empacotamento: " << E.tamanho() << endl;
if (E1.getDisp() == false)
cout << "Empacotador 1 falta " << E1.getTRest(tempo) << " instantes para finalizar o pedido " << E1.getPedido()->num << endl;
else
cout << "Empacotador 1 vazio" << endl;
if (E2.getDisp() == false)
cout << "Empacotador 2 falta " << E2.getTRest(tempo) << " instantes para finalizar o pedido " << E2.getPedido()->num << endl;
else
cout << "Empacotador 2 vazio" << endl;
if (E3.getDisp() == false)
cout << "Empacotador 3 falta " << E3.getTRest(tempo) << " instantes para finalizar o pedido " << E3.getPedido()->num << endl;
else
cout << "Empacotador 3 vazio" << endl;
if (entregues > 0)
{
cout << entregues << " pedidos entregues em " << tempo << " instantes." << endl;
tempoMedio = aux1 / entregues;
cout << "Tempo medio de atendimento: " << tempoMedio << endl;
}
//empacotamento pronto
if (E1.getDisp() == false)
{
if (E1.getPronto() == true)
{
aux = E1.getPedido();
if (aux != NULL)
{
cout << "Pedido de numero " << aux->getNum() << ", com " << aux->getQtdPasteis() << " pasteis e " << aux->getQtdPizza() << " pizzas, foi entregue." << endl;
E1.setDisp(true);
entregues++;
aux1 = aux1 + (tempo - aux->getITempo());
delete aux;
}
}
}
if (E2.getDisp() == false)
{
if (E2.getPronto() == true)
{
aux = E2.getPedido();
if (aux != NULL)
{
cout << "Pedido de numero " << aux->getNum() << ", com " << aux->getQtdPasteis() << " pasteis e " << aux->getQtdPizza() << " pizzas, foi entregue." << endl;
E2.setDisp(true);
entregues++;
aux1 = aux1 + (tempo - aux->getITempo());
delete aux;
}
}
}
if (E3.getDisp() == false)
{
if (E3.getPronto() == true)
{
aux = E3.getPedido();
if (aux != NULL)
{
cout << "Pedido de numero " << aux->getNum() << ", com " << aux->getQtdPasteis() << " pasteis e " << aux->getQtdPizza() << " pizzas, foi entregue." << endl;
E3.setDisp(true);
entregues++;
aux1 = aux1 + (tempo - aux->getITempo());
delete aux;
}
}
}
tempo++;
}
return 0;
}