private static void GoalPathesI(GBSearchModule module,
                                    ArrayList goalpathes, DBNode node, Stack path)
    {
        if (node == null)
        {
            return;
        }

        if (module.IsGoal(node.State))
        {
            ArrayList newGoalPath = new ArrayList();

            foreach (DBNode pNode in path)
            {
                newGoalPath.Add(pNode);
            }

            newGoalPath.Reverse();

            newGoalPath.Add(node);
            goalpathes.Add(newGoalPath);

            return;
        }

        foreach (DBNode child in node.Children)
        {
            path.Push(node);
            GoalPathesI(module, goalpathes, child, path);
            path.Pop();
        }
    }
    private static void GoalPathesI(GBSearchModule module,
		ArrayList goalpathes, DBNode node, Stack path)
    {
        if (node == null)
            return;

        if (module.IsGoal (node.State)) {
            ArrayList newGoalPath = new ArrayList ();

            foreach (DBNode pNode in path)
                newGoalPath.Add (pNode);

            newGoalPath.Reverse ();

            newGoalPath.Add (node);
            goalpathes.Add (newGoalPath);

            return;
        }

        foreach (DBNode child in node.Children) {
            path.Push (node);
            GoalPathesI (module, goalpathes, child, path);
            path.Pop ();
        }
    }
Exemplo n.º 3
0
    private void CheckC2(ArrayList[] affecting)
    {
        int[] n = new int[2];

        for (n[0] = 0; n[0] < affecting.Length; ++n[0])
        {
            for (n[1] = (n[0] + 1); n[1] < affecting.Length; ++n[1])
            {
                int[] count = new int[2];
                int   countN;
                if (affecting[n[0]].Count == 0 || affecting[n[1]].Count == 0)
                {
                    continue;
                }

                do
                {
                    // Enumerate all possible combinations at position (n0, n1)
                    DBNode       node1  = (DBNode)affecting[n[0]][count[0]];
                    DBNode       node2  = (DBNode)affecting[n[1]][count[1]];
                    GBSpaceState state1 = (GBSpaceState)node1.State;
                    GBSpaceState state2 = (GBSpaceState)node2.State;

                    // Check that there is a appropiate dependency node in it and
                    // then for combinability for state1/state2
                    if ((thisStageDependencies.Contains(state1) == true ||
                         thisStageDependencies.Contains(state2) == true) &&
                        state2.GB.CompatibleWith(state1.GB) &&
                        gbS.NotInConflict(state1, state2))
                    {
                        GBSpaceState gComb =
                            (GBSpaceState)state2.LastOperator.Apply(gbS, state1);
                        gComb.GB.AddExtraStones(state2.GB);
                        gComb.UpdateLegalOperators(gbS.maximumCategory);

                        // Now check if the new state results in new operators
                        GBOperator[] n1o = state1.LegalOperators;
                        GBOperator[] n2o = state2.LegalOperators;

                        GBOperator[] nCo = gComb.LegalOperators;
                        if (nCo == null)
                        {
                            goto nextComb;
                        }
                        //Console.WriteLine ("nCo.Length = {0}", nCo.Length);

                        // Check: nCo \setminus (n1o \cup n2o) \neq \emptyset
                        bool seenUnique = false;
                        foreach (GBOperator gbo in nCo)
                        {
                            if (n1o != null && Array.IndexOf(n1o, gbo) >= 0)
                            {
                                continue;
                            }
                            if (n2o != null && Array.IndexOf(n2o, gbo) >= 0)
                            {
                                continue;
                            }

                            seenUnique = true;
                            //Console.WriteLine ("unique: {0}", gbo);
                        }
                        if (seenUnique == false)
                        {
                            goto nextComb;
                        }

                        // We have found a new combination

                        /*
                         * Console.WriteLine ("TODO: found found found:");
                         * Console.WriteLine ("From 1: {0}", state1.GB);
                         * Console.WriteLine ("From 2: {0}", state2.GB);
                         * Console.WriteLine ("To: {0}", gComb.GB);
                         * throw (new ArgumentException ("DEBUG"));
                         */

                        DBNode combNode = new DBNode(DBNode.NodeType.Combination,
                                                     gComb, level);
                        combNode.IsGoal = gbS.IsGoal(gComb);

                        /* TODO: have to get this back to db-search somehow,
                         * or throw exception here.
                         * if (combNode.IsGoal)
                         *      goalCount += 1;
                         */

                        dbS.AddCombinationNode(node1, combNode);
                        node2.CombinedChildren.Add(combNode);
                        gbS.RegisterNewNode(combNode);
                    }

nextComb:
                    for (countN = 0; countN < count.Length; ++countN)
                    {
                        count[countN] += 1;

                        if (count[countN] < affecting[n[countN]].Count)
                        {
                            break;
                        }

                        count[countN] = 0;
                    }
                } while (countN < count.Length);
            }
        }
    }