コード例 #1
0
ファイル: Shell.cs プロジェクト: whoaitsjoe/LatticePolytopes
        public static bool checkCore(Point u, Point v, int[] gi, List <Point> vertices, out bool uRedundant, out bool vRedundant)
        {
            List <Point> corePoints = new List <Point>();
            string       index;

            corePoints.AddRange(vertices);

            for (int i = 0; i < Globals.d; i++)
            {
                index = (Globals.d - 1).ToString() + Globals.k.ToString() + gi[i].ToString();

                if (Globals.coreSet.ContainsKey(index))
                {
                    foreach (Point p in Globals.coreSet[index])
                    {
                        Point q = p.clone();
                        q.increaseDimensionality(i / 2, (i % 2 == 0));
                        corePoints.Add(q);
                    }
                }
            }

            //todo -- this should check that the vertices remain vertices after chull.
            return(CDD.convexHullVertex(corePoints, u, v, out uRedundant, out vRedundant));
        }
コード例 #2
0
        //returns true if points are vertices of the convex core
        private static bool checkConvexCore(Point u, Point v, int[] gap, out bool uRedundant, out bool vRedundant)
        {
            List <Point> corePoints = new List <Point>();
            string       index0, indexk;
            Point        q;

            corePoints.Add(u);
            corePoints.Add(v);

            for (int i = 0; i < Globals.d; i++)
            {
                index0 = (Globals.d - 1).ToString() + Globals.k.ToString() + gap[i].ToString();
                indexk = (Globals.d - 1).ToString() + Globals.k.ToString() + (((2 * Globals.gap - gap[i]) > Globals.gap) ? (Globals.gap) : (2 * Globals.gap - gap[i])).ToString();

                //List<Point> corePoints0 = FileIO.readPointsFromFile(Globals.directory + "/" + index0 + "/coreSet");
                //List<Point> corePointsk = FileIO.readPointsFromFile(Globals.directory + "/" + indexk + "/coreSet");

                List <Point> corePoints0 = (Globals.coreSet.ContainsKey(index0)) ? Globals.coreSet[index0] : new List <Point>();
                List <Point> corePointsk = (Globals.coreSet.ContainsKey(indexk)) ? Globals.coreSet[indexk] : new List <Point>();

                foreach (Point p in corePoints0)
                {
                    q = p.clone();
                    q.increaseDimensionality(i, true);
                    corePoints.Add(q);
                }
                foreach (Point p in corePointsk)
                {
                    q = p.clone();
                    q.increaseDimensionality(i, false);
                    corePoints.Add(q);
                }
            }

            return(CDD.convexHullVertex(corePoints, u, v, out uRedundant, out vRedundant));
        }
コード例 #3
0
ファイル: Shell.cs プロジェクト: whoaitsjoe/LatticePolytopes
        private static List <Graph> shellHelper(Graph currFacets, List <Point> vertexSet, List <Point> nonVertexSet, List <Point> coreSet, bool[] facetsUsed, Point u, Point v, int[] facetDiameter)
        {
            List <Graph> result = new List <Graph>();
            int          sp;
            bool         uRedundant, vRedundant;        //track if either u or v is redundant. For message output.

            bool[]       _facetsUsed = new bool[facetsUsed.Length];
            List <Point> _nonVertexSet = new List <Point>(), _corePointSet = new List <Point>(), _vertexSet = new List <Point>();

            //creating copies of reference data
            for (int i = 0; i < facetsUsed.Length; i++)
            {
                _facetsUsed[i] = facetsUsed[i];
            }

            foreach (Point p in nonVertexSet)
            {
                _nonVertexSet.Add(p.clone());
            }

            foreach (Point p in coreSet)
            {
                _corePointSet.Add(p.clone());
            }

            foreach (Point p in vertexSet)
            {
                _vertexSet.Add(p.clone());
            }

            //calculates gi values
            int[] gi = updateGi(currFacets, u, v);

            //calculates next facet to add
            int nextFacet = calculateNextFacet(u, v, currFacets, facetsUsed, gi);

            List <Point> facetPoints        = currFacets.getAllContainedPoints(nextFacet);
            List <Point> dMinus1FacetPoints = new List <Point>();

            foreach (Point p in facetPoints)
            {
                if (Convert.ToInt32(p.Coordinates[nextFacet / 2].ToString()) == ((nextFacet % 2 == 0) ? 0 : Globals.k))
                {
                    dMinus1FacetPoints.Add(p.decreaseDimensionality(nextFacet / 2));
                }
            }

            //generate all valid d-1 polytopes that can be considered as a facet.
            List <Graph> possibleFacets = Generate.dMinus1Polytopes(dMinus1FacetPoints, gi[nextFacet]);

            _facetsUsed[nextFacet] = true;

            if (possibleFacets != null && possibleFacets.Count > 0)
            {
                if (Globals.messageOn)
                {
                    Console.WriteLine("Number of possible facets: " + possibleFacets.Count);
                }

                //try every possible facet as a shell
                foreach (Graph f in possibleFacets)
                {
                    //todo -- test if .clone() is actually required
                    Graph temp = currFacets.clone();
                    Graph h    = f.clone();

                    //set values for current selected facet to shell
                    facetDiameter[nextFacet] = f.Points.Count / 2;

                    //increase dimensionality of facet
                    h.addDimensionality(nextFacet / 2, (nextFacet % 2 == 0) ? true : false);

                    //add facet to gamma
                    temp.AddFacet(h);

                    //check 1 - looks for sp from u to v
                    sp = ShortestPath.BFS(temp, u, v);
                    if (sp >= 0 && sp < Globals.maxDiameter[Globals.k] + Globals.k - Globals.gap)
                    {
                        if (Globals.messageOn)
                        {
                            Console.WriteLine("SP < " + Globals.maxLength);
                        }

                        continue;
                    }

                    //check 2 - gamma check
                    int gamma = calculateGamma(u, v, temp, gi, facetDiameter);
                    if (gamma > 0)
                    {
                        if (Globals.messageOn)
                        {
                            Console.WriteLine("Gamma > 0.");
                        }

                        continue;
                    }

                    //check 3 - convex core check -- u and v must be vertices of the convex hull generated by the current subgraph.
                    if (!checkCore(u, v, gi, temp.getAllContainedPoints(), out uRedundant, out vRedundant))
                    {
                        if (Globals.messageOn)
                        {
                            Console.WriteLine("Convex Core Check. {0}", ((uRedundant && vRedundant) ? "u and v are not vertices." : (uRedundant ? "u is not a vertex." : "v is not a vertex.")));
                        }

                        continue;
                    }

                    //if shelling is incomplete
                    if (checkUnshelledFacet(_facetsUsed))
                    {
                        result.AddRange(shellHelper(temp, _vertexSet, _nonVertexSet, _corePointSet, _facetsUsed, u, v, facetDiameter));
                    }
                    else
                    {
                        if (!CDD.compareAlToPoints(temp.Points))                         //convex hull call
                        {
                            continue;
                        }

                        totalShelling++;

                        if (Globals.messageOn)
                        {
                            Console.WriteLine("***** FULL SHELLING FOUND *****");
                            Console.WriteLine(temp);
                        }

                        result.Add(temp);
                    }
                }

                facetDiameter[nextFacet] = Globals.maxDiameter[Globals.k];

                if (Globals.messageOn)
                {
                    Console.WriteLine("All facets checked.");
                }

                return(result);
            }
            else
            {
                if (Globals.messageOn)
                {
                    Console.WriteLine("No possible facets.");
                }

                return(new List <Graph>());
            }
        }
