From 83f209e6ec220ff2db7cfae864b0c905932f35d8 Mon Sep 17 00:00:00 2001 From: Congjian Wang Date: Thu, 19 Jul 2018 13:03:25 -0600 Subject: [PATCH 1/4] fix the connected net check and isolated vertices check, which will cause errors in the ensemble model --- framework/Models/EnsembleModel.py | 2 +- framework/utils/graphStructure.py | 50 ++++++++++++++++++------------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/framework/Models/EnsembleModel.py b/framework/Models/EnsembleModel.py index 703a7278d2..c0bef6b165 100644 --- a/framework/Models/EnsembleModel.py +++ b/framework/Models/EnsembleModel.py @@ -309,7 +309,7 @@ def initialize(self,runInfo,inputs,initDict=None): # e -> d -> f if not self.ensembleModelGraph.isConnectedNet(): isolatedModels = self.ensembleModelGraph.findIsolatedVertices() - #self.raiseAnError(IOError, "Some models are not connected. Possible candidates are: "+' '.join(isolatedModels)) + self.raiseAnError(IOError, "Some models are not connected. Possible candidates are: "+' '.join(isolatedModels)) # get all paths allPath = self.ensembleModelGraph.findAllUniquePaths(self.initialStartModels) ################################################### diff --git a/framework/utils/graphStructure.py b/framework/utils/graphStructure.py index f79419ab92..348c1e7234 100644 --- a/framework/utils/graphStructure.py +++ b/framework/utils/graphStructure.py @@ -24,6 +24,7 @@ #External Modules------------------------------------------------------------------------------------ import sys import itertools +import copy #External Modules End-------------------------------------------------------------------------------- #Internal Modules------------------------------------------------------------------------------------ from utils import utils @@ -127,7 +128,7 @@ def findIsolatedVertices(self): @ In, None @ Out, isolated, list, list of isolated nodes (verteces) """ - graph = self.__graphDict + graph = self.__extendDictForGraphTheory() isolated = [] for vertex in graph: if not graph[vertex]: @@ -141,7 +142,11 @@ def findPath(self, startVertex, endVertex, path=[]): @ In, endVertex, string, the ending vertex @ Out, extendedPath, list, list of verteces (path) """ - graph = self.__graphDict + graphDict = copy.copy(self.__graphDict) + for inModel, outModels in self.__graphDict.items(): + for outModel in outModels: + if inModel not in graphDict[outModel]: + graphDict[outModel].append(inModel) path = path + [startVertex] extendedPath = None if startVertex == endVertex: @@ -202,25 +207,25 @@ def findAllPaths(self, startVertex, endVertex, path=[]): paths.append(p) return paths - def isConnected(self, verticesEncountered = None, startVertex=None): + def isConnected(self, graphDict, verticesEncountered = None, startVertex=None): """ Method that determines if the graph is connected (graph theory connectivity) @ In, verticesEncountered, set, the encountered vertices (generally it is None when called from outside) + @ In, graphDict, dict, the graph dictionary @ In, startVertex, string, the starting vertex @ Out, isConnected, bool, is the graph fully connected? """ if verticesEncountered is None: verticesEncountered = set() - gdict = self.__graphDict - vertices = list(gdict.keys()) + vertices = list(graphDict.keys()) if not startVertex: # chosse a vertex from graph as a starting point startVertex = vertices[0] verticesEncountered.add(startVertex) if len(verticesEncountered) != len(vertices): - for vertex in gdict[startVertex]: + for vertex in graphDict[startVertex]: if vertex not in verticesEncountered: - if self.isConnected(verticesEncountered, vertex): + if self.isConnected(graphDict, verticesEncountered, vertex): return True else: return True @@ -233,21 +238,26 @@ def isConnectedNet(self, startVertex=None): @ In, startVertex, string, the starting vertex @ Out, graphNetConnected, bool, is the graph net fully connected? """ - graphNetConnected = self.isConnected() - if graphNetConnected: - return graphNetConnected - # the graph is not connected (Graph theory) - uniquePaths = self.findAllUniquePaths() - # now check if there is at list a node that is common in all the paths - if len(uniquePaths) > 0: - graphNetConnected = True - startPath = set(uniquePaths.pop()) - for otherPath in uniquePaths: - if startPath.isdisjoint(otherPath): - graphNetConnected = False - break + graphDict = self.__extendDictForGraphTheory() + graphNetConnected = self.isConnected(graphDict) return graphNetConnected + def __extendDictForGraphTheory(self): + """ + Method to extend the graph dictionary in order to be accepted by the graph theory + @ In, None + @ Out, graphDict, dict, the extended graph dictionary, used for isConnectedNet and findIsolatedVertices + """ + graphDict = copy.deepcopy(self.__graphDict) + # Extend graph dictionary generated by ensemble model to graph theory acceptable dictionary + # Basicly, if a -> b (a is connected to b), the self.__graphDict = {'a':['b'], 'b':[]} + # Since a is connected to b, from the graph theory, the dictionary should become {'a':['b'], 'b':['a']} + for inModel, outModelList in self.__graphDict.items(): + for outModel in outModelList: + if inModel not in graphDict[outModel]: + graphDict[outModel].append(inModel) + return graphDict + def findAllUniquePaths(self, startVertices=None): """ This method finds all the unique paths in the graph From 6f2ba012d2d6fcad8b7d2244dc8fa0cfd72a08be Mon Sep 17 00:00:00 2001 From: Congjian Wang Date: Thu, 19 Jul 2018 14:02:57 -0600 Subject: [PATCH 2/4] fix debug messages for OutStreamPrint --- framework/OutStreams/OutStreamPrint.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/OutStreams/OutStreamPrint.py b/framework/OutStreams/OutStreamPrint.py index 9ccbcac1d5..f831476939 100644 --- a/framework/OutStreams/OutStreamPrint.py +++ b/framework/OutStreams/OutStreamPrint.py @@ -82,8 +82,8 @@ def localGetInitParams(self): for index in range(len(self.sourceName)): paramDict['Source Name ' + str(index) + ' :'] = self.sourceName[index] if self.what: - for index in range(len(self.what)): - paramDict['Variable Name ' + str(index) + ' :'] = self.what[index] + for index, var in enumerate(self.what.split(',')): + paramDict['Variable Name ' + str(index) + ' :'] = var return paramDict def initialize(self, inDict): From 3def3335224a337e7320009f5a189c3a997d5df0 Mon Sep 17 00:00:00 2001 From: Congjian Wang Date: Thu, 19 Jul 2018 14:13:01 -0600 Subject: [PATCH 3/4] revert the modification --- framework/utils/graphStructure.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/framework/utils/graphStructure.py b/framework/utils/graphStructure.py index 348c1e7234..4b42df6789 100644 --- a/framework/utils/graphStructure.py +++ b/framework/utils/graphStructure.py @@ -142,11 +142,7 @@ def findPath(self, startVertex, endVertex, path=[]): @ In, endVertex, string, the ending vertex @ Out, extendedPath, list, list of verteces (path) """ - graphDict = copy.copy(self.__graphDict) - for inModel, outModels in self.__graphDict.items(): - for outModel in outModels: - if inModel not in graphDict[outModel]: - graphDict[outModel].append(inModel) + graph = self.__graphDict path = path + [startVertex] extendedPath = None if startVertex == endVertex: From e86f4e9df0145d9d6cec3941e07303f091ce3b6f Mon Sep 17 00:00:00 2001 From: Congjian Wang Date: Thu, 19 Jul 2018 14:15:45 -0600 Subject: [PATCH 4/4] remove trailing white space --- plugins/PRAplugin/tests/CRAFT/test1/ET_SG.py | 2 +- plugins/PRAplugin/tests/CRAFT/test1/ET_V2.py | 2 +- plugins/PRAplugin/tests/CRAFT/test1/RUL_P1.py | 4 ++-- plugins/PRAplugin/tests/CRAFT/test1/RUL_SG.py | 6 +++--- plugins/PRAplugin/tests/CRAFT/test1/cost_P1P2.py | 8 ++++---- plugins/PRAplugin/tests/CRAFT/test1/cost_SG.py | 4 ++-- plugins/PRAplugin/tests/CRAFT/test1/cost_V1.py | 6 +++--- plugins/PRAplugin/tests/CRAFT/test1/cost_V2.py | 8 ++++---- plugins/PRAplugin/tests/CRAFT/test1/lambdaV1.py | 2 +- plugins/PRAplugin/tests/CRAFT/test1/lambdaV2.py | 2 +- plugins/PRAplugin/tests/CRAFT/test1/testIntegration.py | 6 +++--- plugins/PRAplugin/tests/CRAFT/test1/unav_P2.py | 2 +- plugins/PRAplugin/tests/CRAFT/testMC/ET_SG.py | 2 +- plugins/PRAplugin/tests/CRAFT/testMC/ET_V2.py | 2 +- plugins/PRAplugin/tests/CRAFT/testMC/PRAmodel.py | 6 +++--- plugins/PRAplugin/tests/CRAFT/testMC/RUL_P1.py | 4 ++-- plugins/PRAplugin/tests/CRAFT/testMC/RUL_SG.py | 6 +++--- plugins/PRAplugin/tests/CRAFT/testMC/cost_P1P2.py | 8 ++++---- plugins/PRAplugin/tests/CRAFT/testMC/cost_SG.py | 4 ++-- plugins/PRAplugin/tests/CRAFT/testMC/cost_V1.py | 6 +++--- plugins/PRAplugin/tests/CRAFT/testMC/cost_V2.py | 8 ++++---- plugins/PRAplugin/tests/CRAFT/testMC/lambdaV1.py | 2 +- plugins/PRAplugin/tests/CRAFT/testMC/lambdaV2.py | 2 +- plugins/PRAplugin/tests/CRAFT/testMC/testIntegration.py | 6 +++--- plugins/PRAplugin/tests/CRAFT/testMC/unav_P2.py | 2 +- plugins/PRAplugin/tests/CRAFT/testMC_timeDep/ET_V2.py | 2 +- plugins/PRAplugin/tests/CRAFT/testMC_timeDep/RUL_P1.py | 4 ++-- plugins/PRAplugin/tests/CRAFT/testMC_timeDep/cost_P1P2.py | 6 +++--- plugins/PRAplugin/tests/CRAFT/testMC_timeDep/cost_SG.py | 6 +++--- plugins/PRAplugin/tests/CRAFT/testMC_timeDep/cost_V1.py | 4 ++-- plugins/PRAplugin/tests/CRAFT/testMC_timeDep/cost_V2.py | 6 +++--- plugins/PRAplugin/tests/CRAFT/testMC_timeDep/lambdaV1.py | 4 ++-- plugins/PRAplugin/tests/CRAFT/testMC_timeDep/lambdaV2.py | 2 +- plugins/PRAplugin/tests/CRAFT/testMC_timeDep/plantData.py | 2 +- plugins/PRAplugin/tests/CRAFT/testMC_timeDep/unav_P2.py | 2 +- 35 files changed, 74 insertions(+), 74 deletions(-) diff --git a/plugins/PRAplugin/tests/CRAFT/test1/ET_SG.py b/plugins/PRAplugin/tests/CRAFT/test1/ET_SG.py index 8294902e10..ff3da0a62a 100644 --- a/plugins/PRAplugin/tests/CRAFT/test1/ET_SG.py +++ b/plugins/PRAplugin/tests/CRAFT/test1/ET_SG.py @@ -14,4 +14,4 @@ def run(self,Input): self.outcome_SG = 1 # SD self.p_SG_ET = self.p_SG - self.t_SG_ET = self.t_SG \ No newline at end of file + self.t_SG_ET = self.t_SG diff --git a/plugins/PRAplugin/tests/CRAFT/test1/ET_V2.py b/plugins/PRAplugin/tests/CRAFT/test1/ET_V2.py index b4d0b2d293..2b40b4c76f 100644 --- a/plugins/PRAplugin/tests/CRAFT/test1/ET_V2.py +++ b/plugins/PRAplugin/tests/CRAFT/test1/ET_V2.py @@ -14,4 +14,4 @@ def run(self,Input): self.outcome_V2 = 1 # SD self.p_V2_ET = self.p_V2 - self.t_V2_ET = self.t_V2 \ No newline at end of file + self.t_V2_ET = self.t_V2 diff --git a/plugins/PRAplugin/tests/CRAFT/test1/RUL_P1.py b/plugins/PRAplugin/tests/CRAFT/test1/RUL_P1.py index 6a818eef2b..b4f62bd640 100644 --- a/plugins/PRAplugin/tests/CRAFT/test1/RUL_P1.py +++ b/plugins/PRAplugin/tests/CRAFT/test1/RUL_P1.py @@ -6,11 +6,11 @@ def RULmodel(a,b): # a = 2.31 # b = 0.267 # https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.beta.html - + rvs = beta.rvs(a, b) time = 7300 * rvs return time - + def run(self,Input): # lambda(t) = a + t*b diff --git a/plugins/PRAplugin/tests/CRAFT/test1/RUL_SG.py b/plugins/PRAplugin/tests/CRAFT/test1/RUL_SG.py index 9407d960e1..f6dcb79e0d 100644 --- a/plugins/PRAplugin/tests/CRAFT/test1/RUL_SG.py +++ b/plugins/PRAplugin/tests/CRAFT/test1/RUL_SG.py @@ -7,7 +7,7 @@ def RULmodel(mu,sigma,time): # b = 0.267 prob = norm.cdf(time, mu, sigma) return prob - + def run(self,Input): # intput: alpha, beta @@ -19,6 +19,6 @@ def run(self,Input): self.t_SG = random.random()*Input['T'] self.p_SG = float(RULmodel(Input['alpha_SG'], Input['beta_SG'], self.t_SG)) else: - self.t_SG = Input['T']+ 1.0 + self.t_SG = Input['T']+ 1.0 self.p_SG = 1.0 - float(RULmodel(Input['alpha_SG'], Input['beta_SG'], self.t_SG)) - + diff --git a/plugins/PRAplugin/tests/CRAFT/test1/cost_P1P2.py b/plugins/PRAplugin/tests/CRAFT/test1/cost_P1P2.py index 61a9587c71..d71e0af71b 100644 --- a/plugins/PRAplugin/tests/CRAFT/test1/cost_P1P2.py +++ b/plugins/PRAplugin/tests/CRAFT/test1/cost_P1P2.py @@ -1,8 +1,8 @@ import random def run(self,Input): - # intput: - # output: + # intput: + # output: if self.outcome_P1P2 == 0: self.cost_P1P2 = 0. @@ -16,11 +16,11 @@ def run(self,Input): costSD = numberDaysSD * costPerDaySD costPerDayReg = 0.2 + 0.1 * random.random() - costReg = numberDaysSD * costPerDayReg + costReg = numberDaysSD * costPerDayReg self.cost_P1P2 = costSD + costReg else: - print('error costP1P2') + print('error costP1P2') self.p_P1P2_cost = self.p_P1P2_ET self.t_P1P2_cost = self.t_P1P2_ET diff --git a/plugins/PRAplugin/tests/CRAFT/test1/cost_SG.py b/plugins/PRAplugin/tests/CRAFT/test1/cost_SG.py index c7a75b8836..92ecb519da 100644 --- a/plugins/PRAplugin/tests/CRAFT/test1/cost_SG.py +++ b/plugins/PRAplugin/tests/CRAFT/test1/cost_SG.py @@ -1,8 +1,8 @@ import random def run(self,Input): - # intput: - # output: + # intput: + # output: if self.outcome_SG == 0: self.cost_SG = 0. diff --git a/plugins/PRAplugin/tests/CRAFT/test1/cost_V1.py b/plugins/PRAplugin/tests/CRAFT/test1/cost_V1.py index 5d5b5f827f..3d555e9667 100644 --- a/plugins/PRAplugin/tests/CRAFT/test1/cost_V1.py +++ b/plugins/PRAplugin/tests/CRAFT/test1/cost_V1.py @@ -1,8 +1,8 @@ import random def run(self,Input): - # intput: - # output: + # intput: + # output: if self.outcome_V1 == 0: self.cost_V1 = 0. @@ -12,4 +12,4 @@ def run(self,Input): self.cost_V1 = numberDaysSD * costPerDay self.p_V1_cost = self.p_V1_ET - self.t_V1_cost = self.t_V1_ET + self.t_V1_cost = self.t_V1_ET diff --git a/plugins/PRAplugin/tests/CRAFT/test1/cost_V2.py b/plugins/PRAplugin/tests/CRAFT/test1/cost_V2.py index 57315c65be..afb17851a4 100644 --- a/plugins/PRAplugin/tests/CRAFT/test1/cost_V2.py +++ b/plugins/PRAplugin/tests/CRAFT/test1/cost_V2.py @@ -1,15 +1,15 @@ import random def run(self,Input): - # intput: - # output: + # intput: + # output: if self.outcome_V2 == 0: self.cost_V2 = 0. else: numberDaysSD = float(random.randint(10,30)) costPerDay = 0.8 + 0.4 * random.random() - self.cost_V2 = numberDaysSD * costPerDay + self.cost_V2 = numberDaysSD * costPerDay self.p_V2_cost = self.p_V2_ET - self.t_V2_cost = self.t_V2_ET \ No newline at end of file + self.t_V2_cost = self.t_V2_ET diff --git a/plugins/PRAplugin/tests/CRAFT/test1/lambdaV1.py b/plugins/PRAplugin/tests/CRAFT/test1/lambdaV1.py index 3d0394f37a..6b2ef39927 100644 --- a/plugins/PRAplugin/tests/CRAFT/test1/lambdaV1.py +++ b/plugins/PRAplugin/tests/CRAFT/test1/lambdaV1.py @@ -8,7 +8,7 @@ def timeDepLambda(t,a,b): def pdfFailure(t,a,b): first = timeDepLambda(t,a,b) - second = math.exp(-quad(timeDepLambda, 0, t, args=(a,b))[0]) + second = math.exp(-quad(timeDepLambda, 0, t, args=(a,b))[0]) return first*second def run(self,Input): diff --git a/plugins/PRAplugin/tests/CRAFT/test1/lambdaV2.py b/plugins/PRAplugin/tests/CRAFT/test1/lambdaV2.py index 6f4e8d0611..c29851e068 100644 --- a/plugins/PRAplugin/tests/CRAFT/test1/lambdaV2.py +++ b/plugins/PRAplugin/tests/CRAFT/test1/lambdaV2.py @@ -9,7 +9,7 @@ def timeDepLambda(t,a,b): def pdfFailure(t,a,b): first = timeDepLambda(t,a,b) - second = math.exp(-quad(timeDepLambda, 0, t, args=(a,b))[0]) + second = math.exp(-quad(timeDepLambda, 0, t, args=(a,b))[0]) return first*second def run(self,Input): diff --git a/plugins/PRAplugin/tests/CRAFT/test1/testIntegration.py b/plugins/PRAplugin/tests/CRAFT/test1/testIntegration.py index 080d629d83..1e5c695e3b 100644 --- a/plugins/PRAplugin/tests/CRAFT/test1/testIntegration.py +++ b/plugins/PRAplugin/tests/CRAFT/test1/testIntegration.py @@ -8,7 +8,7 @@ def timeDepLambda(t,a,b): def pdfFailure(t,a,b): first = timeDepLambda(t,a,b) - second = math.exp(-quad(timeDepLambda, 0, t, args=(a,b))[0]) + second = math.exp(-quad(timeDepLambda, 0, t, args=(a,b))[0]) return first*second t = 3700. @@ -20,5 +20,5 @@ def pdfFailure(t,a,b): print(probability1, time.clock() - start_time) start_time = time.clock() -probability2 = 1. - math.exp(-quad(timeDepLambda, 0, t, args=(a_V2,b_V2))[0]) -print(probability2, time.clock() - start_time) \ No newline at end of file +probability2 = 1. - math.exp(-quad(timeDepLambda, 0, t, args=(a_V2,b_V2))[0]) +print(probability2, time.clock() - start_time) diff --git a/plugins/PRAplugin/tests/CRAFT/test1/unav_P2.py b/plugins/PRAplugin/tests/CRAFT/test1/unav_P2.py index 7fc9bb271c..b1a2a5f718 100644 --- a/plugins/PRAplugin/tests/CRAFT/test1/unav_P2.py +++ b/plugins/PRAplugin/tests/CRAFT/test1/unav_P2.py @@ -18,4 +18,4 @@ def run(self,Input): self.p_P2 = float(unavailability(rho,compLambda,Input['delta_P2'],Input['T'])) else: self.t_P2 = float(Input['T'] + 1.0) - self.p_P2 = 1.0 - float(unavailability(rho,compLambda,Input['delta_P2'],Input['T'])) \ No newline at end of file + self.p_P2 = 1.0 - float(unavailability(rho,compLambda,Input['delta_P2'],Input['T'])) diff --git a/plugins/PRAplugin/tests/CRAFT/testMC/ET_SG.py b/plugins/PRAplugin/tests/CRAFT/testMC/ET_SG.py index 8294902e10..ff3da0a62a 100644 --- a/plugins/PRAplugin/tests/CRAFT/testMC/ET_SG.py +++ b/plugins/PRAplugin/tests/CRAFT/testMC/ET_SG.py @@ -14,4 +14,4 @@ def run(self,Input): self.outcome_SG = 1 # SD self.p_SG_ET = self.p_SG - self.t_SG_ET = self.t_SG \ No newline at end of file + self.t_SG_ET = self.t_SG diff --git a/plugins/PRAplugin/tests/CRAFT/testMC/ET_V2.py b/plugins/PRAplugin/tests/CRAFT/testMC/ET_V2.py index b4d0b2d293..2b40b4c76f 100644 --- a/plugins/PRAplugin/tests/CRAFT/testMC/ET_V2.py +++ b/plugins/PRAplugin/tests/CRAFT/testMC/ET_V2.py @@ -14,4 +14,4 @@ def run(self,Input): self.outcome_V2 = 1 # SD self.p_V2_ET = self.p_V2 - self.t_V2_ET = self.t_V2 \ No newline at end of file + self.t_V2_ET = self.t_V2 diff --git a/plugins/PRAplugin/tests/CRAFT/testMC/PRAmodel.py b/plugins/PRAplugin/tests/CRAFT/testMC/PRAmodel.py index 64bce9ba6e..f5ef1b683f 100644 --- a/plugins/PRAplugin/tests/CRAFT/testMC/PRAmodel.py +++ b/plugins/PRAplugin/tests/CRAFT/testMC/PRAmodel.py @@ -2,10 +2,10 @@ def run(self,Input): - # intput: - # output: + # intput: + # output: IEfreq = 1.E-3 numberDiscretizations = 100 - self.time = np.linspace(0,Input['T'],numberDiscretizations) \ No newline at end of file + self.time = np.linspace(0,Input['T'],numberDiscretizations) diff --git a/plugins/PRAplugin/tests/CRAFT/testMC/RUL_P1.py b/plugins/PRAplugin/tests/CRAFT/testMC/RUL_P1.py index 6a818eef2b..b4f62bd640 100644 --- a/plugins/PRAplugin/tests/CRAFT/testMC/RUL_P1.py +++ b/plugins/PRAplugin/tests/CRAFT/testMC/RUL_P1.py @@ -6,11 +6,11 @@ def RULmodel(a,b): # a = 2.31 # b = 0.267 # https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.beta.html - + rvs = beta.rvs(a, b) time = 7300 * rvs return time - + def run(self,Input): # lambda(t) = a + t*b diff --git a/plugins/PRAplugin/tests/CRAFT/testMC/RUL_SG.py b/plugins/PRAplugin/tests/CRAFT/testMC/RUL_SG.py index 9407d960e1..f6dcb79e0d 100644 --- a/plugins/PRAplugin/tests/CRAFT/testMC/RUL_SG.py +++ b/plugins/PRAplugin/tests/CRAFT/testMC/RUL_SG.py @@ -7,7 +7,7 @@ def RULmodel(mu,sigma,time): # b = 0.267 prob = norm.cdf(time, mu, sigma) return prob - + def run(self,Input): # intput: alpha, beta @@ -19,6 +19,6 @@ def run(self,Input): self.t_SG = random.random()*Input['T'] self.p_SG = float(RULmodel(Input['alpha_SG'], Input['beta_SG'], self.t_SG)) else: - self.t_SG = Input['T']+ 1.0 + self.t_SG = Input['T']+ 1.0 self.p_SG = 1.0 - float(RULmodel(Input['alpha_SG'], Input['beta_SG'], self.t_SG)) - + diff --git a/plugins/PRAplugin/tests/CRAFT/testMC/cost_P1P2.py b/plugins/PRAplugin/tests/CRAFT/testMC/cost_P1P2.py index 61a9587c71..d71e0af71b 100644 --- a/plugins/PRAplugin/tests/CRAFT/testMC/cost_P1P2.py +++ b/plugins/PRAplugin/tests/CRAFT/testMC/cost_P1P2.py @@ -1,8 +1,8 @@ import random def run(self,Input): - # intput: - # output: + # intput: + # output: if self.outcome_P1P2 == 0: self.cost_P1P2 = 0. @@ -16,11 +16,11 @@ def run(self,Input): costSD = numberDaysSD * costPerDaySD costPerDayReg = 0.2 + 0.1 * random.random() - costReg = numberDaysSD * costPerDayReg + costReg = numberDaysSD * costPerDayReg self.cost_P1P2 = costSD + costReg else: - print('error costP1P2') + print('error costP1P2') self.p_P1P2_cost = self.p_P1P2_ET self.t_P1P2_cost = self.t_P1P2_ET diff --git a/plugins/PRAplugin/tests/CRAFT/testMC/cost_SG.py b/plugins/PRAplugin/tests/CRAFT/testMC/cost_SG.py index c7a75b8836..92ecb519da 100644 --- a/plugins/PRAplugin/tests/CRAFT/testMC/cost_SG.py +++ b/plugins/PRAplugin/tests/CRAFT/testMC/cost_SG.py @@ -1,8 +1,8 @@ import random def run(self,Input): - # intput: - # output: + # intput: + # output: if self.outcome_SG == 0: self.cost_SG = 0. diff --git a/plugins/PRAplugin/tests/CRAFT/testMC/cost_V1.py b/plugins/PRAplugin/tests/CRAFT/testMC/cost_V1.py index 5d5b5f827f..3d555e9667 100644 --- a/plugins/PRAplugin/tests/CRAFT/testMC/cost_V1.py +++ b/plugins/PRAplugin/tests/CRAFT/testMC/cost_V1.py @@ -1,8 +1,8 @@ import random def run(self,Input): - # intput: - # output: + # intput: + # output: if self.outcome_V1 == 0: self.cost_V1 = 0. @@ -12,4 +12,4 @@ def run(self,Input): self.cost_V1 = numberDaysSD * costPerDay self.p_V1_cost = self.p_V1_ET - self.t_V1_cost = self.t_V1_ET + self.t_V1_cost = self.t_V1_ET diff --git a/plugins/PRAplugin/tests/CRAFT/testMC/cost_V2.py b/plugins/PRAplugin/tests/CRAFT/testMC/cost_V2.py index 57315c65be..afb17851a4 100644 --- a/plugins/PRAplugin/tests/CRAFT/testMC/cost_V2.py +++ b/plugins/PRAplugin/tests/CRAFT/testMC/cost_V2.py @@ -1,15 +1,15 @@ import random def run(self,Input): - # intput: - # output: + # intput: + # output: if self.outcome_V2 == 0: self.cost_V2 = 0. else: numberDaysSD = float(random.randint(10,30)) costPerDay = 0.8 + 0.4 * random.random() - self.cost_V2 = numberDaysSD * costPerDay + self.cost_V2 = numberDaysSD * costPerDay self.p_V2_cost = self.p_V2_ET - self.t_V2_cost = self.t_V2_ET \ No newline at end of file + self.t_V2_cost = self.t_V2_ET diff --git a/plugins/PRAplugin/tests/CRAFT/testMC/lambdaV1.py b/plugins/PRAplugin/tests/CRAFT/testMC/lambdaV1.py index 3d0394f37a..6b2ef39927 100644 --- a/plugins/PRAplugin/tests/CRAFT/testMC/lambdaV1.py +++ b/plugins/PRAplugin/tests/CRAFT/testMC/lambdaV1.py @@ -8,7 +8,7 @@ def timeDepLambda(t,a,b): def pdfFailure(t,a,b): first = timeDepLambda(t,a,b) - second = math.exp(-quad(timeDepLambda, 0, t, args=(a,b))[0]) + second = math.exp(-quad(timeDepLambda, 0, t, args=(a,b))[0]) return first*second def run(self,Input): diff --git a/plugins/PRAplugin/tests/CRAFT/testMC/lambdaV2.py b/plugins/PRAplugin/tests/CRAFT/testMC/lambdaV2.py index 1b759c296f..81b6e56543 100644 --- a/plugins/PRAplugin/tests/CRAFT/testMC/lambdaV2.py +++ b/plugins/PRAplugin/tests/CRAFT/testMC/lambdaV2.py @@ -9,7 +9,7 @@ def timeDepLambda(t,a,b): def pdfFailure(t,a,b): first = timeDepLambda(t,a,b) - second = math.exp(-quad(timeDepLambda, 0, t, args=(a,b))[0]) + second = math.exp(-quad(timeDepLambda, 0, t, args=(a,b))[0]) return first*second def run(self,Input): diff --git a/plugins/PRAplugin/tests/CRAFT/testMC/testIntegration.py b/plugins/PRAplugin/tests/CRAFT/testMC/testIntegration.py index 080d629d83..1e5c695e3b 100644 --- a/plugins/PRAplugin/tests/CRAFT/testMC/testIntegration.py +++ b/plugins/PRAplugin/tests/CRAFT/testMC/testIntegration.py @@ -8,7 +8,7 @@ def timeDepLambda(t,a,b): def pdfFailure(t,a,b): first = timeDepLambda(t,a,b) - second = math.exp(-quad(timeDepLambda, 0, t, args=(a,b))[0]) + second = math.exp(-quad(timeDepLambda, 0, t, args=(a,b))[0]) return first*second t = 3700. @@ -20,5 +20,5 @@ def pdfFailure(t,a,b): print(probability1, time.clock() - start_time) start_time = time.clock() -probability2 = 1. - math.exp(-quad(timeDepLambda, 0, t, args=(a_V2,b_V2))[0]) -print(probability2, time.clock() - start_time) \ No newline at end of file +probability2 = 1. - math.exp(-quad(timeDepLambda, 0, t, args=(a_V2,b_V2))[0]) +print(probability2, time.clock() - start_time) diff --git a/plugins/PRAplugin/tests/CRAFT/testMC/unav_P2.py b/plugins/PRAplugin/tests/CRAFT/testMC/unav_P2.py index 7fc9bb271c..b1a2a5f718 100644 --- a/plugins/PRAplugin/tests/CRAFT/testMC/unav_P2.py +++ b/plugins/PRAplugin/tests/CRAFT/testMC/unav_P2.py @@ -18,4 +18,4 @@ def run(self,Input): self.p_P2 = float(unavailability(rho,compLambda,Input['delta_P2'],Input['T'])) else: self.t_P2 = float(Input['T'] + 1.0) - self.p_P2 = 1.0 - float(unavailability(rho,compLambda,Input['delta_P2'],Input['T'])) \ No newline at end of file + self.p_P2 = 1.0 - float(unavailability(rho,compLambda,Input['delta_P2'],Input['T'])) diff --git a/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/ET_V2.py b/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/ET_V2.py index 4ce55ef0fa..a8593a5d45 100644 --- a/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/ET_V2.py +++ b/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/ET_V2.py @@ -8,4 +8,4 @@ def run(self,Input): # intput: t, T (max time) # output: outcome - self.outcome_V2 = self.p_V2 * np.ones(Input['time'].size) \ No newline at end of file + self.outcome_V2 = self.p_V2 * np.ones(Input['time'].size) diff --git a/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/RUL_P1.py b/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/RUL_P1.py index 691b284a14..0cb0f57aac 100644 --- a/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/RUL_P1.py +++ b/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/RUL_P1.py @@ -7,11 +7,11 @@ def RULmodel(a,b): # a = 2.31 # b = 0.267 # https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.beta.html - + rvs = beta.rvs(a, b) time = 7300 * rvs return time - + def run(self,Input): # lambda(t) = a + t*b diff --git a/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/cost_P1P2.py b/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/cost_P1P2.py index 49a7ff0110..279756ecd6 100644 --- a/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/cost_P1P2.py +++ b/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/cost_P1P2.py @@ -2,8 +2,8 @@ import numpy as np def run(self,Input): - # intput: - # output: + # intput: + # output: self.cost_P1P2_0 = np.zeros(Input['time'].size) @@ -17,6 +17,6 @@ def run(self,Input): costSD = numberDaysSD * costPerDaySD costPerDayReg = 0.2 + 0.1 * random.random() - costReg = numberDaysSD * costPerDayReg + costReg = numberDaysSD * costPerDayReg self.cost_P1P2_2 = (costSD + costReg) * np.ones(Input['time'].size) diff --git a/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/cost_SG.py b/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/cost_SG.py index dc90a846f9..c98a6e0689 100644 --- a/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/cost_SG.py +++ b/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/cost_SG.py @@ -2,11 +2,11 @@ import numpy as np def run(self,Input): - # intput: - # output: + # intput: + # output: numberDaysSD = float(random.randint(30,60)) costPerDay = 0.8 + 0.4 * random.random() cost_SG = numberDaysSD * costPerDay - self.cost_SG = cost_SG * np.ones(Input['time'].size) \ No newline at end of file + self.cost_SG = cost_SG * np.ones(Input['time'].size) diff --git a/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/cost_V1.py b/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/cost_V1.py index cdc8398351..6ba05e2d3c 100644 --- a/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/cost_V1.py +++ b/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/cost_V1.py @@ -2,8 +2,8 @@ import numpy as np def run(self,Input): - # intput: - # output: + # intput: + # output: numberDaysSD = float(random.randint(10,30)) costPerDay = 0.8 + 0.4 * random.random() diff --git a/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/cost_V2.py b/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/cost_V2.py index 18a6d97f0c..09bee8552e 100644 --- a/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/cost_V2.py +++ b/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/cost_V2.py @@ -2,11 +2,11 @@ import numpy as np def run(self,Input): - # intput: - # output: + # intput: + # output: numberDaysSD = float(random.randint(10,30)) costPerDay = 0.8 + 0.4 * random.random() cost_V2 = numberDaysSD * costPerDay - self.cost_V2 = cost_V2 * np.ones(Input['time'].size) \ No newline at end of file + self.cost_V2 = cost_V2 * np.ones(Input['time'].size) diff --git a/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/lambdaV1.py b/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/lambdaV1.py index 23b1141316..e53000bb87 100644 --- a/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/lambdaV1.py +++ b/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/lambdaV1.py @@ -8,7 +8,7 @@ def timeDepLambda(t,a,b): def pdfFailure(t,a,b): first = timeDepLambda(t,a,b) - second = math.exp(-quad(timeDepLambda, 0, t, args=(a,b))[0]) + second = math.exp(-quad(timeDepLambda, 0, t, args=(a,b))[0]) return first*second def run(self,Input): @@ -20,4 +20,4 @@ def run(self,Input): for index,value in np.ndenumerate(Input['time']): #self.p_V1[index[0]] = quad(pdfFailure, 0, value, args=(Input['a_V1'],Input['b_V1']))[0] - self.p_V1[index[0]] = 1. - math.exp(-quad(timeDepLambda, 0, value, args=(Input['a_V1'],Input['b_V1']))[0]) + self.p_V1[index[0]] = 1. - math.exp(-quad(timeDepLambda, 0, value, args=(Input['a_V1'],Input['b_V1']))[0]) diff --git a/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/lambdaV2.py b/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/lambdaV2.py index 0d820f1ba5..96116ac8c2 100644 --- a/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/lambdaV2.py +++ b/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/lambdaV2.py @@ -9,7 +9,7 @@ def timeDepLambda(t,a,b): def pdfFailure(t,a,b): first = timeDepLambda(t,a,b) - second = math.exp(-quad(timeDepLambda, 0, t, args=(a,b))[0]) + second = math.exp(-quad(timeDepLambda, 0, t, args=(a,b))[0]) return first*second def run(self,Input): diff --git a/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/plantData.py b/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/plantData.py index 017ffdb349..79670bd621 100644 --- a/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/plantData.py +++ b/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/plantData.py @@ -11,7 +11,7 @@ def run(self,Input): powerDuration = 18.*30. # 18 months, 30 days per months SDduration = 30. cycle = powerDuration + SDduration - + self.time = np.arange(dt,T,dt) self.opPower = 100 * np.ones(len(self.time)) diff --git a/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/unav_P2.py b/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/unav_P2.py index 2fdc20344c..b98e919446 100644 --- a/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/unav_P2.py +++ b/plugins/PRAplugin/tests/CRAFT/testMC_timeDep/unav_P2.py @@ -14,4 +14,4 @@ def run(self,Input): T = 1000. #self.delta = 0.2 - self.p_P2 = float(unavailability(rho,compLambda,Input['delta_P2'],T)) * np.ones(Input['time'].size) \ No newline at end of file + self.p_P2 = float(unavailability(rho,compLambda,Input['delta_P2'],T)) * np.ones(Input['time'].size)