Exemplo n.º 1
0
        public static int calculateGamma(Point u, Point v, Graph currFacets, int[] gi, int[] facetDiameter)
        {
            int shortestPath = ShortestPath.BFS(currFacets, u, v);

            if (shortestPath < 0)
            {
                shortestPath = Globals.maxDiameter[Globals.k] + Globals.k - Globals.gap;
            }

            return(Globals.maxDiameter[Globals.k] + Globals.k - Globals.gap - Math.Min(shortestPath, calculateDDot(u, v, currFacets, facetDiameter)));
        }
Exemplo n.º 2
0
        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>());
            }
        }
Exemplo n.º 3
0
 public static int calculateDistanceToFacet(Point u, Graph currFacets, int facet)
 {
     return(Math.Min(ShortestPath.BFStoFacet(currFacets, u, facet), ShortestPath.BFStoFacetEstimator(currFacets, u, facet)));
 }