#!/usr/bin/env python # -*- coding: utf-8 -*- # Cet exemple permet de démontrer l'utilisation de pyfuzzy pour la prise de décision. # L'exemple utilisé est tiré d'un examen Median de l'UV SY10 # enseignée par Z. Zalila (Groupe de logique floue) de l'Université de Technologie de # Compiègne. (d'après une idée de A. Biannic & F. Linget, SY 10 A97) import sys sys.path.append('../../../pyfuzzy') def create_system(): """Create fuzzy system.""" import analyse_risque_floue return analyse_risque_floue.create_system() #import fuzzy.storage.fcl.Reader #return fuzzy.storage.fcl.Reader.Reader().load_from_file("analyse_risque_floue.fcl") def main(): """Main program.""" # build it from scratch system = create_system() output_values = {"output_risque_sit_geo" : 0.0} input_values = { "input_Nbre_habitants" : float (sys.argv[1]), "input_dist_frontiere" : float (sys.argv[2]), } print (input_values) # system.calculate(input={'input_Nbre_habitants':12., 'input_dist_frontiere':50.} , output = output_values) system.calculate(input=input_values , output = output_values) for classes in output_values.values(): for classe in classes: print (classe + " \t\t: %.2f" %classes[classe]) if __name__ == "__main__": # check if we want only generate docs if "doc" in sys.argv: from fuzzy.doc.plot.gnuplot import doc system = create_system() doc = doc.Doc("../doc") doc.createDoc(system) for a in ["Nul","Faible","Moyen","Eleve","Inacceptable"]: doc.create3DPlot_adjective(system,"input_Nbre_habitants","input_dist_frontiere","output_risque_sit_geo",a)#,x_logscale=1,y_logscale=1) elif "dot" in sys.argv: system = create_system() import fuzzy.doc.structure.dot.dot import subprocess for name,rule in system.rules.items(): cmd = "dot -T png -o '%s/Rule %s.png'" % ("../doc",name) f = subprocess.Popen(cmd, shell=True, bufsize=32768, stdin=subprocess.PIPE).stdin fuzzy.doc.structure.dot.dot.print_header(f,"XXX") fuzzy.doc.structure.dot.dot.print_dot(rule,f,system,"") fuzzy.doc.structure.dot.dot.print_footer(f) cmd = "dot -T png -o '%s/System.png'" % "../doc", f = subprocess.Popen(cmd, shell=True, bufsize=32768, stdin=subprocess.PIPE).stdin fuzzy.doc.structure.dot.dot.printDot(system,f) else: # no docs => start main if len(sys.argv) == 1: print ("Usage : \n" + sys.argv[0] +" [Nombre_habitants] [distance_frontiere]\n") sys.exit(0) main()