Ask Your Question
0

Error in datastructure in sagemath

asked 2020-03-15 00:58:33 +0100

MrsO gravatar image

updated 2020-03-16 13:38:28 +0100

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 09:25:26 +0100

Sébastien gravatar image

updated 2020-03-18 20:04:32 +0100

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 22:51:09 +0100 )edit
0

answered 2020-03-16 08:23:27 +0100

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 09:13:06 +0100 )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-15 00:58:33 +0100

Seen: 289 times

Last updated: Mar 18 '20