Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polyhedron.affine_hull() raises AssertionError #24047

Closed
yuan-zhou opened this issue Oct 14, 2017 · 18 comments
Closed

Polyhedron.affine_hull() raises AssertionError #24047

yuan-zhou opened this issue Oct 14, 2017 · 18 comments

Comments

@yuan-zhou
Copy link

The method affine_hull of Polyhedron fails.

sage: P1 = Polyhedron(vertices=([[-1, 1], [0, -1], [0, 0], [-1, -1]]))
sage: P2 = Polyhedron(vertices=[[1, 1], [1, -1], [0, -1], [0, 0]])
sage: P = P1.intersection(P2)
sage: A, b = P.affine_hull(as_affine_map=True, orthonormal=True, extend=True)
AssertionError

This is because the order of the vertices of P is changed by the translation by zero vector.

sage: P.vertices()
(A vertex at (0, 0), A vertex at (0, -1))
sage: P.translation(vector([0,0])).vertices()
(A vertex at (0, -1), A vertex at (0, 0))

CC: @mkoeppe @mo271 @videlec @jplab

Component: geometry

Author: Moritz Firsching

Branch/Commit: 70114be

Reviewer: Travis Scrimshaw, Jean-Philippe Labbé

Issue created by migration from https://trac.sagemath.org/ticket/24047

@yuan-zhou yuan-zhou added this to the sage-8.1 milestone Oct 14, 2017
@videlec
Copy link
Contributor

videlec commented Oct 16, 2017

comment:2
  1. It would be bettter to sort the V and H generators so that this kind of troubles never appear (and equality test would be even faster)

  2. The translation method is stupidly written

    displacement = vector(displacement)
    new_vertices = [x.vector()+displacement for x in self.vertex_generator()]
    new_rays = self.rays()
    new_lines = self.lines()
    new_ring = self.parent()._coerce_base_ring(displacement)
    return Polyhedron(vertices=new_vertices, rays=new_rays, lines=new_lines, base_ring=new_ring)

we should not recompute anything!

@mkoeppe
Copy link
Contributor

mkoeppe commented Oct 16, 2017

comment:3

Replying to @videlec:

we should not recompute anything!

That would require #22701 - Setting up a Polyhedron from both Vrep and Hrep.

@jplab
Copy link

jplab commented Oct 21, 2017

comment:4

@Moritz: You told me you would have a fix for this? It consists in what exactly?

@mo271
Copy link
Contributor

mo271 commented Oct 23, 2017

Branch: u/moritz/24047

@mo271
Copy link
Contributor

mo271 commented Oct 23, 2017

Commit: 0022adc

@mo271
Copy link
Contributor

mo271 commented Oct 23, 2017

comment:6

This should fix at least the reported bug; it simply chooses the zero, instead of relying on the fact that it is the first in the list.


New commits:

ffd2bddcompensate the order change of 'translation'
0022adcadded test from trac

@tscrim
Copy link
Collaborator

tscrim commented Oct 23, 2017

comment:7

You have some tab characters (should be 4 spaces) and your indentation level is wrong:

       Check that :trac:`24047` is fixed::
 
            sage: P1 = Polyhedron(vertices=([[-1, 1], [0, -1], [0, 0], [-1, -1]]))
            sage: P2 = Polyhedron(vertices=[[1, 1], [1, -1], [0, -1], [0, 0]])
            sage: P = P1.intersection(P2)
            sage: A, b = P.affine_hull(as_affine_map=True, orthonormal=True, extend=True)

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 23, 2017

Branch pushed to git repo; I updated commit sha1. New commits:

0bee595tabs to spaces

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 23, 2017

Changed commit from 0022adc to 0bee595

@mo271
Copy link
Contributor

mo271 commented Oct 23, 2017

comment:10

uups, I used a different editor, which changed spaces by tabs..
Should be fixed now.

@mkoeppe
Copy link
Contributor

mkoeppe commented Nov 5, 2017

Author: Moritz Firsching

@jplab
Copy link

jplab commented Nov 10, 2017

comment:12

that we really Q really -> that Q really?

Otherwise, it looks good to me and the bot is happy so I would put it as positive review once the small mistake above is corrected.

Thanks for the quick fix!

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Nov 10, 2017

Changed commit from 0bee595 to 70114be

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Nov 10, 2017

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

7036f1ccompensate the order change of 'translation'
d4456e3added test from trac
e081292tabs to spaces
70114betypo in comment

@mo271
Copy link
Contributor

mo271 commented Nov 10, 2017

comment:14

thanks for the review, JP!

@fchapoton
Copy link
Contributor

comment:15

reviewer name, please

@jplab
Copy link

jplab commented Nov 15, 2017

Reviewer: Travis Scrimshaw, Jean-Philippe Labbé

@vbraun
Copy link
Member

vbraun commented Dec 11, 2017

Changed branch from u/moritz/24047 to 70114be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants