pyrallelsa/examples/tsp/__init__.py
def divide(cls, divisions, problem_data):
        """divide

        :type problem_data: dict
        """
        tspp = TSPProblem(**problem_data)

        def routes_for_subgroup(cs):
            for city in cs:
                if city == tspp.start_city:
                    continue
                cities = tspp.cities.keys()
                cities.remove(tspp.start_city)
                cities.remove(city)
                random.shuffle(cities)
                route = [tspp.start_city, city] + cities
                assert len(set(route)) == len(route)
                assert len(route) == len(tspp.cities)
                yield json.dumps(route)

        if divisions:
            chunk_size = int(math.ceil(len(tspp.cities) / divisions))
        else:
            chunk_size = 1
        for subgroup in chunks(tspp.cities.keys(), chunk_size):
            routes = list(routes_for_subgroup(subgroup))
            if routes:
                yield routes
def divide(cls, divisions, problem_data):
        """divide

        :type problem_data: dict
        """
        tspp = TSPProblem(**problem_data)

        def routes_for_subgroup(cs):
            for city in cs:
                if city == tspp.start_city:
                    continue
                cities = tspp.cities.keys()
                cities.remove(tspp.start_city)
                cities.remove(city)
                random.shuffle(cities)
                route = [tspp.start_city, city] + cities
                assert len(set(route)) == len(route)
                assert len(route) == len(tspp.cities)
                yield json.dumps(route)

        if divisions:
            chunk_size = int(math.ceil(len(tspp.cities) / divisions))
        else:
            chunk_size = 1
        for subgroup in chunks(tspp.cities.keys(), chunk_size):
            routes = list(routes_for_subgroup(subgroup))
            if routes:
                yield routes
def divide ( cls , divisions , problem_data ) : tspp = TSPProblem ( * * problem_data ) def routes_for_subgroup ( cs ) : for city in cs : if city == tspp . start_city : continue cities = tspp . cities . keys ( ) cities . remove ( tspp . start_city ) cities . remove ( city ) random . shuffle ( cities ) route = [ tspp . start_city , city ] + cities assert len ( set ( route ) ) == len ( route ) assert len ( route ) == len ( tspp . cities ) yield json . dumps ( route ) if divisions : chunk_size = int ( math . ceil ( len ( tspp . cities ) / divisions ) ) else : chunk_size = 1 for subgroup in chunks ( tspp . cities . keys ( ) , chunk_size ) : routes = list ( routes_for_subgroup ( subgroup ) ) if routes : yield routes
divide

        :type problem_data: dict
divide