public void GetFactorFieldTypes()
        {
            List <WebFactorFieldType> factorFieldTypes;

            factorFieldTypes = FactorManager.GetFactorFieldTypes(GetContext());
            Assert.IsTrue(factorFieldTypes.IsNotEmpty());
        }
Exemplo n.º 2
0
        public void ConstrainEqualRandomFactorInfo()
        {
            FactorManager.FactorInfo info =
                FactorManager.GetFactorInfo(new MethodReference(typeof(Constrain), "EqualRandom<,>", typeof(bool), typeof(Bernoulli)).GetMethodInfo());
            Assert.Equal(2, info.ParameterNames.Count);
            Console.WriteLine(info);
            IDictionary <string, Type> parameterTypes = new Dictionary <string, Type>();

            parameterTypes["value"]  = typeof(Bernoulli);
            parameterTypes["dist"]   = typeof(Bernoulli);
            parameterTypes["result"] = typeof(Bernoulli);
            MessageFcnInfo fcninfo = info.GetMessageFcnInfo(factorManager, "AverageConditional", "value", parameterTypes);

            Console.WriteLine(fcninfo);
            Assert.False(fcninfo.PassResult);
            Assert.False(fcninfo.PassResultIndex);
            Assert.Equal(1, fcninfo.Dependencies.Count);
            Assert.Equal(1, fcninfo.Requirements.Count);

            Console.WriteLine();
            Console.WriteLine("All MessageFcnInfos:");
            int count = 0;

            foreach (MessageFcnInfo fcninfo2 in info.GetMessageFcnInfos())
            {
                Console.WriteLine(fcninfo2);
                CheckMessageFcnInfo(fcninfo2, info);
                count++;
            }
            //Assert.Equal(4, count);
        }
        public void GetFactors()
        {
            List <WebFactor> factors;

            factors = FactorManager.GetFactors(GetContext());
            Assert.IsTrue(factors.IsNotEmpty());
        }
Exemplo n.º 4
0
        public void ReplicateMessageFcnInfo()
        {
            FactorManager.FactorInfo   info           = FactorManager.GetFactorInfo(new MethodReference(typeof(Factor), "Replicate<>", typeof(bool)).GetMethodInfo());
            IDictionary <string, Type> parameterTypes = new Dictionary <string, Type>();

            parameterTypes["Uses"]   = typeof(DistributionArray <Bernoulli>);
            parameterTypes["Def"]    = typeof(Bernoulli);
            parameterTypes["result"] = typeof(Bernoulli); //typeof(DistributionArray<Bernoulli>);
            MessageFcnInfo fcninfo = info.GetMessageFcnInfo(factorManager, "AverageLogarithm", "Def", parameterTypes);

            Console.WriteLine(fcninfo);
            CheckMessageFcnInfo(fcninfo, info);

            parameterTypes["Uses"] = typeof(Bernoulli[]);
            fcninfo = info.GetMessageFcnInfo(factorManager, "AverageLogarithm", "Def", parameterTypes);
            Console.WriteLine(fcninfo);
            CheckMessageFcnInfo(fcninfo, info);

            DependencyInformation depInfo;

            depInfo = FactorManager.GetDependencyInfo(fcninfo.Method);
            Console.WriteLine("Dependencies:");
            Console.WriteLine(StringUtil.ToString(depInfo.Dependencies));
            Console.WriteLine("Requirements:");
            Console.WriteLine(StringUtil.ToString(depInfo.Requirements));
            Console.WriteLine("Triggers:");
            Console.WriteLine(StringUtil.ToString(depInfo.Triggers));
        }
        public void NegativePerfectNumberIsFalse(int x)
        {
            FactorManager FM = new FactorManager();

            FM.Number = x;
            Assert.IsFalse(FM.PerfectChecker());
        }
Exemplo n.º 6
0
        //creates instance of FM
        //Displays welcome message, starts game
        //gets input from user
        //stores number in _manager.Number
        public void RunFactorizor()
        {
            _manager = new FactorManager();
            ConsoleOutput.DisplayTitle();

            _manager.Number = ConsoleInput.GetNumberFromUser();
        }
        public void IsPrimeIsTrue(int x)
        {
            FactorManager FM = new FactorManager();

            FM.Number = x;
            Assert.IsTrue(FM.PrimeChecker());
        }
        public void NegativePrimeIsFalse(int x)
        {
            FactorManager FM = new FactorManager();

            FM.Number = x;
            Assert.IsFalse(FM.PrimeChecker());
        }
