dft2hd2reliabilityr 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 ARDIS4SD
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,137 @@
1
+ Metadata-Version: 2.4
2
+ Name: dft2hd2reliabilityr
3
+ Version: 0.2.0
4
+ Summary: Dynamic Fault Tree -> Hasse diagram -> Reliability: minimal cut sets, minimal links and system reliability polynomials
5
+ Author-email: "Dr. Fotsa-Mbogne David Jaures" <jauresfotsa@gmail.com>
6
+ Maintainer-email: "Dr. Fotsa-Mbogne David Jaures" <jauresfotsa@gmail.com>
7
+ License: MIT License
8
+
9
+ Copyright (c) 2022 ARDIS4SD
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+
29
+ Project-URL: Homepage, https://github.com/ARDIS4SD/DFT2HD2ReliabilityR
30
+ Project-URL: Repository, https://github.com/ARDIS4SD/DFT2HD2ReliabilityR
31
+ Keywords: fault tree,dynamic fault tree,reliability,safety,Hasse diagram,minimal cut sets,minimal links,dependability
32
+ Classifier: Development Status :: 3 - Alpha
33
+ Classifier: Intended Audience :: Science/Research
34
+ Classifier: Intended Audience :: Manufacturing
35
+ Classifier: License :: OSI Approved :: MIT License
36
+ Classifier: Operating System :: OS Independent
37
+ Classifier: Programming Language :: Python :: 3
38
+ Classifier: Programming Language :: Python :: 3.9
39
+ Classifier: Programming Language :: Python :: 3.10
40
+ Classifier: Programming Language :: Python :: 3.11
41
+ Classifier: Programming Language :: Python :: 3.12
42
+ Classifier: Topic :: Scientific/Engineering
43
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
44
+ Requires-Python: >=3.9
45
+ Description-Content-Type: text/x-rst
46
+ License-File: LICENSE
47
+ Requires-Dist: sympy>=1.9
48
+ Provides-Extra: viz
49
+ Requires-Dist: matplotlib>=3.5; extra == "viz"
50
+ Requires-Dist: networkx>=2.6; extra == "viz"
51
+ Provides-Extra: test
52
+ Requires-Dist: pytest>=7.0; extra == "test"
53
+ Dynamic: license-file
54
+
55
+ .. image:: https://github.com/ARDIS4SD/DFT2HD2ReliabilityR/blob/main/DFT2HD2ReliabilityR.svg
56
+
57
+
58
+ A quoi sert ce projet ?
59
+ ========================
60
+ Le projet a pour de mettre à disposition des maintenanciers ayant
61
+ des connaissances de base de programmation python, des fonctions
62
+ permettant de construire des structures d'évaluation de la fiabilité
63
+ (arbre de défaillance, diagramme de Hasse). En particulier, il vise à
64
+ faire le calcul rapide par la méthode de satisfiabilité (coupe, lien,
65
+ polynôme de fiabilité).
66
+
67
+ The project aims to provide maintainers with basic knowledge of python
68
+ programming, functions to build reliability assessment structures (fault
69
+ tree, Hasse diagram). In particular, it aims to do fast computation by the
70
+ satisfiability method (cut, link, reliability polynomial).
71
+
72
+
73
+ Pourquoi ce projet est-il utile ?
74
+ =================================
75
+
76
+ L'évaluation de la fiabilité est un enjeux majeur de la maintenance qui elle même
77
+ est indispensable pour la productivité des entreprises. Le fait est que la maintenance
78
+ moderne est assistée par ordinateur. Malheureusement, les logiciels de gestion de la
79
+ maintenance sont assez onéreux. Il serait idéal de developper un projet open source
80
+ permettant de pallier le problème de coût, et de developper un communauté collaborative
81
+ qui fera rapidement avancer de façon ludique, les outils logiciels de pointe en matière
82
+ de maintenance.
83
+
84
+ Reliability assessment is a major maintenance issue which itself is essential for business
85
+ productivity. The fact is that maintenance modern is computer-assisted. Unfortunately, maintenance
86
+ management sofwares are quite expensive. It would be ideal to develop an open source project to
87
+ overcome the cost problem, and to develop a collaborative community which will quickly advance in
88
+ a playful way, the cutting-edge software tools for maintenance.
89
+
90
+ Comment démarrer ?
91
+ ====================
92
+
93
+ Installation (package publiable `dft2hd2reliabilityr`, dépendance dure : sympy)::
94
+
95
+ pip install dft2hd2reliabilityr # (après publication PyPI)
96
+ # ou depuis ce dépôt :
97
+ pip install . # dépendance sympy uniquement
98
+ pip install ".[viz]" # + matplotlib/networkx (ViewGraph)
99
+ pip install -e ".[test]" # mode développement + pytest
100
+
101
+ Utilisation minimale — fiabilité d'un système OR 2 composants::
102
+
103
+ from dft2hd2reliabilityr import FaultTree, DownHasseDiagram, One
104
+ import sympy
105
+
106
+ tree = FaultTree(3)
107
+ tree.NewRelation(3, [1, 1, 0], [0, 0, 1]) # OR(c0, c1)
108
+ h = DownHasseDiagram(tree, [0, 1], [sympy.Symbol("R1"), sympy.Symbol("R2")],
109
+ [[1], [1]], [One, One], [0], 1)
110
+ print(h.GetPolyFiab()) # -> poly de fiabilité
111
+
112
+ Vérification (corrections, cf. CORRECTIONS.md)::
113
+
114
+ python -m pytest -q # 14 tests unitaires (< 2 s)
115
+ python -m pytest --doctest-modules src -q # 17 doctests réels (< 1 s)
116
+
117
+ Documentation de projet::
118
+
119
+ ANALYSE.md analyse technique complète + feuille de route publication PyPI
120
+ + plan IA de décision de maintenance (importance -> sampling -> ML)
121
+ CORRECTIONS.md journal complet et tracé de TOUTES les modifications de code
122
+ (identifiants CORRECTION-01..12 — CORRECTION-09 : coupes
123
+ minimales exactes, CORRECTION-10 : sortie unifiée
124
+ ReliabilityResult, CORRECTION-11 : packaging src/ + PyPI-ready,
125
+ CORRECTION-12 : CI/lint/doctests —, tests associés)
126
+
127
+ Où puis-je obtenir plus d'aide, si j'en ai besoin?
128
+ ====================================================
129
+
130
+ En cas de besoin d'aide, bien vouloir contacter l'auteur Dr. Fotsa-Mbogne David Jaures à l'une
131
+ des adresses jauresfotsa@gmail.com, david_jamesf@yahoo.fr et mjd.fotsa@univ-ndere.cm . Dr. Fotsa-Mbogne
132
+ est également disponible sur la page https://sites.google.com/site/mjdavidfotsa/home
133
+
134
+ If you need help, please contact the author Dr. Fotsa-Mbogne David Jaures at one addresses
135
+ jauresfotsa@gmail.com, david_jamesf@yahoo.fr and mjd.fotsa@univ-ndere.cm. Dr. Fotsa-Mbogne is also
136
+ available at https://sites.google.com/site/mjdavidfotsa/home
137
+
@@ -0,0 +1,83 @@
1
+ .. image:: https://github.com/ARDIS4SD/DFT2HD2ReliabilityR/blob/main/DFT2HD2ReliabilityR.svg
2
+
3
+
4
+ A quoi sert ce projet ?
5
+ ========================
6
+ Le projet a pour de mettre à disposition des maintenanciers ayant
7
+ des connaissances de base de programmation python, des fonctions
8
+ permettant de construire des structures d'évaluation de la fiabilité
9
+ (arbre de défaillance, diagramme de Hasse). En particulier, il vise à
10
+ faire le calcul rapide par la méthode de satisfiabilité (coupe, lien,
11
+ polynôme de fiabilité).
12
+
13
+ The project aims to provide maintainers with basic knowledge of python
14
+ programming, functions to build reliability assessment structures (fault
15
+ tree, Hasse diagram). In particular, it aims to do fast computation by the
16
+ satisfiability method (cut, link, reliability polynomial).
17
+
18
+
19
+ Pourquoi ce projet est-il utile ?
20
+ =================================
21
+
22
+ L'évaluation de la fiabilité est un enjeux majeur de la maintenance qui elle même
23
+ est indispensable pour la productivité des entreprises. Le fait est que la maintenance
24
+ moderne est assistée par ordinateur. Malheureusement, les logiciels de gestion de la
25
+ maintenance sont assez onéreux. Il serait idéal de developper un projet open source
26
+ permettant de pallier le problème de coût, et de developper un communauté collaborative
27
+ qui fera rapidement avancer de façon ludique, les outils logiciels de pointe en matière
28
+ de maintenance.
29
+
30
+ Reliability assessment is a major maintenance issue which itself is essential for business
31
+ productivity. The fact is that maintenance modern is computer-assisted. Unfortunately, maintenance
32
+ management sofwares are quite expensive. It would be ideal to develop an open source project to
33
+ overcome the cost problem, and to develop a collaborative community which will quickly advance in
34
+ a playful way, the cutting-edge software tools for maintenance.
35
+
36
+ Comment démarrer ?
37
+ ====================
38
+
39
+ Installation (package publiable `dft2hd2reliabilityr`, dépendance dure : sympy)::
40
+
41
+ pip install dft2hd2reliabilityr # (après publication PyPI)
42
+ # ou depuis ce dépôt :
43
+ pip install . # dépendance sympy uniquement
44
+ pip install ".[viz]" # + matplotlib/networkx (ViewGraph)
45
+ pip install -e ".[test]" # mode développement + pytest
46
+
47
+ Utilisation minimale — fiabilité d'un système OR 2 composants::
48
+
49
+ from dft2hd2reliabilityr import FaultTree, DownHasseDiagram, One
50
+ import sympy
51
+
52
+ tree = FaultTree(3)
53
+ tree.NewRelation(3, [1, 1, 0], [0, 0, 1]) # OR(c0, c1)
54
+ h = DownHasseDiagram(tree, [0, 1], [sympy.Symbol("R1"), sympy.Symbol("R2")],
55
+ [[1], [1]], [One, One], [0], 1)
56
+ print(h.GetPolyFiab()) # -> poly de fiabilité
57
+
58
+ Vérification (corrections, cf. CORRECTIONS.md)::
59
+
60
+ python -m pytest -q # 14 tests unitaires (< 2 s)
61
+ python -m pytest --doctest-modules src -q # 17 doctests réels (< 1 s)
62
+
63
+ Documentation de projet::
64
+
65
+ ANALYSE.md analyse technique complète + feuille de route publication PyPI
66
+ + plan IA de décision de maintenance (importance -> sampling -> ML)
67
+ CORRECTIONS.md journal complet et tracé de TOUTES les modifications de code
68
+ (identifiants CORRECTION-01..12 — CORRECTION-09 : coupes
69
+ minimales exactes, CORRECTION-10 : sortie unifiée
70
+ ReliabilityResult, CORRECTION-11 : packaging src/ + PyPI-ready,
71
+ CORRECTION-12 : CI/lint/doctests —, tests associés)
72
+
73
+ Où puis-je obtenir plus d'aide, si j'en ai besoin?
74
+ ====================================================
75
+
76
+ En cas de besoin d'aide, bien vouloir contacter l'auteur Dr. Fotsa-Mbogne David Jaures à l'une
77
+ des adresses jauresfotsa@gmail.com, david_jamesf@yahoo.fr et mjd.fotsa@univ-ndere.cm . Dr. Fotsa-Mbogne
78
+ est également disponible sur la page https://sites.google.com/site/mjdavidfotsa/home
79
+
80
+ If you need help, please contact the author Dr. Fotsa-Mbogne David Jaures at one addresses
81
+ jauresfotsa@gmail.com, david_jamesf@yahoo.fr and mjd.fotsa@univ-ndere.cm. Dr. Fotsa-Mbogne is also
82
+ available at https://sites.google.com/site/mjdavidfotsa/home
83
+
@@ -0,0 +1,90 @@
1
+ # CORRECTION-11 : packaging PEP 621 (cf. CORRECTIONS.md §2, CORRECTION-11).
2
+ # Layout src/ unique : src/dft2hd2reliabilityr (la racine et l'ancien dossier
3
+ # `source/` n'existent plus).
4
+
5
+ [build-system]
6
+ requires = ["setuptools>=61"]
7
+ build-backend = "setuptools.build_meta"
8
+
9
+ [project]
10
+ name = "dft2hd2reliabilityr"
11
+ version = "0.2.0"
12
+ description = "Dynamic Fault Tree -> Hasse diagram -> Reliability: minimal cut sets, minimal links and system reliability polynomials"
13
+ readme = "README.rst"
14
+ requires-python = ">=3.9"
15
+ license = { file = "LICENSE" }
16
+ authors = [
17
+ { name = "Dr. Fotsa-Mbogne David Jaures", email = "jauresfotsa@gmail.com" },
18
+ ]
19
+ maintainers = [
20
+ { name = "Dr. Fotsa-Mbogne David Jaures", email = "jauresfotsa@gmail.com" },
21
+ ]
22
+ keywords = [
23
+ "fault tree",
24
+ "dynamic fault tree",
25
+ "reliability",
26
+ "safety",
27
+ "Hasse diagram",
28
+ "minimal cut sets",
29
+ "minimal links",
30
+ "dependability",
31
+ ]
32
+ classifiers = [
33
+ "Development Status :: 3 - Alpha",
34
+ "Intended Audience :: Science/Research",
35
+ "Intended Audience :: Manufacturing",
36
+ "License :: OSI Approved :: MIT License",
37
+ "Operating System :: OS Independent",
38
+ "Programming Language :: Python :: 3",
39
+ "Programming Language :: Python :: 3.9",
40
+ "Programming Language :: Python :: 3.10",
41
+ "Programming Language :: Python :: 3.11",
42
+ "Programming Language :: Python :: 3.12",
43
+ "Topic :: Scientific/Engineering",
44
+ "Topic :: Software Development :: Libraries :: Python Modules",
45
+ ]
46
+ # Dépendance dure : sympy uniquement (CORRECTION-04 : matplotlib/networkx
47
+ # restent optionnels, chargés paresseusement par ViewGraph).
48
+ dependencies = [
49
+ "sympy>=1.9",
50
+ ]
51
+
52
+ [project.urls]
53
+ Homepage = "https://github.com/ARDIS4SD/DFT2HD2ReliabilityR"
54
+ Repository = "https://github.com/ARDIS4SD/DFT2HD2ReliabilityR"
55
+
56
+ [project.optional-dependencies]
57
+ # Visualisation (ViewGraph) — importés paresseusement dans les modules.
58
+ viz = ["matplotlib>=3.5", "networkx>=2.6"]
59
+ # Outillage de test.
60
+ test = ["pytest>=7.0"]
61
+ # Futur lot IA (ANALYSE.md §5, P3) — réservé, à activer lors de l'ajout de ml.py.
62
+ # ml = ["numpy", "scikit-learn"]
63
+
64
+ [tool.setuptools]
65
+ include-package-data = false
66
+
67
+ [tool.setuptools.packages.find]
68
+ where = ["src"]
69
+
70
+ [tool.pytest.ini_options]
71
+ testpaths = ["tests"]
72
+
73
+ # CORRECTION-12 : base de lint minimaliste pour le legs de code — on intercepte
74
+ # les erreurs de syntaxe/runtime et les pièges critiques sans imposer le style
75
+ # strict aux ~2 500 lignes antérieures (cf. CORRECTIONS.md).
76
+ [tool.ruff]
77
+ line-length = 120
78
+ target-version = "py39"
79
+
80
+ [tool.ruff.lint]
81
+ select = [
82
+ "E9", # erreurs de syntaxe/runtime
83
+ "F63", # comparaisons always-true/false accidentelles
84
+ "F7", # annotations syntaxiquement invalides
85
+ "F82", # variables non définies
86
+ ]
87
+
88
+ [tool.ruff.lint.per-file-ignores]
89
+ # Le legs peut conserver ses longueurs de ligne et imports historiques.
90
+ "src/dft2hd2reliabilityr/*.py" = ["E501"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,291 @@
1
+ # It's a class that creates a directed graph
2
+ """
3
+ Bibliothèques utiles
4
+ """
5
+
6
+ #import plotly.graph_objects as go
7
+ # CORRECTION-04 : matplotlib/networkx sont importés paresseusement dans ViewGraph
8
+ # (deviennent un extra optionnel [viz] pour la publication PyPI).
9
+ from .LogicDoorLib import * # CORRECTION-11 : imports relatifs au package
10
+
11
+ """
12
+ Fault tree construction
13
+ """
14
+
15
+ FaultTrees={}
16
+ class FaultTree:
17
+ NFaultTree=0
18
+ def __init__(self,n):
19
+ """
20
+ It creates a new object of class Tree, and adds it to the dictionary FaultTreeRs
21
+
22
+ :param n: number of nodes
23
+ """
24
+ self.id=id(self)
25
+ FaultTrees[str(self.id)]=self
26
+ self.__class__.NFaultTree+=1
27
+ self.NNode=n # Le système a moins de composant que n
28
+ self.Node=[]
29
+ self.Label=[]
30
+ self.AdjMat={}#matlib.zeros((n, n))
31
+ self.RelMat=[[],[],[],[],[],[]]
32
+ #[[Door],[NodeIn],[NodeOut],[Orders],[Times],[IndicesPrincipal]]
33
+ self.IdxTable=[[],[],[]]
34
+ #[[NumRel],[Node i],[Node j]]
35
+
36
+ def __del__(self):
37
+ """
38
+ The __del__ method is called when the instance is about to be destroyed
39
+ """
40
+ self.__class__.NFaultTree-=1
41
+
42
+ def IdxNode(self,Indices=None):
43
+ """
44
+ It returns the index of the node in the list of nodes
45
+
46
+ :param Indices: The index of the node you want to find
47
+ :return: The index of the node in the list of nodes.
48
+ """
49
+ res=None
50
+
51
+ if (Indices in self.Node):
52
+ res=0
53
+ while (self.Node[res]!=Indices):
54
+ res=res+1
55
+ return res
56
+
57
+ def Root(self):
58
+ """
59
+ It returns the roots of the graph.
60
+ :return: The roots of the graph.
61
+ """
62
+ res=[]
63
+ for i in self.AdjMat.keys():
64
+ if (sum(self.AdjMat[i])<=self.AdjMat[i][i]):
65
+ res.append(i)
66
+ return res
67
+
68
+ def Leaves(self):
69
+ """
70
+ The function `Leaves` returns a list of all the leaf nodes in the graph
71
+ :return: The function `Leaves` returns a list of all the leaf nodes in the graph.
72
+ """
73
+ res=[]
74
+ # Checking if the node is a leaf node.
75
+ for j in range(len(self.AdjMat)):
76
+ Temp=0
77
+ # Iterating over the keys of the dictionary `self.AdjMat`.
78
+ for i in range(len(self.AdjMat)):
79
+ # Checking if the node is a leaf node.
80
+ if (i!=j):
81
+ Temp+=self.AdjMat[i][j]
82
+ if (Temp==0):#((Temp==0) and (self.RelMat[0][j]==1)):
83
+ res.append(j)
84
+ return res
85
+
86
+ def Update(self,ID_P=None ):
87
+ """
88
+ If the number of nodes is less than the maximum number of nodes, then add the new node to the
89
+ list of nodes
90
+
91
+ CORRECTION-01 (cf. CORRECTIONS.md) : ``ID_P`` devient optionnel et prend ``ID_G``
92
+ par defaut. Avant, ``NewRelation`` appelait ``self.Update()`` sans argument,
93
+ donc TOUTE creation de relation levait ``TypeError``.
94
+ """
95
+ if ID_P is None: # CORRECTION-01 : generateur d'etiquettes par defaut
96
+ ID_P = ID_G
97
+ n=len(self.RelMat[0])
98
+ if (n>0):
99
+ Test=(len(self.Node)<=self.NNode-2)
100
+ Test=Test or ((self.RelMat[1][-1] in self.Node) and (self.RelMat[2][-1] in self.Node))
101
+ Test=Test or ((not(self.RelMat[1][-1] in self.Node) or not(self.RelMat[2][-1] in self.Node)) and (len(self.Node)<=self.NNode-1))
102
+ if not(Test):
103
+ del(self.RelMat[0][-1])
104
+ del(self.RelMat[1][-1])
105
+ del(self.RelMat[2][-1])
106
+ del(self.RelMat[3][-1])
107
+ del(self.RelMat[4][-1])
108
+ del(self.RelMat[5][-1])
109
+ else:
110
+ if not(self.RelMat[1][-1] in self.Node):
111
+ self.Node.append(self.RelMat[1][-1])
112
+ # Appending the label of the node to the list of labels.
113
+ self.Label.append(ID_P(1))
114
+ for i in range(len(self.Node)-1):
115
+ self.AdjMat[i].append(0)
116
+ self.AdjMat[len(self.Node)-1]=[0 for i in range(len(self.Node))]
117
+ if not(self.RelMat[2][-1] in self.Node):
118
+ self.Node.append(self.RelMat[2][-1])
119
+ # Appending the label of the node to the list of labels.
120
+ self.Label.append(ID_P(self.RelMat[0][-1]))
121
+ for i in range(len(self.Node)-1):
122
+ self.AdjMat[i].append(0)
123
+ self.AdjMat[len(self.Node)-1]=[0 for i in range(len(self.Node))]
124
+ if (self.RelMat[0][-1]>=0):
125
+ self.IdxTable[0].append(n-1)
126
+ self.IdxTable[1].append(self.IdxNode(self.RelMat[1][-1]))
127
+ self.IdxTable[2].append(self.IdxNode(self.RelMat[2][-1]))
128
+ self.AdjMat[self.IdxTable[1][-1]][self.IdxTable[2][-1]]=1
129
+
130
+ def InOrder2(self,xx=[1,3,2],yy=[1,2,30]):
131
+ """
132
+ The function `InOrder2` takes two lists of numbers as input and returns `True` if the first list
133
+ is in ascending order and the second list is in descending order
134
+
135
+ :param xx: the list of x-coordinates of the points in the first polygon
136
+ :param yy: the list of the values of the nodes in the tree
137
+ :return: True or False
138
+
139
+
140
+ Examples:
141
+ ---------
142
+
143
+ >>> FaultTree.InOrder2(None, [1,3,2], [1,2,30])
144
+ False
145
+ """
146
+ res=True
147
+ i=0
148
+ while ((res==True) and (i<min(len(xx),len(yy)))):
149
+ res=(res and (xx[i]<=yy[i]))
150
+ i=i+1
151
+ return res
152
+
153
+ def Sort(self):
154
+ """
155
+ It sorts the relations in the order of the nodes in the graph
156
+ """
157
+ Temp1=[]
158
+ Temp2=[]
159
+ for i in range(len(self.IdxTable[0])):
160
+ j=0
161
+ for k in range(len(self.IdxTable[0])):
162
+ #if (self.InOrder2(self.RelMat[2][k],self.RelMat[1][i]) and (self.IdxTable[2][k]!=self.IdxTable[1][i])):
163
+ Test=(self.AdjMat[self.IdxNode(self.RelMat[2][k])][self.IdxNode(self.RelMat[1][i])]==1)
164
+ Test=Test or (self.InOrder2(self.RelMat[2][k],self.RelMat[1][i]))
165
+ Test=Test and (self.IdxTable[2][k]!=self.IdxTable[1][i])
166
+ if Test:
167
+ j=j+1
168
+ while (j in Temp1):
169
+ j=j+1
170
+ Temp1.append(j)
171
+ Temp2.append(0)
172
+ for i in range(len(self.IdxTable[0])):
173
+ Temp2[int(Temp1[i])]=i
174
+ Temp3=[[],[],[]]
175
+ Temp4=[[],[],[],[],[],[]]
176
+ for i in range(len(self.IdxTable[0])):
177
+ Temp3[0].append(i)
178
+ Temp3[1].append(self.IdxTable[1][int(Temp2[i])])
179
+ Temp3[2].append(self.IdxTable[2][int(Temp2[i])])
180
+ Temp4[0].append(self.RelMat[0][int(Temp2[i])])
181
+ Temp4[1].append(self.RelMat[1][int(Temp2[i])])
182
+ Temp4[2].append(self.RelMat[2][int(Temp2[i])])
183
+ Temp4[3].append(self.RelMat[3][int(Temp2[i])])
184
+ Temp4[4].append(self.RelMat[4][int(Temp2[i])])
185
+ Temp4[5].append(self.RelMat[5][int(Temp2[i])])
186
+ self.IdxTable=Temp3.copy()
187
+ self.RelMat=Temp4.copy()
188
+
189
+ def NewRelation(self,Port=1,IndicesIn=None,IndicesOut=None,Orders=None,Times=None,IndicesPrincipal=None):
190
+ """
191
+ It takes in a list of lists, and appends a list to the end of the list of lists
192
+
193
+ :param Port: The port number of the relation, defaults to 1 (optional)
194
+ :param IndicesIn: The indices of the nodes that are input to the relation
195
+ :param IndicesOut: The indices of the output nodes
196
+ :param Orders: a list of the orders of the relations
197
+ :param Times: The time at which the relation is applied
198
+ :param IndicesPrincipal: This is a list of indices that are the principal indices of the relation
199
+ """
200
+ if (IndicesIn!=None) and (IndicesOut!=None):
201
+ if True:#(len(IndicesIn)==self.NNode) and (len(IndicesOut)==self.NNode):
202
+ self.RelMat[0].append(Port)
203
+ self.RelMat[1].append(IndicesIn)
204
+ self.RelMat[2].append(IndicesOut)
205
+ self.RelMat[3].append(Orders)
206
+ self.RelMat[4].append(Times)
207
+ self.RelMat[5].append(IndicesPrincipal)
208
+ self.Update()
209
+ self.Sort()
210
+ #print(self.RelMat)
211
+
212
+ def ViewGraph(self,ID_P,Dir=None):
213
+ """
214
+ It takes a graph and returns a graph with the same nodes and edges, but with the nodes labeled
215
+ with their index in the original graph.
216
+
217
+ :param Dir: the directory where the graph will be saved
218
+ """
219
+ # CORRECTION-04 : import paresseux de la pile graphique optionnelle
220
+ try:
221
+ import networkx as nx
222
+ import matplotlib.pyplot as plt
223
+ except ImportError as exc:
224
+ raise ImportError(
225
+ "ViewGraph requires the optional visualization extras: "
226
+ "pip install matplotlib networkx"
227
+ ) from exc
228
+ G=nx.DiGraph()
229
+ GNode={}
230
+ nn=len(self.Node)
231
+ for i in self.AdjMat.keys():
232
+ for j in range(len(self.AdjMat[i])):
233
+ if (self.AdjMat[i][j]==1):
234
+ GNode[nn-1-self.IdxNode(self.Node[i])]=str(nn-1-self.IdxNode(self.Node[i]))+':'+self.Label[i]
235
+ GNode[nn-1-self.IdxNode(self.Node[j])]=str(nn-1-self.IdxNode(self.Node[j]))+':'+self.Label[j]
236
+ G.add_edge(GNode[nn-1-self.IdxNode(self.Node[i])],GNode[nn-1-self.IdxNode(self.Node[j])])
237
+ #G.add_edge(str(nn-1-self.IdxNode(self.Node[i]))+':'+self.Label[i],str(nn-1-self.IdxNode(self.Node[j]))+':'+self.Label[j])
238
+ #G.add_edge(str(self.Node[j]),str(self.Node[i]))
239
+ #CompleteNode=self.Node.copy()
240
+
241
+ mm=nn
242
+ for i in range(nn):
243
+ #print("yeah !")
244
+ #print(self.Node[i])
245
+ for j in range(nn):
246
+ if (i!=j) and self.InOrder2(self.Node[i],self.Node[j]):
247
+ G.add_edge(GNode[nn-1-self.IdxNode(self.Node[i])],GNode[nn-1-self.IdxNode(self.Node[j])])
248
+ for j in range(self.NNode):
249
+ Temp=[0 for k in range(self.NNode)]
250
+ Temp[j]=1
251
+ if (self.InOrder2(Temp,self.Node[i])) and (Temp!=self.Node[i]):
252
+ #print(Temp)
253
+ if not(Temp in self.Node):
254
+ # Adding a node to the graph.
255
+ GNode[mm]=str(mm)+':'+ID_P(1)
256
+ G.add_edge(GNode[mm],GNode[nn-1-self.IdxNode(self.Node[i])])
257
+ mm+=1
258
+ #G.add_edge(str(self.Node[i]),str(Temp))
259
+ #CompleteNode.append(Temp)
260
+
261
+ #print(G.adj)
262
+ #fig=plt.figure(figsize=(5,5))
263
+ plt.subplots(figsize=(10, 10))
264
+ plt.clf() # Efface le contenu de la figure courante
265
+ nx.draw_networkx(G,pos=nx.circular_layout(G),node_size=(10**4)/2)
266
+ #nx.draw(G)
267
+ #nx.draw(G,pos=nx.circular_layout(G),node_color='r',edge_color='b')
268
+ plt.axis('off')
269
+ #plt.grid(False)
270
+ if (Dir!=None):
271
+ plt.savefig(Dir+"AD.png")
272
+ plt.savefig(Dir+"AD.pdf",format="pdf")
273
+ plt.show()
274
+
275
+ """
276
+ Dir="E:/Pedagogie/Encadrement/EncadrementEnsai/MasterRThese/20192020/TadieBenjaulys/"
277
+ MyTree=FaultTree(2)
278
+ #MyTree.NewRelation(1,[1,0],[1,0])
279
+ #MyTree.NewRelation(1,[0,1],[0,1])
280
+ MyTree.NewRelation(4,[0,1],[1,1])
281
+ MyTree.NewRelation(3,[1,1],[1,1])
282
+
283
+ print(MyTree.NNode)
284
+ print(MyTree.Leaves())
285
+ print(MyTree.Node)
286
+ print(MyTree.IdxTable)
287
+ print(MyTree.RelMat)
288
+ print(MyTree.AdjMat)
289
+ print(MyTree.Root())
290
+ MyTree.ViewGraph(Dir)
291
+ """