示例#1
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;
        }
示例#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;
        }
示例#3
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);
        }
示例#4
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;
        }