Example #1
0
    def generate_solution(n_clicks, city, coords, df_time, cache):
        if n_clicks and city and coords and df_time and n_clicks > 0:
            tic = time.time()

            df_time = parse_contents(df_time)
            solution, cities, edges = make_plot_data(
                cities=parse_contents(city),
                paths=parse_contents(coords),
                time=df_time)

            solving_time = time.time() - tic

            # Save solution
            fh.save_solution(solution, df_time.time.values[0])

            # Generate html elements
            output = [html.H3(children='The magic TSP graph'), comp.vbar()]
            output += comp.stats(solving_time, solution, cities)

            # Cache data
            cache = {'cities': prepare_data(cities), 'edges': list(edges)}

            return output, cache

        if n_clicks is not None and n_clicks > 0:
            return [html.P('no data')], dict()

        return None, dict()
Example #2
0
    def upload_paths(content, cities, name):
        if content:
            if '.csv' not in name:
                return html.Div(comp.error('Only .csv files ar supported!')),

            df = parse_contents(content)
            cities = parse_contents(cities)
            result = fh.validate_paths(df, cities)
            if not result.status:
                return comp.error(result.msg)

            return comp.upload_table(name, df)
        return [None]
Example #3
0
    def show_graph(n_clicks, city, coords, info):
        if n_clicks is not None \
                and city is not None \
                and coords is not None \
                and info is not None \
                and n_clicks > 0:
            # to check loading
            time.sleep(2)

            graph_data = tsp(cities=parse_contents(city),
                             coords=parse_contents(coords),
                             info=parse_contents(info))

            return [
                html.H3(children='The magic TSP graph'), Vbar.component,
                MainGraph.component
            ]
Example #4
0
    def upload_coordinates(content, name):
        if content is not None:
            if '.csv' not in name:
                return html.Div(['Only .csv files ar supported!']),
            df = parse_contents(content)
            result = fh.validate_paths(df)
            if not result.status:
                return html.P(result.msg),

            return comp.upload_table(name, df),
        return None,
Example #5
0
    def upload_info(content, name):
        if content is not None:
            if '.csv' not in name:
                return [
                    html.Div(['Only .csv files ar supported!']), {
                        'visibility': 'hidden'
                    }
                ]
            df = parse_contents(content)
            result = fh.validate_time(df)
            if not result.status:
                return html.P(result.msg),

            return comp.upload_table(name, df),
        return None,
Example #6
0
    def upload_time_solution(old_solution, content, name):
        if old_solution and content:
            if '.txt' not in name:
                return html.Div(comp.error('Only .txt files ar supported!')),

            result = fh.validate_solution(content)
            if not result.status:
                return comp.error(result.msg)
            return [html.Div([html.P(f'File {name} successfully uploaded!')])]

        if content:
            if '.csv' not in name:
                return [html.Div(comp.error('Only .csv files ar supported!'))]

            df = parse_contents(content)
            result = fh.validate_time(df)
            if not result.status:
                return comp.error(result.msg)

            return comp.upload_table(name, df)
        return [None]
Example #7
0
    def generate_solution(old_solution, exact, n_clicks, city, paths, df_time, n_sim, time_limit, cache):
        global CLICKS
        if old_solution and n_clicks and n_clicks > CLICKS:
            solution_content = df_time
            if solution_content:
                CLICKS += 1
                solution = fh.solution_to_output(solution_content)

                if city and paths:
                    paths = parse_contents(paths)
                    if paths.shape[0] > 0:
                        mean_time = np.mean(paths.travel_time.values)
                    else:
                        mean_time = 0.0
                    cities, edges = data_from_solution(cities=parse_contents(city),
                                                       paths=paths,
                                                       solution=solution)
                else:
                    mean_time = 0.0
                    cities, edges = data_from_solution(cities=None,
                                                       paths=None,
                                                       solution=solution)

                # Save solution
                fh.save_solution(solution, solution.time_left, new=False)

                # Generate html elements
                output = [html.H3(children='Solution'), comp.vbar()]
                output += comp.stats(0.0, solution, cities, new=False, mean_time=mean_time)

                # Cache data
                cache = {'cities': prepare_data(cities), 'edges': list(edges)}

                return output, cache

        # New solution
        elif n_clicks and city and paths and df_time and n_clicks > CLICKS:
            CLICKS += 1

            tic = time.time()
            df_time = parse_contents(df_time)
            paths = parse_contents(paths)
            if paths.shape[0] > 0:
                mean_time = np.mean(paths.travel_time.values)
            else:
                mean_time = 0.0

            solution, cities, edges = make_plot_data(cities=parse_contents(city),
                                                     paths=paths,
                                                     time=df_time,
                                                     simulations=n_sim,
                                                     time_limit=time_limit,
                                                     exact=exact)
            solving_time = time.time() - tic

            # Save solution
            fh.save_solution(solution, df_time.time.values[0])

            # Generate html elements
            output = [html.H3(children='Solution'), comp.vbar()]
            output += comp.stats(solving_time, solution, cities, input_time=df_time.time.values[0], mean_time=mean_time)

            # Cache data
            cache = {'cities': prepare_data(cities), 'edges': list(edges)}

            return output, cache

        return [None], None