Exemplo n.º 1
0
 def __init__(O, qe):
     O.qe = qe
     O.q_size = len(qe)
     #
     c, s = math.cos(qe[0]), math.sin(qe[0])
     e = matrix.sqr((c, s, 0, -s, c, 0, 0, 0, 1))  # RBDA Tab. 2.2
     #
     O.cb_ps = matrix.rt((e, (0, 0, 0)))
     O.cb_sp = matrix.rt((e.transpose(), (0, 0, 0)))
     O.motion_subspace = matrix.col((0, 0, 1, 0, 0, 0))
Exemplo n.º 2
0
 def __init__(O, qe):
   O.qe = qe
   O.q_size = len(qe)
   #
   c, s = math.cos(qe[0]), math.sin(qe[0])
   e = matrix.sqr((c, s, 0, -s, c, 0, 0, 0, 1)) # RBDA Tab. 2.2
   #
   O.cb_ps = matrix.rt((e, (0,0,0)))
   O.cb_sp = matrix.rt((e.transpose(), (0,0,0)))
   O.motion_subspace = matrix.col((0,0,1,0,0,0))
Exemplo n.º 3
0
def run(args):
  assert len(args) == 3, 'radius isituation cutoff'
  radius = int(args[0])
  isituation = int(args[1])
  cutoff = int(args[2])

  group_symmetry_masks = []
  r90 = (0, -1, 1, 0)
  mx = (-1, 0, 0, 1)
  group = set()
  multiply_into_group(group, r90)
  multiply_into_group(group, mx)
  ij_lookup_table = build_ij_lookup_table(radius)
  num_bits = len(ij_lookup_table)
  for mx in reversed(sorted(group)):
    mx = matrix.sqr(mx)
    symmetry_masks = [None] * num_bits
    a = 0
    for i in xrange(-radius, radius + 1):
      for j in xrange(-radius, radius + 1):
        p = matrix.col((i, j))
        q = mx * p
        b = get_ipacked(radius, *q.elems)
        if b is not None:
          assert ij_lookup_table[a] == p.elems
          assert ij_lookup_table[b] == q.elems
          symmetry_masks[b] = (0x1 << a)
          a += 1
    assert None not in symmetry_masks
    for a in xrange(num_bits):
      p = mx * matrix.col(ij_lookup_table[a])
      b = get_ipacked(radius, *p.elems)
      assert apply_symmetry_masks(symmetry_masks, (0x1 << a)) == (0x1 << b)
    group_symmetry_masks.append(tuple(symmetry_masks))
  group_symmetry_masks = tuple(group_symmetry_masks)
  assert len(group_symmetry_masks) == 8

  for ipacked in xrange(num_bits):
    assert get_ipacked_from_bit(0x1 << ipacked) == ipacked

  moves = build_moves(radius)
  center_bit = 0x1 << get_ipacked(radius, 0, 0)
  situations = (
      center_bit,
      (0x1 << get_ipacked(radius,  0, -2) |
       0x1 << get_ipacked(radius, -2, -1) |
       0x1 << get_ipacked(radius, -1, -1)),
      ~center_bit & ((0x1 << num_bits) - 1),
      (0x1 << get_ipacked(radius, -3, -1) |
       0x1 << get_ipacked(radius,  1, -3) |
       0x1 << get_ipacked(radius,  3,  1) |
       0x1 << get_ipacked(radius, -1,  3)),
  )

  print 'Constants for dfs_core.cc:'
  print num_bits
  print situations
  print get_ipacked(radius, 0, 0);
  for symmetry_mask in group_symmetry_masks:
    print symmetry_mask
  for move in moves:
    print move.fingerprint
  print

  situation = situations[isituation]
  show_game(radius, situation)
  print
  show_equiv_games(radius, situation, None, group_symmetry_masks)

  imoves_canonical = (
      7, 13, 0, 4, 20, 11, 22, 29, 32, 0, 30, 32, 40, 3, 45, 40,
      66, 47, 50, 5, 35, 58, 8, 65, 57, 74, 41, 72, 74, 63, 68)

  imoves = None
  if cutoff in [100, 101]:
    imoves = imoves_canonical
    if cutoff == 101:
      imoves = imoves[:-1] + (55,)
  elif cutoff == 200:
    imove_by_wiki = {}
    wne = build_wikipedia_notation_english(radius)
    for imove, move in enumerate(moves):
      pair = []
      for i in [0, 2]:
        ipacked = get_ipacked_from_bit(move.fingerprint[i])
        pair.append(wne[ipacked])
      imove_by_wiki[''.join(pair)] = imove

    wiki_solution = (
        'ex,lj,ck,Pf,DP,GI,JH,mG,GI,ik,gi,LJ,JH,Hl,lj,jh,'
        'CK,pF,AC,CK,Mg,gi,ac,ck,kI,dp,pF,FD,DP,Pp,ox')
    imoves = tuple([imove_by_wiki[pair] for pair in wiki_solution.split(',')])

  if imoves is not None:
    print
    tracked_situations = [situation]
    for imove in imoves:
      move = moves[imove]
      next_situation = move.apply(situation)
      if next_situation is None:
        raise RuntimeError('Invalid move.')
      show_equiv_games(radius, next_situation, situation, group_symmetry_masks)
      print
      situation = next_situation
      tracked_situations.append(situation)

    if cutoff == 200:
      tracked_iter = iter(tracked_situations)
      situation = tracked_iter.next()
      for imove in imoves_canonical:
        move = moves[imove]
        situation = move.apply(situation)
        tracked_situation = tracked_iter.next()
        print 'Canonical'
        show_game(radius, situation)
        print 'Wikipedia'
        show_game(radius, tracked_situation)
        for symmetry_masks in group_symmetry_masks:
          equiv_situation = apply_symmetry_masks(symmetry_masks, situation)
          if equiv_situation == tracked_situation:
            print 'MATCH OK'
            break
        else:
          print 'MATCH OFF'

    sys.stdout.flush()
    return

  all_lexmins = {}
  pruning_counts = []
  for len_path in xrange(num_bits - 1):
    all_lexmins[len_path] = set()
    pruning_counts.append(0)
  path = []
  continue_play(radius, cutoff, group_symmetry_masks, moves, all_lexmins,
                situation, path, pruning_counts)
  for len_path in xrange(num_bits - 1):
    print len_path, len(all_lexmins[len_path]), pruning_counts[len_path]
  print 'Done.'
