Git Product home page Git Product logo

parallel-new-bidirectional-a-star's Introduction

Parallel New Bidirectional A* (PNBA*)

Build Status Coverage Status License: AGPL v3

Uses the algorithm detailed in A Parallel Bidirectional Heuristic Search Algorithm (PNBA*) by Luis Henrique Oliveira Rios and Luiz Chaimowicz from Departamento de Ciência da Computaçã̃o – Universidade Federal de Minas Gerais (UFMG) – Belo Horizonte, MG – Brasil.

Example Usage

This example is a solution to Question 22 in Chapter 17 in the book Cracking the Coding Interview:

import one.util.streamex.IntStreamEx;

import java.util.Arrays;
import java.util.List;
import java.util.function.Function;

import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableListMultimap.toImmutableListMultimap;
import static java.util.function.Function.identity; 

public class Q_17_22 {
    ImmutableList<String> transform(String from, String to, String[] dictionary) {
        var wildcards = IntStreamEx.range(from.length())
             .parallel()
             .mapToObj(i -> Arrays.stream(dictionary)
                     .collect(toImmutableListMultimap(
                             word -> removeCharacter(word, i),
                             identity())))
             .collect(toImmutableList());

        Function<String, Iterable<String>> connectedNodes = s -> IntStreamEx.range(from.length())
                 .flatMapToObj(i -> wildcards
                         .get(i)
                         .get(removeCharacter(s, i))
                         .stream());
        return new ParallelShortestPathFinder<>(
                 (a, b) -> 1,
                 this::distance,
                 connectedNodes)
                 .search(from, to);
    }

    private int distance(String a, String b) {
        int count = 0;
        for (int i = 0; i < a.length(); i++) {
            if (a.charAt(i) == b.charAt(i)) {
                count++;
            }
        }
        return count;
    }

    private String removeCharacter(String s, int i) {
        return s.substring(0, i) + s.substring(i + 1);
    }
}

parallel-new-bidirectional-a-star's People

Contributors

davidleston avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.