Пример #1
0
def intialize():
	for i in range(FoodNumber):
		for j in range(D):
			phi = random.uniform(0.0,0.999999)
			Foods[i][j] = lb[j] + phi*(ub[j] -lb[j])
			solution[j] = Foods[i][j]
		if(solution[3]>solution[2]):
			solution[3] = solution[2]
		if(solution[3]<solution[2]/2):
			solution[3] = solution[2]/2
		if(solution[0]<solution[1]*0.3):
			solution[0] = solution[1]*0.3
		if(solution[0]>solution[1]):
			solution[0] = solution[1]
		Foods[i] = solution
		print(Foods[i])
		fn_vals[i] = flexural_analysis(solution[0],solution[1],solution[2],solution[3])
		fitness[i] = CalculateFitness(fn_vals[i])
		trial[i] = 0
Пример #2
0
def soutBeephase():
	maxtrialindex=0
	for i in range(FoodNumber):
		if trial[i]>trial[maxtrialindex]:
			maxtrialindex=i
		if trial[maxtrialindex]>=limit:
			for j in range(D):
				phi = random.uniform(0.0,0.999999)
				Foods[maxtrialindex][j] = lb[j] + phi*(ub[j] -lb[j])
				solution[j] = Foods[maxtrialindex][j]
			if(solution[3]>solution[2]):
				solution[3] = solution[2]
			if(solution[3]<solution[2]/2):
				solution[3] = solution[2]/2
			if(solution[0]<solution[1]*0.3):
				solution[0] = solution[1]*0.3
			if(solution[0]>solution[1]):
				solution[0] = solution[1]
			Foods[i] = solution
			fn_vals[i] = flexural_analysis(solution[0],solution[1],solution[2],solution[3])
			fitness[i] = CalculateFitness(fn_vals[i])
			trial[i] = 0
Пример #3
0
def employedBeephase():

    for i in range(FoodNumber):
        r = random.uniform(0.0, 0.999999)
        neighbour = int(r * FoodNumber)
        while (neighbour == i):
            r = random.uniform(0.0, 0.999999)
            neighbour = int(r * FoodNumber)
        parmchange = False
        for j in range(D):
            r = random.uniform(0.0, 0.9999)
            if (r < mr):
                parmchange = True
                phi = randgen()
                solution[j] = Foods[i][j] + phi * (Foods[i][j] -
                                                   Foods[neighbour][j])
                if solution[j] < lb[j]:
                    solution[j] = lb[j]
                if solution[j] > ub[j]:
                    solution[j] = ub[j]
            else:
                solution[j] = Foods[i][j]

        r = random.uniform(0.0, 0.9999)
        parm2change = int(r * D)
        if (parmchange == False):
            parmchange = True
            phi = randgen()
            solution[parm2change] = Foods[i][parm2change] + phi * (
                Foods[i][parm2change] - Foods[neighbour][parmchange])

            if solution[parm2change] < lb[parm2change]:
                solution[parm2change] = lb[parm2change]
            if solution[parm2change] > ub[parm2change]:
                solution[parm2change] = ub[parm2change]
        if (solution[3] > solution[2]):
            solution[3] = solution[2]
        if (solution[3] < solution[2] / 2):
            solution[3] = solution[2] / 2
        if (solution[0] < solution[1] * 0.3):
            solution[0] = solution[1] * 0.3
        if (solution[0] > solution[1]):
            solution[0] = solution[1]
        Foods[i] = solution
        #for j in range(D):
        #Foods[i][j]=solution[j]

        #return Foods
        print(solution)
        objval = flexural_analysis(solution[0], solution[1], solution[2],
                                   solution[3])
        print(objval)
        FitnessSol = CalculateFitness(objval)
        #print(FitnessSol)
        #violationSol = violation(objval)

        if FitnessSol > fitness[i]:
            trial[i] = 0
            for j in range(D):
                Foods[i][j] = solution[j]
            fn_vals[i] = objval
            fitness[i] = FitnessSol
        else:
            trial[i] = trial[i] + 1