def Plot(): permutationSize = 4 ants=15 epoch=100 nrOfRuns=30 alpha=1.9 beta=0.9 rho=0.05 q0=0.5 #controller = Controller(ants,permutationSize,alpha,beta,q0,rho,epoch) fitnesses = [] for i in range(nrOfRuns): controller=Controller(ants,permutationSize,alpha,beta,q0,rho,epoch) controller.RunAlg() sol= controller.getMinFitness() print(sol) fitnesses.append(sol) m = np.mean(fitnesses, axis=0) stddev = np.std(fitnesses, axis=0) means = [] dev = [] for i in range(nrOfRuns): means.append(m) dev.append(abs(m-fitnesses[i])) plt.plot(range(nrOfRuns), means) plt.plot(range(nrOfRuns), dev) print("Standard deviation is: "+str(stddev)) plt.plot(range(nrOfRuns), fitnesses) plt.show()
def MainMenu(self): while(True): print("Give the number of runs") runs=int(input()) controller=Controller(runs) average,maximum=controller.RunAlg() print("Average accuracy: ",average, " Maximum accuracy: ",maximum) print("Exit(yes or no)?") choice=input() if choice=="yes": return
class LoadProblem(): def __init__(self): self.loadFromFile() self.__Controller=Controller(self.__noAnts,self.__n,self.__alpha,self.__beta,self.__q0,self.__rho,self.__noOfEpochs) def loadFromFile(self): with open('C:\\Users\\Catalin\\Desktop\\Faculty\\AI\\Lab 5\\parameters.txt', 'r') as file: line = file.readline().strip() self.__n = int(line.replace("permutation size:", "")) line = file.readline().strip() self.__noOfEpochs = int(line.replace("number of epoch:", "")) line = file.readline().strip() self.__noAnts = int(line.replace("number of ants:", "")) line = file.readline().strip() self.__alpha = float(line.replace("alpha:", "")) line = file.readline().strip() self.__beta = float(line.replace("beta:", "")) line = file.readline().strip() self.__rho = float(line.replace("rho:", "")) line = file.readline().strip() self.__q0 = float(line.replace("q0:", "")) def run(self): f=self.__Controller.RunAlg() print("Print the minimum fitness from each epoch [minimum, ant that got that minimum]:\n",f) fMin=self.__Controller.getMinFitness() print("The minimum fitness in the whole run: ",fMin ) def main(self): while(True): print("1-run,2-validate") choice=input() if choice=="1": self.run() elif choice=="2": Plot() else: return