public IVariable Calculate(IMilpManager milpManager, OperationType type, params IVariable[] arguments) { if (!SupportsOperation(type, arguments)) { throw new NotSupportedException(SolverUtilities.FormatUnsupportedMessage(type, arguments)); } if (arguments.All(a => a.IsConstant())) { var constantResult = (int)arguments[0].ConstantValue.Value % (int)arguments[1].ConstantValue.Value; return(milpManager.FromConstant((int)constantResult)); } IVariable numerator = arguments[0]; IVariable denominator = arguments[1]; var one = milpManager.FromConstant(1); var any = milpManager.CreateAnonymous(Domain.PositiveOrZeroInteger); any.Operation(OperationType.Multiplication, denominator).Set(ConstraintType.LessOrEqual, numerator); any.Operation(OperationType.Addition, one) .Operation(OperationType.Multiplication, denominator) .Set(ConstraintType.GreaterOrEqual, numerator.Operation(OperationType.Addition, one)); IVariable result = milpManager.CreateAnonymous(Domain.PositiveOrZeroInteger); result.Set(ConstraintType.LessOrEqual, denominator); result.Set(ConstraintType.Equal, numerator.Operation(OperationType.Subtraction, denominator.Operation(OperationType.Multiplication, any))); result.ConstantValue = numerator.ConstantValue % denominator.ConstantValue; result.Expression = $"{numerator.FullExpression()} % {denominator.FullExpression()}"; return(result); }
public virtual IVariable Create(IVariable value) { var variable = CreateAnonymous(value.Domain.MakeNonConstant()); variable.ConstantValue = value.ConstantValue; variable.Expression = $"{value.FullExpression()}"; Set(ConstraintType.Equal, variable, value); return(variable); }
public virtual IVariable Create(IVariable value) { var variable = CreateAnonymous(value.Domain.MakeNonConstant()); variable.ConstantValue = value.ConstantValue; variable.Expression = $"{value.FullExpression()}"; Set(ConstraintType.Equal, variable, value); return variable; }