public void PrintAllSolutions() { List <SolutionAgg> theSolutions = solutions.GetSolutions(); for (int s = 0; s < theSolutions.Count; s++) { #if HARD_CODED_UI UIDebugPublisher.getInstance().publishString((s + 1) + " (" + string.Format("{0:N4}", theSolutions[s].solArea) + "): " + theSolutions[s].solEq.CheapPrettyString()); #else Debug.WriteLine((s + 1) + " (" + string.Format("{0:N4}", theSolutions[s].solArea) + "): " + theSolutions[s].solEq.CheapPrettyString()); #endif } }
public Page(IDictionary <string, string> initParams) { System.Windows.Threading.SmartDispatcher.Initialize(); initParseWorker(); UseLayoutRounding = true; MEFHost.Instance.RegisterExtensionAssemblyFromType <Page>(); // this needs to be initialized first since subsequent calls // rely on having serializable settings already available DynamicGeometry.Settings.Instance = new IsolatedStorageBasedSettings(); drawingHost = new DrawingHost(); AddBehaviors(); this.Content = drawingHost; drawingHost.AIDebugWindow.MakeUIDebugPublisher(); UIDebugPublisher = GeometryTutorLib.UIDebugPublisher.getInstance(); ProblemDrawer.create(drawingHost); InitParams = initParams; var settings = Application.Current.Host.Settings; if (Application.Current.IsRunningOutOfBrowser) { settings.EnableAutoZoom = false; } //settings.EnableGPUAcceleration = true; //settings.EnableRedrawRegions = true; //settings.EnableCacheVisualization = true; //settings.EnableFrameRateCounter = true; PageSettings = new Settings(this); if (initParams.ContainsKey("ShowToolbar")) { PageSettings.ShowToolbar = bool.Parse(initParams["ShowToolbar"]); } drawingHost.ReadyForInteraction += drawingHost_ReadyForInteraction; drawingHost.UnhandledException += drawingHost_UnhandledException; InitializeToolbar(); this.KeyDown += Page_KeyDown; DownloadDemoFile(); IsolatedStorage.LoadAllTools(); IsolatedStorage.RegisterToolStorage(); if (isolatedSettings.Contains("UserParseGroup")) { List <ParseGroup> userParseGroups = (List <ParseGroup>)isolatedSettings["UserParseGroup"]; foreach (ParseGroup pg in userParseGroups) { ParseGroup.AddParseGroup(pg.Name, pg.Assumptions); UIDebugPublisher.publishString(pg.Name); } } parseOptionsWindow = new ParseOptionsWindow(); parseOptionsWindow.Closed += new EventHandler(ParseOptionsWindow_Closed); manageGivensWindow = new ManageGivensWindow() { drawingHost = drawingHost }; problemCharacteristicsWindow = new ProblemCharacteristicsWindow(manageGivensWindow); problemCharacteristicsWindow.Closed += new EventHandler(ProblemCharacteristicsWindow_Closed); enterSolutionWindow = new EnterSolutionWindow() { drawingHost = drawingHost }; bookProblemWindow = new BookProblemWindow(); bookProblemWindow.Closed += new EventHandler(DrawProblemWindow_Close); synthProblemWindow = new SynthesizeProblemWindow(); }
/// <summary> /// Create a new UIDebugPublisher. This object can publish strings to the window or clear the window. /// The publish and clear operations can be called from any thread but will be asyncrhonously invoked on the UI thread. /// </summary public void MakeUIDebugPublisher() { UIDebugPublisher.create(produceString, clearWindow); }
// 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); }