/// <summary> /// Constrains <paramref name="variable"/> to never take values in <paramref name="multiInterval"/> /// </summary> public static void Exclude(RealVariable variable, MultiInterval multiInterval) { foreach (var interval in multiInterval) { Exclude(variable, interval); } }
/// <summary> /// Creates a new real variable that represents the square of <paramref name="variable"/> /// </summary> public static RealVariable Square(RealVariable variable) { var result = variable * variable; Constraint.GreaterThanOrEqual(result, 0.0); return(result); }
public ScoreContraint(RealVariable score, FiniteDomainVariable <T> finiteDomainVariable, ScoreMapping <T> scoreMapping) : base(score, finiteDomainVariable) { _scoreMapping = scoreMapping; if (finiteDomainVariable.FiniteDomain != scoreMapping.FiniteDomain) { throw new InvalidOperationException("The finite domains of the variable and score mapping did not match."); } }
/// <summary> /// Creates and returns an real variable that represents the difference of <paramref name="a"/> and <paramref name="b"/> /// </summary> public static RealVariable Subtract(RealVariable a, RealVariable b) { RealVariable difference = new RealVariable(a.ConstraintThingySolver, null, RealVariable.DefaultRange); Constraint.InRange(difference, a.AllowableValues.First - b.AllowableValues.First); Difference(difference, a, b); return(difference); }
/// <summary> /// Creates a real variable whose value can be any one of a set of intervals, which correspond to values of the specified finite domain /// </summary> public static RealVariable ScoreVariable <T>(FiniteDomainVariable <T> finiteDomainVariable, ScoreMapping <T> scoreMapping) { RealVariable realVariable = new RealVariable(finiteDomainVariable.ConstraintThingySolver, null, RealVariable.DefaultRange); Constraint.InRange(realVariable, scoreMapping.Select(pair => pair.Second).Aggregate(Interval.Union)); Constraint.Score(realVariable, finiteDomainVariable, scoreMapping); return(realVariable); }
/// <summary> /// Creates and returns a real variable which represents the minimum of <paramref name="a"/> and <paramref name="b"/> /// </summary> public static RealVariable Minimize(RealVariable a, RealVariable b) { RealVariable min = new RealVariable(a.ConstraintThingySolver, null, RealVariable.DefaultRange); // calculate the possible range for the sum so we improve the speed of the search Constraint.InRange(min, MultiInterval.Min(a.AllowableValues.First, b.AllowableValues.First)); Min(min, a, b); return(min); }
/// <summary> /// Creates and returns a real variable which represents the minimum of <paramref name="a"/> and <paramref name="b"/> /// </summary> public static RealVariable Minimize(params RealVariable[] variables) { RealVariable min = new RealVariable(variables[0].ConstraintThingySolver, null, RealVariable.DefaultRange); // calculate the possible range for the sum so we improve the speed of the search Constraint.InRange(min, variables.Select(var => var.AllowableValues.First).Aggregate(MultiInterval.Min)); Min(min, variables); return(min); }
/// <summary> /// Creates and returns an real variable that represents the sum of <paramref name="a"/> and <paramref name="b"/> /// </summary> public static RealVariable Add(RealVariable a, RealVariable b) { RealVariable sum = new RealVariable(a.ConstraintThingySolver, null, RealVariable.DefaultRange); // calculate the possible range for the sum so we improve the speed of the search Constraint.InRange(sum, a.AllowableValues.First + b.AllowableValues.First); Sum(sum, a, b); return(sum); }
/// <summary> /// Creates and returns an real variable that represents the distance squared between <paramref name="a"/> and <paramref name="b"/> /// </summary> public static RealVariable DistanceSquared(Vector2Variable a, Vector2Variable b) { RealVariable x1MinusX2 = a.X - b.X; RealVariable y1MinusY2 = a.Y - b.Y; RealVariable result = Square(x1MinusX2) + Square(y1MinusY2); Constraint.GreaterThanOrEqual(result, 0.0); return(result); }
/// <summary> /// Creates and returns an real variable that represents the quotient of <paramref name="dividend"/> and <paramref name="divisor"/> /// </summary> public static RealVariable Divide(RealVariable dividend, RealVariable divisor) { RealVariable quotient; quotient = new RealVariable(dividend.ConstraintThingySolver, null, RealVariable.DefaultRange); Constraint.InRange(quotient, dividend.AllowableValues.First / divisor.AllowableValues.First); Quotient(quotient, dividend, divisor); return(quotient); }
/// <summary> /// Creates and returns an real variable that represents the product of <paramref name="a"/> and <paramref name="b"/> /// </summary> public static RealVariable Multiply(RealVariable a, RealVariable b) { RealVariable product; product = new RealVariable(a.ConstraintThingySolver, null, RealVariable.DefaultRange); Constraint.InRange(product, a.AllowableValues.First * b.AllowableValues.First); Product(product, a, b); return(product); }
/// <summary> /// Constrains <paramref name="variable"/> to be in <paramref name="multiInterval"/> /// </summary> public static void InRange(RealVariable variable, MultiInterval multiInterval) { variable.BackdoorSet(variable.AllowableValues.Rest.AddFront(MultiInterval.Intersection(variable.AllowableValues.First, multiInterval))); }
/// <summary> /// Constraints <paramref name="variable"/> to never take values in <paramref name="interval"/> /// </summary> public static void Exclude(RealVariable variable, Interval interval) { InRange(variable, new MultiInterval(new Interval(double.NegativeInfinity, interval.LowerBound), new Interval(interval.UpperBound, double.PositiveInfinity))); }
/// <summary> /// Constrains <paramref name="variable"/> to never take the specified value <paramref name="value"/> /// </summary> public static void Exclude(RealVariable variable, double value) { Exclude(variable, new Interval(value)); }
/// <summary> /// Constrains <paramref name="min"/> to be the minimum of <paramref name="a"/> and <paramref name="b"/> /// </summary> public static void Min(RealVariable min, RealVariable a, RealVariable b) { new RealMinConstraint(min, a, b); }
/// <summary> /// Constrains <paramref name="sum"/> to be the sum of <paramref name="a"/> and <paramref name="b"/> /// </summary> public static void Sum(RealVariable sum, RealVariable a, RealVariable b) { new RealSumConstraint(sum, a, b); }
/// <summary> /// Constraints <paramref name="variable"/> to be at most <paramref name="value"/> /// </summary> public static void LessThanOrEqual(RealVariable variable, double value) { InRange(variable, double.NegativeInfinity, value); }
/// <summary> /// Creates and returns an real variable that represents the difference of <paramref name="a"/> and <paramref name="b"/> /// </summary> public static void Difference(RealVariable difference, RealVariable a, RealVariable b) { new RealDifferenceConstraint(difference, a, b); }
/// <summary> /// Constrains <paramref name="quotient"/> to be the quotient of <paramref name="dividend"/> and <paramref name="divisor"/> /// </summary> public static void Quotient(RealVariable quotient, RealVariable dividend, RealVariable divisor) { new RealQuotientConstraint(quotient, dividend, divisor); }
/// <summary> /// Constrains <paramref name="max"/> to be the maximum of <paramref name="a"/> and <paramref name="b"/> /// </summary> public static void Max(RealVariable max, RealVariable a, RealVariable b) { new RealMaxConstraint(max, a, b); }
/// <summary> /// Constraints <paramref name="product"/> to be the product of <paramref name="a"/> and <paramref name="b"/> /// </summary> public static void Product(RealVariable product, RealVariable a, RealVariable b) { new RealProductConstraint(product, a, b); }
/// <summary> /// Constrains <paramref name="variable" /> to be in <paramref name="range"/> /// </summary> public static void InRange(RealVariable variable, Interval range) { InRange(variable, new MultiInterval(range)); }
/// <summary> /// Constrains <paramref name="variable"/> to be between <paramref name="minValue"/> and <paramref name="maxValue"/> /// </summary> public static void InRange(RealVariable variable, double minValue, double maxValue) { InRange(variable, new Interval(minValue, maxValue)); }
/// <summary> /// Creates a new Vector2 variable /// </summary> public Vector2Variable(RealVariable x, RealVariable y) { X = x; Y = y; }
/// <summary> /// Constrains <paramref name="variable"/> to be at least <paramref name="value"/> /// </summary> public static void GreaterThanOrEqual(RealVariable variable, double value) { InRange(variable, value, double.PositiveInfinity); }
/// <summary> /// Constrains <paramref name="min"/> to be the minimum of the specified variables /// </summary> public static void Min(RealVariable min, params RealVariable[] variables) { new RealMinConstraint(min, variables); }
/// <summary> /// Creates a new score constraint, which constrains the value of the <paramref name="score"/> variable to be some assignment of a value in the <paramref name="finiteDomainVariable"/> based on the specified <paramref name="scoreMapping"/> from finite domain items to real-valued intervals /// </summary> public static void Score <T>(RealVariable score, FiniteDomainVariable <T> finiteDomainVariable, ScoreMapping <T> scoreMapping) { new ScoreContraint <T>(score, finiteDomainVariable, scoreMapping); }
/// <summary> /// Constrains that the values of <paramref name="a"/> and <paramref name="b"/> are equal. /// </summary> public static void Equal(RealVariable a, RealVariable b) { new RealEqualityConstraint(a, b); }
/// <summary> /// Constraints <paramref name="variable"/> to be exactly <paramref name="value"/> /// </summary> public static void Equal(RealVariable variable, double value) { InRange(variable, value, value); }
/// <summary> /// Constrains <paramref name="max"/> to be the maximum of the specified variables /// </summary> public static void Max(RealVariable max, params RealVariable[] variables) { new RealMaxConstraint(max, variables); }