예제 #1
0
파일: webservice.py 프로젝트: tskhoo/ovrp
        def get_xml_solution():
            """
            generates a xml solution from arguments
            """
            maps_dir = "maps"
            image_base_dir = 'graphs_images'

            cur_algorithm = "closest pair"
            cur_max_distance = 8000
            in_comment = 'Web Service OVRP Demo'

            #load_test_values()
            my_solution = HeuristicsVrp(tsp_filename="", base_dir=maps_dir, algorithm=cur_algorithm,
                                        max_distance=cur_max_distance, image_base_dir=image_base_dir,
                                        coordinates_type=self.coordinates_type, comment=in_comment,
                                        transport_capacity=self.transport_capacity, demand=self.demand,
                                        nodes=self.nodes)
            return my_solution.solution_xml()
예제 #2
0
파일: test_suite.py 프로젝트: tskhoo/ovrp
def run_test(name, max_distance, save_file, maps_location, save_all_routes, image_base_dir, max_iteractions,
             dump_explain):
    """
    @param name: map to load
    @param max_distance: max distance to test
    @save_file file to append with json results
    @return: Nothing
    """
    def local_dump_explain(solution, file_name):
        heuristic = solution.heuristic
        dirname = explain_dir + heuristic + "/" + os.path.dirname(file_name).replace("%s/" % maps_dir, "") + "/"
        if not os.path.isdir(dirname):
            os.makedirs(dirname)
        filename = os.path.basename(file_name).replace("%s" % ".vrp", "") + ".explain.txt"
        explain_text = solution.explain_solution()
        handle = open(dirname + filename, 'a')
        handle.write("%s\n" % explain_text)
        handle.close()

        pass

    print "\t\t%s" % name
    for i in range(0, len(algoritms_names)):
        if name in test_limits_max_distance.keys():
            #print "will change max distance in %s from %d to %d" % (name, max_distance, test_limits_max_distance[name])
            max_distance = test_limits_max_distance[name]
        print "\t\t\tAlgoritm: %s" % algoritms_names[i]
        my_solution = HeuristicsVrp(tsp_filename=name,
                                    base_dir=maps_location,
                                    algorithm=algoritms_names[i],
                                    max_distance=max_distance,
                                    image_base_dir=image_base_dir)
        sanity_status = my_solution.__sanity_check__()
        if sanity_status:
            #print "Sanity Check 1 Status OK"
            pass
        else:
            print "Sanity Check 1 Status FAILED, check test for %s with %s " % (name, algoritms_names[i])
            sys.exit(-1)

        f = open(save_file, 'a')
        f.write("%s\n" % my_solution.solution_json())
        f.close()
        if save_all_routes:
            my_solution.draw_all_routes(save=True)
        if dump_explain:
            local_dump_explain(solution=my_solution, file_name=name)
        #
        # Improve
        print "\t\t\tAlgoritm: %s - Improve n-2-pair-swap " % algoritms_names[i]
        my_solution.improve_base_solution_n_two_pair_swap(max_iteractions, debug=False)
        if sanity_status:
            #print "Sanity Check 2 Status OK"
            pass
        else:
            print "Sanity Check 2 Status FAILED, check test for %s with %s " % (name, algoritms_names[i])
            sys.exit(-1)


        f = open(save_file, 'a')
        f.write("%s\n" % my_solution.solution_json())
        f.close()
        if save_all_routes:
            my_solution.draw_all_routes(save=True)
        if dump_explain:
            local_dump_explain(solution=my_solution, file_name=name)

        print "\t\t\tAlgoritm: %s - Improve minimize routes  " % algoritms_names[i]
        try:
            my_solution.improve_base_solution_minimize_routes(max_iteractions, debug=False)
            if sanity_status:
                #print "Sanity Check 3 Status OK"
                pass
            else:
                print "Sanity Check 3 Status FAILED, check test for %s with %s " % (name, algoritms_names[i])
                sys.exit(-1)

            f = open(save_file, 'a')
            f.write("%s\n" % my_solution.solution_json())
            f.close()
            if save_all_routes:
                my_solution.draw_all_routes(save=True)
            if dump_explain:
                local_dump_explain(solution=my_solution, file_name=name)

        except:
            print "ERRO in minimize routes for map %s" % name