コード例 #1
0
ファイル: OperationTable.cs プロジェクト: ajlopez/AjGroups
        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);
        }
コード例 #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
ファイル: TableGroup.cs プロジェクト: ajlopez/AjGroups
        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;
        }
コード例 #4
0
ファイル: OperationTable.cs プロジェクト: ajlopez/AjGroups
 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);
 }
コード例 #5
0
ファイル: OperationTable.cs プロジェクト: ajlopez/AjGroups
        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);
        }
コード例 #6
0
ファイル: OperationTable.cs プロジェクト: ajlopez/AjGroups
 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);
 }
コード例 #7
0
ファイル: OperationTable.cs プロジェクト: ajlopez/AjGroups
        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;
        }