Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LineSegmentTheoremObject"/> class.
        /// </summary>
        /// <param name="point1">The first point of the line segment.</param>
        /// <param name="point2">The second line of the line segment.</param>
        public LineSegmentTheoremObject(PointTheoremObject point1, PointTheoremObject point2)
        {
            // Set the points
            Point1 = point1 ?? throw new ArgumentNullException(nameof(point1));
            Point2 = point2 ?? throw new ArgumentNullException(nameof(point2));

            // Create the point set
            PointSet = new HashSet <PointTheoremObject> {
                Point1, Point2
            }.AsReadOnly();
        }
Ejemplo n.º 2
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));
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConfigurationGeneratorInput"/> class.
 /// </summary>
 /// <param name="initialConfiguration">The initial configuration from which the generation process starts. </param>
 /// <param name="constructions">The constructions that are used to create new objects for configurations.</param>
 /// <param name="numberOfIterations">The number of iterations that are to be performed by the generator.</param>
 /// <param name="maximalNumbersOfObjectsToAdd">The dictionary representing at most how many objects of each type should be added to the initial configuration.</param>
 /// <param name="configurationFilter">The function for filtrating generated configurations.</param>
 public ConfigurationGeneratorInput(Configuration initialConfiguration,
                                    IReadOnlyHashSet <Construction> constructions,
                                    int numberOfIterations,
                                    IReadOnlyDictionary <ConfigurationObjectType, int> maximalNumbersOfObjectsToAdd,
                                    Func <GeneratedConfiguration, bool> configurationFilter)
 {
     InitialConfiguration         = initialConfiguration ?? throw new ArgumentNullException(nameof(initialConfiguration));
     Constructions                = constructions ?? throw new ArgumentNullException(nameof(constructions));
     NumberOfIterations           = numberOfIterations;
     MaximalNumbersOfObjectsToAdd = maximalNumbersOfObjectsToAdd ?? throw new ArgumentNullException(nameof(maximalNumbersOfObjectsToAdd));
     ConfigurationFilter          = configurationFilter ?? throw new ArgumentNullException(nameof(configurationFilter));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LoadedInferenceRule"/> class.
 /// </summary>
 /// <param name="declaredObjects">The objects that are referenced in the assumptions and the conclusion.</param>
 /// <param name="assumptionGroups">The assumptions grouped in a way that assumptions in the same group are mutually isomorphic (see <see cref="InferenceRule"/>).</param>
 /// <param name="negativeAssumptions">The assumptions that must be not true in order for inferred theorems to hold.</param>
 /// <param name="conclusion">The conclusion that can be inferred if the assumptions are met.</param>
 /// <param name="relativeFileName">The file name relative to the inference rule folder of the rule.</param>
 /// <param name="number">The ordinal number of the rule in the inference rule file.</param>
 /// <param name="adjustmentMessage">The message indicating whether how the rule has been adjusted by the loader (see <see cref="AdjustmentMessage"/>).</param>
 public LoadedInferenceRule(IReadOnlyList <ConstructedConfigurationObject> declaredObjects,
                            IReadOnlyHashSet <IReadOnlyHashSet <Theorem> > assumptionGroups,
                            IReadOnlyList <Theorem> negativeAssumptions,
                            Theorem conclusion,
                            string relativeFileName,
                            int number,
                            string adjustmentMessage)
     : base(declaredObjects, assumptionGroups, negativeAssumptions, conclusion)
 {
     RelativeFileName  = relativeFileName ?? throw new ArgumentNullException(nameof(relativeFileName));
     Number            = number;
     AdjustmentMessage = adjustmentMessage ?? throw new ArgumentNullException(nameof(adjustmentMessage));
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InferenceRule"/> class.
        /// </summary>
        /// <param name="declaredObjects">The objects that are referenced in the assumptions and the conclusion.</param>
        /// <param name="assumptionGroups">The assumptions grouped in a way that assumptions in the same group are mutually isomorphic (see <see cref="InferenceRule"/>).</param>
        /// <param name="negativeAssumptions">The assumptions that must be not true in order for inferred theorems to hold.</param>
        /// <param name="conclusion">The conclusion that can be inferred if the assumptions are met.</param>
        public InferenceRule(IReadOnlyList <ConstructedConfigurationObject> declaredObjects,
                             IReadOnlyHashSet <IReadOnlyHashSet <Theorem> > assumptionGroups,
                             IReadOnlyList <Theorem> negativeAssumptions,
                             Theorem conclusion)
        {
            DeclaredObjects     = declaredObjects ?? throw new ArgumentNullException(nameof(declaredObjects));
            AssumptionGroups    = assumptionGroups ?? throw new ArgumentNullException(nameof(assumptionGroups));
            NegativeAssumptions = negativeAssumptions ?? throw new ArgumentNullException(nameof(negativeAssumptions));
            Conclusion          = conclusion ?? throw new ArgumentNullException(nameof(conclusion));

            // Find the number of needed construction by taking the declared objects
            NeededConstructionTypes = declaredObjects
                                      // Grouping them by their construction
                                      .GroupBy(template => template.Construction)
                                      // And counting the number of objects in each group
                                      .ToDictionary(group => group.Key, group => group.Count());

            // Find the number of needed assumption types by taking flattened assumptions
            NeededAssumptionTypes = assumptionGroups.Flatten()
                                    // Grouping them by their type
                                    .GroupBy(group => group.Type)
                                    // And counting the number of objects in each group
                                    .ToDictionary(group => group.Key, group => group.Count());

            // Find the explicit objects mappable to implicit ones by taking the assumptions
            ExplicitObjectsMappableToImplicitOnes = AssumptionGroups.Flatten()
                                                    // And the conclusion
                                                    .Concat(Conclusion)
                                                    // Take their inner objects
                                                    .SelectMany(templateTheorem => templateTheorem.InvolvedObjects)
                                                    // That are distinct
                                                    .Distinct()
                                                    // And are objects with points
                                                    .OfType <TheoremObjectWithPoints>()
                                                    // And are defined explicitly
                                                    .Where(templateObject => templateObject.DefinedByExplicitObject
                                                    // And their explicit object is loose
                                                           && templateObject.ConfigurationObject is LooseConfigurationObject
                                                    // And there is no assumption
                                                           && !AssumptionGroups.Flatten()
                                                    // Or conclusion
                                                           .Concat(Conclusion)
                                                    // That is incidence
                                                           .Any(templateTheorem => templateTheorem.Type == TheoremType.Incidence
                                                    // And contains this object
                                                                && templateTheorem.InvolvedObjects.Contains(templateObject)))
                                                    // Enumerate
                                                    .ToReadOnlyHashSet();
        }
Ejemplo n.º 7
0
        public IAsyncResult BeginLogin(
            Uri server,
            string accessToken,
            SubscriptionMode subscriptionMode,
            IReadOnlyHashSet <AccountId> presenceSubscriptions,
            IReadOnlyHashSet <AccountId> blockedPresenceSubscriptions,
            IReadOnlyHashSet <AccountId> allowedPresenceSubscriptions,
            AsyncCallback callback)
        {
            if (string.IsNullOrEmpty(accessToken))
            {
                throw new ArgumentNullException(nameof(accessToken));
            }

            AssertLoggedOut();
            AsyncNoResult result = new AsyncNoResult(callback);

            State = LoginState.LoggingIn;

            _client.BeginGetConnectorHandle(server, ar2 =>
            {
                string connectorHandle;
                try
                {
                    connectorHandle = _client.EndGetConnectorHandle(ar2);
                }
                catch (Exception e)
                {
                    VivoxDebug.Instance.VxExceptionMessage($"BeginGetConnectorHandle failed: {e}");
                    State = LoginState.LoggedOut;
                    result.SetComplete(e);
                    if (VivoxDebug.Instance.throwInternalExcepetions)
                    {
                        throw;
                    }
                    return;
                }
                Debug.Write($"connectorHandle={connectorHandle}");
                Login(accessToken, connectorHandle, result, subscriptionMode);
            });
            return(result);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SetConstructionArgument"/> class.
 /// </summary>
 /// <param name="passedArguments">The set containing all the passed arguments.</param>
 public SetConstructionArgument(HashSet <ConstructionArgument> passedArguments)
 {
     PassedArguments = passedArguments?.AsReadOnly() ?? throw new ArgumentNullException(nameof(passedArguments));
 }
Ejemplo n.º 9
0
        /// <summary>
        /// The entry method of the application.
        /// </summary>
        private static void Main()
        {
            // Setup simple logger
            Log.Logger = new LoggerConfiguration().WriteTo.Console().CreateLogger();

            // Initialize the kernel
            _kernel = NinjectUtilities.CreateKernel()
                      // Add the constructor
                      .AddConstructor()
                      // Add the configuration generator that uses fast generation (it does not really matter here)
                      .AddConfigurationGenerator(new GenerationSettings(ConfigurationFilterType.Fast));

            // Bind the generator
            _kernel.Bind <IProblemGenerator>().To <ProblemGenerator.ProblemGenerator>();

            // Add an empty failure tracer
            _kernel.Bind <IGeometryFailureTracer>().To <EmptyGeometryFailureTracer>();

            // Add an empty theorem finder
            _kernel.Bind <ITheoremFinder>().To <EmptyTheoremFinder>();

            // Load the construction file
            _constructions = File.ReadAllLines("constructions.txt")
                             // Each line should be a construction
                             .Select(Parser.ParseConstruction)
                             // Enumerate
                             .ToReadOnlyHashSet();

            // Load the template input file
            _templateInputFile = File.ReadAllText("input_template.txt");

            #region Preparing the results folder

            // Create the path to the folder with inputs
            var resultsFolder = "Results";

            // If the folder exists, clear it
            if (Directory.Exists(resultsFolder))
            {
                Directory.Delete(resultsFolder, recursive: true);
            }

            // Otherwise create it
            else
            {
                Directory.CreateDirectory(resultsFolder);
            }

            #endregion

            // Prepare the stopwatch
            var stopwatch = Stopwatch.StartNew();

            // Prepare the counter of generated inputs
            var counter = 0;

            // Go through the all types of generated input files
            new[]
            {
                Triangle_TwoObjects_PlusThreeObjects(),
                Triangle_FourObjects_OnlyFullySymmetric_PlusTwoObjects(),
                Triangle_FourObjects_TwoLinesAndTwoPoints_OnlySymmetric_OnlyUsedLines_PlusTwoObjects(),
                Triangle_FourObjects_ThreeLinesAndOnePoint_OnlySymmetric_OnlyUsedLines_PlusTwoObjects(),
                Quadrilateral_TwoObjects_PlusTwoObjects()
            }
            // Merge the inputs
            .Flatten()
            // Handle each generated file
            .ForEach(input =>
            {
                // Count the input in
                counter++;

                // Log the count, but not too often
                if (counter % 100 == 0)
                {
                    Log.Information("{count} files after {time} ms.", counter, stopwatch.ElapsedMilliseconds);
                }

                // Prepare the constructions as a single string
                var constructionString = input.Constructions
                                         // For each take the name
                                         .Select(construction => construction.Name)
                                         // Each on a separate line
                                         .ToJoinedString("\n");

                // Prepare the formatted configuration by creating a formatter for it
                var configurationString = new OutputFormatter(input.InitialConfiguration.AllObjects)
                                          // Formatting it
                                          .FormatConfiguration(input.InitialConfiguration)
                                          // Replacing any curly braces in the definitions
                                          .Replace("{", "").Replace("}", "");

                // Prepare the content by taking the template file
                var content = _templateInputFile
                              // Replace the constructions
                              .Replace("{Constructions}", constructionString)
                              // Replace the configuration
                              .Replace("{InitialConfiguration}", configurationString)
                              // Replace the iterations
                              .Replace("{Iterations}", input.NumberOfIterations.ToString())
                              // Replace maximal points
                              .Replace("{MaximalPoints}", input.MaximalNumbersOfObjectsToAdd[Point].ToString())
                              // Replace maximal lines
                              .Replace("{MaximalLines}", input.MaximalNumbersOfObjectsToAdd[Line].ToString())
                              // Replace maximal circles
                              .Replace("{MaximalCircles}", input.MaximalNumbersOfObjectsToAdd[Circle].ToString())
                              // Replace the symmetry generation mode
                              .Replace("{SymmetryGenerationMode}", input.SymmetryGenerationMode.ToString());

                // Create the directory where the file goes
                Directory.CreateDirectory(Path.Combine(resultsFolder, $"input_{counter}"));

                // Write the content
                File.WriteAllText(Path.Combine(resultsFolder, $"input_{counter}/input_{counter}.txt"), content);
            });

            // Log how many files have been created
            Log.Information("Generated {counter} file(s) after {time} ms.", counter, stopwatch.ElapsedMilliseconds);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Initialize a new instance of the <see cref="PointObject"/> class wrapping a given point <see cref="ConfigurationObject"/>.
 /// </summary>
 /// <param name="configurationObject">The point configuration object represented by this geometric object.</param>
 public PointObject(ConfigurationObject configurationObject)
     : base(configurationObject)
 {
     Lines   = _lines.AsReadOnly();
     Circles = _circles.AsReadOnly();
 }