pedrolbacelar / Digital_Twin

6 stars 0 forks source link

[Validation]Code Crashing #266

Closed pedrolbacelar closed 1 year ago

pedrolbacelar commented 1 year ago
-----------------------------------------------------------------------------------------
 28 March 17:08:55 |[Validator] Duration of the TDS and qTDS being used: 36
parts_branch_queue_vect = []
============ Running quasi Trace Driven Simulation ============
### ============ Simulation Started ============ ###
Time: 0 - [Machine 2] got Part 34 from Queue 2 (capacity= 0)
Time: 0 - [Machine 5] got Part 24 from Queue 5 (capacity= 0)
! Using 'alternated' policy to allocate Part 34 to Queue 4
Time: nan - [Conveyor towards Queue 4] GOT Part 34
! Using 'alternated' policy to allocate Part 35 to Queue 2
Time: 11 - [Conveyor towards Queue 2] GOT Part 35
Time: 22 - [Conveyor towards Queue 2] PUT Part 35 in the Queue 2
! Using 'alternated' policy to allocate Part 26 to Queue 5
Time: 37 - [Conveyor towards Queue 5] GOT Part 26
Time: 37 - [Machine 4] got Part 28 from Queue 4 (capacity= 2)
! Using 'alternated' policy to allocate Part 25 to Queue 5
Time: 39 - [Conveyor towards Queue 5] GOT Part 25
Time: 39 - [Machine 3] got Part 27 from Queue 3 (capacity= 3)
Time: 48 - [Conveyor towards Queue 5] PUT Part 26 in the Queue 5
Time: 50 - [Conveyor towards Queue 5] PUT Part 25 in the Queue 5
! Using 'alternated' policy to allocate Part 28 to Queue 5
Time: 77 - [Conveyor towards Queue 5] GOT Part 28
Time: 77 - [Machine 4] got Part 30 from Queue 4 (capacity= 1)
Time: 88 - [Conveyor towards Queue 5] PUT Part 28 in the Queue 5
! Using 'alternated' policy to allocate Part 27 to Queue 5
Time: 101 - [Conveyor towards Queue 5] GOT Part 27
Time: 101 - [Machine 3] got Part 29 from Queue 3 (capacity= 2)
Time: 112 - [Conveyor towards Queue 5] PUT Part 27 in the Queue 5
! Using 'alternated' policy to allocate Part 30 to Queue 5
Time: 117 - [Conveyor towards Queue 5] GOT Part 30
Time: 117 - [Machine 4] got Part 32 from Queue 4 (capacity= 0)
Time: 128 - [Conveyor towards Queue 5] PUT Part 30 in the Queue 5
! Using 'alternated' policy to allocate Part 32 to Queue 5
Time: 152 - [Conveyor towards Queue 5] GOT Part 32
! Using 'alternated' policy to allocate Part 29 to Queue 5
Time: 163 - [Conveyor towards Queue 5] GOT Part 29
Time: 163 - [Machine 3] got Part 31 from Queue 3 (capacity= 1)
Time: 163 - [Conveyor towards Queue 5] PUT Part 32 in the Queue 5
Time: 174 - [Conveyor towards Queue 5] PUT Part 29 in the Queue 5
! Using 'alternated' policy to allocate Part 31 to Queue 5
Time: 225 - [Conveyor towards Queue 5] GOT Part 31
Time: 225 - [Machine 3] got Part 33 from Queue 3 (capacity= 0)
Time: 236 - [Conveyor towards Queue 5] PUT Part 31 in the Queue 5
! Using 'alternated' policy to allocate Part 33 to Queue 5
Time: 282 - [Conveyor towards Queue 5] GOT Part 33
Time: 293 - [Conveyor towards Queue 5] PUT Part 33 in the Queue 5
arts_zero: []
Printing unique machines ids with completed traces
('Machine 2',)
machine name: Machine 2
Xr_vector: [17, 17]
value 1 not found in 'u' variable
Printing unique machines ids with completed traces
('Machine 2',)
-----------------------------------------------------------------------------------------
=== matrix_ptime_qTDS ===
Machine 2: [nan nan]

=== matrix_ptime_TDS ===
Part 24: [6]
Part 25: [19]
Part 26: [26]
Part 27: []
Part 28: []
Part 34: [17]
Part 35: [2, 17]
Part 36: [10]
-----------------------
pedrolbacelar commented 1 year ago
-------------------------------------
 28 March 17:47:13 |[interfaceDB.py/update_end_time] Pointer End Time updated from 140 to 141
