コード例 #1
0
def check_some_core_hom_is_by_subspace(vs, G, H=None, require_isomorphic=True, limit=10000):
  """
  Check if there is a retract from G to H that "contracts" a subspace of vs.
  See hom.hom_is_by_subspace. If not given, H is a core of G.
  Returns True/False.
  """
  if not H:
    H = hom.find_core(G)
  return any((hom.hom_is_by_subspace(G, vs, h) for h in hom.extend_hom(G, H, limit=limit)))
コード例 #2
0
ファイル: cayley.py プロジェクト: rostam/homsearch
def test():
    "Run unit tests for the module."
    log.getLogger().setLevel(log.DEBUG)

    from sage.graphs.graph_generators import graphs
    K2 = graphs.CompleteGraph(2)
    K4 = graphs.CompleteGraph(4)
    Z2_3 = VectorSpace(GF(2), 3)
    Z2_2 = VectorSpace(GF(2), 2)

    # nonisomorphic_cubes_Z2
    assert len(list(nonisomorphic_cubes_Z2(1))) == 1
    assert len(list(nonisomorphic_cubes_Z2(2))) == 2
    assert len(list(nonisomorphic_cubes_Z2(3))) == 6

    # CayleyGraph
    K4b = CayleyGraph(Z2_2, [(1, 0), (0, 1), (1, 1)])
    assert K4.is_isomorphic(K4b)

    # squash_cube
    Ge = CayleyGraph(Z2_2, [(1, 0), (0, 1)])
    Smap = squash_cube(Ge, (1, 1))
    K2e = Ge.subgraph(Smap.values())
    assert K2.is_isomorphic(K2e)
    assert is_hom(Ge, K2e, Smap)

    # hom_is_by_subspace
    Gg = CayleyGraph(Z2_3, [(1, 0, 0), (0, 1, 0)])
    Hg = CayleyGraph(Z2_2, [(1, 0), (0, 1), (1, 1)])
    homg = {
        (0, 0, 0): (0, 0),
        (1, 0, 0): (1, 0),
        (0, 1, 0): (0, 1),
        (1, 1, 0): (1, 1),
        (0, 0, 1): (0, 0),
        (1, 0, 1): (1, 0),
        (0, 1, 1): (1, 1),
        (1, 1, 1): (0, 1)
    }
    assert is_hom(Gg, Hg, homg)
    assert hom_is_by_subspace(Gg, Z2_3, homg, require_isomorphic=False)
    assert not hom_is_by_subspace(Gg, Z2_3, homg, require_isomorphic=True)
    for h in extend_hom(Gg, K2, limit=10):
        assert hom_is_by_subspace(Gg, Z2_3, h, require_isomorphic=True)

    log.info("All tests passed.")
コード例 #3
0
ファイル: cayley.py プロジェクト: gavento/homsearch
def test():
  "Run unit tests for the module."
  log.getLogger().setLevel(log.DEBUG)

  from sage.graphs.graph_generators import graphs
  K2 = graphs.CompleteGraph(2)
  K4 = graphs.CompleteGraph(4)
  Z2_3 = VectorSpace(GF(2), 3)
  Z2_2 = VectorSpace(GF(2), 2)

  # nonisomorphic_cubes_Z2
  assert len(list(nonisomorphic_cubes_Z2(1))) == 1
  assert len(list(nonisomorphic_cubes_Z2(2))) == 2
  assert len(list(nonisomorphic_cubes_Z2(3))) == 6

  # CayleyGraph
  K4b = CayleyGraph(Z2_2, [(1,0), (0,1), (1,1)])
  assert K4.is_isomorphic(K4b)

  # squash_cube
  Ge = CayleyGraph(Z2_2, [(1,0), (0,1)])
  Smap = squash_cube(Ge, (1,1))
  K2e = Ge.subgraph(Smap.values())
  assert K2.is_isomorphic(K2e)
  assert is_hom(Ge, K2e, Smap)

  # hom_is_by_subspace
  Gg = CayleyGraph(Z2_3, [(1,0,0), (0,1,0)])
  Hg = CayleyGraph(Z2_2, [(1,0), (0,1), (1,1)])
  homg = {(0,0,0):(0,0), (1,0,0):(1,0), (0,1,0):(0,1), (1,1,0):(1,1),
          (0,0,1):(0,0), (1,0,1):(1,0), (0,1,1):(1,1), (1,1,1):(0,1)}
  assert is_hom(Gg, Hg, homg)
  assert hom_is_by_subspace(Gg, Z2_3, homg, require_isomorphic=False)
  assert not hom_is_by_subspace(Gg, Z2_3, homg, require_isomorphic=True)
  for h in extend_hom(Gg, K2, limit=10):
    assert hom_is_by_subspace(Gg, Z2_3, h, require_isomorphic=True)

  log.info("All tests passed.")
コード例 #4
0
ファイル: par_homomorphisms.py プロジェクト: rostam/homsearch
def parallel_extend_hom_partmaps(G, H, partmap, kwargs):
  log.debug("Running extend_hom with %s" % (partmap))
  res = hom.extend_hom(G, H, partmap=partmap, **kwargs)
  log.debug("Done    extend_hom with %s" % (partmap))
  return res