コード例 #4
0
        //todo -- generalize this function to any d, currently using iVal and jVal.
        //This function currently generates just delta(d-1,k) - gap polytopes, should also generate delta(d-1,k) polytopes
        public static List <Graph> dMinus1PolytopesHelper(List <Point> vertices, List <Point> nonVertices, List <Point> corePoints, int iVal, int jVal, int gap)
        {
            List <Graph> result          = new List <Graph>();
            List <Point> currVertices    = new List <Point>();
            List <Point> currNonVertices = new List <Point>();
            Graph        facet;

            if (vertices.Count > (Globals.maxDiameter[Globals.k] * 2 + 1))
            {
                return(result);
            }

            if (vertices.Count == (Globals.maxDiameter[Globals.k] * 2 + 1) || vertices.Count == (Globals.maxDiameter[Globals.k] * 2))
            {
                Graph tempGraph;
                if (CDD.convexHullAdjList(vertices, new List <Point>(), out tempGraph))
                {
                    totalCount++;
                    result.Add(tempGraph.clone());
                }
            }

            foreach (Point p in vertices)
            {
                currVertices.Add(p.clone());
            }
            foreach (Point p in nonVertices)
            {
                currNonVertices.Add(p.clone());
            }

            for (int i = iVal; i <= Globals.k; i++)
            {
                int  vCount = vertexCount(vertices, i);
                bool _found;
                //find max number of potential vertices (e.g. terminate if not enough vertices can exist)
                if (vCount + (2 * (Globals.k - (iVal - 1))) < 2 * (Globals.maxDiameter[Globals.k] - gap))
                {
                    return(result);
                }

                for (int j = (i == iVal ? jVal + 1 : 0); j <= Globals.k; j++)
                {
                    _found = false;

                    foreach (Point p in nonVertices)
                    {
                        if (i == (int)Char.GetNumericValue(p.Coordinates[0]) && j == (int)Char.GetNumericValue(p.Coordinates[1]))
                        {
                            _found = true;
                            break;
                        }
                    }
                    if (!_found)
                    {
                        foreach (Point p in vertices)
                        {
                            if (i == (int)Char.GetNumericValue(p.Coordinates[0]) && j == (int)Char.GetNumericValue(p.Coordinates[1]))
                            {
                                _found = true;
                                break;
                            }
                        }
                    }

                    if (_found)
                    {
                        continue;
                    }

                    Point tempVertex = new Point(new int[2] {
                        i, j
                    });

                    currVertices.Add(tempVertex);

                    if (!check2PointsInRow(currVertices, i))
                    {
                        currVertices.Remove(tempVertex);
                        jVal = 0;
                        break;
                    }
                    else if (!check2PointsInCol(currVertices, j))
                    {
                        currVertices.Remove(tempVertex);
                        continue;
                    }
                    else if (!checkDiagonals(currVertices))
                    {
                        currVertices.Remove(tempVertex);
                        continue;
                    }
                    else
                    {
                        if (CDD.convexHullAdjList(currVertices, corePoints, out facet))
                        {
                            if (currVertices.Count >= (Globals.maxDiameter[Globals.k] - gap) * 2)
                            {
                                totalCount++;
                                result.Add(facet.clone());
                                result.AddRange(dMinus1PolytopesHelper(currVertices, currNonVertices, corePoints, i, j, gap));
                            }
                            else
                            {
                                result.AddRange(dMinus1PolytopesHelper(currVertices, currNonVertices, corePoints, i, j, gap));
                            }
                        }
                    }

                    currVertices.Remove(tempVertex);
                    currNonVertices.Add(tempVertex.clone());
                }
            }
            return(result);
        }