Exemple #1
0
    def _initialize_routes(self):
        """
        Create one route (i.e one vehicle) for each stop
        :return: a dict[route_id] = route
        """

        for i,stop_id in enumerate(list(self.manager_stop.keys())):
            stop = self.manager_stop[stop_id]

            assert stop.demand <= self.env.capacity, stop.demand

            new_guid = "route_" + str(i)
            short_sequence = [self.manager_stop.depot,stop, self.manager_stop.depot]
            self.current_route[new_guid] = route.Route(sequence_stop=short_sequence,guid=new_guid)
Exemple #2
0
    def _concatenate_all_routes(self):
        """
        Merge all routes left
        :return: a route object
        """
        final_sequence_stop = []
        for route_id in self.current_route:
            route_considered = self.current_route[route_id]

            final_sequence_stop.extend(route_considered.sequence_stops[0:-1])  # we take everything but the last depot

        # need to add the final depot
        final_sequence_stop.append(self.manager_stop.depot)

        final_route = route.Route(sequence_stop=final_sequence_stop,guid="final_route")

        assert final_route.nb_stops == len(self.manager_stop)
        return final_route
    def _read_line(self, line):
        """
        :param line:
        :return: a route in the case where no tw
        """
        assert self.args['task_name'] == 'vrp', self.args['task_name']
        words = line.strip().split(" ")
        nb_stops = int(len(words) / 2)

        seq = []
        for i in range(0, nb_stops):
            new_guid = "i"
            seq.append(
                stop.Stop(guid=new_guid,
                          x=words[2 * i],
                          y=words[2 * i + 1],
                          demand=-1))

        return route.Route(seq)
    def _dump_results_for_transfer_learning(self,list_routes):
        """
        Write the results in the output file
        :param list_routes: a list of sequence of stops including depot if necessary
        """
        data_file =open(self.output_file_transfer_learning, 'w')
        for seq in list_routes:
            route_considered = route.Route(seq)
            data_file.write(str(route_considered.vehicles) + "*")
            depot = route_considered.depot
            # write the depot
            data_file.write(str(depot.x) + "-" + str(depot.y) + "-" + str(depot.begin_tw) + "-" + str(depot.end_tw) + "*" )
            stop_in_route = route_considered.get_only_true_stops()
            # assert len(stop_in_route) == route_considered.nb_stops
            for stop in stop_in_route:
                data_file.write(str(stop.x) + "-" + str(stop.y) + "-" + str(stop.begin_tw) + "-" + str(stop.end_tw) + "-" + str(stop.demand) + "_")

            data_file.write("\n")

        data_file.close()
    def _initialize_routes(self):
        """
        Create one route (i.e one vehicle) with the stop the furthest away from the depot
        :return: a dict[route_id] = route
        """
        depot_id = self.manager_stop.depot.guid
        list_dist_depot = [(self.matrix_dist[depot_id][stop_id], stop_id)
                           for stop_id in self.un_assigned_stop]
        list_dist_depot.sort(reverse=True)

        further = list_dist_depot[0][1]
        stop = self.manager_stop[further]
        new_guid = "route_" + str(len(self.current_route_dict))
        short_sequence = [
            self.manager_stop.depot, stop, self.manager_stop.depot
        ]
        self.current_route_dict[new_guid] = route.Route(
            sequence_stop=short_sequence, guid=new_guid)
        self.current_route = self.current_route_dict[new_guid]

        self.un_assigned_stop.remove(further)
    def _read_line_tw(self, line):
        """
        :param line:
        :return: a route in the case where tw
        """
        assert self.args['task_name'] == 'vrptw', self.args['task_name']
        words = line.strip().split(" ")
        nb_stops = int(len(words) / 4)

        seq = []
        for i in range(0, nb_stops):
            new_guid = "i"
            seq.append(
                stop_tw.StopTW(guid=new_guid,
                               x=words[4 * i],
                               y=words[4 * i + 1],
                               begin_tw=words[4 * i + 2],
                               end_tw=words[4 * i + 3],
                               demand=-1))

        return route.Route(seq)