示例#1
0
    def add_path(self, aper, *path):

        if self._expansion > 0.0:
            if isinstance(aper, tuple):
                s = gerbertools.Shape(1e6)
                s.append_int(aper)
                s = s.offset(self._expansion, True)
                assert len(s) == 1
                aper = tuple(s.get_int(0))
            else:
                aper += from_mm(self._expansion)

        paths = self._paths.get(aper, None)

        # Due to roundoff error during rotation, some almost-identical
        # (actually identical in the gerber file) apertures can appear
        # for region apertures. To avoid this, look for apertures that
        # are "close enough".
        if paths is None and isinstance(aper, tuple):
            for ap2 in self._paths:
                if not isinstance(ap2, tuple):
                    continue
                if len(aper) != len(ap2):
                    continue
                err = 0
                for c1, c2 in zip(aper, ap2):
                    err += (c1[0] - c2[0])**2
                    err += (c1[1] - c2[1])**2
                    if err > 100:
                        break
                else:
                    aper = ap2
                    paths = self._paths[aper]
                    break

        if paths is None:
            paths = Paths()
            self._paths[aper] = paths
        paths.add(*path)
[m, _] = np.shape(distances)

heap = []

k = 1

connections = np.zeros((m, m), dtype=int)

with open('1-best-connectivity-path.txt', 'w') as file:
    for start in range(m):
        print(start)

        ps = Paths(k, m)

        p = BrainPath(start)
        heappush(heap, p)

        while len(heap) > 0:
            path: BrainPath = heappop(heap)
            for next_node in range(m):
                if next_node not in path.elements:
                    new_path = path.add(next_node, distances[path.last(),
                                                             next_node])
                    if ps.add(new_path):
                        heappush(heap, new_path)
        file.write(ps.str(start) + '\n')

        connections += ps.matrix_representation()

np.savetxt('best_connectivity_paths_matrix.txt', connections)
示例#3
0
class LaseredAcrylicPlate:
    def __init__(self, material, thickness, flipped=False):
        super().__init__()
        self._cuts = Paths()
        self._lines = Paths()
        self._regions = []
        self._material = material
        self._thickness = thickness
        self._flipped = flipped

    def add_cut(self, *path):
        self._cuts.add(*path)

    def add_line(self, *path):
        self._lines.add(*path)

    def add_region(self, *path):
        assert path[-1] == path[0]
        assert len(path) > 2
        self._regions.append(path)

    def get_material(self):
        return self._material

    def get_thickness(self):
        return self._thickness

    def is_flipped(self):
        return self._flipped

    def iter_cuts(self):
        return iter(self._cuts)

    def iter_lines(self):
        return iter(self._lines)

    def iter_regions(self):
        return iter(self._regions)

    def get_bounds(self):
        x_min = None
        x_max = None
        y_min = None
        y_max = None
        for paths in (self._cuts, self._lines, self._regions):
            for path in paths:
                for x, y in path:
                    if x_max is None:
                        x_min = x
                        x_max = x
                        y_min = y
                        y_max = y
                    else:
                        x_min = min(x_min, x)
                        x_max = max(x_max, x)
                        y_min = min(y_min, y)
                        y_max = max(y_max, y)
        if x_min is None:
            return 0, 0, 0, 0
        return x_min, x_max, y_min, y_max

    def instantiate(self, plate, transformer, translate, rotate):
        for path in self._cuts:
            plate.add_cut(
                *transformer.path_to_global(path, translate, rotate, True))
        for path in self._lines:
            plate.add_line(
                *transformer.path_to_global(path, translate, rotate, True))
        for path in self._regions:
            plate.add_region(
                *transformer.path_to_global(path, translate, rotate, True))

    def to_file(self, fname):
        """Output the acylic plate as gerber files. This is f*****g weird, I
        know, and requires a circular module dependency because acrylic plates
        were also shoehorned into CircuitBoard, but this is the easiest path
        that I have right now for getting them rendered as SVGs and 3D
        models."""
        from circuit_board import GerberLayer

        cuts = GerberLayer('GM1')
        for path in self._cuts:
            cuts.add_path(from_mm(0.3), *path)
        cuts.to_file(fname)

        engravings = GerberLayer('GM2')
        for path in self._lines:
            engravings.add_path(from_mm(0.3), *path)
        for path in self._regions:
            engravings.add_region(True, *path)
        engravings.to_file(fname)
示例#4
0
from brain_path import BrainPath
from paths import Paths
from kpaths import KPaths
from copy import deepcopy
from heapq import heappush
from heapq import heappop

p = BrainPath(5)

k = 10
ps = Paths(k, 20)

print(p)

for i in range(20):
    p = p.add(i, 1)
    print(p)
    print(ps.add(p))
    print(ps.add(p))

p = BrainPath(1)
for i in range(20):
    p = p.add(i, 0.1)
    print(p)
    print(ps.add(p))
    print(ps.add(p))
    print(len(ps))

print(ps)
print(len(ps))