Thanks, Moritz.

I found a solution which used strings instead of tuples:

for v in G.vertex_iterator():
    v.rename(str(v)[12:])

Probably not as elegant as your solution, but it did the job!

-Alasdair

On Monday, 26 February 2018 06:22:32 UTC+11, moritz wrote:
>
>
>
> On Saturday, February 24, 2018 at 9:56:04 AM UTC+1, Alasdair wrote:
>>
>> Hello,
>>
>> I have defined a polyhedron by a collection of linear inequalities over 
>> three variables, and it's all lovely: I can access the vertices, draw all 
>> sorts of nice pictures, get all sorts of information.  The one problem is 
>> the vertex graph.  If my polyhedron is P, say, then P.vertex_graph() gives 
>> me a graph where each vertex is labelled something like "A vertex at 
>> (0,1,0)".  This seems somewhat redundant labelling, and ideally I'd like to 
>> relabel the vertices to simply "(0,1,0)".
>>
>> I attempted to  relabel the vertex graph with:
>>
>> dict ={i:j, for (i,j) in zip(P.vertices(),P.vertex_list())
>> G = P.vertex_graph()
>> G.relabel(dict)
>>
>>
>> However, that attempt produced the error:
>>
>> TypeError: unhashable type: 'list'
>>
>>
>> I'm not sure how to go about this relabelling... any idea?  Thanks!
>>
> a 'list' cant be a vertex of a graph. It needs to be something hashable, 
> like a 'tupe'. Try the code below.
>
> Cheers
>  Moritz
>
> sage: P = polytopes.cube()
> sage: G = P.graph()
> sage: G.vertices()
> [A vertex at (-1, -1, -1),
>  A vertex at (-1, -1, 1),
>  A vertex at (-1, 1, -1),
>  A vertex at (-1, 1, 1),
>  A vertex at (1, -1, -1),
>  A vertex at (1, -1, 1),
>  A vertex at (1, 1, -1),
>  A vertex at (1, 1, 1)]
> sage: dict ={i:tuple(j) for (i,j) in zip(P.vertices(),P.vertices_list())}
> sage: G.relabel(dict)
> sage: G.vertices()
> [(-1, -1, -1),
>  (-1, -1, 1),
>  (-1, 1, -1),
>  (-1, 1, 1),
>  (1, -1, -1),
>  (1, -1, 1),
>  (1, 1, -1),
>  (1, 1, 1)]
> sage: dict
> {A vertex at (-1, -1, -1): (-1, -1, -1),
>  A vertex at (-1, -1, 1): (-1, -1, 1),
>  A vertex at (-1, 1, -1): (-1, 1, -1),
>  A vertex at (-1, 1, 1): (-1, 1, 1),
>  A vertex at (1, -1, -1): (1, -1, -1),
>  A vertex at (1, -1, 1): (1, -1, 1),
>  A vertex at (1, 1, -1): (1, 1, -1),
>  A vertex at (1, 1, 1): (1, 1, 1)} 
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to