Esempio n. 1
0
for opts in newsys_options:  #for each option
    sysOut_phi, sysOut_FoM, sysOut_LD, sysOut_etaP, sysOut_GWT, sysOut_Pin, sysOut_VH = runFramework(
        opts)

    results_new[newsys_options.index(opts)].append(sysOut_phi)
    results_new[newsys_options.index(opts)].append(sysOut_FoM)
    results_new[newsys_options.index(opts)].append(sysOut_LD)
    results_new[newsys_options.index(opts)].append(sysOut_etaP)
    results_new[newsys_options.index(opts)].append(sysOut_GWT)
    results_new[newsys_options.index(opts)].append(sysOut_Pin)
    results_new[newsys_options.index(opts)].append(sysOut_VH)

for i in range(len(results)):
    print system_names[i]
    print "Objective        FPoS     Centroid"
    fpos1 = fuzzyOps.fuzzyPOS(results[i][0][0], results[i][0][1],
                              goalVals['sys_phi'])
    cent = fuzz.defuzz(np.array(results[i][0][0]), np.array(results[i][0][1]),
                       'centroid')
    print "Phi:             %.3f     %.3f" % (fpos1, cent)
    fpos2 = fuzzyOps.fuzzyPOS(results[i][1][0],
                              results[i][1][1],
                              goalVals['sys_FoM'],
                              plot=False)
    cent = fuzz.defuzz(np.array(results[i][1][0]), np.array(results[i][1][1]),
                       'centroid')
    print "FoM:             %.3f     %.3f" % (fpos2, cent)
    fpos3 = fuzzyOps.fuzzyPOS(results[i][2][0], results[i][2][1],
                              goalVals['sys_LoD'])
    cent = fuzz.defuzz(np.array(results[i][2][0]), np.array(results[i][2][1]),
                       'centroid')
    print "L/D:             %.3f     %.3f" % (fpos3, cent)
for opts in newsys_options: #for each option
    sysOut_phi, sysOut_FoM, sysOut_LD, sysOut_etaP, sysOut_GWT, sysOut_Pin, sysOut_VH = runFramework(opts)
    
    results_new[newsys_options.index(opts)].append(sysOut_phi)
    results_new[newsys_options.index(opts)].append(sysOut_FoM)
    results_new[newsys_options.index(opts)].append(sysOut_LD)
    results_new[newsys_options.index(opts)].append(sysOut_etaP)
    results_new[newsys_options.index(opts)].append(sysOut_GWT)
    results_new[newsys_options.index(opts)].append(sysOut_Pin)
    results_new[newsys_options.index(opts)].append(sysOut_VH)
    
    
for i in range(len(results)): 
    print system_names[i]
    print "Objective        FPoS     Centroid"
    fpos1 = fuzzyOps.fuzzyPOS(results[i][0][0],results[i][0][1], goalVals['sys_phi'])
    cent = fuzz.defuzz(np.array(results[i][0][0]),np.array(results[i][0][1]), 'centroid')
    print "Phi:             %.3f     %.3f" % (fpos1, cent)
    fpos2 = fuzzyOps.fuzzyPOS(results[i][1][0],results[i][1][1], goalVals['sys_FoM'], plot=False)
    cent = fuzz.defuzz(np.array(results[i][1][0]),np.array(results[i][1][1]), 'centroid')
    print "FoM:             %.3f     %.3f" % (fpos2, cent)
    fpos3 = fuzzyOps.fuzzyPOS(results[i][2][0],results[i][2][1], goalVals['sys_LoD'])
    cent = fuzz.defuzz(np.array(results[i][2][0]),np.array(results[i][2][1]), 'centroid')
    print "L/D:             %.3f     %.3f" % (fpos3, cent)
    fpos4 = fuzzyOps.fuzzyPOS(results[i][3][0],results[i][3][1], goalVals['sys_etaP'])
    cent = fuzz.defuzz(np.array(results[i][3][0]),np.array(results[i][3][1]), 'centroid')
    print "etaP:            %.3f     %.3f" % (fpos4, cent)
    fpos5 = fuzzyOps.fuzzyPOS(results[i][5][0],results[i][5][1], goalVals['sys_Pin'], direction='min')
    cent = fuzz.defuzz(np.array(results[i][5][0]),np.array(results[i][5][1]), 'centroid')
    print "Pin:             %.3f     %.3f" % (fpos5, cent)
    print "TOTAL:           %.3f" % min(fpos1,fpos2,fpos3,fpos4,fpos5)
