Ejemplo n.º 1
0
def intersect_great_circles(points, opposite_points, edges):
    print("points:", len(points), "edges:", len(edges), file=sys.stderr)
    all_points = copy.deepcopy(points)
    all_opposite_points = copy.deepcopy(opposite_points)
    circles_to_points = []
    for i in range(len(edges)):
        print(i, file=sys.stderr)
        cur_points = set()
        for j in range(len(edges)):
            if j != i:
                points_in_cross = cross.cross(points, edges[i], edges[j])
                found = False
                idx_found = -1
                for idx in range(len(all_points)):
                    if common.same_points(points_in_cross[0], all_points[idx]):
                        found = True
                        idx_found = idx
                        break
                idx1, idx2 = -1, -1
                if not found:
                    idx1 = len(all_points)
                    all_points.append(points_in_cross[0])
                    idx2 = len(all_points)
                    all_points.append(points_in_cross[1])
                    all_opposite_points[idx1] = idx2
                    all_opposite_points[idx2] = idx1
                else:
                    idx1 = idx_found
                    idx2 = all_opposite_points[idx1]
                cur_points.add(idx1)
                cur_points.add(idx2)
        circles_to_points.append(list(cur_points))
    return all_points, all_opposite_points, circles_to_points
Ejemplo n.º 2
0
    def cross_axis(self):
        leftCurlBr = Literal("{").suppress()
        rightCurlBr = Literal("}").suppress()
        cross_parser = self.mdx_level()
        cross_parser.setParseAction(lambda s, a, toks: cross.cross(toks))

        cross_parse = leftCurlBr + cross_parser + rightCurlBr

        return cross_parse
Ejemplo n.º 3
0
    def cross_axis(self):
        leftCurlBr = Literal("{").suppress()
        rightCurlBr = Literal("}").suppress()
        cross_parser = self.mdx_level()
        cross_parser.setParseAction(lambda s,a,toks:cross.cross(toks))

        cross_parse = leftCurlBr + cross_parser + rightCurlBr

        return cross_parse 
Ejemplo n.º 4
0
def calc_vel(A0, AA, v0, w0, q, qd):
    vv = np.zeros((num_q, 3))
    ww = np.zeros((num_q, 3))
    if num_q == 0:
        print('Single body, there is no link')
    else:
        for i in range(num_q):
            if BB[i] == -1:
                A_I_i = AA[i, :, :]
                if J_type[i] == 'R':
                    ww[i, :] = w0[0:3] + np.dot(np.dot(A_I_i, Ez), qd[i])
                    vv[i, :] = v0[0:3] \
                               + cross(w0[0:3], np.dot(A0, c0[i, :])) \
                               - cross(ww[i, :], np.dot(A_I_i, cc[i, i, :]))
                else:
                    ww[i, :] = w0[0:3]
                    vv[i, :] = v0[0:3] \
                               + cross(w0[0:3], np.dot(A0, c0[i, :])) \
                               - cross(ww[i, :], np.dot(A_I_i, cc[i, i, :])) \
                               + cross(ww[i, :], np.dot(np.dot(A_I_i, Ez), q[i])) \
                               + np.dot(np.dot(A_I_i, Ez), qd[i])

            else:
                A_I_BB = AA[BB[i], :, :]
                A_I_i = AA[i, :, :]
                if J_type == 'R':
                    ww[i, :] = ww[BB[i], :] + np.dot(np.dot(A_I_i, Ez), qd[i])
                    vv[i, :] = vv[BB[i], :] \
                               + cross(ww[BB[i], :], np.dot(A_I_BB, cc[BB[i], i, :])) \
                               - cross(ww[i, :], np.dot(A_I_i, cc[i, i, :]))
                else:
                    ww[i, :] = ww[BB[i], :]
                    vv[i, :] = vv[BB[i], :] \
                               + cross(ww[BB[i], :], np.dot(A_I_BB, cc[BB[i], i, :])) \
                               - cross(ww[i, :], np.dot(A_I_i, cc[i, i, :])) \
                               + cross(ww[i, :], np.dot(np.dot(A_I_i, Ez), q[i])) \
                               + np.dot(np.dot(A_I_i, Ez), qd[i])

    return vv, ww
