First time here? Check out the FAQ!

Ask Your Question
0

Error in datastructure in sagemath

asked 5 years ago

MrsO gravatar image

updated 5 years ago

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).

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
1

answered 5 years ago

Sébastien gravatar image

updated 5 years ago

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.

Preview: (hide)
link

Comments

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

MrsO gravatar imageMrsO ( 5 years ago )
0

answered 5 years ago

vdelecroix gravatar image
Preview: (hide)
link

Comments

each question is a duplicate of itself:)

Sébastien gravatar imageSébastien ( 5 years ago )

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: 5 years ago

Seen: 322 times

Last updated: Mar 18 '20