コード例 #1
0
    def __init__(self, start, end, size, gap, angle=None, align='center', layer=None, datatype=None):

        self.start=np.array(start)
        self.end=np.array(end)
        self.size=np.array(size)
        self.gap=gap
        self.align=align

        pts=np.array([[0,0], [0, size[1]], size, [size[0], 0]])
        if angle is not None:
            pts=rotate(pts, angle, 'com')
            
        if align.lower()=='bottom':
            pass
        elif align.lower()=='top':
            pts=translate(pts, (0, -self.size[1]))
        elif align.lower()=='center':
            pts=translate(pts, (0, -self.size[1]/2))        
        else:
            raise ValueError('Align parameter must be one of bottom/top/center')

        strip_width=size[0]+gap
        
        v=self.end-self.start
        l=np.sqrt(np.dot(v,v))        
        N=int(np.floor(l/strip_width))
        spacing=v/N
        rotation=math.atan2(v[1], v[0])*180/np.pi
        pts=rotate(pts, rotation)

        origin = start + 0.5* v* (l-(N*strip_width - gap))/l

        polys=[translate(pts, origin + i*spacing) for i in range(N)]

        Elements.__init__(self, polys, layer, datatype)
コード例 #2
0
from typing import List

import core.Elements as elems
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import core.utils as utils
import random
import math

N = elems.Network()

i = 0
snrs = []
gsnrs = []
bit_rates = []
m_values = [0]
free_conns = [N.total_possible_connections]
refused_conns = [0]

total_capacity = 0.0

nodes = list(N.nodes.keys())
T = pd.DataFrame(columns=nodes, index=nodes)

processed_conn_list = []

for M in range(1, 50):
    N = elems.Network()
    total_capacity = 0.0
    for i in nodes:
コード例 #3
0
ファイル: utils.py プロジェクト: afrutig/gdsMaskFramework
def boolean(layer, objects, operation, max_points=199, datatype=0, eps=1e-13):
    """
    Edited by Andreas Frutiger
    :revised: 18.01.2017


    Parameters

    layer : integer
        The GDSII layer number for the resulting element.
    objects : array-like
        Operands of the boolean operation. Each element of this array must
        be a ``Polygon``, ``PolygonSet``, ``CellReference``, ``CellArray``,
        or an array-like[N][2] of vertices of a polygon.
    operation : function
        Function that accepts as input ``len(objects)`` integers.  Each
        integer represents the incidence of the corresponding ``object``.
        The function must return a bool or integer (interpreted as bool).
    max_points : integer
        If greater than 4, fracture the resulting polygons to ensure they
        have at most ``max_points`` vertices. This is not a tessellating
        function, so this number should be as high as possible. For
        example, it should be set to 199 for polygons being drawn in GDSII
        files.
    datatype : integer
        The GDSII datatype for the resulting element (between 0 and 255).
    eps : positive number
        Small number to be used as tolerance in intersection and overlap
        calculations.

    Returns

    out : PolygonSet
        Result of the boolean operation.

    Notes

    Since ``operation`` receives a list of integers as input, it can be
    somewhat more general than boolean operations only. See the examples
    below.

    Because of roundoff errors there are a few cases when this function
    can cause segmentation faults. If that happens, increasing the value
    of ``eps`` might help.

    Examples

    >>> circle = gdspy.Round(0, (0, 0), 10)
    >>> triangle = gdspy.Round(0, (0, 0), 12, number_of_points=3)
    >>> bad_poly = gdspy.L1Path(1, (0, 0), '+y', 2,
            [6, 4, 4, 8, 4, 5, 10], [-1, -1, -1, 1, 1, 1])
    >>> union = gdspy.boolean(1, [circle, triangle],
            lambda cir, tri: cir or tri)
    >>> intersection = gdspy.boolean(1, [circle, triangle],
            lambda cir, tri: cir and tri)
    >>> subtraction = gdspy.boolean(1, [circle, triangle],
            lambda cir, tri: cir and not tri)
    >>> multi_xor = gdspy.boolean(1, [badPath], lambda p: p % 2)

    The boolean operations cannot be chained, also as soon as a shape is split into two parts it does not 
    work anymore. 
    """

    polygons = []
    indices = [0]
    special_function = False

    for obj in objects:
        if isinstance(obj, ElementBase):
            # is treated correctly.
            polygons.append(obj.points)
            indices.append(indices[-1] + 1)
        elif isinstance(obj, Elements):
            # The special function does not work anymore, the rest is fine.
            special_function = True
            polygons += obj.polygons
            indices.append(indices[-1] + len(obj.polygons))
        elif isinstance(obj, CellReference) or isinstance(obj, CellArray):
            special_function = True
            a = obj.get_polygons()
            polygons += a
            indices.append(indices[-1] + len(a))

            polygons.append(obj)
            indices.append(indices[-1] + 1)

    if special_function:

        result = boolext.clip(
            polygons, lambda *p: operation(*[
                sum(p[indices[ia]:indices[ia + 1]])
                for ia in range(len(indices) - 1)
            ]), eps)

    else:
        result = boolext.clip(polygons, operation, eps)

    # check whether there is more than one element that was obtained.

    if result is None:

        return None

    if len(result) == 1:

        result = [i for i in result[0]]
        return Boundary(result, layer, datatype, False)
    else:
        elements = Elements()

        for i in result:
            elements.add(Boundary(i, layer, datatype, False))
        return elements