Ejemplo n.º 5
0
 def evaluate(layout):
     for (position, index) in enumerate(layout):
         coordinates[index] = divmod(position, col_count)
     segments = [(coordinates[p1], coordinates[p2]) for (p1, p2) in links]
     total_distances = 0
     short_segments = []
     for  ((y1, x1), (y2, x2)) in segments:
         distance = distances[abs(x1-x2)][abs(y1-y2)]
         if distance <= max_crossing:
             short_segments.append((x1, y1, x2, y2))
         total_distances += distance
     crossing_count = (link_count - len(short_segments)) * link_count
     for (i, (x1, y1, x2, y2)) in enumerate(short_segments):
          for (x3, y3, x4, y4) in short_segments[i+1:]:
              crossing_count += cross((x1, y1, x2, y2, x3, y3, x4, y4))
     return (crossing_count, total_distances)
Ejemplo n.º 6
0
def calc_jte(RR, AA, q, joints):
    n = len(joints)
    JJ_te = np.zeros((n, 3))
    if num_q == 0:
        print('Single body, there is no link')
    else:
        POS_j, ORI_j = f_kin_j(RR, AA, q, joints)
        POS_e, ORI_e = f_kin_e(RR, AA, joints)
        for i in range(n):
            A_I_i = AA[joints[i], :, :]
            if J_type[joints[i]] == 'R':
                temp = cross(np.dot(A_I_i, Ez), (POS_e - POS_j[i, :]))
                JJ_te[i, :] = temp
            else:
                JJ_te[i, :] = np.dot(A_I_i, Ez)

    return JJ_te
Ejemplo n.º 7
0
def calc_jt(RR, AA):
    JJ_t = np.zeros((num_q, num_q, 3))
    if num_q == 0:
        print('Single body, there is no link')
    else:
        for i in range(num_q):
            j = i
            while j > -1:
                A_I_j = AA[j, :, :]
                if J_type[j] == 'R':
                    JJ_t[i, j, :] = cross(
                        np.dot(A_I_j, Ez),
                        (RR[i, :] - RR[j, :] - np.dot(A_I_j, cc[j, j, :])))
                else:
                    JJ_t[i, j, :] = np.dot(A_I_j, Ez)

                if BB[j] == -1:
                    j = -1
                    j = j - 1
                else:
                    j = j - 1
    return JJ_t
