def test_overlapping_simplices(overlapping_simplices_2):
    s = Sweep(overlapping_simplices_2.events)
    assert round(s.calculate_volume(), 3) == round((8 ** 3) / 6. + 0.5 / 3, 3)
def test_nodes_and_edges(simplex):
    s = Sweep(simplex.events)
    nodes, edges = s.nodes_and_edges()
    assert len(nodes) == 1
    assert len(edges) == 0
def test_simplex_in_cube(simplex_in_cube):
    s = Sweep(simplex_in_cube.events)
    assert round(s.calculate_volume(), 5) == 4
def test_precision(cube_simplex_overlapping_3d_imprecise):
    s = Sweep(cube_simplex_overlapping_3d_imprecise.events)
    assert round(s.calculate_volume(), 3) == round(1 + 8. / 6. - 0.5 ** 3, 3)
def test_simplex_cube_overlapping_2d(cube_simplex_overlapping_2d):
    s = Sweep(cube_simplex_overlapping_2d.events)
    assert round(s.calculate_volume(), 8) == 1.
def test_unbounded_non_regular(unbounded_non_regular):
    s = Sweep(unbounded_non_regular.events, sweep_plane=np.array([0, 1]))
    assert round(s.calculate_volume(1), 3) == 1
    assert round(s.calculate_volume(2), 3) == 4
    assert round(s.calculate_volume(400), 3) == 400 ** 2
def test_simplex(simplex):
    s = Sweep(simplex.events)
    assert round(s.calculate_volume(), 8) == round(1. / np.math.factorial(simplex.dim), 8)
Beispiel #8
0
        of format: --[argName] [value].
        """
        for arg in arg_line.split():
            if not arg.strip():
                continue
            yield arg


    # Create argument parser object and override read-method.
    parser = argparse.ArgumentParser(fromfile_prefix_chars='@',
                                     formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.convert_arg_line_to_args = convert_arg_line_to_args

    arguments = _arguments()
    for k, v in arguments.items():
        parser.add_argument(v.arg, **v.kwargs)
        parser.set_defaults()

    # Parse args and init parameter dictionary.
    args = parser.parse_args()
    sweep_plane = args.sweepPlane
    if sweep_plane is not None:
        sweep_plane = list(map(float, sweep_plane))

    polytope_file = args.polytopesFile
    cell_decomposition = get_cell_decomposition(polytope_file)
    sweep = Sweep(cell_decomposition.events, sweep_plane=sweep_plane)
    logging.info(f'Volume of the union of polytopes: {sweep.calculate_volume()}')
    if args.plotSweep:
        plot_sweep(sweep)
Beispiel #9
0
 def _union_volume(self):
     return Sweep(self.union_cd.events).calculate_volume()
Beispiel #10
0
def test_unit_cube(unit_cube):
    s = Sweep(unit_cube.events)
    assert round(s.calculate_volume(), 8) == 1.
Beispiel #11
0
 def _convex_hull_volume(self):
     return Sweep(self.convex_cd.events).calculate_volume()
Beispiel #12
0
 def find_clusters(self):
     clusters = detect_clusters(Sweep(self.union_cd.possible_events))
     logging.info("Clusters found : %s" % clusters)
     return clusters
Beispiel #13
0
def test_dataloader_2():
    p = str((Path(__file__).parent / 'test2.json').absolute())
    cell_decomposition = get_cell_decomposition(p)
    sweep = Sweep(cell_decomposition.events)
    assert np.abs(1 - sweep.calculate_volume()) < 0.001
Beispiel #14
0
def test_graph_one_connected_component(hole_2d):
    s = Sweep(hole_2d.events)
    graph = s.graph()
    assert len([cc for cc in nx.connected_components(graph.to_undirected())]) == 1
Beispiel #15
0
def test_non_regular_overlapping(cube_simplex_overlapping_3d):
    s = Sweep(cube_simplex_overlapping_3d.events)
    assert round(s.calculate_volume(), 8) == 1.
Beispiel #16
0
def test_graph_two_connected_components(simplex_cube_disconnected):
    s = Sweep(simplex_cube_disconnected.events)
    graph = s.graph()
    assert len([cc for cc in nx.connected_components(graph.to_undirected())]) == 2
def test_halfspace_restriction_3(translated_triangles):
    a = Hyperplane(np.array([1., 0., ]), 0.)
    translated_triangles.restrict_to_halfspace(a, 1)
    assert (len(translated_triangles.events)) == 3
    s = Sweep(translated_triangles.events)
    assert round(s.calculate_volume(), 6) == 0.25