class_robot_task_completion.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 """
5 
6  PHM Robot Task Completion Class
7 
8 """
9 
10 import math
11 from phm_reliability_calculation.class_reliability_calculation import ReliabilityCalculation
12 
13 
15  """
16  Actual POTC Calculation Class
17  """
18  def __init__(self, selected_reliability_model, selected_reliability_unit, shape_parameter):
19  self.r_calculation_class = ReliabilityCalculation()
20  self.selected_reliability_model = selected_reliability_model
21  self.selected_reliability_unit = selected_reliability_unit
22  self.shape_parameter = shape_parameter
23 
24  self.main_reliability = float(1)
25  self.total_time = float(0)
26  self.total_distance = float(0)
27  self.last_potc = float(0)
28 
29  self.current_potc_time = float(0)
30  self.current_potc_distance = float(0)
31 
32  @classmethod
33  def probability_of_task_completion_formula(cls, reliability, distance):
34  """
35  POTC = R ^ d
36 
37  Calculation POTC Function
38  """
39  potc_result = float(pow(float(reliability), float(distance)))
40 
41  return potc_result
42 
43  @classmethod
44  def distance_calculate(cls, start_position, finish_position):
45  """
46  Distance calculation function between 2 points
47  """
48  distance_result = float(math.sqrt(abs(pow((float(finish_position[0]) - float(start_position[0])), 2) + pow((float(finish_position[1]) - float(start_position[1])), 2))))
49 
50  return distance_result
51 
52 
53  def path_calculate(self, task_position):
54  """
55  Function of calculating distances in a mission
56  """
57  goals = task_position
58  distance_list = list()
59 
60  for goal in range(len(goals) - 1):
61  distance_list.append(self.distance_calculate(goals[goal], goals[goal+1]))
62 
63  return distance_list
64 
65 
66  def probability_of_task_completion_calculate_func(self, time_list, task_position, hazard_rate, reliability):
67  """
68  POTC Value Calculation Function
69  """
70  path_calculate_list = self.path_calculate(task_position)
71  self.current_potc_time = 0
72  self.current_potc_distance = 0
73  self.main_reliability = reliability
74 
75  potc_calculate_list = list()
76  potc_calculate_list.append([0, 1])
77  counter = 0
78 
79  for path in path_calculate_list:
80  temp_task_time = time_list[counter]
81  self.total_time += temp_task_time
82  self.current_potc_time += temp_task_time
83  new_reliability = self.r_calculation_class.reliability_calculate_func(temp_task_time, hazard_rate, self.selected_reliability_model, self.selected_reliability_unit, self.shape_parameter)
84 
85  self.main_reliability = self.main_reliability * new_reliability
86 
87  calculate_distance = path
88 
89  self.total_distance += calculate_distance
90  self.current_potc_distance += calculate_distance
91  potc = self.probability_of_task_completion_formula(self.main_reliability, calculate_distance)
92  potc_calculate_list.append([counter+1, potc])
93  counter += 1
94  self.last_potc = potc
95 
96  return self.last_potc
97 
98 
100  """
101  Predict POTC Calculation Class
102  """
103  def __init__(self, hazard_rate, reliability, selected_reliability_model, selected_reliability_unit, shape_parameter):
104  self.r_calculation_class = ReliabilityCalculation()
105  self.hazard_rate = hazard_rate
106  self.main_reliability = reliability
107  self.selected_reliability_model = selected_reliability_model
108  self.selected_reliability_unit = selected_reliability_unit
109  self.shape_parameter = shape_parameter
110 
111  self.main_dict = dict()
112 
113  self.simulation_potc = float(0)
114  self.simulation_time = float(0)
115  self.simulation_distance = float(0)
116 
117  @classmethod
118  def calculate_time_func(cls, distance, speed):
119  """
120  Time Calculation Function
121 
122  """
123  time = float(distance / speed)
124 
125  return time
126 
127 
128  def calculate_time_list_func(self, path_list, speed_list):
129  """
130  Function of calculating times in a mission
131  """
132  time_list = list()
133  counter = 0
134 
135  for path in path_list:
136  calculated_time = self.calculate_time_func(path, speed_list[counter])
137  time_list.append(calculated_time)
138  counter += 1
139 
140  return time_list
141 
142 
143  def split_robot_task_list_func(self, robot_task_list):
144  """
145  Split incoming robot tasks into position list and time list
146  """
147  position_list = list()
148  speed_list = list()
149  time_list = list()
150 
151  for item in robot_task_list:
152  position_list.append([item[0], item[1]])
153  speed_list.append(item[2])
154 
155  path_list = self.path_calculate(position_list)
156  time_list = self.calculate_time_list_func(path_list, speed_list)
157 
158  return position_list, time_list
159 
160  @classmethod
161  def probability_of_task_completion_formula(cls, reliability, distance):
162  """
163  POTC = R ^ d
164 
165  Calculation POTC Function
166  """
167  potc_result = float(pow(float(reliability), float(distance)))
168 
169  return potc_result
170 
171  @classmethod
172  def distance_calculate(cls, start_position, finish_position):
173  """
174  Distance calculation function between 2 points
175  """
176  distance_result = float(math.sqrt(abs(pow((float(finish_position[0]) - float(start_position[0])), 2) + pow((float(finish_position[1]) - float(start_position[1])), 2))))
177 
178  return distance_result
179 
180 
181  def path_calculate(self, task_position_list):
182  """
183  Function of calculating distances in a mission
184  """
185  goals = task_position_list
186  distance_list = list()
187 
188  for goal in range(len(goals) - 1):
189  distance_list.append(self.distance_calculate(goals[goal], goals[goal+1]))
190 
191  return distance_list
192 
193 
195  """
196  POTC Reliability Value Calculation Function
197  """
198  self.simulation_time += time
199  new_reliability = self.r_calculation_class.reliability_calculate_func(time, self.hazard_rate, self.selected_reliability_model, self.selected_reliability_unit, self.shape_parameter)
200  self.main_reliability = self.main_reliability * new_reliability
201  self.main_dict[str(float(self.simulation_time))] = {"new_reliability": float(new_reliability), "main_reliability": float(self.main_reliability), "potc": float(0.0)}
202  temp_dict = {"Reliability": self.main_reliability, "Total Time": self.simulation_time}
203 
204  return temp_dict
205 
206 
207  def calculate_potc_func(self, time_list, task_position_list):
208  """
209  POTC Value Calculation Function
210  """
211  last_potc = float(0)
212  counter = 0
213 
214  for task_position in task_position_list:
215  calculate_reliability_dict = self.calculate_potc_reliability_func(time_list[counter])
216  current_potc_result = self.probability_of_task_completion_formula(calculate_reliability_dict["Reliability"], task_position)
217  self.simulation_potc = current_potc_result
218  self.simulation_distance += task_position
219  self.main_dict[str(float(calculate_reliability_dict["Total Time"]))]["potc"] = current_potc_result
220  last_potc = current_potc_result
221  counter += 1
222 
223  return last_potc
224 
225 
226  def prognostic_calculate_last_potc_func(self, time_list, task_position_list):
227  """
228  Get POTC Value
229  """
230  path_list = self.path_calculate(task_position_list)
231  potc = float(1.0)
232 
233  potc = self.calculate_potc_func(time_list, path_list)
234 
235  return potc
236 
237 
238  def prognostic_calculate_potc_func(self, simulation_count, time_list, task_position_list):
239  """
240  Get POTC values as many as the number of simulations
241 
242  Potc list = [Simulation Count, POTC Value]
243  """
244  path_list = self.path_calculate(task_position_list)
245 
246  potc_calculate_list = list()
247  potc_calculate_list.append([0, 1])
248 
249  for count in range(int(simulation_count)):
250  potc = self.calculate_potc_func(time_list, path_list)
251  potc_calculate_list.append([count+1, potc])
252 
253  return potc_calculate_list
def __init__(self, selected_reliability_model, selected_reliability_unit, shape_parameter)
def prognostic_calculate_potc_func(self, simulation_count, time_list, task_position_list)
def probability_of_task_completion_calculate_func(self, time_list, task_position, hazard_rate, reliability)
def __init__(self, hazard_rate, reliability, selected_reliability_model, selected_reliability_unit, shape_parameter)


phm_robot_task_completion
Author(s):
autogenerated on Thu Aug 13 2020 16:41:49