1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 try:
19 import Gnuplot
20 have_Gnuplot = 1
21 except:
22 have_Gnuplot = 0
23
25 system = FuzzyController.getFuzzySystem()
26 from fuzzy.doc.plot.gnuplot import doc
27 doc = doc.Doc("../doc")
28 doc.createDoc(system)
29 doc.create2DPlot(system,"input_temperature","output_temperature")
30
32 system = FuzzyController.getFuzzySystem()
33 import fuzzy.doc.structure.dot.dot
34 import subprocess
35 for name,rule in system.rules.items():
36 cmd = "dot -T png -o '%s/Rule %s.png'" % ("../doc",name)
37 f = subprocess.Popen(cmd, shell=True, bufsize=32768, stdin=subprocess.PIPE).stdin
38
39 fuzzy.doc.structure.dot.dot.print_header(f,"XXX")
40 fuzzy.doc.structure.dot.dot.print_dot(rule,f,system,"")
41 fuzzy.doc.structure.dot.dot.print_footer(f)
42 cmd = "dot -T png -o '%s/System.png'" % "../doc",
43 f = subprocess.Popen(cmd, shell=True, bufsize=32768, stdin=subprocess.PIPE).stdin
44 fuzzy.doc.structure.dot.dot.printDot(system,f)
45
47 from Controller import Controller
48 FuzzyController = Controller(0,0,0)
49 import cPickle
50 file = open(filename,"rb")
51 FuzzyController.system = cPickle.load(file)
52 file.close()
53 return FuzzyController
54
56 import cPickle
57 file = open(filename,"wb")
58 cPickle.dump(FuzzyController.getFuzzySystem(),file,1)
59 file.close()
60
61
63 """Main program."""
64 import sys
65
66
67
68
69 FILENAME = "Mixer.pickle"
70
71 if "load" in sys.argv[1:]:
72
73 FuzzyController = loadController(FILENAME)
74 else:
75
76
77 Sollwert = 26.3
78 from Controller import Controller
79 FuzzyController = Controller(Sollwert,10,60)
80
81 if "save" in sys.argv[1:]:
82
83 saveController(FILENAME,FuzzyController)
84
85
86 if "doc" in sys.argv[1:]:
87 generateDocs(FuzzyController)
88 sys.exit(0)
89
90 if "dot" in sys.argv[1:]:
91 generateDot(FuzzyController)
92 sys.exit(0)
93
94 from LoggingProcess import LoggingProcess
95 process = LoggingProcess(FuzzyController)
96
97
98
99 print "\ncalculations started:"
100 import os
101 starttime = os.times()
102
103 Schritte = 600
104 for _ in range(Schritte):
105 process.step(1./20.)
106
107
108 endtime = os.times()
109 print "END: wanted value: %6.3f °C rltemp: %6.3f °C vltemp: %6.3f °C" % (Sollwert,process.rltemp,process.vltemp)
110 print "USER: %6.3f sec %d steps (%6.3fms/step)" % (endtime[0]-starttime[0],Schritte,(endtime[0]-starttime[0])/Schritte*1000.)
111 print "SYSTEM: %6.3f sec %d steps (%6.3fms/step)" % (endtime[1]-starttime[1],Schritte,(endtime[1]-starttime[1])/Schritte*1000.)
112 print "USER(C): %6.3f sec %d steps (%6.3fms/step)" % (endtime[2]-starttime[2],Schritte,(endtime[2]-starttime[2])/Schritte*1000.)
113 print "SYSTEM(C): %6.3f sec %d steps (%6.3fms/step)" % (endtime[3]-starttime[3],Schritte,(endtime[3]-starttime[3])/Schritte*1000.)
114 print "REAL: %6.3f sec %d steps (%6.3fms/step)" % (endtime[4]-starttime[4],Schritte,(endtime[4]-starttime[4])/Schritte*1000.)
115
116 process.plot()
117
118
119 if __name__ == "__main__":
120 main()
121