本文整理汇总了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;
}
示例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;
}