示例#1
0
 public override bool IsSatisfied(CspModel model)
 {
     // if parent is enabled, child must be enabled   11
     // if parent is disable, child can be off/on     01 | 00
     // value that is not allowed is                  10
     return((Variables[PARENT].Value << 1 | Variables[CHILD].Value) != 0b10);
 }
示例#2
0
 public override bool IsSatisfied(CspModel model)
 {
     // parent on then child off       10
     // parent off the child on/off    01 | 00
     // value that is not allowed is   11
     return((Variables[PARENT].Value << 1 | Variables[CHILD].Value) != 0b11);
 }
示例#3
0
 public override bool IsSatisfied(CspModel model)
 {
     // If parent is on, then at least one must be enabled.
     if (Variables[PARENT].Value == ON)
     {
         int count = 0;
         for (int i = 1; i < Variables.Length; i++)
         {
             if (Variables[i].Value == ON)
             {
                 count++;
             }
         }
         return(count > 0);
     }
     else
     // If parent is off, then everything must be off.
     {
         for (int i = 1; i < Variables.Length; i++)
         {
             if (Variables[i].Value == ON)
             {
                 return(false);
             }
         }
         return(true);
     }
 }
 public void PrintModel(CspModel model)
 {
     foreach (var variable in model.Variables)
     {
         Console.WriteLine($"{variable.Name} {{{string.Join(", ", variable.Domain.Values)}}}"
                           + $" = {variable.Value} (Set: {variable.IsSet})");
     }
 }
示例#5
0
 public override bool IsSatisfied(CspModel model)
 {
     // not allowed: parent disabled, child enabled, so 01
     return((Variables[PARENT].Value << 1 | Variables[CHILD].Value) != 0b01);
     // return Variables[0].Value == ON && Variables[1].Value == OFF
     //     || Variables[0].Value == ON && Variables[1].Value == ON
     //     || Variables[0].Value == OFF && Variables[1].Value == OFF;
 }
示例#6
0
        public CspModel BuildCspModel()
        {
            var model = new CspModel
            {
                Variables   = this.Variables.ToArray(),
                Constraints = this.Constraints.ToArray()
            };

            return(model);
        }
示例#7
0
 public bool VariablesSet(CspModel model)
 {
     for (int i = 0; i < Variables.Length; i++)
     {
         var id = Variables[i].Id;
         if (!model.Variables[id].IsSet)
         {
             return(false);
         }
     }
     return(true);
 }
示例#8
0
        public override bool IsSatisfied(CspModel model)
        {
            var values = new Dictionary <int, bool>();

            for (int i = 0; i < Variables.Length; i++)
            {
                Variable variable = model.Variables[i];
                if (values.ContainsKey(variable.Value))
                {
                    return(false);
                }
                values.Add(variable.Value, true);
            }
            return(true);
        }
 public BacktrackSearcher(CspModel model)
 {
     Model = model;
     ConstraintPropagator = new ConstraintPropagator(model);
 }
示例#10
0
 public ConstraintPropagator(CspModel model)
 {
     Model = model;
 }
示例#11
0
 public override bool IsSatisfied(CspModel model)
 {
     // Either 00 or 11, so not 01 or 10
     return(Variables[PARENT].Value == ON && Variables[CHILD].Value == ON ||
            Variables[PARENT].Value == OFF && Variables[CHILD].Value == OFF);
 }
示例#12
0
 public abstract bool IsSatisfied(CspModel model);