Ask Your Question
0

Error in datastructure in sagemath

asked 2020-03-14 18:58:33 -0500

MrsO gravatar image

updated 2020-03-16 07:38:28 -0500

FrédéricC gravatar image

I am new to creating a graph. I am trying to analyse a code by recreating it. My sample code is given below:

n=10
show(graphs.CompleteGraph(2*n+2))
g=graphs.CompleteGraph(2*n+2)
time_window_interval = [0, 4*60]
g = g.to_directed(time_window_interval)
g.show

On running the code, I am getting "ValueError: data_structure must be equal to 'sparse', 'static_sparse' or 'dense'" on the line g = g.to_directed(time_window_interval).

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
1

answered 2020-03-16 03:25:26 -0500

Sébastien gravatar image

updated 2020-03-18 14:04:32 -0500

Once you create the graph:

sage: g = graphs.CompleteGraph(5)
sage: g
Complete graph: Graph on 5 vertices

This is what happens if you provide wrong input:

sage: g.to_directed('wrong input')
Traceback (most recent call last)
...
ValueError: data_structure must be equal to 'sparse', 'static_sparse' or 'dense'

Following what the documentation of the method to_directed for undirected graphs says, you may instead write:

sage: g.to_directed('dense')
Complete graph: Digraph on 5 vertices

You may also create a directed graph directly using DiGraph (various different type of inputs), see the documentation.

edit flag offensive delete link more

Comments

Thanks.. I used g.to_directed() without any input. That also worked..

MrsO gravatar imageMrsO ( 2020-03-16 16:51:09 -0500 )edit
0

answered 2020-03-16 02:23:27 -0500

vdelecroix gravatar image
edit flag offensive delete link more

Comments

each question is a duplicate of itself:)

Sébastien gravatar imageSébastien ( 2020-03-16 03:13:06 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2020-03-14 18:58:33 -0500

Seen: 61 times

Last updated: Mar 18