コード例 #4
0
ファイル: utils.py プロジェクト: afrutig/gdsMaskFramework
def slice(layer, objects, position, axis, datatype=0):
    """
    **BROKEN** Slice polygons and polygon sets at given positions along an axis.

    Parameters

    layer : integer, list
        The GDSII layer numbers for the elements between each division.  If
        the number of layers in the list is less than the number of divided
        regions, the list is repeated.
    objects : ``Polygon``, ``PolygonSet``, or list
        Operand of the slice operation.  If this is a list, each element
        must be a ``Polygon``, ``PolygonSet``, ``CellReference``,
        ``CellArray``, or an array-like[N][2] of vertices of a polygon.
    position : number or list of numbers
        Positions to perform the slicing operation along the specified
        axis.
    axis : 0 or 1
        Axis along which the polygon will be sliced.
    datatype : integer
        The GDSII datatype for the resulting element (between 0 and 255).

    Returns

    out : list[N] of PolygonSet
        Result of the slicing operation, with N = len(positions) + 1.  Each
        PolygonSet comprises all polygons between 2 adjacent slicing
        positions, in crescent order.

    Examples

    >>> ring = gdspy.Round(1, (0, 0), 10, inner_radius = 5)
    >>> result = gdspy.slice(1, ring, [-7, 7], 0)
    >>> cell.add(result[1])
    """
    if (layer.__class__ != [].__class__):
        layer = [layer]
    if (objects.__class__ != [].__class__):
        objects = [objects]
    if (position.__class__ != [].__class__):
        position = [position]
    position.sort()
    result = [[] for i in range(len(position) + 1)]
    polygons = []
    for obj in objects:
        if isinstance(obj, Boundary):
            polygons.append(obj.points)
        elif isinstance(obj, Elements):
            polygons += obj.polygons
        elif isinstance(obj, CellReference) or isinstance(obj, CellArray):
            polygons += obj.get_polygons()
        else:
            polygons.append(obj)
    for i, p in enumerate(position):
        nxt_polygons = []
        for pol in polygons:
            (pol1, pol2) = chop(pol, p, axis)
            result[i] += pol1
            nxt_polygons += pol2
        polygons = nxt_polygons
    result[-1] = polygons
    for i in range(len(result)):
        result[i] = Elements(layer[i % len(layer)], result[i], datatype)
    return result
コード例 #5
0
ファイル: Lab4.py プロジェクト: Karrick99/OVN_Laboratories
from typing import List

import core.Elements as elems
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import random

N = elems.Network()

i = 0

nodes = list(N.nodes.keys())
param = ''
snrs = []
gsnrs = []
latencies = []
bit_rates = []
total_capacity = 0.0

number_connections = 100

while i < number_connections:
    n1 = random.choices(nodes)[0]
    n2 = random.choices(nodes)[0]
    if n1 != n2:
        conn = elems.Connection(n1, n2, 1)

        param = 'snr'

        N.stream([conn], param)