Example #1
0
        /// <summary>
        /// todo: Muss noch mehr ausgereizt werden. Hier können anhand von arithmetischen Gleichungen oder
        /// Ungleichungen und deren Eigenschaften Beschränkungen am Wertebereich durchgeführt werden
        /// </summary>
        /// <remarks>
        /// Es finden Beschränkungen im Wertebereich der Variablen von der übergebenen Konfiguration statt.
        /// </remarks>
        /// <example>
        /// Aus x1 + x2 &lt;= 7 wird
        /// x1Max = 7 - x2Min und
        /// x2Max = 7 - X1Min
        /// </example>
        /// <param name="configuration">Die übergebene Konfiguration, die es zu testen gilt.</param>
        /// <returns>Gibt true zurück, wenn die Konfiguration grenzenkonsistent ist, sonst false.</returns>
        protected bool CheckBoundsConsistency(ConstraintConfiguration configuration)
        {
            bool changing     = true;
            bool tempChanging = false;

            while (changing == true)
            {
                changing     = false;
                tempChanging = false;
                foreach (Constraint constraint in _constraintList.GetConstraints())
                {
                    if (ConstraintForms.CheckBoundsConsistency(constraint, ref tempChanging) == false)
                    {
                        return(false);
                    }
                    if (tempChanging == true)
                    {
                        changing = true;
                    }
                }
            }
            return(true);
        }
Example #2
0
 /// <summary>
 /// Der Konstruktor.
 /// <remarks>
 /// Dem Konstruktor wird eine AusgangsKonfiguration übergeben, die alle Variablen und deren Wertebereiche enthält.
 /// Diese Variablen sollen dann mit festen Werten belegt werden.
 /// </remarks>
 /// </summary>
 /// <param name="configuration">AusgangsKonfiguration</param>
 public ConstraintProblem(ConstraintConfiguration configuration)
 {
     _begin = CreateNode(null, configuration);
     ConstraintForms.Init();
 }
Example #3
0
        /// <summary>
        /// Für den übergebenen Knoten werden neue Unterknoten generiert.
        /// </summary>
        /// <param name="node">Anhand des übergebenen Knotens werden neue Unterknoten
        /// generiert.</param>
        /// <param name="maxCount">Beschränkt die Anzahl der Unterknoten.</param>
        /// <returns>
        /// Gibt die Menge der generierten Knoten als Array zurück.
        /// </returns>
        public virtual INode[] GenerateChildren(INode node, int maxCount)
        {
            ConstraintConfiguration parentConfiguration = (ConstraintConfiguration)node.Data;
            Variable     nextVar        = _heuristicVariable.GetHeuristicVariable(parentConfiguration, _constraintList);
            List <INode> generatedNodes = new List <INode>();

            if (nextVar == null)
            {
                throw new Exception("nextVar is null");
            }

            //// Zufall
            //List<KeyValuePair<double, double>> sortedList = new List<KeyValuePair<double, double>>(nextVar.Domain.Count);
            //foreach (double value in nextVar.Domain)
            //{
            //    sortedList.Add(new KeyValuePair<double,double>(_random.NextDouble(), value));
            //}
            //sortedList.Sort();

            //foreach (KeyValuePair<double,double> pair in sortedList)
            foreach (double value in nextVar.Domain)
            {
                ConstraintConfiguration configuration = new ConstraintConfiguration(parentConfiguration);
                Variable currentVar = configuration.GetVariable(nextVar.Name);
                currentVar.Value = value;

                List <Constraint> constraints = _constraintList.GetConstraints(nextVar.Name);
                bool operationFailed          = false;
                foreach (Constraint cons in constraints)
                {
                    bool tempChanging = false;
                    cons.SetCurrentConfiguration(configuration);
                    // todo: Ist diese Abfrage wirklich notwendig?
                    //if (cons.IsComplied == false)
                    //{
                    //    operationFailed = true;
                    //    break;
                    //}
                    if (_consistencyOptions.GetCheckConsistencyActive(ConsistencyCheckRegion.EachNodeGenerating, ConsistencyType.Bounds) && ConstraintForms.CheckBoundsConsistency(cons, ref tempChanging) == false)
                    {
                        operationFailed = true;
                        break;
                    }
                    else if (_consistencyOptions.GetCheckConsistencyActive(ConsistencyCheckRegion.EachNodeGenerating, ConsistencyType.Node) && configuration.CheckNodeConsistency(cons, false) == false)
                    {
                        operationFailed = true;
                        break;
                    }
                    else if (_consistencyOptions.GetCheckConsistencyActive(ConsistencyCheckRegion.EachNodeGenerating, ConsistencyType.Arc) && CheckArcConsistency(configuration) == false)
                    {
                        operationFailed = true;
                        break;
                    }
                }
                if (!operationFailed)
                {
                    // Die Domaene kann gelöscht werden
                    currentVar.Domain = null;
                    generatedNodes.Add(CreateNode(node, configuration));
                    //configuration.Show();
                }
            }


            INode[] result;
            result = new INode[generatedNodes.Count];

            generatedNodes.CopyTo(result);
            return(result);
        }