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


C# IVariable.CompositeOperation方法代码示例

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


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

示例1: CalculatePower

        private static IVariable CalculatePower(IVariable number, IVariable power, IMilpManager milpManager, IVariable isEdgeCase)
        {
            var digits = (int)Math.Ceiling(Math.Log(milpManager.IntegerWidth, 2.0));

            var infinity = milpManager.FromConstant(milpManager.MaximumIntegerValue);
            var currentPower = milpManager.Operation(OperationType.Minimum, number, isEdgeCase.Operation(OperationType.BinaryNegation).Operation(OperationType.Multiplication, infinity));
            var decomposition = power.CompositeOperation(CompositeOperationType.UnsignedMagnitudeDecomposition).Take(digits).ToArray();
            var one = milpManager.FromConstant(1);
            var result = one;

            for (int i = 0; i < digits; ++i)
            {
                if (i > 0)
                {
                    var isAnyNonzeroDigitLater = milpManager.Operation(OperationType.Disjunction, decomposition.Skip(i).ToArray());
                    var numberToMultiply = milpManager.Operation(OperationType.Minimum, currentPower, isAnyNonzeroDigitLater.Operation(OperationType.Multiplication, infinity));
                    currentPower = numberToMultiply.Operation(OperationType.Multiplication, numberToMultiply);
                }

                result = result.Operation(OperationType.Multiplication, one.Operation(OperationType.Maximum, currentPower.Operation(OperationType.Multiplication, decomposition[i])));
            }

            return result;
        }
开发者ID:afish,项目名称:MilpManager,代码行数:24,代码来源:ExponentiationCalculator.cs

示例2: MakeLongMultiplication

        private IVariable MakeLongMultiplication(IMilpManager baseMilpManager, Domain domain, IVariable zero, IVariable second,
            IVariable first)
        {
            var result = zero;

            var secondDigits = second.CompositeOperation(CompositeOperationType.UnsignedMagnitudeDecomposition).ToArray();
            for (int index = 0, power = 1; index < secondDigits.Length; ++index, power = power*2)
            {
                result = result.Operation(OperationType.Addition,
                    MultipleByBinaryDigit(baseMilpManager, first, secondDigits[index])
                        .ChangeDomain(domain)
                        .Operation(OperationType.Multiplication, baseMilpManager.FromConstant(power))
                    );
            }
            return result;
        }
开发者ID:afish,项目名称:MilpManager,代码行数:16,代码来源:MultiplicationCalculator.cs


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