Esempio n. 1
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);
        }
Esempio n. 2
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;
        }