def startAt(self,r): """ Define the initial position of the agent and wipe its memory. Parameters: ---------- position : list, the initial solution to start at """ self.r = r self.car = carObjective.normCarVector_to_car(r) self.memory = [Solution(r=self.r,score=self.f(),agent_class=type(self))]
def moveTo(self,r): """ Change the agent's current solution to r and update it's score. Also add the new solution to the agent's memory and increment the agent's move countself. Parameters: ---------- r : list, shape = [nDims] the new solution to move to """ self.r = r self.car = carObjective.normCarVector_to_car(r) self.score = self.f() self.memory.append(Solution(self.r,self.score,type(self))) self.nmoves += 1
def constrain(self,r,p): self.car = carObjective.normCarVector_to_car(r) carConstrained = carObjective.constrain(self.car) rConstrained = carObjective.normalizedCarVector(carConstrained) return rConstrained #[-1 for i in range(len(x))]
def fr(self,new_r): newCar = carObjective.normCarVector_to_car(new_r) return carObjective.objective(newCar)
def f(self): #evaluate objective function for this agent's current solution self.car = carObjective.normCarVector_to_car(self.r) return carObjective.objective(self.car)
def fr(self,new_r): newCar = carObjective.normCarVector_to_car(new_r) return carObjective.objective(newCar,weights=self.obj_weights)