Esempio n. 3
0
    def execute(self):
        """
        Translate fuzzy inputs to crisp values to optimize system.
        """      
        inputs = [self.fuzzSys_in_1, self.fuzzSys_in_2, self.fuzzSys_in_3, 
        		  self.fuzzSys_in_4, self.fuzzSys_in_5, self.fuzzSys_in_6,
                  self.fuzzSys_in_7, self.fuzzSys_in_8, self.fuzzSys_in_9]
        outs  = [[self.response_1][0], [self.response_2][0], self.response_3, 
                 self.response_4, self.response_5, self.response_6,
                 self.response_7, self.response_8, self.response_9]
        outs_r  = [self.response_1_r, self.response_2_r, self.response_3_r, 
                   self.response_4_r, self.response_5_r, self.response_6_r,
                   self.response_7_r, self.response_8_r, self.response_9_r]
        
        if self.passthrough == 1:
            if self.printResults == 1: print "Incompatible combo found..."
            self.response_1     = 0.0 #phi
            self.response_1_r   = 0.0 
            self.response_1_POS = -1.0

            self.response_2     = 0.0 #FoM
            self.response_2_r   = 0.0
            self.response_2_POS = -1.0

            self.response_3     = 0.0 #LoD
            self.response_3_r   = 0.0
            self.response_3_POS = -1.0

            self.response_4     = 0.0 #etaP
            self.response_4_r   = 0.0
            self.response_4_POS = -1.0

            self.response_5     = 0.0 #GWT
            self.response_5_r   = 0.0
            self.response_5_POS = -1.0

            self.response_6     = -99999.0 #P
            self.response_6_r   = 0.0
            self.response_6_POS = 0.0 

            self.response_7     = 0.0 #VH
            self.response_7_r   = 0.0
            self.response_7_POS = -1.0

            return None

        else:
            #get alpha cuts for crisp responses and ranges 
            for i in range(len(inputs)):
                
                if inputs[i].mf_key	<> '':
                    if len(inputs[i].mf_dict[inputs[i].mf_key]) 	 == 1: #crisp value
                        self.ranges_out[inputs[i].mf_key] = [inputs[i].mf_dict[inputs[i].mf_key][0], inputs[i].mf_dict[inputs[i].mf_key][0]]
                    elif len(inputs[i].mf_dict[inputs[i].mf_key])  == 2: #fuzzy function
                        self.ranges_out[inputs[i].mf_key] = fuzzyOps.alpha_cut(self.alpha_val, inputs[i].mf_dict[inputs[i].mf_key])

                    #capture results for crisp measures
                    if self.ranges_out[inputs[i].mf_key] <> None: y = self.ranges_out[inputs[i].mf_key]
                    else:                                         y = [0.0, 0.0]

                    if inputs[i].mf_key == 'sys_phi': 
                        self.response_1 = fuzz.defuzz(inputs[i].mf_dict[inputs[i].mf_key][0],np.array(inputs[i].mf_dict[inputs[i].mf_key][1]),'centroid')
                        self.response_1 = self.response_1 * math.exp(-self.incompatCount)**0.5
                        self.response_1_r = max(y) - min(y)
                        self.response_1_POS = fuzzyOps.fuzzyPOS(inputs[i].mf_dict[inputs[i].mf_key][0],np.array(inputs[i].mf_dict[inputs[i].mf_key][1]), self.goalVals['sys_phi'])
                   
                    if inputs[i].mf_key == 'sys_FoM': 
                        self.response_2 = fuzz.defuzz(inputs[i].mf_dict[inputs[i].mf_key][0],np.array(inputs[i].mf_dict[inputs[i].mf_key][1]),'centroid')
                        self.response_2 = self.response_2 * math.exp(-self.incompatCount)**0.5
                        self.response_2_r = max(y) - min(y)
                        #if self.response_2 < 0.6:  
                        #    self.response_2_POS = fuzzyOps.fuzzyPOS(inputs[i].mf_dict[inputs[i].mf_key][0],np.array(inputs[i].mf_dict[inputs[i].mf_key][1]), self.goalVals['sys_FoM'], direction='max', plot=True)
                        self.response_2_POS = fuzzyOps.fuzzyPOS(inputs[i].mf_dict[inputs[i].mf_key][0],np.array(inputs[i].mf_dict[inputs[i].mf_key][1]), self.goalVals['sys_FoM'])

                    if inputs[i].mf_key == 'sys_LoD': 
                        self.response_3 = fuzz.defuzz(inputs[i].mf_dict[inputs[i].mf_key][0],np.array(inputs[i].mf_dict[inputs[i].mf_key][1]),'centroid')
                        self.response_2 = self.response_3 * math.exp(-self.incompatCount)**0.5
                        self.response_3_r = max(y) - min(y)
                        self.response_3_POS = fuzzyOps.fuzzyPOS(inputs[i].mf_dict[inputs[i].mf_key][0],np.array(inputs[i].mf_dict[inputs[i].mf_key][1]), self.goalVals['sys_LoD'])

                    if inputs[i].mf_key == 'sys_etaP': 
                        self.response_4 = fuzz.defuzz(inputs[i].mf_dict[inputs[i].mf_key][0],np.array(inputs[i].mf_dict[inputs[i].mf_key][1]),'centroid')
                        self.response_4 = self.response_4 * math.exp(-self.incompatCount)**0.5
                        self.response_4_r = max(y) - min(y)
                        self.response_4_POS = fuzzyOps.fuzzyPOS(inputs[i].mf_dict[inputs[i].mf_key][0],np.array(inputs[i].mf_dict[inputs[i].mf_key][1]), self.goalVals['sys_etaP'])

                    if inputs[i].mf_key == 'sys_GWT': #invert GWT to maximize all
                        self.response_5 = fuzz.defuzz(inputs[i].mf_dict[inputs[i].mf_key][0],np.array(inputs[i].mf_dict[inputs[i].mf_key][1]),'centroid')
                        self.response_5 = self.response_5 * math.exp(-self.incompatCount)**0.5
                        self.response_5_r = max(y) - min(y)
                        self.response_5_POS = fuzzyOps.fuzzyPOS(inputs[i].mf_dict[inputs[i].mf_key][0],np.array(inputs[i].mf_dict[inputs[i].mf_key][1]), self.goalVals['sys_GWT'], direction='min')

                    
                    if inputs[i].mf_key == 'sys_P': #invert GWT to maximize all
                        self.response_6 = 0.0-fuzz.defuzz(inputs[i].mf_dict[inputs[i].mf_key][0],np.array(inputs[i].mf_dict[inputs[i].mf_key][1]),'centroid')
                        self.response_6 = self.response_6 * math.exp(-self.incompatCount)**0.5
                        self.response_6_r = max(y) - min(y)
                        self.response_6_POS = fuzzyOps.fuzzyPOS(inputs[i].mf_dict[inputs[i].mf_key][0],np.array(inputs[i].mf_dict[inputs[i].mf_key][1]), self.goalVals['sys_Pin'], direction='min')

                    if inputs[i].mf_key == 'sys_VH': #invert GWT to maximize all
                        self.response_7 = fuzz.defuzz(inputs[i].mf_dict[inputs[i].mf_key][0],np.array(inputs[i].mf_dict[inputs[i].mf_key][1]),'centroid')
                        self.response_7 = self.response_7 * math.exp(-self.incompatCount)**0.5
                        self.response_7_r = max(y) - min(y)
                        self.response_7_POS = fuzzyOps.fuzzyPOS(inputs[i].mf_dict[inputs[i].mf_key][0],np.array(inputs[i].mf_dict[inputs[i].mf_key][1]), self.goalVals['sys_VH'])

                        self.fuzzyPOS = self.response_1_POS*self.response_2_POS*self.response_3_POS*self.response_4_POS*self.response_6_POS


        if self.printResults == 1: #print results
            print "Alternative:", self.passthrough, ":",
            print "PHI: %.1f, (%.3f)" % (self.response_1, self.response_1_POS),
            print "  FoM: %.3f, (%.3f)" % (self.response_2, self.response_2_POS), 
            print "  L/D: %.1f, (%.3f)" % (self.response_3, self.response_3_POS),
            print "  etaP: %.3f, (%.3f)" % (self.response_4, self.response_4_POS),
            print "  GWT: %.0f, (%.3f)" % (self.response_5, self.response_5_POS),
            print "  Pinst: %.0f, (%.3f)" % (self.response_6, self.response_6_POS),
            print "  VH: %.0f, (%.3f)" % (self.response_7, self.response_7_POS),
            print "  FPOS: %.3f" % self.fuzzyPOS

        #plotting for testing
        if self.PLOTMODE == 1: #plot results
            plt.figure()
            i=1
            for r in inputs:
                plt.subplot(3,2,i)
                if r.mf_key <> '':
                    if len(r.mf_dict[r.mf_key])      == 1: #crisp value
                        pass#self.ranges_out[r.mf_key] = [r.mf_dict[r.mf_key][0], r.mf_dict[r.mf_key][1]]
                    elif len(r.mf_dict[r.mf_key])  == 2: #fuzzy function
                        plt.plot(r.mf_dict[r.mf_key][0],r.mf_dict[r.mf_key][1])
                    i = i + 1

            plt.show()