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 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> /// 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); }