def __init__(self, cvrp_problem, vehicles): super(MonteCarloSavingsSolution, self).__init__(cvrp_problem, vehicles) self._vehicles = vehicles self._routes = [ models.Route(cvrp_problem, cvrp_problem.capacity()) for _ in range(len(self._nodes) - 1) ] for i, node in enumerate([ node for node in self._nodes.values() if node != cvrp_problem.depot() ]): self._routes[i].allocate([node])
def __init__(self, cvrp_problem, vehicles): """Initialize class Parameters: cvrp_problem: CVRPData instance vehicles: Vehicles number """ self._routes = [ models.Route(cvrp_problem, cvrp_problem.capacity()) for _ in range(vehicles) ] self._problem = cvrp_problem self._nodes = { x.name(): models.Node(x.name(), x.demand()) for x in cvrp_problem.nodes() } self._allocated = 0
def clone(self): """Returns a deep copy of self Clones: routes allocation nodes """ new_solution = self.__class__(self._problem, self._vehicles) # Clone routes for index, r in enumerate(self._routes): new_route = new_solution._routes[index] = models.Route( self._problem, self._problem.capacity()) for node in r.nodes(): # Insere new node on new route new_node = new_solution._nodes[node] new_route.allocate([new_node]) return new_solution