New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Errors while exporting and importing graphs #2
Comments
@Annwenn |
Yes sure, here's the code of the def export_graph(graph, file \\ "priv/graph.txt") do
n = :graph.num_of_vertices(graph)
m = :graph.num_of_edges(graph)
{:graph, t, _} = graph
d = "d"
first_line = ~s(#{n} #{m} #{t} #{d})
data =
:graph.edges_with_weights(graph) |>
Enum.map_join("\n", fn(x) -> {{foo, bar}, w} = x ;
"#{foo} #{bar} #{w}" end)
content = """
#{first_line}
#{data}
"""
IO.puts("Graph contains #{n} vertices, #{m} edges and is #{t}.")
IO.inspect content
File.write(file, content)
end Most of my functions are wrappers around yours and return the graph (which is stored as a state in the GenServer) so I can pipeline them with the iex(3)⋅❯ Uwotm8.add_user("foo")
{:graph, :directed, {:digraph, 290855, 294953, 299050, true}}
iex(4)⋅❯ Uwotm8.add_user("bar")
{:graph, :directed, {:digraph, 290855, 294953, 299050, true}}
iex(5)⋅❯ Uwotm8.add_user("baz")
{:graph, :directed, {:digraph, 290855, 294953, 299050, true}}
iex(6)⋅❯ Uwotm8.add_edge("foo", "bar", 20)
{:graph, :directed, {:digraph, 290855, 294953, 299050, true}}
iex(7)⋅❯ Uwotm8.add_edge("bar", "foo", 20)
{:graph, :directed, {:digraph, 290855, 294953, 299050, true}}
iex(8)⋅❯ Uwotm8.add_edge("bar", "baz", 80)
{:graph, :directed, {:digraph, 290855, 294953, 299050, true}}
iex(9)⋅❯ Uwotm8.print_graph
:ok
[{From, [{To, Weight}]}]
========================
iex(10)⋅❯ [{<<"bar">>,[{<<"foo">>,20},{<<"baz">>,80}]},
{<<"baz">>,[]},
{<<"foo">>,[{<<"bar">>,20}]}]
iex(10)⋅❯ Uwotm8.Worker.export_graph {:graph, :directed, {:digraph, 290855, 294953, 299050, true}}
Graph contains 3 vertices, 3 edges and is directed.
"3 3 directed d\nbar foo 20\nfoo bar 20\nbar baz 80\n"
:ok Then the file looks like :
After a few corrections in the code, the error now looks like iex(36)⋅❯ :graph.from_file('priv/graph.txt')
** (MatchError) no match of right hand side value: {:error, {:fread, :integer}}
:graph.read_edge/2
:graph.init_edges/6
:graph.from_file/3
(stdlib) :digraph.del_edge/2 |
@Annwenn Hello! The problem is that To facilitate importing / exporting graphs I just added two new MFAs:
I've also added your use case an example in import_export.erl. A possibly better example of importing a graph can be found in a_star_demo. |
Woah, thank you! |
@Annwenn |
@aggelgian |
@aggelgian
I'm using the
graph
module to export & import graphs.While exporting a graph, I sometimes get this error
When I export the graph to a file and call
:graph.from_file/('priv/graph.txt')
, I get this error:Right now my priority is the ability to import a graph. Could you tell me what I'm missing?
The text was updated successfully, but these errors were encountered: