- # Catch obvious mistakes so that we can generate clear error
- # messages.
-
- if min_dim < 0:
- raise ValueError('min_dim must be nonnegative.')
-
- if min_rays < 0:
- raise ValueError('min_rays must be nonnegative.')
-
- if max_dim is not None:
- if max_dim < 0:
- raise ValueError('max_dim must be nonnegative.')
- if (max_dim < min_dim):
- raise ValueError('max_dim cannot be less than min_dim.')
- if min_rays > 2*max_dim:
- raise ValueError('min_rays cannot be larger than twice max_dim.')
-
- if max_rays is not None:
- if max_rays < 0:
- raise ValueError('max_rays must be nonnegative.')
- if (max_rays < min_rays):
- raise ValueError('max_rays cannot be less than min_rays.')
-
-
- def random_min_max(l,u):
- r"""
- We need to handle two cases for the upper bounds, and we need to do
- the same thing for max_dim/max_rays. So we consolidate the logic here.
- """
- if u is None:
- # The upper bound is unspecified; return a random integer
- # in [l,infinity).
- return l + ZZ.random_element().abs()
- else:
- # We have an upper bound, and it's greater than or equal
- # to our lower bound. So we generate a random integer in
- # [0,u-l], and then add it to l to get something in
- # [l,u]. To understand the "+1", check the
- # ZZ.random_element() docs.
- return l + ZZ.random_element(u - l + 1)
-
- d = random_min_max(min_dim, max_dim)
- r = random_min_max(min_rays, max_rays)
-
- L = ToricLattice(d)
-
- # The rays are trickier to generate, since we could generate v and
- # 2*v as our "two rays." In that case, the resuting cone would
- # have one generating ray. To avoid such a situation, we start by
- # generating ``r`` rays where ``r`` is the number we want to end
- # up with...
- rays = [L.random_element() for i in range(0, r)]
-
- # (The lattice parameter is required when no rays are given, so we
- # pass it just in case ``r == 0``).
- K = Cone(rays, lattice=L)
-
- # Now if we generated two of the "same" rays, we'll have fewer
- # generating rays than ``r``. In that case, we keep making up new
- # rays and recreating the cone until we get the right number of
- # independent generators. We can obviously stop if ``K`` is the
- # entire ambient vector space.
- while r > K.nrays() and not is_full_space(K):
- rays.append(L.random_element())
- K = Cone(rays)
-
- return K
-
-
-def discrete_complementarity_set(K):
- r"""
- Compute the discrete complementarity set of this cone.