رفتن به مطلب
انجمن اندروید ایران | آموزش برنامه نویسی اندروید و موبایل
  • android.png.1fab383bc8500cd93127cebc65b1dcab.png

پست های پیشنهاد شده

سلام من دنبال الگوریتم مسیریابی سخن گو به زبان فارسی هستم یه نرم افزاری شبیه به Navitel Navigator و یه سری قابلیت های دیگه است برای پروژه یکی از دروسم لازم دارم اگر کسی میتونه کمکم کنه یا این پروژه رو انجام میده خبر بده. ممنون

لینک ارسال
به اشتراک گذاری در سایت های دیگر

میتوانید با الگوریتم Dijestra که کوتاهترین مسیر را انتخاب کنید اینکار را پیاده سازی کنید

https://play.google.com/store/apps/details?id=com.navitel&hl=en

لینک ارسال
به اشتراک گذاری در سایت های دیگر

میتوانید با الگوریتم Dijestra که کوتاهترین مسیر را انتخاب کنید اینکار را پیاده سازی کنید

https://play.google.com/store/apps/details?id=com.navitel&hl=en

ممنون از کمکتون ولی لینکی که گفتین باز نمیشه

لینک ارسال
به اشتراک گذاری در سایت های دیگر

کد الگوریتم Dijestra :

[shcode=java]

public class Dijkstra {

    private final List nodes;

    private final List edges;

    private Set unSettledNodes;

    private Set settledNodes;

    private Map predecessors;

    private Map distance;

    private Context context;

    private StationsDBAdapter stationsDBAdapter;

    public Dijkstra(Graph graph, Context c) {

        // Create a copy of the array so that we can operate on this array

        this.nodes = new ArrayList(graph.getVertexes());

        this.edges = new ArrayList(graph.getEdges());

        this.context = c;

        this.stationsDBAdapter = new StationsDBAdapter(this.context);

    }

    public void execute(Station source) {

        settledNodes = new HashSet();

        unSettledNodes = new HashSet();

        distance = new HashMap();

        predecessors = new HashMap();

        distance.put(source, 0);

        unSettledNodes.add(source);

        while (unSettledNodes.size() > 0) {

            Station node = getMinimum(unSettledNodes);

            settledNodes.add(node);

            unSettledNodes.remove(node);

            findMinimalDistances(node);

        }

    }

    public void execute(int source) {

        settledNodes = new HashSet();

        unSettledNodes = new HashSet();

        distance = new HashMap();

        predecessors = new HashMap();

        distance.put(getSrc(source), 0);

        unSettledNodes.add(getSrc(source));

        while (unSettledNodes.size() > 0) {

            Station node = getMinimum(unSettledNodes);

            settledNodes.add(node);

            unSettledNodes.remove(node);

            findMinimalDistances(node);

        }

    }

    private Station getMinimum(Set vertexes) {

        Station minimum = null;

        for (Station vertex : vertexes) {

            if (minimum == null) {

                minimum = vertex;

            } else {

                if (getShortestDistance(vertex) < getShortestDistance(minimum)) {

                    minimum = vertex;

                }

            }

        }

        return minimum;

    }

    private void findMinimalDistances(Station node) {

        List adjacentNodes = getNeighbors(node);

        for (Station target : adjacentNodes) {

            if (getShortestDistance(target) > getShortestDistance(node)

                    + getDistance(node, target)) {

                distance.put(target,

                        getShortestDistance(node) + getDistance(node, target));

                predecessors.put(target, node);

                unSettledNodes.add(target);

            }

        }

    }

    private int getShortestDistance(Station destination) {

        Integer d = distance.get(destination);

        if (d == null) {

            return Integer.MAX_VALUE;

        } else {

            return d;

        }

    }

    private List getNeighbors(Station node) {

        List neighbors = new ArrayList();

        for (Edge edge : edges) {

            if (edge.getSource().equals(node) && !isSettled(this.getDest(edge))) {

                neighbors.add(this.getDest(edge));

            }

        }

        return neighbors;

    }

    private int getDistance(Station node, Station target) {

        for (Edge edge : edges) {

            if (edge.getSource().equals(node)

                    && edge.getDestination().equals(target)) {

                return edge.getWeight();

            }

        }

        throw new RuntimeException("Should not happen");

    }

    private boolean isSettled(Station vertex) {

        return settledNodes.contains(vertex);

    }

    private Station getDest(Edge edge) {

        Station station = new Station();

        station = this.stationsDBAdapter.getStationDetails(edge

                .getDestinationID());

        return station;

    }

    private Station getSrc(int id) {

        Station station = new Station();

        station = this.stationsDBAdapter.getStationDetails(id);

        return station;

    }

    /*

     * This method returns the path from the source to the selected target and

     * NULL if no path exists

     */

    public LinkedList getPath(Station target) {

        LinkedList path = new LinkedList();

        Station step = target;

        // Check if a path exists

        if (predecessors.get(step) == null) {

            return null;

        }

        path.add(step);

        while (predecessors.get(step) != null) {

            step = predecessors.get(step);

            path.add(step);

        }

        // Put it into the correct order

        Collections.reverse(path);

        return path;

    }

    public LinkedList getPath(int target) {

        LinkedList path = new LinkedList();

        Station step = this.getSrc(target);

        // Check if a path exists

        if (predecessors.get(step) == null) {

            return null;

        }

        path.add(step);

        while (predecessors.get(step) != null) {

            step = predecessors.get(step);

            path.add(step);

        }

        // Put it into the correct order

        Collections.reverse(path);

        return path;

    }

}

[/shcode]

لینک ارسال
به اشتراک گذاری در سایت های دیگر

