growing and shrinking polygons for random testing of … · 2020-06-06 · growing and shrinking...

116
Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience Report ICFP 2016 September 20th, 2016

Upload: others

Post on 05-Jul-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Growing and Shrinking Polygons for Random Testing

of Computational Geometry Algorithms

Ilya Sergey

Experience Report

ICFP 2016 September 20th, 2016

Page 2: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Polygons

Page 3: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Polygons

Page 4: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Polygons

Page 5: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Polygons

Page 6: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Polygons are Trees

Page 7: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Polygons are Trees

• We can grow them;

Page 8: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Polygons are Trees

• We can grow them;• We can also trim them;

Page 9: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Polygons are Trees

• We can grow them;• We can also trim them;• We can use QuickCheck to test their properties.

Page 10: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience
Page 11: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience
Page 12: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience
Page 13: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Would you like to run a scenario project this year?

Page 14: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Sure, why not.

Would you like to run a scenario project this year?

Page 15: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Scenario Project Requirements

Page 16: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Scenario Project Requirements• For 2nd year undergrads, team work,

Page 17: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Scenario Project Requirements• For 2nd year undergrads, team work,

• One week-long,

Page 18: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Scenario Project Requirements• For 2nd year undergrads, team work,

• One week-long,

• Should involve math and programming,

Page 19: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Scenario Project Requirements• For 2nd year undergrads, team work,

• One week-long,

• Should involve math and programming,

• Challenging for students, but easy to assess,

Page 20: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Scenario Project Requirements• For 2nd year undergrads, team work,

• One week-long,

• Should involve math and programming,

• Challenging for students, but easy to assess,

• To be delivered in about a month.

Page 21: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Scenario Project Requirements• For 2nd year undergrads, team work,

• One week-long,

• Should involve math and programming,

• Challenging for students, but easy to assess,

• To be delivered in about a month.

Page 22: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience
Page 23: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience
Page 24: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience
Page 25: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience
Page 26: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

How many guards do we really need?

Page 27: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

How many guards do we really need?

The answer depends on the shape of the gallery.

Page 28: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

How many guards do we really need?

The answer depends on the shape of the gallery.

Page 29: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

How many guards do we really need?

The answer depends on the shape of the gallery.

Page 30: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

How many guards do we really need?

Page 31: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

How many guards do we really need?

Page 32: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

How many guards do we really need?

Page 33: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

How many guards do we really need?

Page 34: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

For a given gallery (polygon), find the minimal set of guards’ positions,

so together the guards can “see” the whole interior.

Art Gallery Problem

Page 35: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

For a given gallery (polygon), find the minimal set of guards’ positions,

so together the guards can “see” the whole interior.

NP-hard

Art Gallery Problem

Page 36: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Project: Art Gallery Competition

Find the best solutions for a collection of large polygons.

Page 37: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Project: Art Gallery Competition

Find the best solutions for a collection of large polygons.

• 58 vertices• 5 guards

Page 38: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Organizers’ TODO

Page 39: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Organizers’ TODO

• Problem generator;‣ Polygons with different “features” (convex, rectangular, etc.)

Page 40: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Organizers’ TODO

• Problem generator;‣ Polygons with different “features” (convex, rectangular, etc.)

• Solution checker with online feedback‣ geometric machinery (triangulation, visibility, …)‣ web-server

Page 41: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Organizers’ TODO

• Problem generator;‣ Polygons with different “features” (convex, rectangular, etc.)

• Solution checker with online feedback‣ geometric machinery (triangulation, visibility, …)‣ web-server

• Make sure that it all works.

Page 42: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Organizers’ TODO

• Problem generator;‣ Polygons with different “features” (convex, rectangular, etc.)

• Solution checker with online feedback‣ geometric machinery (triangulation, visibility, …)‣ web-server

• Make sure that it all works.

Page 43: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Organizers’ TODO

• Problem generator;‣ Polygons with different “features” (convex, rectangular, etc.)

• Solution checker with online feedback‣ geometric machinery (triangulation, visibility, …)‣ web-server

• Make sure that it all works.

Page 44: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