Ejemplo n.º 8
0
 def recurs(box_coords, next_boxes, already_placed_segments, cumulated_distances):
     if cumulated_distances > objective:
         # print "cut"
         return None
     if len(next_boxes) == 0:
         return {
             "coords": box_coords,
             "crossings": 0,
             "distances": cumulated_distances,
         }
     outside_hull_count = len(next_boxes) - len(hull(frozenset(box_coords.values())))
     if outside_hull_count * outside_hull_minimal_distance + cumulated_distances > objective:
         # print "Lower bound cut"
         return None
     if has_expired():
         raise RuntimeError(("Mocodo Err.10 - " + _('Layout calculation time exceeded.')).encode("utf8"))
     if iteration.next() > call_limit:
         # print "call limit exceeded"
         return None
     box_to_place = next_boxes[0]
     already_placed_successors = {box_coords[box]: box for box in successors[box_to_place] if box in box_coords}
     if already_placed_successors:
         already_placed_successor_coords = iter(already_placed_successors)
         possible_coords = neighborhood(already_placed_successor_coords.next()).copy()
         # print already_placed_successors[0], possible_coords
         for coord in already_placed_successor_coords:
             possible_coords.intersection_update(neighborhood(coord))
             if not possible_coords:
                 # print "neighborhood intersection is empty"
                 return None
     else:
         # print "the box to place has no successors: all empty coords are possible"
         possible_coords = set(product(range(col_count), range(row_count)))
     possible_coords.difference_update(box_coords.values())
     if not possible_coords:
         # print "neighborhood intersection is not free"
         return None
     non_crossing_possible_coords = []
     for (x1,y1) in possible_coords:
         for ((x2, y2), (x3, y3, x4, y4)) in product(already_placed_successors, already_placed_segments):
             if cross((x1, y1, x2, y2, x3, y3, x4, y4)):
                 break
         else:
             non_crossing_possible_coords.append((x1, y1))
     if not non_crossing_possible_coords:
         # print "all possible coords result in a crossing with existing segment"
         return None
     weighted_possible_coords = []
     for (x1,y1) in non_crossing_possible_coords:
         cumulated_distance = 0
         for ((x2, y2), placed_box) in already_placed_successors.iteritems():
             cumulated_distance += distances[abs(x1-x2)][abs(y1-y2)] * multiplicity[(box_to_place, placed_box)]
         weighted_possible_coords.append((cumulated_distance, random(), x1, y1))
     weighted_possible_coords.sort()
     for (cumulated_distance, _, x1, y1) in weighted_possible_coords:
         box_coords[box_to_place] = (x1, y1)
         new_segments = [(x1, y1, x2, y2) for (x2, y2) in already_placed_successors]
         new_next_boxes = list(successors[box_to_place].difference(box_coords).difference(next_boxes))
         if len(next_boxes) == 1 and len(new_next_boxes) == 0 and len(box_coords) != box_count:
             # print "the placed boxes have no more non placed successors"
             new_next_boxes = list(set(range(box_count)).difference(box_coords))
             if new_next_boxes:
                 new_next_boxes = [choice(new_next_boxes)]
         shuffle(new_next_boxes)
         result = recurs(
             box_coords,
             next_boxes[1:] + new_next_boxes,
             already_placed_segments + new_segments,
             cumulated_distances + cumulated_distance
         )
         if result:
             return result
         del box_coords[box_to_place]
Ejemplo n.º 9
0
wait_clear(1)
sad.sad()
wait_clear(1)
grimace.grimace()
wait_clear(1)
bit_sad.bit_sad()
wait_clear(1)
small_neutral.small_neutral()
wait_clear(1)
very_sad.very_sad()
wait_clear(1)
neutral.neutral()
wait_clear(1)
grin.grin()
wait_clear(1)
cross.cross()
wait_clear(1)
tick.tick()
wait_clear(1)
question.question()
wait_clear(1)
speak1.speak1()
wait_clear(0.1)
speak2.speak2()
wait_clear(0.1)
speak1.speak1()
wait_clear(0.1)
speak2.speak2()
wait_clear(0.1)
speak1.speak1()
wait_clear(0.1)
Ejemplo n.º 10
0
from cube import Cube
from cross import cross
from corners import corners

