Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        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.");
            }
        }
Exemplo n.º 3
0
        /// <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.");
            }
        }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
        /// <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);
        }
Exemplo n.º 6
0
        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;
        }
Exemplo n.º 7
0
 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();
 }
Exemplo n.º 9
0
 /// <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);
 }
Exemplo n.º 10
0
        /// <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);
        }
Exemplo n.º 11
0
 /// <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);
 }
Exemplo n.º 12
0
 /// <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)));
 }
Exemplo n.º 13
0
 /// <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);
 }
Exemplo n.º 14
0
 /// <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);
 }