V
V
Vyacheslav2017-11-06 01:34:58
Python
Vyacheslav, 2017-11-06 01:34:58

Is it possible to save a graph or a tree in a file?

You need to create a very large graph (adjacency list) or tree, and creating it every time you start the program is not an option. Is it possible to save it in a file (and then somehow read or recreate) so as not to lose information after the program is closed.
PS The whole complexity is not in the size of the graph, but rather in tons of information that needs to be read and the same number of operations to create it. Therefore, if it can be created only 1 time and saved, then this will solve my problem.
Language : C++ or Python

Answer the question

In order to leave comments, you need to log in

5 answer(s)
L
longclaps, 2017-11-06
@ShamanSBubnom

piclie is very fast.
dot is for visualization/debugging.

D
Denis Zagaevsky, 2017-11-06
@zagayevskiy

Can

M
maxfox, 2017-11-06
@maxfox

Here it is proposed to use a dictionary with keys-vertices and values ​​- lists of adjacent vertices.
Serialization - to your taste, even in JSON.

import json

g = {
    'A': ['B', 'C'],
    'B': ['C', 'D'],
    'C': ['D'],
    'D': ['C'],
    'E': ['F'],
    'F': ['C']
}

output = json.dumps(g)

A
amorphine, 2017-11-06
@amorphine

Usually they use caching through redis / sqlite or something else. Interfaces and bindings will decide for themselves how to serialize the object for the cache.

A
Alexander Skusnov, 2017-11-06
@AlexSku

In the 12th lecture, Dm. Soshnikov according to func. programming is told how any tree can be converted to binary, and binary to a list (a list is the basic structure for FP languages). And there is no problem to reset the list to a file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question