Пример #1
0
        /// <summary>
        /// Another constructor that allows greater specification of parameteres
        /// </summary>
        /// <param name="n">
        /// A <see cref="System.Int32"/>
        /// </param>
        /// <param name="modelFun">
        /// A <see cref="ModelFcn"/>
        /// </param>
        /// <param name="abstol">
        /// A <see cref="System.Double"/>
        /// </param>
        /// <param name="reltol">
        /// A <see cref="System.Double"/>
        /// </param>
        /// <param name="type">
        /// A <see cref="System.Int32"/>
        /// </param>
        public CVode(int n, double[] initialValues, ModelFunction modelFun, double[] abstol, double reltol, int type)
        {
            this.n = n;
            this.modelFunction = modelFun;

            if (type==0)
            {
                this.cvodeMem = CVodeCreate(1, 1);
            }
            else
            {
                this.cvodeMem = CVodeCreate(2, 2);
            }

            this.y = NewCvode_Vector(this.n);
            this.absoluteTolerance = NewCvode_Vector(this.n);

            for (int i=0; i<this.n; i++)
            {
                System.Console.WriteLine("abstol = "+abstol[i]);
                Cvode_SetVector (this.absoluteTolerance, i, abstol[i]);
                Cvode_SetVector (this.y, i, initialValues[i]);
            }

            this.relativeTolerance = reltol;
            System.Console.WriteLine("relative tolerance = "+reltol);

            this.errCode = AllocateCvodeMem(this.cvodeMem, this.modelFunction, 0.0, this.y, 1, ref this.relativeTolerance, this.absoluteTolerance);
            this.errCode = CvDense (this.cvodeMem, n);  // int = size of systems
        }
Пример #2
0
        /// <summary>
        /// RunUntil(custom delegate)
        ///     Powerful, where you own the code in the handler, and determine exactly when to stop execution
        ///     ie: RunUntil(delegate() { return _x > 5; }  //Where _x > 5 is any c# code expression
        ///
        /// </summary>
        /// <param name="func"></param>
        /// <returns></returns>
        public bool             RunUntil(ModelFunction func)
        {
            //Build up a ModelRequirement around the delegate
            ModelRequirements criteria = new ModelRequirements(
                new ModelExpression(func, new ModelValue(true))
                );

            return(this.RunUntil(criteria));
        }
Пример #3
0
        /// <summary>
        /// 获取LotteryEnum中彩种的数量
        /// </summary>
        /// <returns></returns>
        public static List <Lottery> GetLotteryList()
        {
            Type             type      = typeof(LotteryEnum);
            List <FieldInfo> fieldInfo = type.GetFields().ToList();

            return((from f in fieldInfo
                    select new Lottery
            {
                create_time = DateTime.Now,
                name = ModelFunction.GetLotteryName(f.Name),
                code = f.Name
            }).ToList());
        }
        private void _ModelFunctionT1Test()
        {
            ModelFunction <int, int> function = new ModelFunction <int, int>();

            function.BindHandler((i) =>
            {
                Assert.AreEqual(1337, i);
                return(123);
            });

            Assert.AreEqual(123, function.Invoke(1337));

            LogAssert.Expect(LogType.Error, "Invoked ModelFunction with no function bound!");
            Assert.AreEqual(default(int), new ModelFunction <int, int>().Invoke(1));
        }
        public void ModelFunctionTest()
        {
            ModelFunction <int> function = new ModelFunction <int>();

            function.BindHandler(() => 123);

            Assert.AreEqual(123, function.Invoke());

            LogAssert.Expect(LogType.Error, "Invoked ModelFunction with no function bound!");
            Assert.AreEqual(default(int), new ModelFunction <int>().Invoke());

            // Test generic versions
            _ModelFunctionT1Test();
            _ModelFunctionT1T2Test();
        }
Пример #6
0
        /// <summary>
        /// Возвращает модель просмоторщика файла
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        private static FrameworkElement GetModel(object obj)
        {
            FrameworkElement result = null;

            if (obj is FileModule)
            {
                result = new ModelOtherFile((FileType)obj);
            }
            else if (obj is FunctionInfo)
            {
                result = new ModelFunction((FunctionInfo)obj);
            }
            else if (obj is FileForm)
            {
                result = NewModelXML((FileType)obj);
            }
            else if (obj is FileMdo)
            {
                result = NewModelXML((FileType)obj);
            }
            else if (obj is FilePicture)
            {
                result = new ModelPicture((FilePicture)obj);
            }
            else if (obj is FileMXLX)
            {
                result = NewModelXML((FileType)obj);
            }
            else if (obj is FileHTML)
            {
                result = NewModelXML((FileType)obj);
            }
            else if (obj is FileZIP)
            {
                result = null;
            }
            else if (obj is FileOther)
            {
                result = new ModelOtherFile((FileType)obj);
            }
            else
            {
                new Exception(" Не определен тип.");
            }

            return(result);
        }
Пример #7
0
        /// <summary>
        /// Default constructor, defaults to BDF Newton method.
        /// </summary>
        /// <param name="n">
        /// A <see cref="System.Int32"/>
        /// </param>
        public CVode(int n, ModelFunction modelFun)
        {
            this.n = n;
            this.modelFunction = modelFun;

            this.cvodeMem = CVodeCreate(2, 2);

            this.y = NewCvode_Vector(this.n);
            this.absoluteTolerance = NewCvode_Vector(this.n);

            for (int i=0; i<this.n; i++)
            {
                Cvode_SetVector (this.absoluteTolerance, i, 1.0e-6);
                Cvode_SetVector (this.y, i, 0.0);
            }

            this.relativeTolerance = 1.0e-8;

            this.errCode = AllocateCvodeMem(this.cvodeMem, this.modelFunction, 0.0, this.y, 1, ref this.relativeTolerance, this.absoluteTolerance);
            this.errCode = CvDense (this.cvodeMem, n);  // int = size of systems
        }