کد الگوریتم Dijestra :

[shcode=java]

public class Dijkstra {

    private final List nodes;

    private final List edges;

    private Set unSettledNodes;

    private Set settledNodes;

    private Map predecessors;

    private Map distance;

    private Context context;

    private StationsDBAdapter stationsDBAdapter;

    public Dijkstra(Graph graph, Context c) {

        // Create a copy of the array so that we can operate on this array

        this.nodes = new ArrayList(graph.getVertexes());

        this.edges = new ArrayList(graph.getEdges());

        this.context = c;

        this.stationsDBAdapter = new StationsDBAdapter(this.context);

    }

    public void execute(Station source) {

        settledNodes = new HashSet();

        unSettledNodes = new HashSet();

        distance = new HashMap();

        predecessors = new HashMap();

        distance.put(source, 0);

        unSettledNodes.add(source);

        while (unSettledNodes.size() > 0) {

            Station node = getMinimum(unSettledNodes);

            settledNodes.add(node);

            unSettledNodes.remove(node);

            findMinimalDistances(node);

        }

    }

    public void execute(int source) {

        settledNodes = new HashSet();

        unSettledNodes = new HashSet();

        distance = new HashMap();

        predecessors = new HashMap();

        distance.put(getSrc(source), 0);

        unSettledNodes.add(getSrc(source));

        while (unSettledNodes.size() > 0) {

            Station node = getMinimum(unSettledNodes);

            settledNodes.add(node);

            unSettledNodes.remove(node);

            findMinimalDistances(node);

        }

    }

    private Station getMinimum(Set vertexes) {

        Station minimum = null;

        for (Station vertex : vertexes) {

            if (minimum == null) {

                minimum = vertex;

            } else {

                if (getShortestDistance(vertex) < getShortestDistance(minimum)) {

                    minimum = vertex;

                }

            }

        }

        return minimum;

    }

    private void findMinimalDistances(Station node) {

        List adjacentNodes = getNeighbors(node);

        for (Station target : adjacentNodes) {

            if (getShortestDistance(target) > getShortestDistance(node)

                    + getDistance(node, target)) {

                distance.put(target,

                        getShortestDistance(node) + getDistance(node, target));

                predecessors.put(target, node);

                unSettledNodes.add(target);

            }

        }

    }

    private int getShortestDistance(Station destination) {

        Integer d = distance.get(destination);

        if (d == null) {

            return Integer.MAX_VALUE;

        } else {

            return d;

        }

    }

    private List getNeighbors(Station node) {

        List neighbors = new ArrayList();

        for (Edge edge : edges) {

            if (edge.getSource().equals(node) && !isSettled(this.getDest(edge))) {

                neighbors.add(this.getDest(edge));

            }

        }

        return neighbors;

    }

    private int getDistance(Station node, Station target) {

        for (Edge edge : edges) {

            if (edge.getSource().equals(node)

                    && edge.getDestination().equals(target)) {

                return edge.getWeight();

            }

        }

        throw new RuntimeException("Should not happen");

    }

    private boolean isSettled(Station vertex) {

        return settledNodes.contains(vertex);

    }

    private Station getDest(Edge edge) {

        Station station = new Station();

        station = this.stationsDBAdapter.getStationDetails(edge

                .getDestinationID());

        return station;

    }

    private Station getSrc(int id) {

        Station station = new Station();

        station = this.stationsDBAdapter.getStationDetails(id);

        return station;

    }

    /*

     * This method returns the path from the source to the selected target and

     * NULL if no path exists

     */

    public LinkedList getPath(Station target) {

        LinkedList path = new LinkedList();

        Station step = target;

        // Check if a path exists

        if (predecessors.get(step) == null) {

            return null;

        }

        path.add(step);

        while (predecessors.get(step) != null) {

            step = predecessors.get(step);

            path.add(step);

        }

        // Put it into the correct order

        Collections.reverse(path);

        return path;

    }

    public LinkedList getPath(int target) {

        LinkedList path = new LinkedList();

        Station step = this.getSrc(target);

        // Check if a path exists

        if (predecessors.get(step) == null) {

            return null;

        }

        path.add(step);

        while (predecessors.get(step) != null) {

            step = predecessors.get(step);

            path.add(step);

        }

        // Put it into the correct order

        Collections.reverse(path);

        return path;

    }

}

[/shcode]

سلام خسته نباشید از سایت بسیار خوبتون خیلی ممنونم

من دنبال یه کدی هستم که بتونه فرد را به مکان مورد نظرش به صورت سخن گو راهنمایی و جهت یابی کند (به اینصورت که بعد از شناسایی موقعیت فعلی کاربر با استفاده از GPS گوشیش موقعیت مورد نظرش را از طریق نقشه گوگل پیدا کند و به فرد اعلام کند)

آیا این کار با نرم افزار SDK انجام می شود؟

اگر کسی می دونه کمکم کنه و منو راهنمایی کنه

لینک ارسال
به اشتراک گذاری در سایت های دیگر

به گفتگو بپیوندید

هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .

مهمان
ارسال پاسخ به این موضوع...

×   شما در حال چسباندن محتوایی با قالب بندی هستید.   حذف قالب بندی

  تنها استفاده از 75 اموجی مجاز می باشد.

×   لینک شما به صورت اتوماتیک جای گذاری شد.   نمایش به صورت لینک

×   محتوای قبلی شما بازگردانی شد.   پاک کردن محتوای ویرایشگر

×   شما مستقیما نمی توانید تصویر خود را قرار دهید. یا آن را اینجا بارگذاری کنید یا از یک URL قرار دهید.

×
×
  • اضافه کردن...