当前位置: 首页>>代码示例>>C#>>正文


C# IVariable.All方法代码示例

本文整理汇总了C#中IVariable.All方法的典型用法代码示例。如果您正苦于以下问题:C# IVariable.All方法的具体用法?C# IVariable.All怎么用?C# IVariable.All使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IVariable的用法示例。


在下文中一共展示了IVariable.All方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CalculateDomain

        private static Domain CalculateDomain(IVariable[] arguments)
        {
            if (arguments.All(a => a.IsBinary()))
            {
                return Domain.BinaryInteger;
            }

            if (IsDividingByConstant(arguments))
            {
                if (arguments.All(a => a.IsInteger()))
                {

                    if (arguments.All(a => a.IsPositiveOrZero() || a.IsBinary()))
                    {
                        return Domain.PositiveOrZeroInteger;
                    }
                    return Domain.AnyInteger;
                }
                else
                {
                    if (arguments.All(a => a.IsPositiveOrZero() || a.IsBinary()))
                    {
                        return Domain.PositiveOrZeroReal;
                    }
                    return Domain.AnyReal;
                }
            }

            if (arguments.All(a => a.IsPositiveOrZero() || a.IsBinary()))
            {
                return Domain.PositiveOrZeroInteger;
            }
            return Domain.AnyInteger;
        }
开发者ID:afish,项目名称:MilpManager,代码行数:34,代码来源:DivisionCalculator.cs

示例2: CalculateDomain

        private static Domain CalculateDomain(IVariable[] arguments)
        {
            Domain domain;
            if (MultiplyBinaryVariables(arguments))
            {
                domain = Domain.BinaryInteger;
            }
            else if (arguments.All(a => a.IsPositiveOrZero() || a.IsBinary()))
            {
                domain = arguments.Any(a => a.IsReal()) ? Domain.PositiveOrZeroReal : Domain.PositiveOrZeroInteger;
            }
            else
            {
                domain = arguments.Any(a => a.IsReal()) ? Domain.AnyReal : Domain.AnyInteger;
            }

            return arguments.All(a => a.IsConstant()) ? domain.MakeConstant() : domain;
        }
开发者ID:afish,项目名称:MilpManager,代码行数:18,代码来源:MultiplicationCalculator.cs

示例3: CalculateForTwoVariables

        private static IVariable CalculateForTwoVariables(IMilpManager milpManager, OperationType type, IVariable[] arguments)
        {
            if (arguments.All(a => a.IsConstant()))
            {
                var values = arguments.Select(a => a.ConstantValue.Value);
                var result = type == OperationType.Maximum ? values.Max() : values.Min();
                if (arguments.All(a => a.IsInteger()))
                {
                    return milpManager.FromConstant((int) result);
                }
                else
                {
                    return milpManager.FromConstant(result);
                }
            }
            var first = arguments[0];
            var second = arguments[1];

            IVariable max = milpManager.CreateAnonymous(CalculateDomain(arguments));
            IVariable min = milpManager.CreateAnonymous(CalculateDomain(arguments));

            max.Set(ConstraintType.GreaterOrEqual, first);
            max.Set(ConstraintType.GreaterOrEqual, second);
            min.Set(ConstraintType.LessOrEqual, first);
            min.Set(ConstraintType.LessOrEqual, second);

            max.Operation(OperationType.Subtraction, min)
                .Set(ConstraintType.Equal,
                    first.Operation(OperationType.Subtraction, second).Operation(OperationType.AbsoluteValue));

            max.ConstantValue = arguments.All(a => a.ConstantValue.HasValue)
                ? Math.Max(arguments[0].ConstantValue.Value, arguments[1].ConstantValue.Value)
                : (double?)null;
            min.ConstantValue = arguments.All(a => a.ConstantValue.HasValue)
                ? Math.Min(arguments[0].ConstantValue.Value, arguments[1].ConstantValue.Value)
                : (double?)null;
            max.Expression = $"max({arguments[0].FullExpression()}, {arguments[1].FullExpression()}";
            min.Expression = $"min({arguments[0].FullExpression()}, {arguments[1].FullExpression()}";
            return type == OperationType.Maximum ? max : min;
        }
开发者ID:afish,项目名称:MilpManager,代码行数:40,代码来源:MaximumMinimumCalculator.cs

示例4: CalculateDomain

        private static Domain CalculateDomain(IVariable[] arguments)
        {
            if (arguments.All(a => a.IsPositiveOrZero() || a.IsBinary()))
            {
                if (arguments.Any(a => a.IsReal()))
                {
                    return arguments.Any(a => a.IsNotConstant()) ? Domain.PositiveOrZeroReal : Domain.PositiveOrZeroConstantReal;
                }

                return arguments.Any(a => a.IsNotConstant()) ? Domain.PositiveOrZeroInteger : Domain.PositiveOrZeroConstantInteger;
            }

            if (arguments.Any(a => a.IsReal()))
            {
                return arguments.Any(a => a.IsNotConstant()) ? Domain.AnyReal : Domain.AnyConstantReal;
            }

            return arguments.Any(a => a.IsNotConstant()) ? Domain.AnyInteger : Domain.AnyConstantInteger;
        }
开发者ID:afish,项目名称:MilpManager,代码行数:19,代码来源:AdditionCalculator.cs

示例5: MultiplyAnyIntegers

 private static bool MultiplyAnyIntegers(IVariable[] arguments)
 {
     return arguments.All(a => a.IsInteger());
 }
开发者ID:afish,项目名称:MilpManager,代码行数:4,代码来源:MultiplicationCalculator.cs

示例6: MultiplyOnlyConstants

 private static bool MultiplyOnlyConstants(IVariable[] arguments)
 {
     return arguments.All(a => a.IsConstant());
 }
开发者ID:afish,项目名称:MilpManager,代码行数:4,代码来源:MultiplicationCalculator.cs

示例7: MultiplyBinaryVariables

 private static bool MultiplyBinaryVariables(IVariable[] arguments)
 {
     return arguments.All(a => a.IsBinary());
 }
开发者ID:afish,项目名称:MilpManager,代码行数:4,代码来源:MultiplicationCalculator.cs


注:本文中的IVariable.All方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。