コード例 #1
0
        /// <summary>
        /// Returns if we the signature can be matched with the objects from given objects map.
        /// In other words, if there are enough objects to be passed to the arguments.
        /// </summary>
        /// <param name="availableObjects">The available objects that we can use.</param>
        /// <returns>true, if the signature can be matched, false otherwise.</returns>
        public bool CanBeMatched(ConfigurationObjectMap availableObjects)
        {
            // Let's have a look at each pair of [ObjectType, NeededCount] to find out
            // if we have enough objects from this type
            foreach (var pair in ObjectTypesToNeededCount)
            {
                // Deconstruct
                var(type, neededCount) = pair;

                // If there is no object of the type, we certainly can't match the signature
                if (!availableObjects.ContainsKey(type))
                {
                    return(false);
                }

                // If there are more needed arguments than available objects,
                // then we can't match the signature either
                if (neededCount > availableObjects[type].Count)
                {
                    return(false);
                }
            }

            // If we got here, we can match it
            return(true);
        }
コード例 #2
0
ファイル: Configuration.cs プロジェクト: PatrikBak/GeoGen
        /// <summary>
        /// Initializes a new instance of the <see cref="Configuration"/> class.
        /// </summary>
        /// <param name="looseObjectsHolder">The holder of the loose objects of this configurations.</param>
        /// <param name="constructedObjects">The list of constructed configuration objects ordered in a way that we can construct them in this order.</param>
        public Configuration(LooseObjectHolder looseObjectsHolder, IReadOnlyList <ConstructedConfigurationObject> constructedObjects)
        {
            LooseObjectsHolder    = looseObjectsHolder;
            ConstructedObjects    = constructedObjects ?? throw new ArgumentNullException(nameof(constructedObjects));
            ObjectMap             = new ConfigurationObjectMap(LooseObjects.Cast <ConfigurationObject>().Concat(constructedObjects));
            ConstructedObjectsSet = ConstructedObjects.ToReadOnlyHashSet();

            // Make sure there are no duplicated
            if (ConstructedObjectsSet.Count != constructedObjects.Count)
            {
                throw new GeoGenException("Configuration contains equal constructed objects.");
            }
        }
コード例 #3
0
ファイル: LooseObjectHolder.cs プロジェクト: PatrikBak/GeoGen
        /// <summary>
        /// Initializes a new instance of the <see cref="LooseObjectHolder"/>
        /// instance wrapping the actual loose objects and possible their layout.
        /// </summary>
        /// <param name="looseObjects">The actual loose configurations objects.</param>
        /// <param name="layout">The layout of these loose objects.</param>
        public LooseObjectHolder(IEnumerable <LooseConfigurationObject> looseObjects, LooseObjectLayout layout)
        {
            LooseObjects = looseObjects?.ToList() ?? throw new ArgumentNullException(nameof(looseObjects));
            ObjectMap    = new ConfigurationObjectMap(looseObjects);
            Layout       = layout;

            // Make sure the objects match the layout
            if (!LooseObjects.Select(looseObject => looseObject.ObjectType).SequenceEqual(layout.ObjectTypes()))
            {
                throw new GeoGenException($"The loose objects don't match the specified layout {layout}.");
            }

            // Make sure they are distinct
            if (LooseObjects.AnyDuplicates())
            {
                throw new GeoGenException("The loose objects are not distinct.");
            }
        }