Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LoadedProblemGeneratorInput"/> class.
 /// </summary>
 /// <inheritdoc cref="ProblemGeneratorInput(Configuration, IReadOnlyHashSet{Construction}, int, IReadOnlyDictionary{ConfigurationObjectType, int}, bool)"/>
 /// <param name="filePath"><inheritdoc cref="FilePath" path="/summary"/></param>
 /// <param name="id"><inheritdoc cref="Id" path="/summary"/></param>
 public LoadedProblemGeneratorInput(Configuration initialConfiguration,
                                    IReadOnlyHashSet <Construction> constructions,
                                    int numberOfIterations,
                                    IReadOnlyDictionary <ConfigurationObjectType, int> maximalNumbersOfObjectsToAdd,
                                    SymmetryGenerationMode symmetryGenerationMode,
                                    string filePath,
                                    string id)
     : base(initialConfiguration, constructions, numberOfIterations, maximalNumbersOfObjectsToAdd, symmetryGenerationMode)
 {
     FilePath = filePath ?? throw new ArgumentNullException(nameof(filePath));
     Id       = id ?? throw new ArgumentNullException(nameof(id));
 }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProblemGeneratorInput"/> class.
 /// </summary>
 /// <param name="initialConfiguration"><inheritdoc cref="InitialConfiguration" path="/summary"/></param>
 /// <param name="constructions"><inheritdoc cref="Constructions" path="/summary"/></param>
 /// <param name="numberOfIterations"><inheritdoc cref="NumberOfIterations" path="/summary"/></param>
 /// <param name="maximalNumbersOfObjectsToAdd"><inheritdoc cref="MaximalNumbersOfObjectsToAdd" path="/summary"/></param>
 /// <param name="symmetryGenerationMode"><inheritdoc cref="SymmetryGenerationMode" path="/summary"/></param>
 public ProblemGeneratorInput(Configuration initialConfiguration,
                              IReadOnlyHashSet <Construction> constructions,
                              int numberOfIterations,
                              IReadOnlyDictionary <ConfigurationObjectType, int> maximalNumbersOfObjectsToAdd,
                              SymmetryGenerationMode symmetryGenerationMode)
 {
     InitialConfiguration         = initialConfiguration ?? throw new ArgumentNullException(nameof(initialConfiguration));
     Constructions                = constructions ?? throw new ArgumentNullException(nameof(constructions));
     NumberOfIterations           = numberOfIterations;
     MaximalNumbersOfObjectsToAdd = maximalNumbersOfObjectsToAdd ?? throw new ArgumentNullException(nameof(maximalNumbersOfObjectsToAdd));
     SymmetryGenerationMode       = symmetryGenerationMode;
 }
Пример #3
0
        /// <summary>
        /// Performs the analysis of a given generator output.
        /// </summary>
        /// <param name="output">The generator output to be analyzed.</param>
        /// <param name="mode">Indicates how we handle asymmetric problems with regards to generation.</param>
        /// <param name="constructProofs">Indicates whether we should construct proofs or not, which affects the type of result.</param>
        /// <returns>The result depending on whether we're constructing proofs or not.</returns>
        private dynamic Analyze(ProblemGeneratorOutput output, SymmetryGenerationMode mode, bool constructProofs)
        {
            // Call the prover
            var proverOutput = constructProofs
                               // If we should construct proofs, do so
                ? (object)_prover.ProveTheoremsAndConstructProofs(output.OldTheorems, output.NewTheorems, output.ContextualPicture)
                               // If we shouldn't construct proofs, don't do it
                : _prover.ProveTheorems(output.OldTheorems, output.NewTheorems, output.ContextualPicture);

            // Find the proved theorems
            var provedTheorems = constructProofs
                                 // If we have constructed proofs, there is a dictionary
                ? (IReadOnlyCollection <Theorem>)((IReadOnlyDictionary <Theorem, TheoremProof>)proverOutput).Keys
                                 // Otherwise there is a collection directly
                : (IReadOnlyCollection <Theorem>)proverOutput;

            // Get the unproven theorems by taking all the new theorems
            var interestingTheorems = output.NewTheorems.AllObjects
                                      // Excluding those that are proven
                                      .Where(theorem => !provedTheorems.Contains(theorem))
                                      // Enumerate
                                      .ToArray();

            // Find the problems that should excluded based on symmetry
            var notInterestingTheorems = mode switch
            {
                // No restrictions
                SymmetryGenerationMode.GenerateBothSymmetricAndAsymmetric => (IReadOnlyList <Theorem>)Array.Empty <Theorem>(),

                // Detect symmetric theorems
                SymmetryGenerationMode.GenerateOnlySymmetric => interestingTheorems.Where(theorem => !theorem.IsSymmetric(output.Configuration)).ToArray(),

                // Detect fully symmetric theorems
                SymmetryGenerationMode.GenerateOnlyFullySymmetric => interestingTheorems.Where(theorem => !theorem.IsFullySymmetric(output.Configuration)).ToArray(),

                // Unhandled cases
                _ => throw new GeoGenException($"Unhandled value of {nameof(SymmetryGenerationMode)}: {mode}"),
            };

            // Interesting theorems can now be reseted
            interestingTheorems = interestingTheorems
                                  // By the exclusion of not interesting asymmetric ones
                                  .Except(notInterestingTheorems)
                                  // Enumerate
                                  .ToArray();

            // Prepare the map of all theorems
            var allTheorems = new TheoremMap(output.OldTheorems.AllObjects.Concat(output.NewTheorems.AllObjects));

            // Rank the interesting theorems
            var rankedInterestingTheorems = interestingTheorems
                                            // Rank given one
                                            .Select(theorem => _ranker.Rank(theorem, output.Configuration, allTheorems))
                                            // By rankings ASC (that's why -)
                                            .OrderBy(rankedTheorem => - rankedTheorem.Ranking.TotalRanking)
                                            // Enumerate
                                            .ToArray();

            // Now we can finally return the result
            return(constructProofs
                   // If we're constructing proofs, then we have a proof dictionary
                ? new GeneratedProblemAnalyzerOutputWithProofs(rankedInterestingTheorems, notInterestingTheorems, (IReadOnlyDictionary <Theorem, TheoremProof>)proverOutput)
                   // If we're not constructing proofs, then we have just a proved theorem collection
                : (GeneratedProblemAnalyzerOutputBase) new GeneratedProblemAnalyzerOutputWithoutProofs(rankedInterestingTheorems, notInterestingTheorems, (IReadOnlyCollection <Theorem>)proverOutput));
        }
Пример #4
0
 /// <inheritdoc/>
 public GeneratedProblemAnalyzerOutputWithoutProofs AnalyzeWithoutProofConstruction(ProblemGeneratorOutput generatorOutput, SymmetryGenerationMode mode)
 // Delegate the call to the general method
 => Analyze(generatorOutput, mode, constructProofs: false);