Exemplo n.º 1
0
 public override DomainElement ElementForIndex(int index)
 {
     if (index >= GetCardinality() || index < 0)
     {
         throw new IndexOutOfRangeException();
     }
     return(DomainElement.Of(First + index));
 }
Exemplo n.º 2
0
        public override DomainElement ElementForIndex(int index)
        {
            int[] values = new int[GetNumberOfComponents()];

            for (int i = GetNumberOfComponents() - 1; i >= 0; --i)
            {
                int n = _domains[i].GetCardinality();
                values[i] = _domains[i].ElementForIndex(index % n)[0];
                index    /= n;
            }

            return(DomainElement.Of(values));
        }
Exemplo n.º 3
0
        public override int IndexOfElement(DomainElement element)
        {
            if (element.GetNumberOfComponents() != GetNumberOfComponents())
            {
                throw new Exception("Element not in domain!");
            }

            int index        = 0;
            int combinations = 1;

            for (int i = GetNumberOfComponents() - 1; i >= 0; --i)
            {
                DomainElement value = DomainElement.Of(element.GetComponentValue(i));
                index        += (combinations * _domains[i].IndexOfElement(value));
                combinations *= _domains[i].GetCardinality();
            }

            return(index);
        }