Exemplo n.º 4
0
 def tau_as_d_e_pot_d_q(O, tau):
   d = d_unit_quaternion_d_qe_matrix(q=O.qe)
   c = d * 4 * rbda_eq_4_13(q=O.unit_quaternion)
   n, f = matrix.col_list([tau.elems[:3], tau.elems[3:]])
   return matrix.col((c * n, O.e.transpose() * f)).resolve_partitions()
Exemplo n.º 5
0
 def new_linear_velocity(O, qd, value):
   return matrix.col((matrix.col(qd.elems[:3]), value)).resolve_partitions()
Exemplo n.º 6
0
 def get_linear_velocity(O, qd):
   return matrix.col(qd.elems[3:])
Exemplo n.º 7
0
 def new_q(O, q):
   return translational(qr=matrix.col(q))
Exemplo n.º 8
0
 def new_q(O, q):
   return revolute(qe=matrix.col(q))
Exemplo n.º 9
0
 def new_q(O, q):
   return spherical(qe=matrix.col(q))
Exemplo n.º 10
0
 def tau_as_d_e_pot_d_q(O, tau):
     d = d_unit_quaternion_d_qe_matrix(q=O.qe)
     c = d * 4 * rbda_eq_4_13(q=O.unit_quaternion)
     n, f = matrix.col_list([tau.elems[:3], tau.elems[3:]])
     return matrix.col((c * n, O.e.transpose() * f)).resolve_partitions()
Exemplo n.º 11
0
 def new_linear_velocity(O, qd, value):
     return matrix.col(
         (matrix.col(qd.elems[:3]), value)).resolve_partitions()
Exemplo n.º 12
0
 def get_linear_velocity(O, qd):
     return matrix.col(qd.elems[3:])
Exemplo n.º 13
0
 def new_q(O, q):
     return translational(qr=matrix.col(q))
Exemplo n.º 14
0
 def new_q(O, q):
     return revolute(qe=matrix.col(q))
Exemplo n.º 15
0
 def new_q(O, q):
     return spherical(qe=matrix.col(q))