Module analyse_risque_floue
|
|
1
2
3
4
5
6
7
8
10 """Create fuzzy system."""
11 import fuzzy
12 import fuzzy.System
13 import fuzzy.InputVariable
14 import fuzzy.OutputVariable
15 import fuzzy.fuzzify.Plain
16 import fuzzy.defuzzify.COG
17 import fuzzy.defuzzify.Dict
18 import fuzzy.Adjective
19 import fuzzy.AdjectiveProxy
20 import fuzzy.Rule
21 import fuzzy.operator
22 import fuzzy.operator.Input
23 import fuzzy.operator.Compound
24 import fuzzy.norm
25 import fuzzy.norm.Min
26 import fuzzy.set
27 import fuzzy.set.Function
28 import fuzzy.set.Polygon
29 import fuzzy.set.Trapez
30 import fuzzy.set.Triangle
31 import fuzzy.set.SFunction
32 import fuzzy.set.ZFunction
33 import fuzzy.set.PiFunction
34
35
36 system = fuzzy.System.System()
37
38
39 input_Nbre_habitants = fuzzy.InputVariable.InputVariable(
40 fuzzy.fuzzify.Plain.Plain(),
41 description="Taille aglomération",
42 min=0.0,max=10000.0,
43 unit="Milliers d'habitants"
44 )
45
46
47
48 system.variables["input_Nbre_habitants"] = input_Nbre_habitants
49
50
51
52 in1_set = fuzzy.set.Polygon.Polygon([(1.,1.),(20.,1.),(40.,0.)])
53
54 in1 = fuzzy.Adjective.Adjective(in1_set)
55
56 input_Nbre_habitants.adjectives["Petite"] = in1
57
58
59 in2_set = fuzzy.set.Triangle.Triangle(m=60.,alpha=40., beta=40.)
60
61 in2 = fuzzy.Adjective.Adjective(in2_set)
62
63 input_Nbre_habitants.adjectives["Moyenne"] = in2
64
65
66
67 in3_set = fuzzy.set.Polygon.Polygon([(80.,0.),(100.,1.),(120.,1.)])
68
69 in3 = fuzzy.Adjective.Adjective(in3_set)
70
71 input_Nbre_habitants.adjectives["Grande"] = in3
72
73
74
75
76
77 input_dist_frontiere = fuzzy.InputVariable.InputVariable(
78 fuzzy.fuzzify.Plain.Plain(),
79 description="Distance de la frontière",
80 min=0.0,max=1000.0,
81 unit="km"
82 )
83
84
85
86 system.variables["input_dist_frontiere"] = input_dist_frontiere
87
88
89
90 in1_set = fuzzy.set.Polygon.Polygon([(0.,1.),(50.,1.),(100.,0.)])
91
92 in1 = fuzzy.Adjective.Adjective(in1_set)
93
94 input_dist_frontiere.adjectives["Faible"] = in1
95
96
97 in2_set = fuzzy.set.Triangle.Triangle(m=100.,alpha=50., beta=50.)
98
99 in2 = fuzzy.Adjective.Adjective(in2_set)
100
101 input_dist_frontiere.adjectives["Moyenne"] = in2
102
103
104
105 in3_set = fuzzy.set.Polygon.Polygon([(125.,0.),(200.,1.),(250.,1.)])
106
107 in3 = fuzzy.Adjective.Adjective(in3_set)
108
109 input_dist_frontiere.adjectives["Elevee"] = in3
110
111
112
113
114 output_risque_sit_geo = fuzzy.OutputVariable.OutputVariable(defuzzify=fuzzy.defuzzify.Dict.Dict())
115
116
117
118
119
120 system.variables["output_risque_sit_geo"] = output_risque_sit_geo
121
122 out1_set = fuzzy.set.Function.Function()
123 out1 = fuzzy.Adjective.Adjective(out1_set)
124 output_risque_sit_geo.adjectives["Nul"] = out1
125
126 out2_set = fuzzy.set.Function.Function()
127 out2 = fuzzy.Adjective.Adjective(out2_set)
128 output_risque_sit_geo.adjectives["Faible"] = out2
129
130 out3_set = fuzzy.set.Function.Function()
131 out3 = fuzzy.Adjective.Adjective(out3_set)
132 output_risque_sit_geo.adjectives["Moyen"] = out3
133
134 out4_set = fuzzy.set.Function.Function()
135 out4 = fuzzy.Adjective.Adjective(out4_set)
136 output_risque_sit_geo.adjectives["Eleve"] = out4
137
138 out5_set = fuzzy.set.Function.Function()
139 out5 = fuzzy.Adjective.Adjective(out5_set)
140 output_risque_sit_geo.adjectives["Inacceptable"] = out5
141
142
143
144 rule1 = fuzzy.Rule.Rule(
145 adjective=system.variables["output_risque_sit_geo"].adjectives["Nul"],
146 operator=fuzzy.operator.Compound.Compound(
147 fuzzy.norm.Min.Min(),
148 fuzzy.operator.Input.Input(
149 system.variables["input_Nbre_habitants"].adjectives["Petite"],
150 ),
151 fuzzy.operator.Input.Input(
152 system.variables["input_dist_frontiere"].adjectives["Elevee"],
153 )
154 )
155 )
156
157
158 rule2 = fuzzy.Rule.Rule(
159 adjective=system.variables["output_risque_sit_geo"].adjectives["Faible"],
160 operator=fuzzy.operator.Compound.Compound(
161 fuzzy.norm.Min.Min(),
162 fuzzy.operator.Input.Input(
163 system.variables["input_Nbre_habitants"].adjectives["Moyenne"],
164 ),
165 fuzzy.operator.Input.Input(
166 system.variables["input_dist_frontiere"].adjectives["Elevee"],
167 )
168 )
169 )
170
171
172 rule3 = fuzzy.Rule.Rule(
173 adjective=system.variables["output_risque_sit_geo"].adjectives["Eleve"],
174 operator=fuzzy.operator.Compound.Compound(
175 fuzzy.norm.Min.Min(),
176 fuzzy.operator.Input.Input(
177 system.variables["input_Nbre_habitants"].adjectives["Grande"],
178 ),
179 fuzzy.operator.Input.Input(
180 system.variables["input_dist_frontiere"].adjectives["Elevee"],
181 )
182 )
183 )
184
185
186 rule4 = fuzzy.Rule.Rule(
187 adjective=system.variables["output_risque_sit_geo"].adjectives["Faible"],
188 operator=fuzzy.operator.Compound.Compound(
189 fuzzy.norm.Min.Min(),
190 fuzzy.operator.Input.Input(
191 system.variables["input_Nbre_habitants"].adjectives["Petite"],
192 ),
193 fuzzy.operator.Input.Input(
194 system.variables["input_dist_frontiere"].adjectives["Moyenne"],
195 )
196 )
197 )
198
199
200 rule5 = fuzzy.Rule.Rule(
201 adjective=system.variables["output_risque_sit_geo"].adjectives["Moyen"],
202 operator=fuzzy.operator.Compound.Compound(
203 fuzzy.norm.Min.Min(),
204 fuzzy.operator.Input.Input(
205 system.variables["input_Nbre_habitants"].adjectives["Moyenne"],
206 ),
207 fuzzy.operator.Input.Input(
208 system.variables["input_dist_frontiere"].adjectives["Moyenne"],
209 )
210 )
211 )
212
213
214 rule6 = fuzzy.Rule.Rule(
215 adjective=system.variables["output_risque_sit_geo"].adjectives["Inacceptable"],
216 operator=fuzzy.operator.Compound.Compound(
217 fuzzy.norm.Min.Min(),
218 fuzzy.operator.Input.Input(
219 system.variables["input_Nbre_habitants"].adjectives["Grande"],
220 ),
221 fuzzy.operator.Input.Input(
222 system.variables["input_dist_frontiere"].adjectives["Moyenne"],
223 )
224 )
225 )
226
227
228 rule7 = fuzzy.Rule.Rule(
229 adjective=system.variables["output_risque_sit_geo"].adjectives["Eleve"],
230 operator=fuzzy.operator.Compound.Compound(
231 fuzzy.norm.Min.Min(),
232 fuzzy.operator.Input.Input(
233 system.variables["input_Nbre_habitants"].adjectives["Petite"],
234 ),
235 fuzzy.operator.Input.Input(
236 system.variables["input_dist_frontiere"].adjectives["Faible"],
237 )
238 )
239 )
240
241
242 rule8 = fuzzy.Rule.Rule(
243 adjective=system.variables["output_risque_sit_geo"].adjectives["Inacceptable"],
244 operator=fuzzy.operator.Compound.Compound(
245 fuzzy.norm.Min.Min(),
246 fuzzy.operator.Input.Input(
247 system.variables["input_Nbre_habitants"].adjectives["Moyenne"],
248 ),
249 fuzzy.operator.Input.Input(
250 system.variables["input_dist_frontiere"].adjectives["Faible"],
251 )
252 )
253 )
254
255
256 rule9 = fuzzy.Rule.Rule(
257 adjective=system.variables["output_risque_sit_geo"].adjectives["Inacceptable"],
258 operator=fuzzy.operator.Compound.Compound(
259 fuzzy.norm.Min.Min(),
260 fuzzy.operator.Input.Input(
261 system.variables["input_Nbre_habitants"].adjectives["Grande"],
262 ),
263 fuzzy.operator.Input.Input(
264 system.variables["input_dist_frontiere"].adjectives["Faible"],
265 )
266 )
267 )
268
269 system.rules["rule1"] = rule1
270 system.rules["rule2"] = rule2
271 system.rules["rule3"] = rule3
272 system.rules["rule4"] = rule4
273 system.rules["rule5"] = rule5
274 system.rules["rule6"] = rule6
275 system.rules["rule7"] = rule7
276 system.rules["rule8"] = rule8
277 system.rules["rule9"] = rule9
278
279
280 return system
281