Пример #8
0
 //Constructor
 public ModelExpression(ModelFunction func, ModelValue value)
     : base(null, value)
 {
     _func = func;
 }
Пример #9
0
 /// <summary>
 /// 获取彩种名称
 /// </summary>
 /// <param name="result"></param>
 /// <returns></returns>
 public static string LotteryName(this OpenResult result)
 {
     return(ModelFunction.GetLotteryName(result.lottery_code));
 }
Пример #10
0
        /// <summary>
        /// RunUntil(custom delegate)
        ///     Powerful, where you own the code in the handler, and determine exactly when to stop execution
        ///     ie: RunUntil(delegate() { return _x > 5; }  //Where _x > 5 is any c# code expression
        /// 
        /// </summary>
        /// <param name="func"></param>
        /// <returns></returns>
        public bool             RunUntil(ModelFunction func)
        {
            //Build up a ModelRequirement around the delegate
            ModelRequirements criteria = new ModelRequirements(
                                            new ModelExpression(func, new ModelValue(true))
                                            );

            return this.RunUntil(criteria);
        }
Пример #11
0
 //Constructor
 public ModelExpression(ModelFunction func, ModelValue value)
     : base(null, value)
 {
     _func = func;
 }
        private static TypeUsage GetFunctionTypeUsage(
            bool isModelFunction,
            System.Data.Entity.Core.SchemaObjectModel.Function somFunction,
            FacetEnabledSchemaElement somParameter,
            DbProviderManifest providerManifest,
            bool areConvertingForProviderManifest,
            System.Data.Entity.Core.SchemaObjectModel.SchemaType type,
            CollectionKind collectionKind,
            bool isRefType,
            Converter.ConversionCache convertedItemCache,
            Dictionary <SchemaElement, GlobalItem> newGlobalItems)
        {
            if (somParameter != null && areConvertingForProviderManifest && somParameter.HasUserDefinedFacets)
            {
                return(somParameter.TypeUsage);
            }
            if (type == null)
            {
                if (isModelFunction && somParameter != null && somParameter is Parameter)
                {
                    ((Parameter)somParameter).ResolveNestedTypeNames(convertedItemCache, newGlobalItems);
                    return(somParameter.TypeUsage);
                }
                if (somParameter == null || !(somParameter is ReturnType))
                {
                    return((TypeUsage)null);
                }
                ((ReturnType)somParameter).ResolveNestedTypeNames(convertedItemCache, newGlobalItems);
                return(somParameter.TypeUsage);
            }
            EdmType edmType;

            if (!areConvertingForProviderManifest)
            {
                ScalarType scalarType = type as ScalarType;
                if (scalarType != null)
                {
                    if (isModelFunction && somParameter != null)
                    {
                        if (somParameter.TypeUsage == null)
                        {
                            somParameter.ValidateAndSetTypeUsage(scalarType);
                        }
                        return(somParameter.TypeUsage);
                    }
                    if (isModelFunction)
                    {
                        ModelFunction modelFunction = somFunction as ModelFunction;
                        if (modelFunction.TypeUsage == null)
                        {
                            modelFunction.ValidateAndSetTypeUsage(scalarType);
                        }
                        return(modelFunction.TypeUsage);
                    }
                    if (somParameter != null && somParameter.HasUserDefinedFacets && somFunction.Schema.DataModel == SchemaDataModelOption.ProviderDataModel)
                    {
                        somParameter.ValidateAndSetTypeUsage(scalarType);
                        return(somParameter.TypeUsage);
                    }
                    edmType = (EdmType)Converter.GetPrimitiveType(scalarType, providerManifest);
                }
                else
                {
                    edmType = (EdmType)Converter.LoadSchemaElement(type, providerManifest, convertedItemCache, newGlobalItems);
                    if (isModelFunction && type is SchemaEnumType)
                    {
                        if (somParameter != null)
                        {
                            somParameter.ValidateAndSetTypeUsage(edmType);
                            return(somParameter.TypeUsage);
                        }
                        if (somFunction != null)
                        {
                            ModelFunction modelFunction = (ModelFunction)somFunction;
                            modelFunction.ValidateAndSetTypeUsage(edmType);
                            return(modelFunction.TypeUsage);
                        }
                    }
                }
            }
            else
            {
                edmType = !(type is TypeElement) ? (EdmType)(type as ScalarType).Type : (EdmType)(type as TypeElement).PrimitiveType;
            }
            TypeUsage typeUsage;

            if (collectionKind != CollectionKind.None)
            {
                typeUsage = convertedItemCache.GetCollectionTypeUsageWithNullFacets(edmType);
            }
            else
            {
                EntityType entityType = edmType as EntityType;
                typeUsage = entityType == null || !isRefType?convertedItemCache.GetTypeUsageWithNullFacets(edmType) : TypeUsage.Create((EdmType) new RefType(entityType));
            }
            return(typeUsage);
        }
Пример #13
0
 static extern int AllocateCvodeMem(IntPtr cvode_mum, ModelFunction fcn, double t0, IntPtr y, int itol, ref double reltol, IntPtr abstol);