コード例 #1
0
ファイル: SolverNode.cs プロジェクト: hmmueller/Movimentum
        private SolverNode(IEnumerable<AbstractConstraint> constraints,
                           IDictionary<IVariable, AbstractClosedVariable> closedVariables,
                           SolverNode origin)
        {
            _debugOrigin = origin;
            if (origin != null) {
                origin._debugSuccessors++;
            }

            //var foldingVisitor = new ConstantFoldingVisitor();
            var foldingVisitor = new PolynomialFoldingVisitor();
            _constraints = constraints.Select(c => c.Accept(foldingVisitor, Ig.nore)).ToArray(); // !!!TOARRAY
            foreach (var c in _constraints) {
                c.SetDebugCreatingNodeIdIfMissing(DebugId);
            }

            _closedVariables = new SortedDictionary<IVariable, AbstractClosedVariable>(closedVariables);
        }
コード例 #2
0
ファイル: SolverNode.cs プロジェクト: hmmueller/Movimentum
 public abstract IEnumerable<SolverNode> SuccessfulMatch(SolverNode current, ScalarConstraint constraint);
コード例 #3
0
ファイル: SolverNode.cs プロジェクト: hmmueller/Movimentum
 private SolverNode(IEnumerable<AbstractConstraint> constraints,
                    SolverNode origin)
     : this(constraints, origin.ClosedVariables, origin)
 {
 }
コード例 #4
0
ファイル: SolverNode.cs プロジェクト: hmmueller/Movimentum
        public static IEnumerable<SolverNode> SolverStep(IEnumerable<SolverNode> open, 
                IDictionary<IVariable, VariableWithValue> previousValues, 
                out SolverNode solutionOrNull, 
                EvaluationVisitor debugExpectedResults = null)
        {
            double minRank = open.Min(cs => cs.Rank);
            SolverNode selected;
            if (debugExpectedResults == null) {
                selected = open.First(cs => cs.Rank <= minRank);
            } else {
                // The debugExpectedResults are intended to steer the solver only on
                // nodes that match the expected result!
                selected = open.FirstOrDefault(cs =>
                    cs.Constraints.All(c => DebugIsTrueOrUnknown(c, debugExpectedResults))
                );
                if (selected == null) {
                    Debug.WriteLine("---- All open nodes do not match expected results:");
                    foreach (var node in open) {
                        Debug.WriteLine(node.DebugToString(debugExpectedResults));
                    }

                    throw new InvalidOperationException("No node matches expected results");
                }
            }
            IEnumerable<SolverNode> expanded = selected.Expand( /*previousValues*/).ToArray();

            if (!expanded.Any()) {
                // Dead node - register in dead nodes.
                DebugDeadNodes.Add(selected);

                // ????
                if (debugExpectedResults != null) {
                    Debug.WriteLine(".... Constraint state " + selected.DebugToString(debugExpectedResults));
                }
            }

            //IEnumerable<SolverNode> newOpen = open.Except(selected).Concat(expandedSets);
            IEnumerable<SolverNode> newOpen = expanded.Concat(open.Except(selected)).ToArray();

            // Not really correct: We should also check whether all anchor variables have
            // a single value. For the moment, in our tests, we live with this rough check.
            solutionOrNull = expanded.FirstOrDefault(cs => cs.IsSolved());

            return newOpen;
        }