// Returns: <number of interesting problems, number of original problems generated>
        public ShadedAreaFigureStatisticsAggregator AnalyzeFigure()
        {
            ShadedAreaFigureStatisticsAggregator figureStats = new ShadedAreaFigureStatisticsAggregator();

            // Set the number of atomic regions.
            figureStats.numAtomicRegions = this.implied.atomicRegions.Count;

            // Start overall timing
            figureStats.stopwatch.Start();

            // Start stopwatch.
            stopwatch.Start();

            // Handle givens that strengthen the intrinsic parts of the figure; modifies if needed
            given = DoGivensStrengthenFigure();

            // Use a worklist technique to instantiate nodes to construct the hypergraph for this figure
            ConstructHypergraph();

            // Track implicit and explicit facts.
            figureStats.totalImplicitFacts = figure.Count;
            figureStats.totalExplicitFacts = deductiveGraph.Size() - figure.Count;

            // Create the integer-based hypergraph representation
            ConstructPebblingHypergraph();

            // Pebble that hypergraph
            Pebble();

            //
            // Stop stopwatch and mark deduction timing.
            //
            stopwatch.Stop();
            deductionTiming = stopwatch.Elapsed;
            stopwatch.Reset();

            //
            // Restart stopwatch for solving.
            //
            stopwatch.Reset();
            stopwatch.Start();

            //
            // Acquire the list of strengthened (pebbled) polygon nodes.
            //
            List<int> pebbledIndices = pebblerGraph.GetPebbledNodes();
            List<GeometryTutorLib.ConcreteAST.Strengthened> strengthenedNodes = deductiveGraph.GetStrengthenedNodes(pebbledIndices);

            // Perform any calculations required for shaded-area solution synthesis: strengthening, hierarchy construction, etc.
            AreaBasedCalculator areaCal = new AreaBasedCalculator(implied, strengthenedNodes);
            areaCal.PrepareAreaBasedCalculations();
            figureStats.numShapes = areaCal.GetAllFigures().Count;

            // Save the roots of the hierarchy for interesting analysis.
            roots = areaCal.GetRootShapes();
            figureStats.numRootShapes = roots.Count;

            //
            // Based on pebbling, we have a specific set of reachable nodes in the hypergraph.
            // Determine all the known values in the figure based on the pebbled hypergraph and all the known values stated in the problem.
            //
            List<GeometryTutorLib.ConcreteAST.GroundedClause> reachableConEqs = FindReachableCongEquationNodes();
            List<GeometryTutorLib.ConcreteAST.GroundedClause> triangles = FindReachableTriangles();
            known = GeometryTutorLib.Area_Based_Analyses.KnownValueAcquisition.AcquireAllKnownValues(known, reachableConEqs, triangles);

            //
            // Find the set of all equations for the shapes in this figure.
            //
            solutionAreaGenerator = new GeometryTutorLib.Area_Based_Analyses.AreaSolutionGenerator(areaCal.GetShapeHierarchy(), areaCal.GetUpdatedAtomicRegions());
            solutionAreaGenerator.SolveAll(known, areaCal.GetAllFigures());

            //
            // Stop the stopwatch for solving.
            //
            stopwatch.Stop();
            this.solverTiming = stopwatch.Elapsed;

            // Acquire a single solution for this specific problem for validation purposes.
            KeyValuePair<GeometryTutorLib.Area_Based_Analyses.ComplexRegionEquation, double> result = solutionAreaGenerator.GetSolution(goalRegions);

            // Number of area facts
            figureStats.numAreaFacts = result.Key.expr.NumRegions();

            #if HARD_CODED_UI
            UIDebugPublisher.getInstance().clearWindow();
            UIDebugPublisher.getInstance().publishString("Original Problem: " + string.Format("{0:N4}", result.Value) + " = " + result.Key.CheapPrettyString());
            #else
            if (Utilities.SHADED_AREA_SOLVER_DEBUG)
            {
                Debug.WriteLine("Original Problem: " + string.Format("{0:N4}", result.Value) + " = " + result.Key.CheapPrettyString());
            }
            #endif
            //
            // Validate that calculated area value matches the value from the hard-coded problem.
            //
            Validate(result.Key, result.Value);
            figureStats.originalProblemInteresting = OriginalProblemInteresting();

            //figureStats.numCalculableRegions = solutionAreaGenerator.GetNumComputable();
            //figureStats.numIncalculableRegions = solutionAreaGenerator.GetNumIncomputable();

            //Debug.WriteLine("Calculable Regions: " + figureStats.numCalculableRegions);
            //Debug.WriteLine("Incalculable Regions: " + figureStats.numIncalculableRegions);
            //Debug.WriteLine("Total:                " + (figureStats.numCalculableRegions +  figureStats.numIncalculableRegions));

            // Stop overall timing.
            figureStats.stopwatch.Stop();

            if (Utilities.SHADED_AREA_SOLVER_DEBUG)
            {
                solutionAreaGenerator.PrintAllSolutions();
            }

            return figureStats;
        }