• Problem generator;‣ Polygons with different “features” (convex, rectangular, etc.)

• Solution checker with online feedback‣ geometric machinery (triangulation, visibility, …)‣ web-server

• Make sure that it all works.

Organizers’ TODO

Page 45: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Growing polygons

Page 46: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Growing polygons

Primitive polygons with specific “features”

Page 47: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Growing polygons

Primitive polygons with specific “features”

Page 48: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Seed

Growing polygons

Page 49: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Seed

Growing polygons

Page 50: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Growing polygons

Page 51: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Growing polygons

Page 52: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Growing polygons

Page 53: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Growing polygons

Page 54: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Growing polygons

Page 55: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Growing polygons

Page 56: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Growing polygons

Page 57: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Growing polygons

Page 58: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Growing polygons

Page 59: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Growing polygons

Page 60: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Growing polygons

Page 61: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Algorithm for growing polygons

1. Pick a primitive polygon;2. Locate a segment on a host polygon edge;3. Scale, rotate and attach the primitive;

check for self-intersections4. Repeat

Page 62: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Abstract polygon generator

trait PolygonGenerator extends GeneratorPrimitives { val seeds : List[Polygon] val primitives : List[(Int) => Polygon] val locate : Double => Option[(Double, Double)]

val seedFreqs : List[Int] val primFreqs : List[Int] val generations : Int

... }

Page 63: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Abstract polygon generator

trait PolygonGenerator extends GeneratorPrimitives { val seeds : List[Polygon] val primitives : List[(Int) => Polygon] val locate : Double => Option[(Double, Double)]

val seedFreqs : List[Int] val primFreqs : List[Int] val generations : Int

... }

Page 64: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Abstract polygon generator

trait PolygonGenerator extends GeneratorPrimitives { val seeds : List[Polygon] val primitives : List[(Int) => Polygon] val locate : Double => Option[(Double, Double)]

val seedFreqs : List[Int] val primFreqs : List[Int] val generations : Int

... }

Page 65: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Abstract polygon generator

trait PolygonGenerator extends GeneratorPrimitives { val seeds : List[Polygon] val primitives : List[(Int) => Polygon] val locate : Double => Option[(Double, Double)]

val seedFreqs : List[Int] val primFreqs : List[Int] val generations : Int

... }

Page 66: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Generating contest problems

Rectilinear

Page 67: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Quasi-convex

Generating contest problems

Page 68: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Crazy

Generating contest problems

Page 69: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

• Problem generator;‣ Polygons with different “features” (convex, rectangular, etc.)

• Solution checker with online feedback‣ geometric machinery (triangulation, visibility, …)‣ web-server

• Make sure that it all works.

Organizers’ TODO

Page 70: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

• Problem generator;‣ Polygons with different “features” (convex, rectangular, etc.)

• Solution checker with online feedback‣ geometric machinery (triangulation, visibility, …)‣ web-server

• Make sure that it all works.

Organizers’ TODO

Page 71: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Testing with ScalaCheck

Page 72: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Testing with ScalaCheck• Triangulation of a polygon of size N:

• centre of each triangle lies within a polygon;• triangulation generates N − 2 (possibly degenerate) triangles;

Page 73: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Testing with ScalaCheck• Triangulation of a polygon of size N:

• centre of each triangle lies within a polygon;• triangulation generates N − 2 (possibly degenerate) triangles;

• Joe-Simpson algorithm for visibility polygons (VPs):• a vertex of a VP is also within the original polygon;• every VP’s edge is within the original polygon;• a random point within a VP is indeed visible from its origin;

Page 74: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Testing with ScalaCheck• Triangulation of a polygon of size N:

• centre of each triangle lies within a polygon;• triangulation generates N − 2 (possibly degenerate) triangles;

• Joe-Simpson algorithm for visibility polygons (VPs):• a vertex of a VP is also within the original polygon;• every VP’s edge is within the original polygon;• a random point within a VP is indeed visible from its origin;

• Solution visibility checker:• a refutation (if it exists) is within the original polygon;• a refutation for a set of guards is not within any of their VPs;