-------- Printing the traces: --------
(129, None, 'Machine 2', 'Started', 'Part 20', 'Queue 2', '28 March 17:46:21', 1680021981)
(130, None, 'Machine 1', 'Started', 'Part 23', 'Queue 1', '28 March 17:46:25', 1680021985)
(131, None, 'Machine 3', 'Finished', 'Part 12', 'Queue 5', '28 March 17:46:34', 1680021994)
(132, None, 'Machine 3', 'Started', 'Part 15', 'Queue 1', '28 March 17:46:35', 1680021995)
(133, None, 'Machine 2', 'Finished', 'Part 20', 'Queue 3', '28 March 17:46:38', 1680021999)
(134, None, 'Machine 1', 'Finished', 'Part 23', 'Queue 2', '28 March 17:46:38', 1680021999)
(135, None, 'Machine 2', 'Started', 'Part 21', 'Queue 2', '28 March 17:46:39', 1680022000)
(136, None, 'Machine 5', 'Started', 'Part 12', 'Queue 1', '28 March 17:46:41', 1680022002)
(137, None, 'Machine 4', 'Finished', 'Part 13', 'Queue 5', '28 March 17:46:41', 1680022002)
(138, None, 'Machine 4', 'Started', 'Part 14', 'Queue 1', '28 March 17:46:42', 1680022003)
(139, None, 'Machine 5', 'Finished', 'Part 12', 'Queue 1', '28 March 17:46:49', 1680022010)
(140, None, 'Machine 5', 'Started', 'Part 13', 'Queue 1', '28 March 17:46:50', 1680022011)
(141, None, 'Machine 2', 'Finished', 'Part 21', 'Queue 4', '28 March 17:46:57', 1680022018)
---------- Pointer Status Updated ----------
Start Time: 1680021981
Start Time ID: 129

End Time: 1680022018
End Time ID: 141
-------------------------------------
parts_zero: []
Printing unique machines ids with completed traces
('Machine 2',)
('Machine 5',)
machine name: Machine 2
Xr_vector: [18, 18]
28 March 17:47:13 |[ERROR][validator.py/generate_Xs_machine()] value 1 not found in 'u' variable
u: [0.5, 0.5]
Printing input parameters...
loc = 16
scale = 2
distribution= norm
Xr = [18, 18]
28 March 17:47:13 |[ERROR][validator.py/generate_Xs_machine()] The Xs vector is not a made by numbers! Check the U vector:
u: [0.5, 0.5]
|--- Printing input parameters...
loc = 16
scale = 2
distribution= norm
Xr = [18, 18]
|--- Printing output
Xs= [16. 16.]
machine name: Machine 5
Xr_vector: [8]
28 March 17:47:13 |[ERROR][validator.py/generate_Xs_machine()] The Xs vector is not a made by numbers! Check the U vector:
u: [0.9599]
|--- Printing input parameters...
loc = 10
scale = 0
distribution= norm
Xr = [8]
|--- Printing output
Xs= [nan]
Printing unique machines ids with completed traces
('Machine 2',)
('Machine 5',)
pedrolbacelar commented 1 year ago
Traceback (most recent call last):
  File "C:\Users\pedro\Github_repos\Digital_Twin\Digital Twin\testing_stho.py", line 31, in <module>
    mydt.run()
  File "C:\Users\pedro\Github_repos\Digital_Twin\Digital Twin\dtwinpylib\dtwinpy\Digital_Twin.py", line 845, in run
    self.Internal_Services()
  File "C:\Users\pedro\Github_repos\Digital_Twin\Digital Twin\dtwinpylib\dtwinpy\Digital_Twin.py", line 601, in Internal_Services
    [lcss_indicator_logic, lcss_indicator_input] = self.run_validation(copied_realDB= self.copied_realDB, start_time= start_time, end_time= end_time)
                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pedro\Github_repos\Digital_Twin\Digital Twin\dtwinpylib\dtwinpy\Digital_Twin.py", line 423, in run_validation
    (lcss_input, lcss_time_input, lcss_indicator_input) = validator_input.run()
                                                          ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pedro\Github_repos\Digital_Twin\Digital Twin\dtwinpylib\dtwinpy\validator.py", line 810, in run
    (lcss, lcss_time, lcss_indicator) = self.LCSS(Sequence1= Ys_event, Sequence1_time= Ys_time, Sequence2= Yr_event, Sequence2_time= Yr_time, delta_t= self.delta_t_treshold)
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pedro\Github_repos\Digital_Twin\Digital Twin\dtwinpylib\dtwinpy\validator.py", line 602, in LCSS
    if (Sequence1[i-1] == Sequence2[j-1]) and (abs(Sequence1_time[i-1] - Sequence2_time[j-1]) <= delta_t):
                                                   ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for -: 'int' and 'NoneType'
pedrolbacelar commented 1 year ago

Basically when trying to run validation qTDS some machines was receiving None as process time correlated given the output of the function: generate_Xs_machine(self, loc, scale, distribution, Xr, a= None, b= None)

This was happening because Xs = (dist.ppf(u, loc, scale)) was return infinity. This is explained when we start printing the input parameter when we received that error. Than we noticed that for those cases the scale being passed was 0, which doesnt make sense to find a distribution. The scale was zero from the model.

The updator was receiving only one trace (one process time) and because of that the scale was being updated to zero.

Solve that problem we just always update the scale to 1 if it was suppose to be 0.