/// <summary> /// Maps <paramref name="x"/> onto a new set via the specified <paramref name="mapping"/> /// </summary> public static FiniteDomainVariable <T2> Map <T1, T2>(FiniteDomainVariable <T1> x, Mapping <T1, T2> mapping) { FiniteDomainVariable <T2> newVariable = x.ConstraintThingySolver.CreateFiniteDomainVariable(mapping.End); Mapping(x, newVariable, mapping); return(newVariable); }
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 a new equality constraint /// </summary> public MappingConstraint(FiniteDomainVariable <T1> x, FiniteDomainVariable <T2> y, Mapping <T1, T2> mapping) : base(new Variable[] { x, y }) { _mapping = mapping; if (x.FiniteDomain != mapping.Start || y.FiniteDomain != mapping.End) { throw new InvalidOperationException("The finite domains on the variables are not the same as the provided mapping."); } }
/// <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> /// Constrains <paramref name="variable"/> to one element of <paramref name="values"/> /// </summary> public static void ElementOf <T>(FiniteDomainVariable <T> variable, IEnumerable <T> values) { ulong mask = 0UL; foreach (var value in values) { mask = mask.SetBit(variable.FiniteDomain.IndexOf(value)); } variable.BackdoorSet(variable.AllowableValues & mask); }
protected internal override void UpdateVariable(FiniteDomainVariable <T> variable, out bool success) { FiniteDomainVariable <T> otherVariable = (variable == Variables[0]) ? Variables[1] : Variables[0]; if (otherVariable.IsUnique) { variable.NarrowTo(~otherVariable.AllowableValues, out success); if (!success) { return; } } success = true; return; }
public InequalityConstraint(FiniteDomainVariable <T> x, FiniteDomainVariable <T> y) : base(new [] { x, y }) { }
protected internal override void UpdateVariable(FiniteDomainVariable <T> variable, out bool success) { throw new NotImplementedException(); }
/// <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> /// Prohibits <paramref name="variable"/> from assuming <paramref name="value"/> /// </summary> public static void NotEqual <T>(FiniteDomainVariable <T> variable, T value) { UInt64 newValue = variable.AllowableValues.ClearBit(variable.FiniteDomain.IndexOf(value)); variable.BackdoorSet(newValue); }
/// <summary> /// Constrains <paramref name="variable"/> to one element of <paramref name="values"/> /// </summary> public static void ElementOf <T>(FiniteDomainVariable <T> variable, params T[] values) { ElementOf(variable, (IEnumerable <T>)values); }
/// <summary> /// Constrains <paramref name="variable"/> to <paramref name="value"/> /// </summary> public static void Equal <T>(FiniteDomainVariable <T> variable, T value) { variable.BackdoorSet(variable.AllowableValues & BitHelper.GetMask(variable.FiniteDomain.IndexOf(value))); }
/// <summary> /// Constrains that the values of <paramref name="a"/> and <paramref name="b"/> are not equal. /// </summary> public static void NotEqual <T>(FiniteDomainVariable <T> a, FiniteDomainVariable <T> b) { new InequalityConstraint <T>(a, b); }
/// <summary> /// Specifies a formal mapping between the values of variables <paramref name="x"/> and <paramref name="y"/> using the specified <paramref name="mapping"/> /// </summary> public static void Mapping <T1, T2>(FiniteDomainVariable <T1> x, FiniteDomainVariable <T2> y, Mapping <T1, T2> mapping) { new MappingConstraint <T1, T2>(x, y, mapping); }