function paths = LEM_asp(G,s,t)
%

paths = [];

num_paths = 0;
min_cost = distances(G,s,t);
edges = table2array(G.Edges);
[num_edges,dummy] = size(edges);
w = edges(:,3);
tail = edges(:,2);

nodes(1).name = s;
nodes(1).level = 0;
nodes(1).parent = 0;
nodes(1).val = 0;
nodes(1).children = [];
num_nodes = 1;
OPEN = [1,s];
CLOSED = [];

while ~isempty(OPEN)
    cur_node = OPEN(1,1);
    cur_name = OPEN(1,2)
    OPEN = OPEN(2:end,:);
    CLOSED = [CLOSED;cur_node,cur_name];
    if nodes(cur_node).val==min_cost
        num_paths = num_paths + 1;
        paths(num_paths).path = LEM_traceback(nodes,cur_node);
    elseif nodes(cur_node).val<min_cost
        indexes = find(edges(:,1)==cur_name);
        if ~isempty(indexes)
            out_names = edges(indexes,2);
        else
            out_names = [];
        end
        for k = 1:length(out_names)
            index_k_OPEN = find(out_names(k)==OPEN(:,2));
            index_k_CLOSED = find(out_names(k)==CLOSED(:,2))
            if isempty(index_k_OPEN)&isempty(index_k_CLOSED)...
                    &isempty(find(out_names(k)==CLOSED(:,2)))
                num_nodes = num_nodes + 1;
                nodes(num_nodes).name = out_names(k);
                nodes(num_nodes).parent = cur_node;
                nodes(num_nodes).val = nodes(cur_node).val + w(indexes(k));
                nodes(num_nodes).level = nodes(cur_node).level + 1;
                nodes(num_nodes).children = [];
                nodes(cur_node).children = [nodes(cur_node).children,...
                    out_names(k)];
                OPEN = [OPEN;num_nodes,nodes(num_nodes).name];
            elseif ~isempty(index_k_OPEN)&isempty(index_k_CLOSED)
                new_val = nodes(cur_node).val + w(indexes(k));
                node_index = OPEN(index_k_OPEN,1);
                if nodes(node_index).val>new_val
                    nodes(node_index).val = new_val;
                    nodes(node_index).parent = cur_name;
                end
                nodes(cur_node).children = [nodes(cur_node).children,...
                    out_names(k)];
            end
        end
    end
end
