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 int IndexOfElement(DomainElement element)
        {
            int value = element[0];

            if (value < First || value >= Second || element.GetNumberOfComponents() > 1)
            {
                throw new Exception("Element not in domain!");
            }

            return(value - First);
        }
Exemplo n.º 3
0
 public bool HasElement(DomainElement element)
 {
     try
     {
         IndexOfElement(element);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 4
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.º 5
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);
        }
Exemplo n.º 6
0
 public abstract int IndexOfElement(DomainElement element);