cube = Cube()
cube.input()
# cube.scramble()
cube.printFaces()
# cube.turn('r',1)
cross(cube)
corners(cube)
cube.printFaces()
Ejemplo n.º 11
0
def r_ne(R0, RR, A0, AA, v0, w0, vd0, wd0, q, qd, qdd, Fe, Te):
    A_I_0 = A0
    vv, ww = calc_vel(A0, AA, v0, w0, q, qd)
    vd, wd = calc_acc(A0, AA, w0, ww, vd0, wd0, q, qd, qdd)
    FF0 = m0 * (vd0 - Gravity)
    inertia_I_0 = np.dot(np.dot(A_I_0, inertia0), A_I_0.T)
    TT0 = np.dot(inertia_I_0, wd0[0:3]) + cross(w0[0:3],
                                                np.dot(inertia_I_0, w0[0:3]))

    FF = np.zeros((num_q, 3))
    TT = np.zeros((num_q, 3))

    if num_q == 0:
        print('Single body, there is no link')
    else:
        for i in range(num_q):
            A_I_i = AA[i, :, :]
            in_i = inertia[i, :, :]
            FF[i, :] = m[i] * (vd[i, :] - Gravity)
            inertia_I_i = np.dot(np.dot(A_I_i, in_i), A_I_i.T)
            TT[i, :] = np.dot(inertia_I_i, wd[i, :]) + cross(
                ww[i, :], np.dot(inertia_I_i, ww[i, :]))

    Fj = np.zeros((num_q, 3))
    Tj = np.zeros((num_q, 3))

    if num_q != 0:
        for i in range(num_q - 1, -1, -1):
            F = np.zeros(3)
            T = np.zeros(3)
            for j in range(i + 1, num_q, 1):
                F = F + SS[i, j] * Fj[j, :]
            Fj[i, :] = FF[i, :] + F - SE[i] * Fe[i, :]

            for j in range(i + 1, num_q, 1):
                A_I_i = AA[i, :, :]
                T = T + SS[i, j] * (cross(
                    np.dot(A_I_i,
                           (cc[i, j, :] - cc[i, i, :] +
                            np.dot(np.dot(
                                (J_type[i] == 'P'), Ez), q[i]))), Fj[j, :]) +
                                    Tj[j, :])
            if J_type[i] == 'R':
                A_I_i = AA[i, :, :]
                Tj[i, :] = TT[i, :] + T - cross(np.dot(A_I_i, cc[i, i, :]),
                                                FF[i, :])
            else:
                A_I_i = AA[i, :, :]
                Tj[i, :] = TT[i, :] + T + cross(
                    np.dot(A_I_i, np.dot(Ez, q[i])) -
                    np.dot(A_I_i, cc[i, i, :]), FF[i, :])
            Tj[i, :] = Tj[i, :] - SE[i] * (cross(
                np.dot(A_I_i, (ce[i, :] - cc[i, i, :] + np.dot(
                    np.dot(
                        (J_type[i] == 'P'), Ez), q[i]))), Fe[i, :]) + Te[i, :])

        F = np.zeros(3)
        T = np.zeros(3)
        for i in range(num_q):
            if S0[i] != 0:
                F = F + S0[i] * Fj[i, :]
        FF0 = FF0 + F

        for i in range(num_q):
            if S0[i] != 0:
                T = T + S0[i] * (cross(np.dot(A_I_0, c0[i, :]), Fj[i, :]) +
                                 Tj[i, :])
            TT0 = TT0 + T

    tau = np.zeros(num_q)
    if num_q == 0:
        tau = np.zeros(num_q)
    else:
        for i in range(num_q):
            A_I_i = AA[i, :, :]
            if J_type == 'R':
                tau[i] = np.dot(Tj[i, :].T, np.dot(A_I_i, Ez))
            else:
                tau[i] = np.dot(Fj[i, :].T, np.dot(A_I_i, Ez))

    Force = np.zeros(num_q + 6)
    if num_q == 0:
        Force[0:3] = FF0
        Force[3:6] = TT0
    else:
        Force[0:3] = FF0
        Force[3:6] = TT0
        Force[6:num_q + 6] = tau

    return Force