Page 75: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Testing with ScalaCheck• Triangulation of a polygon of size N:

• centre of each triangle lies within a polygon;• triangulation generates N − 2 (possibly degenerate) triangles;

• Joe-Simpson algorithm for visibility polygons (VPs):• a vertex of a VP is also within the original polygon;• every VP’s edge is within the original polygon;• a random point within a VP is indeed visible from its origin;

• Solution visibility checker:• a refutation (if it exists) is within the original polygon;• a refutation for a set of guards is not within any of their VPs;

• Basic algorithm for solving AGP by Fisk:

• delivers a solution of size within the boundary ⌊N/3⌋;• the solution checker finds no refutations for its result.

Page 76: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

How well did that work?

Page 77: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

How well did that work?• Multiple bugs (>20) due to inaccurate treatment of

floating points;

Page 78: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

How well did that work?• Multiple bugs (>20) due to inaccurate treatment of

floating points;

• Several bugs (~10) due to misreading of the textbook algorithms or simplifications in their descriptions;

Page 79: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

How well did that work?• Multiple bugs (>20) due to inaccurate treatment of

floating points;

• Several bugs (~10) due to misreading of the textbook algorithms or simplifications in their descriptions;

• Two bugs in the Joe-Simpson algorithm itself;

Page 80: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

How well did that work?• Multiple bugs (>20) due to inaccurate treatment of

floating points;

• Several bugs (~10) due to misreading of the textbook algorithms or simplifications in their descriptions;

• Two bugs in the Joe-Simpson algorithm itself;• Bonus: an undocumented behavior in the

state-of-the-art CGAL library (written in C++ using exact arithmetics).

Page 81: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

How well did that work?• Multiple bugs (>20) due to inaccurate treatment of

floating points;

• Several bugs (~10) due to misreading of the textbook algorithms or simplifications in their descriptions;

• Two bugs in the Joe-Simpson algorithm itself;• Bonus: an undocumented behavior in the

state-of-the-art CGAL library (written in C++ using exact arithmetics).

Page 82: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Testing basic visibility algorithm

• Main component for checking arbitrary solutions;• Original description (1986) has a number of simplifications and

is given in pseudocode.

Page 83: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

import RandomRectilinearPolygonGenerator._

property("All visibility polygons lie within the original polygon") = forAll { (p : Polygon) =>

val guards = p.vertices val vps = guards.map(visibilityPolygon(p, _))

"Every edge of a visibility polygon is within ${p}" |: {

val edges = for (vp <- vps; e <- vp.edges) yield e

edges.forall(p.containsSegment)

} }

Testing basic visibility algorithm

Page 84: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

import RandomRectilinearPolygonGenerator._

property("All visibility polygons lie within the original polygon") = forAll { (p : Polygon) =>

val guards = p.vertices val vps = guards.map(visibilityPolygon(p, _))

"Every edge of a visibility polygon is within ${p}" |: {

val edges = for (vp <- vps; e <- vp.edges) yield e

edges.forall(p.containsSegment)

} }

Testing basic visibility algorithm

Page 85: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

import RandomRectilinearPolygonGenerator._

property("All visibility polygons lie within the original polygon") = forAll { (p : Polygon) =>

val guards = p.vertices val vps = guards.map(visibilityPolygon(p, _))

"Every edge of a visibility polygon is within ${p}" |: {

val edges = for (vp <- vps; e <- vp.edges) yield e

edges.forall(p.containsSegment)

} }

Testing basic visibility algorithm

Page 86: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

import RandomRectilinearPolygonGenerator._

property("All visibility polygons lie within the original polygon") = forAll { (p : Polygon) =>

val guards = p.vertices val vps = guards.map(visibilityPolygon(p, _))

"Every edge of a visibility polygon is within ${p}" |: {

val edges = for (vp <- vps; e <- vp.edges) yield e

edges.forall(p.containsSegment)

} }

Testing basic visibility algorithm

Page 87: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Bug in Joe-Simpson algorithmRandomly generated,

260 vertices, guards in every node

Page 88: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Bug in Joe-Simpson algorithm

??!