Exemplo n.º 9
0
        /// <summary>
        /// Split existing fields into different field types.
        /// </summary>
        private void InitFields()
        {
            Int32 fieldIndex;

            // Init field holders.
            _fieldArray = new FactorField[FactorManager.GetFactorFieldMaxCount()];
            for (fieldIndex = 0; fieldIndex < FactorManager.GetFactorFieldMaxCount(); fieldIndex++)
            {
                _fieldArray[fieldIndex] = null;
            }
            _mainField         = null;
            _substantialFields = new FactorFieldList();

            // Add information to field holders.
            foreach (FactorField field in Fields)
            {
                _fieldArray[field.Index] = field;
                if (field.IsSubstantial)
                {
                    _substantialFields.Add(field);
                }
                if (field.IsMain)
                {
                    _mainField = field;
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Get information about taxa with a protection level
        /// that is higher than public.
        /// </summary>
        /// <param name="includeSubTaxa">If true, all sub taxa are included in the result.</param>
        /// <param name="taxonInformationType">Type of taxa information to get.</param>
        /// <returns>Information about protected taxa.</returns>
        public static TaxonList GetProtectedTaxa(Boolean includeSubTaxa,
                                                 TaxonInformationType taxonInformationType)
        {
            Factor                     factor;
            List <WebTaxon>            webTaxa;
            SpeciesFactCondition       speciesFactCondition;
            SpeciesFactFieldCondition  speciesFactFieldCondition;
            SpeciesProtectionLevelEnum protectionLevel;
            WebDataQuery               webDataQuery;

            // Create data query.
            speciesFactCondition = new SpeciesFactCondition();
            factor = FactorManager.GetFactor(FactorId.ProtectionLevel);
            speciesFactCondition.Factors.Add(factor);

            for (protectionLevel = SpeciesProtectionLevelEnum.Protected1;
                 protectionLevel <= SpeciesProtectionLevelEnum.MaxProtected;
                 protectionLevel++)
            {
                speciesFactFieldCondition             = new SpeciesFactFieldCondition();
                speciesFactFieldCondition.FactorField = factor.FactorDataType.Field1;
                speciesFactFieldCondition.SetValue((Int32)protectionLevel);
                speciesFactCondition.SpeciesFactFieldConditions.Add(speciesFactFieldCondition);
            }

            // Get data from web service.
            webDataQuery = GetDataQuery(speciesFactCondition);
            webTaxa      = WebServiceClient.GetTaxaByQuery(webDataQuery, taxonInformationType);
            return(GetTaxa(webTaxa));
        }
        public static List <WebFactor> GetSomeFactors(WebServiceContext context)
        {
            List <WebFactor> factors;

            factors = new List <WebFactor>();
            foreach (WebFactor factor in FactorManager.GetFactors(context))
            {
                if (factor.Id == LANDSCAPE_AGRICULTURE_FACTOR_ID)
                {
                    factors.Add(factor);
                }
                if (factor.Id == LANDSCAPE_FOREST_FACTOR_ID)
                {
                    factors.Add(factor);
                }
                if (factor.Id == LANDSCAPE_MOUNTAIN_FACTOR_ID)
                {
                    factors.Add(factor);
                }
                if (factor.Id == LANDSCAPE_FRESH_WATER_FACTOR_ID)
                {
                    factors.Add(factor);
                }
            }
            return(factors);
        }
        public void isPerfectIsTrue(int x)
        {
            FactorManager FM = new FactorManager();

            FM.Number = x;
            Assert.IsTrue(FM.PerfectChecker());
        }
 /// <summary>
 /// Create a FactorField instance.
 /// </summary>
 /// <param name="id">Id of the factor field</param>
 /// <param name="sortOrder">Sort order of the factor field</param>
 /// <param name="factorDataTypeId">Id of the datatype of the factor field</param>
 /// <param name="fieldIndex">Index of this factor field related to all possible factor fields.</param>
 /// <param name="label">Label of the factor field</param>
 /// <param name="information">Information about the factor field</param>
 /// <param name="isMain">Indicates whether or not the factor field is the main field</param>
 /// <param name="isSubstantial">Indicates whether or not the factor field is a substantial field</param>
 /// <param name="factorFieldTypeId">Id of the field type</param>
 /// <param name="size">Size of the field (Max length of text fields)</param>
 /// <param name="factorFieldEnumId">Id of the factor field enum object. Id less than 0 indicates that the factor has no factor field enum</param>
 /// <param name="unitLabel">Unit label of the factor field</param>
 public FactorField(
     Int32 id,
     Int32 sortOrder,
     Int32 factorDataTypeId,
     Int32 fieldIndex,
     String label,
     String information,
     Boolean isMain,
     Boolean isSubstantial,
     Int32 factorFieldTypeId,
     Int32 size,
     Int32 factorFieldEnumId,
     String unitLabel)
     : base(id, sortOrder)
 {
     _factorDataTypeId = factorDataTypeId;
     _fieldIndex       = fieldIndex;
     _information      = information;
     _isMain           = isMain;
     _isSubstantial    = isSubstantial;
     _label            = label;
     if (factorFieldEnumId > -1)
     {
         _factorFieldEnum = FactorManager.GetFactorFieldEnum(factorFieldEnumId);
     }
     _type      = FactorManager.GetFactorFieldType(factorFieldTypeId);
     _size      = size;
     _unitLabel = unitLabel;
 }
Exemplo n.º 14
0
        /// <summary>
        /// Writes the XML documentation for all message operators in Microsoft.ML.Probabilistic using a given XML writer.
        /// </summary>
        /// <param name="writer">The XML writer.</param>
        public static void WriteFactorDocumentation(XmlWriter writer)
        {
            var typeToFactors          = new Dictionary <Type, HashSet <FactorInfoWrapper> >();
            var typeToMessageFunctions = new Dictionary <Type, HashSet <MessageFunctionInfoWrapper> >();

            foreach (FactorManager.FactorInfo factorInfo in FactorManager.GetFactorInfos())
            {
                foreach (MessageFcnInfo messageFunctionInfo in factorInfo.GetMessageFcnInfos())
                {
                    Type declaringType = messageFunctionInfo.Method.DeclaringType;
                    if (!typeToFactors.ContainsKey(declaringType))
                    {
                        typeToFactors.Add(declaringType, new HashSet <FactorInfoWrapper>());
                        typeToMessageFunctions.Add(declaringType, new HashSet <MessageFunctionInfoWrapper>());
                    }

                    typeToFactors[declaringType].Add(new FactorInfoWrapper(factorInfo));
                    // TODO: sometimes the same message operator is used by more than one factor.
                    // TODO: Can we pick any factor to generate the doc?
                    typeToMessageFunctions[declaringType].Add(new MessageFunctionInfoWrapper(messageFunctionInfo, factorInfo));
                }
            }

            foreach (Type type in typeToFactors.Keys)
            {
                if (type.Assembly.GetCustomAttributes(typeof(HasMessageFunctionsAttribute), true).Length > 0)
                {
                    WriteTypeDocumentation(writer, type, typeToFactors[type], typeToMessageFunctions[type]);
                }
            }
        }
Exemplo n.º 15
0
 public void GetFactorInfos()
 {
     foreach (FactorManager.FactorInfo info in FactorManager.GetFactorInfos())
     {
         Console.WriteLine(info.Method);
     }
 }
        public void GetFactorUpdateModes()
        {
            List <WebFactorUpdateMode> factorUpdateModes;

            factorUpdateModes = FactorManager.GetFactorUpdateModes(GetContext());
            Assert.IsTrue(factorUpdateModes.IsNotEmpty());
        }
Exemplo n.º 17
0
        public void IsPositiveFactorInfo()
        {
            FactorManager.FactorInfo info = FactorManager.GetFactorInfo(new Func <double, bool>(Factor.IsPositive));
            Assert.True(info.IsDeterministicFactor);
            var parameterTypes = new Dictionary <string, Type>
            {
                ["isPositive"] = typeof(bool),
                ["x"]          = typeof(Gaussian)
            };
            MessageFcnInfo fcninfo = info.GetMessageFcnInfo(factorManager, "AverageConditional", "x", parameterTypes);

            Assert.True(fcninfo.NotSupportedMessage == null);
            CheckMessageFcnInfo(fcninfo, info);

            DependencyInformation depInfo = FactorManager.GetDependencyInfo(fcninfo.Method);

            Assert.Throws <NotSupportedException>(() =>
            {
                fcninfo = info.GetMessageFcnInfo(factorManager, "AverageLogarithm", "x", parameterTypes);
            });
            bool found = false;

            foreach (MessageFcnInfo fcninfo2 in info.GetMessageFcnInfos("AverageLogarithm", null, null))
            {
                CheckMessageFcnInfo(fcninfo2, info);
                if (fcninfo2.TargetParameter.Equals("x"))
                {
                    Assert.True(fcninfo2.NotSupportedMessage != null);
                    found = true;
                }
            }
            Assert.True(found);
            fcninfo = info.GetMessageFcnInfo(factorManager, "LogAverageFactor", "", parameterTypes);
            CheckMessageFcnInfo(fcninfo, info);
        }
        public void GetFactorsBySearchCriteria()
        {
            List <WebFactor>        factors;
            List <Int32>            factorIds;
            Int32                   count1, count2;
            WebFactorSearchCriteria searchCriteria;

            searchCriteria = new WebFactorSearchCriteria();
            factorIds      = new List <Int32>();
            factorIds.Add(LANDSCAPES_FACTOR_ID);

            searchCriteria.NameSearchString = null;
            factors = FactorManager.GetFactorsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsTrue(factors.IsNull() || factors.IsEmpty());

            searchCriteria.NameSearchString = "Rödli%";
            searchCriteria.NameSearchMethod = SearchStringComparisonMethod.Like;
            factors = FactorManager.GetFactorsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsFalse(factors.IsNull() || factors.IsEmpty());

            searchCriteria.NameSearchString = "Rödli";
            searchCriteria.NameSearchMethod = SearchStringComparisonMethod.Iterative;
            factors = FactorManager.GetFactorsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsTrue(factors.IsNotEmpty());

            searchCriteria.NameSearchString = "Landskapstyper";
            searchCriteria.NameSearchMethod = SearchStringComparisonMethod.Exact;
            factors = FactorManager.GetFactorsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsFalse(factors.IsNull() || factors.IsEmpty());
            count1 = factors.Count;
            Assert.IsNotNull(count1);
            Assert.IsTrue(count1 > 0);

            searchCriteria.NameSearchString       = LANDSCAPES_FACTOR_ID.ToString();
            searchCriteria.NameSearchMethod       = SearchStringComparisonMethod.Like;
            searchCriteria.IsIdInNameSearchString = true;
            factors = FactorManager.GetFactorsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsFalse(factors.IsNull() || factors.IsEmpty());
            count2 = factors.Count;
            Assert.IsNotNull(count2);
            Assert.IsTrue(count2 > 0);
            Assert.AreEqual(count1, count2);

            searchCriteria = new WebFactorSearchCriteria();
            searchCriteria.RestrictSearchToFactorIds = factorIds;
            searchCriteria.RestrictReturnToScope     = FactorSearchScope.AllChildFactors;
            factors = FactorManager.GetFactorsBySearchCriteria(GetContext(), searchCriteria);
            Assert.IsFalse(factors.IsNull() || factors.IsEmpty());
            Assert.AreEqual(factors.Count, 10);

            foreach (FactorSearchScope factorSearchScope in Enum.GetValues(typeof(FactorSearchScope)))
            {
                searchCriteria = new WebFactorSearchCriteria();
                searchCriteria.RestrictSearchToFactorIds = factorIds;
                searchCriteria.RestrictReturnToScope     = factorSearchScope;
                factors = FactorManager.GetFactorsBySearchCriteria(GetContext(), searchCriteria);
                Assert.IsFalse(factors.IsNull() || factors.IsEmpty());
            }
        }
        public static void DisplayFactors(FactorManager FM)
        {
            int[] factorArray = FM.FactorFinder();

            string factorString = String.Join(",", factorArray);

            Console.WriteLine("The Factors of {0} are {1}", FM.Number, factorString);
        }
        public void GetFactorTrees()
        {
            List <WebFactorTreeNode> factorTrees;

            factorTrees = FactorManager.GetFactorTrees(GetContext());
            Assert.IsTrue(factorTrees.IsNotEmpty());
            CheckCircularTree(factorTrees);
        }
        public void NumberPropertyIsSet(int x)
        {
            FactorManager FM = new FactorManager();

            FM.Number = x;
            Assert.AreEqual(x, FM.Number);
            Assert.AreNotEqual(0, FM.Number);
        }
        public void GetFactorsByIdEmptyFactorIdsError()
        {
            List <WebFactor> factors;
            List <Int32>     factorIds;

            factorIds = new List <Int32>();
            factors   = FactorManager.GetFactorsById(GetContext(), factorIds);
        }
Exemplo n.º 23
0
        /// <summary>
        /// A method that obtains red list information.
        /// </summary>
        private void LoadRedListInformation()
        {
            SpeciesFactList        speciesFacts;
            UserParameterSelection parameters;

            if (_organismGroupName.IsNull())
            {
                _organismGroupName          = String.Empty;
                _redlistCategoryName        = String.Empty;
                _redlistCategoryShortString = String.Empty;
                _redlistCriteria            = String.Empty;

                parameters = new UserParameterSelection();
                parameters.Taxa.Add(_taxon);
                parameters.Factors.Add(FactorManager.GetFactor(FactorId.RedlistCategory));
                parameters.Factors.Add(FactorManager.GetFactor(FactorId.RedlistCriteriaString));
                parameters.Factors.Add(FactorManager.GetFactor(FactorId.Redlist_OrganismLabel1));
                parameters.Periods.Add(_period);
                speciesFacts = SpeciesFactManager.GetSpeciesFactsByUserParameterSelection(parameters);
                if (speciesFacts.IsNotEmpty())
                {
                    foreach (SpeciesFact speciesFact in speciesFacts)
                    {
                        switch (speciesFact.Factor.Id)
                        {
                        case (Int32)FactorId.RedlistCategory:
                            if (speciesFact.HasField1)
                            {
                                _redlistCategoryName = speciesFact.Field1.EnumValue.OriginalLabel;
                                _redlistCategoryName = _redlistCategoryName.Remove(_redlistCategoryName.Length - 5);
                            }
                            if (speciesFact.HasField4)
                            {
                                _redlistCategoryShortString = speciesFact.Field4.StringValue;
                            }
                            break;

                        case (Int32)FactorId.RedlistCriteriaString:
                            if (speciesFact.HasField4 &&
                                speciesFact.Field4.StringValue.IsNotEmpty())
                            {
                                _redlistCriteria = speciesFact.Field4.StringValue.Trim();
                            }
                            break;

                        case (Int32)FactorId.Redlist_OrganismLabel1:
                            if (speciesFact.MainField.HasValue)
                            {
                                _organismGroupName = speciesFact.MainField.EnumValue.OriginalLabel;
                            }
                            break;
                        }
                    }
                }
            }
        }
        private FactorManager GetFactorManager(Boolean refresh = false)
        {
            if (_factorManager.IsNull() || refresh)
            {
                _factorManager            = new FactorManager();
                _factorManager.DataSource = new FactorDataSource();
            }

            return(_factorManager);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Reades one row from the xml format.
        /// </summary>
        /// <param name='xmlDoc'>The xml document that the row node will be read from.</param>
        /// <param name="nsmgr">Namespacemanager containing all namespaces used by the excel compatible xml format</param>
        protected override void ReadXmlRows(XmlDocument xmlDoc, XmlNamespaceManager nsmgr)
        {
            XmlNodeList rowNodes = xmlDoc.SelectNodes("/ss:Workbook/ss:Worksheet/ss:Table/ss:Row", nsmgr);

            foreach (XmlNode rowNode in rowNodes)
            {
                XmlNode dataNode = rowNode.SelectSingleNode("ss:Cell/ss:Data", nsmgr);
                this.Add(FactorManager.GetFactor(Convert.ToInt32(dataNode.InnerText)));
            }
        }
        public void DeleteUserSelectedFactors()
        {
            foreach (UserSelectedFactorUsage factorUsage in Enum.GetValues(typeof(UserSelectedFactorUsage)))
            {
                FactorManager.AddUserSelectedFactors(GetContext(), GetSomeFactorIds(), factorUsage);
                FactorManager.DeleteUserSelectedFactors(GetContext());
            }

            // Should be ok to delete zero factors.
            FactorManager.DeleteUserSelectedFactors(GetContext());
        }
 public static WebFactor GetOneFactor(WebServiceContext context)
 {
     foreach (WebFactor factor in FactorManager.GetFactors(context))
     {
         if (factor.Id == LANDSCAPE_FOREST_FACTOR_ID)
         {
             return(factor);
         }
     }
     return(null);
 }
        public void GetFactorFieldEnums()
        {
            List <WebFactorFieldEnum> factorFieldEnums;

            factorFieldEnums = FactorManager.GetFactorFieldEnums(GetContext());
            Assert.IsTrue(factorFieldEnums.IsNotEmpty());
            foreach (WebFactorFieldEnum factorFieldEnum in factorFieldEnums)
            {
                Assert.IsTrue(factorFieldEnum.Values.IsNotEmpty());
            }
        }
        public static void DisplayIsPerfect(FactorManager FM)
        {
            if (FM.PerfectChecker())
            {
                Console.WriteLine("{0} is a Perfect Number", FM.Number);
            }

            else
            {
                Console.WriteLine("{0} is NOT Perfect Number", FM.Number);
            }
        }
        public static void DisplayIsPrime(FactorManager FM)
        {
            if (FM.PrimeChecker())
            {
                Console.WriteLine("{0} is a Prime Number", FM.Number);
            }

            else
            {
                Console.WriteLine("{0} is NOT Prime Number", FM.Number);
            }
        }