Ejemplo n.º 12
0
def calc_acc(A0, AA, w0, ww, vd0, wd0, q, qd, qdd):
    vd = np.zeros((num_q, 3))
    wd = np.zeros((num_q, 3))

    if num_q == 0:
        print('Single body, there is no link')
    else:
        A_I_0 = A0
        for i in range(num_q):
            if BB[i] == -1:
                A_I_i = AA[i, :, :]

                if J_type[i] == 'R':
                    wd[i, :] = wd0[0:3] \
                               + cross(ww[i, :], np.dot(np.dot(A_I_i, Ez), qd[i])) \
                               + np.dot(np.dot(A_I_i, Ez), qdd[i])
                    vd[i, :] = vd0[0:3] \
                               + cross(wd0[0:3], np.dot(A_I_0, c0[i, :])) \
                               + cross(w0[0:3], cross(w0[0:3], np.dot(A_I_0, c0[i, :]))) \
                               - cross(wd[i, :], np.dot(A_I_i, cc[i, i, :])) \
                               - cross(ww[i, :], cross(ww[i, :], np.dot(A_I_i, cc[i, i, :])))

                else:
                    wd[i, :] = wd0[0:3]
                    vd[i, :] = vd0[0:3] \
                               + cross(wd0[0:3], np.dot(A_I_0, c0[i, :])) \
                               + cross(w0[i, :], cross(w0[0:3], np.dot(A_I_0, c0[i, :]))) \
                               + cross(wd[i, :], np.dot(np.dot(A_I_i, Ez), q[i])) \
                               + cross(ww[i, :], cross(ww[i, :], np.dot(np.dot(A_I_i, Ez), q[i]))) \
                               + 2 * cross(ww[i, :], np.dot(np.dot(A_I_i, Ez), qd[i])) \
                               + np.dot(np.dot(A_I_i, Ez), qdd[i]) \
                               - cross(wd[i, :], np.dot(A_I_i, cc[i, i, :])) \
                               - cross(ww[i, :], cross(ww[i, :], np.dot(A_I_i, cc[i, i, :])))

            else:
                A_I_BB = AA[BB[i], :, :]
                A_I_i = AA[i, :, :]
                if J_type(i) == 'R':
                    wd[i, :] = wd[BB[i], :] \
                               + cross(ww[i, :], np.dot(np.dot(A_I_i, Ez), qd[i])) \
                               + np.dot(np.dot(A_I_i, Ez), qdd[i])
                    vd[i, :] = vd[BB[i], :] \
                               + cross(wd[BB[i], :], np.dot(A_I_BB, cc[BB[i], i, :])) \
                               + cross(ww[BB[i], :], cross(ww[BB[i], :], np.dot(A_I_BB, cc[BB[i], i, :]))) \
                               - cross(wd[i, :], np.dot(A_I_i, cc[i, i, :])) \
                               - cross(ww[i, :], cross(ww[i, :], np.dot(A_I_i, cc[i, i, :])))
                else:
                    wd[i, :] = wd[BB[i], :]
                    vd[i, :] = vd[BB[i], :] \
                               + cross(wd[BB[i], :], np.dot(A_I_BB, cc[BB[i], i, :])) \
                               + cross(ww[BB[i], :], cross(ww[BB[i], :], np.dot(A_I_BB, cc[BB[i], i, :]))) \
                               + cross(wd[i, :], np.dot(np.dot(A_I_i, Ez), q[i])) \
                               + cross(ww[i, :], cross(ww[i, :], np.dot(np.dot(A_I_i, Ez), q[i]))) \
                               + 2 * cross(ww[i, :], np.dot(np.dot(A_I_i, Ez), qd[i])) \
                               + np.dot(np.dot(A_I_i, Ez), qdd[i]) \
                               - cross(wd[i, :], np.dot(A_I_i, cc[i, i, :])) \
                               - cross(ww[i, :], cross(ww[i, :], np.dot(A_I_i, cc[i, i, :])))

    return vd, wd
Ejemplo n.º 13
0
 def presentationCross(self):
     self.obj = cross();
     self.obj.init();
     self.obj.drawCross();
     cv2.destroyAllWindows();
    # BEST UNIT SELECTION
    # the best bus in current generation
    contender_bus = best.best_bus(unit_parent)
    best_fit, change = best.dominants(best_fit, contender_bus)
    best_drive_fitness.append(best_fit)

    # the best bus company in current generation
    contender = best.best(unit_parent)
    best_unit = best.dominant(best_unit, contender)
    best_unit_fitness.append(best_unit.fitness)

    # ROUTE MUTATION
    unit_child = mut.mutate(unit_parent, citcon)

    # PARENT'S CROSSOVER
    unit_crossed = cs.cross(unit_parent)

    # CROSSED INDIVIDUALS BECOME NEW PARENT GENERATION
    unit_parent = unit_crossed

    if change == True:
        plt.plot(pos_x, pos_y, 'ro')
        best_drive.append(contender_bus)
        ind_x, ind_y = town.track_map(best_drive[-1])
        for i in range(len(pos_x)):
            plt.text(pos_x[i], pos_y[i], str(graph[i].indeks), fontsize=14)
        for i in range(len(x)):
            p1 = [graph[x[i]].x, graph[y[i]].x]
            p2 = [graph[x[i]].y, graph[y[i]].y]
            plt.plot(p1, p2, 'g')
        for i in range(len(ind_x)):