Example #2
0
        // Returns: <number of interesting problems, number of original problems generated>
        public ShadedAreaFigureStatisticsAggregator AnalyzeFigure()
        {
            ShadedAreaFigureStatisticsAggregator figureStats = new ShadedAreaFigureStatisticsAggregator();

            // Set the number of atomic regions.
            figureStats.numAtomicRegions = this.implied.atomicRegions.Count;

            // Start overall timing
            figureStats.stopwatch.Start();

            // Start stopwatch.
            stopwatch.Start();

            // Handle givens that strengthen the intrinsic parts of the figure; modifies if needed
            given = DoGivensStrengthenFigure();

            // Use a worklist technique to instantiate nodes to construct the hypergraph for this figure
            ConstructHypergraph();

            // Track implicit and explicit facts.
            figureStats.totalImplicitFacts = figure.Count;
            figureStats.totalExplicitFacts = deductiveGraph.Size() - figure.Count;

            // Create the integer-based hypergraph representation
            ConstructPebblingHypergraph();

            // Pebble that hypergraph
            Pebble();

            //
            // Stop stopwatch and mark deduction timing.
            //
            stopwatch.Stop();
            deductionTiming = stopwatch.Elapsed;
            stopwatch.Reset();

            //
            // Restart stopwatch for solving.
            //
            stopwatch.Reset();
            stopwatch.Start();

            //
            // Acquire the list of strengthened (pebbled) polygon nodes.
            //
            List <int> pebbledIndices = pebblerGraph.GetPebbledNodes();
            List <GeometryTutorLib.ConcreteAST.Strengthened> strengthenedNodes = deductiveGraph.GetStrengthenedNodes(pebbledIndices);

            // Perform any calculations required for shaded-area solution synthesis: strengthening, hierarchy construction, etc.
            AreaBasedCalculator areaCal = new AreaBasedCalculator(implied, strengthenedNodes);

            areaCal.PrepareAreaBasedCalculations();
            figureStats.numShapes = areaCal.GetAllFigures().Count;

            // Save the roots of the hierarchy for interesting analysis.
            roots = areaCal.GetRootShapes();
            figureStats.numRootShapes = roots.Count;

            //
            // Based on pebbling, we have a specific set of reachable nodes in the hypergraph.
            // Determine all the known values in the figure based on the pebbled hypergraph and all the known values stated in the problem.
            //
            List <GeometryTutorLib.ConcreteAST.GroundedClause> reachableConEqs = FindReachableCongEquationNodes();
            List <GeometryTutorLib.ConcreteAST.GroundedClause> triangles       = FindReachableTriangles();

            known = GeometryTutorLib.Area_Based_Analyses.KnownValueAcquisition.AcquireAllKnownValues(known, reachableConEqs, triangles);

            //
            // Find the set of all equations for the shapes in this figure.
            //
            solutionAreaGenerator = new GeometryTutorLib.Area_Based_Analyses.AreaSolutionGenerator(areaCal.GetShapeHierarchy(), areaCal.GetUpdatedAtomicRegions());
            solutionAreaGenerator.SolveAll(known, areaCal.GetAllFigures());

            //
            // Stop the stopwatch for solving.
            //
            stopwatch.Stop();
            this.solverTiming = stopwatch.Elapsed;

            // Acquire a single solution for this specific problem for validation purposes.
            KeyValuePair <GeometryTutorLib.Area_Based_Analyses.ComplexRegionEquation, double> result = solutionAreaGenerator.GetSolution(goalRegions);

            // Number of area facts
            figureStats.numAreaFacts = result.Key.expr.NumRegions();

#if HARD_CODED_UI
            UIDebugPublisher.getInstance().clearWindow();
            UIDebugPublisher.getInstance().publishString("Original Problem: " + string.Format("{0:N4}", result.Value) + " = " + result.Key.CheapPrettyString());
#else
            if (Utilities.SHADED_AREA_SOLVER_DEBUG)
            {
                Debug.WriteLine("Original Problem: " + string.Format("{0:N4}", result.Value) + " = " + result.Key.CheapPrettyString());
            }
#endif
            //
            // Validate that calculated area value matches the value from the hard-coded problem.
            //
            Validate(result.Key, result.Value);
            figureStats.originalProblemInteresting = OriginalProblemInteresting();

            //figureStats.numCalculableRegions = solutionAreaGenerator.GetNumComputable();
            //figureStats.numIncalculableRegions = solutionAreaGenerator.GetNumIncomputable();

            //Debug.WriteLine("Calculable Regions: " + figureStats.numCalculableRegions);
            //Debug.WriteLine("Incalculable Regions: " + figureStats.numIncalculableRegions);
            //Debug.WriteLine("Total:                " + (figureStats.numCalculableRegions +  figureStats.numIncalculableRegions));

            // Stop overall timing.
            figureStats.stopwatch.Stop();

            if (Utilities.SHADED_AREA_SOLVER_DEBUG)
            {
                solutionAreaGenerator.PrintAllSolutions();
            }

            return(figureStats);
        }