Randomly generated, 260 vertices,

guards in every node

Page 89: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Shrinking Polygons

Page 90: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Shrinking PolygonsTrimming

Page 91: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Reconstructing polygon generation

Page 92: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Reconstructing polygon generation

1

2 34

5

6 7

1

2 34

5

6 7

Page 93: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Reconstructing polygon generation

1

2 34

5

6 7

1

2

34

5

6

7

“Attachment tree”

Page 94: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Trimming polygons

1

34

5

6 7

1

2

4

5

6

7

3

2

Page 95: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

1

2 34

5

6 7

1

2

34

5

6

7

Trimming polygons

Page 96: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Shrinking strategy

• Build the attachment tree while constructing a random polygon;

• Construct all its subtrees; • “Render” the corresponding trimmed polygons.

Page 97: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Bug in Joe-Simpson algorithmRandomly generated,

260 vertices, guards in every node

Page 98: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Bug in Joe-Simpson algorithmRandomly generated,

260 vertices, guards in every node

Page 99: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Bug in Joe-Simpson algorithmAfter trimming,

20 vertices

Page 100: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Bug in Joe-Simpson algorithmRemoved

irrelevant guards

Page 101: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Bug in Joe-Simpson algorithm

Page 102: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Bug in Joe-Simpson algorithm

Page 103: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

...

intersectWithWindow(v(i), v(i + 1), s.top, windowEnd) match { case Some(p) => s.push(p) advance(v, s, i) case _ => scan(v, s, i, windowEnd, ccw) }

...

Bug in Joe-Simpson algorithm

Page 104: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Bug in Joe-Simpson algorithm

...

intersectWithWindow(v(i), v(i + 1), s.top, windowEnd) match { case Some(p) if !(windowEnd.isDefined && p =~= windowEnd) => s.push(p) advance(v, s, i) case _ => scan(v, s, i, windowEnd, ccw) }

...

Page 105: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Implementation effort

• Geometric primitives and procedures: 1450 LOC

• Server infrastructure: 1500 LOC

• Testing framework: 350 LOC

Page 106: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Running the Art Gallery Competition

Page 107: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Running the Art Gallery Competition• 94 participants, 24 teams, 2360 submissions in five days

Page 108: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Running the Art Gallery Competition• 94 participants, 24 teams, 2360 submissions in five days

• Server running 24/5 • for different teams, solution processed concurrently• no crashes during the week• one non-critical bug in server logic (fixed without restarting)

Page 109: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Running the Art Gallery Competition• 94 participants, 24 teams, 2360 submissions in five days

• Server running 24/5 • for different teams, solution processed concurrently• no crashes during the week• one non-critical bug in server logic (fixed without restarting)

• Most of the solutions: textbook algorithm with optimizations;

Page 110: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Running the Art Gallery Competition• 94 participants, 24 teams, 2360 submissions in five days

• Server running 24/5 • for different teams, solution processed concurrently• no crashes during the week• one non-critical bug in server logic (fixed without restarting)

• Most of the solutions: textbook algorithm with optimizations;

• The winning team implemented the state-of-the art algorithm (2014) using linear programming;

Page 111: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

Mon

Tue

Wed

The

Fri

Page 112: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

To take away

Page 113: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

To take away• FP works great for rapid development of

non-trivial and robust geometric applications;

Page 114: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

To take away• FP works great for rapid development of

non-trivial and robust geometric applications;

• QuickCheck-ing CG with polygons is feasible and efficient in practice;

Page 115: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

To take away• FP works great for rapid development of

non-trivial and robust geometric applications;

• QuickCheck-ing CG with polygons is feasible and efficient in practice;

• Polygons can be grown and trimmed, just like trees.

Page 116: Growing and Shrinking Polygons for Random Testing of … · 2020-06-06 · Growing and Shrinking Polygons for Random Testing of Computational Geometry Algorithms Ilya Sergey Experience

To take away

Thanks!

• FP works great for rapid development of non-trivial and robust geometric applications;

• QuickCheck-ing CG with polygons is feasible and efficient in practice;

• Polygons can be grown and trimmed, just like trees.