Exemple #1
0
        public IEnumerable <OperationTable> GetSolutions()
        {
            int n = this.elements.Count;

            for (int k = 0; k < n; k++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (this.cells[k, j] != null)
                    {
                        continue;
                    }

                    foreach (IElement element in this.elements)
                    {
                        OperationTable table = this.GetCompatibleTable(this.elements[k], this.elements[j], element);
                        if (table != null)
                        {
                            foreach (OperationTable solution in table.GetSolutions())
                            {
                                yield return(solution);
                            }
                        }
                    }

                    yield break;
                }
            }

            yield return(this);
        }
Exemple #2
0
        public TableGroup(OperationTable table)
        {
            this.elements = new List <IElement>();

            foreach (IElement element in table.Elements)
            {
                this.elements.Add(new NamedElement(((NamedElement)element).Name));
            }

            OperationTable newtable = new OperationTable(this.elements);

            int n = this.elements.Count;

            for (int k = 0; k < n; k++)
            {
                for (int j = 0; j < n; j++)
                {
                    IElement oldvalue = table.GetValue(k, j);
                    IElement newvalue = this.elements[this.elements.IndexOf(oldvalue)];
                    newtable.SetValue(k, j, newvalue);
                }
            }

            foreach (IElement element in this.elements)
            {
                NamedElement nelement = (NamedElement)element;
                nelement.OperationTable = newtable;
            }

            this.table = newtable;
        }
Exemple #3
0
        public TableGroup(OperationTable table)
        {
            this.elements = new List<IElement>();

            foreach (IElement element in table.Elements)
                this.elements.Add(new NamedElement(((NamedElement) element).Name));

            OperationTable newtable = new OperationTable(this.elements);

            int n = this.elements.Count;

            for (int k = 0; k < n; k++)
                for (int j = 0; j < n; j++)
                {
                    IElement oldvalue = table.GetValue(k, j);
                    IElement newvalue = this.elements[this.elements.IndexOf(oldvalue)];
                    newtable.SetValue(k, j, newvalue);
                }

            foreach (IElement element in this.elements)
            {
                NamedElement nelement = (NamedElement) element;
                nelement.OperationTable = newtable;
            }

            this.table = newtable;
        }
Exemple #4
0
 public OperationTable(OperationTable table)
 {
     this.elements = new List <IElement>(table.elements);
     this.cells    = new IElement[this.elements.Count, this.elements.Count];
     Array.Copy(table.cells, this.cells, this.elements.Count * this.elements.Count);
 }
Exemple #5
0
        public OperationTable GetCompatibleTable(IElement left, IElement right, IElement value)
        {
            IElement actualvalue = this.GetValue(left, right);

            if (actualvalue == value)
            {
                return(this);
            }

            if (actualvalue != null)
            {
                return(null);
            }

            if (!this.elements.Contains(left))
            {
                return(null);
            }

            if (!this.elements.Contains(right))
            {
                return(null);
            }

            int x = this.elements.IndexOf(left);
            int y = this.elements.IndexOf(right);

            for (int k = 0; k < this.elements.Count; k++)
            {
                if (value.Equals(this.cells[k, y]))
                {
                    return(null);
                }
                if (value.Equals(this.cells[x, k]))
                {
                    return(null);
                }
            }

            OperationTable table = new OperationTable(this);

            // TODO complete other values, test compatibility
            table.SetValue(left, right, value);

            // TODO Review Associative expansion
            for (int k = 0; k < this.elements.Count; k++)
            {
                for (int j = 0; j < this.elements.Count; j++)
                {
                    if (cells[k, j] != null && cells[k, j].Equals(left))
                    {
                        IElement newleft  = this.elements[k];
                        IElement newright = this.GetValue(this.elements[j], right);
                        if (newright != null)
                        {
                            table = table.GetCompatibleTable(newleft, newright, value);
                            if (table == null)
                            {
                                return(null);
                            }
                        }
                    }

                    if (cells[k, j] != null && cells[k, j].Equals(right))
                    {
                        IElement newleft  = this.GetValue(left, this.elements[k]);
                        IElement newright = this.elements[j];
                        if (newleft != null)
                        {
                            table = table.GetCompatibleTable(newleft, newright, value);
                            if (table == null)
                            {
                                return(null);
                            }
                        }
                    }
                }
            }

            return(table);
        }
Exemple #6
0
 public OperationTable(OperationTable table)
 {
     this.elements = new List<IElement>(table.elements);
     this.cells = new IElement[this.elements.Count, this.elements.Count];
     Array.Copy(table.cells, this.cells, this.elements.Count * this.elements.Count);
 }
Exemple #7
0
        public OperationTable GetCompatibleTable(IElement left, IElement right, IElement value)
        {
            IElement actualvalue = this.GetValue(left, right);

            if (actualvalue == value)
                return this;

            if (actualvalue != null)
                return null;

            if (!this.elements.Contains(left))
                return null;

            if (!this.elements.Contains(right))
                return null;

            int x = this.elements.IndexOf(left);
            int y = this.elements.IndexOf(right);

            for (int k = 0; k < this.elements.Count; k++)
            {
                if (value.Equals(this.cells[k, y]))
                    return null;
                if (value.Equals(this.cells[x, k]))
                    return null;
            }

            OperationTable table = new OperationTable(this);

            // TODO complete other values, test compatibility
            table.SetValue(left, right, value);

            // TODO Review Associative expansion
            for (int k = 0; k < this.elements.Count; k++)
                for (int j = 0; j < this.elements.Count; j++)
                {
                    if (cells[k, j] != null && cells[k, j].Equals(left))
                    {
                        IElement newleft = this.elements[k];
                        IElement newright = this.GetValue(this.elements[j], right);
                        if (newright != null)
                        {
                            table = table.GetCompatibleTable(newleft, newright, value);
                            if (table == null)
                                return null;
                        }
                    }

                    if (cells[k, j] != null && cells[k, j].Equals(right))
                    {
                        IElement newleft = this.GetValue(left, this.elements[k]);
                        IElement newright = this.elements[j];
                        if (newleft != null)
                        {
                            table = table.GetCompatibleTable(newleft, newright, value);
                            if (table == null)
                                return null;
                        }
                    }
                }

            return table;
        }