Ejemplo n.º 1
0
        static void Procedure_Search(Char endChar, int lastPoint)
        {
            goalNode = nodes[lastPoint];
            while (!nodeBank.Contains(nodes[lastPoint]))
            {
                List <Rules> usedOnes = new List <Rules>();
START0:
                Rules rulesUsing = PickRule(nodes[lastPoint], usedOnes, "");
                usedOnes.Add(rulesUsing);
                if (endProg)
                {
                    goto Endofit;
                }
                file.Write("   " + iteration + ") Goal " + nodes[lastPoint].getName() + ". Find R" + rulesUsing.getRuleNo() + ":");
                iteration++;

                if (rulesUsing.getRulElem() == 3)
                {
                    rulesUsing.getNode().calledP();
                    file.WriteLine(rulesUsing.getNode().getName() + "," + rulesUsing.getNode2().getName() + "," + rulesUsing.getNode3().getName() +
                                   "->" + rulesUsing.getAim().getName() + ". New goals " +
                                   rulesUsing.getNode().getName() + ", " + rulesUsing.getNode2().getName() + ", " + rulesUsing.getNode3().getName() + ".");
                    if (Procedure_Search2(rulesUsing.getNode(), 1))
                    {
                        nodeBank.Add(rulesUsing.getNode());
                        rulesUsing.getNode2().calledP();
                        iteration++;
                        if (Procedure_Search2(rulesUsing.getNode2(), 2))
                        {
                            nodeBank.Add(rulesUsing.getNode2());
                            rulesUsing.getNode3().calledP();
                            iteration++;
                            if (Procedure_Search2(rulesUsing.getNode3(), 3))
                            {
                                nodeBank.Add(rulesUsing.getNode3());
                                trePlus = 0;
                                initialState(rulesUsing.getNode3(), "-");
                                file.WriteLine(". Back, OK.");

                                iteration++;
                                rulesUsed.Add(rulesUsing);
                                goal = true;
                            }
                            else
                            {
                                nodeBank.Remove(rulesUsing.getNode2());
                            }
                        }
                        else
                        {
                            nodeBank.Remove(rulesUsing.getNode());
                        }
                    }
                }
                else if (rulesUsing.getRulElem() == 2)
                {
                    rulesUsing.getNode().calledP();
                    file.WriteLine(rulesUsing.getNode().getName() + "," + rulesUsing.getNode2().getName() +
                                   "->" + rulesUsing.getAim().getName() + ". New goals " +
                                   rulesUsing.getNode().getName() + "," + rulesUsing.getNode2().getName() + ".");
                    if (Procedure_Search2(rulesUsing.getNode(), 1))
                    {
                        nodeBank.Add(rulesUsing.getNode());
                        initialState(rulesUsing.getNode(), "-");
                        file.WriteLine(". Back, OK.");
                        rulesUsing.getNode2().calledP();
                        nodeZero();
                        iteration++;
                        if (Procedure_Search2(rulesUsing.getNode2(), 1))
                        {
                            if (!nodeBank.Contains(rulesUsing.getNode2()))
                            {
                                nodeBank.Add(rulesUsing.getNode2());
                            }
                            trePlus = 0;
                            initialState(rulesUsing.getNode2(), "-");
                            file.WriteLine(". Back, OK.");

                            iteration++;
                            rulesUsed.Add(rulesUsing);
                            goal = true;
                        }
                        else
                        {
                            nodeBank.Remove(rulesUsing.getNode());
                        }
                    }
                }
                else
                {
                    rulesUsing.getNode().calledP();
                    file.WriteLine(rulesUsing.getNode().getName() +
                                   "->" + rulesUsing.getAim().getName() + ". New goal " +
                                   rulesUsing.getNode().getName() + ".");
                    if (Procedure_Search2(rulesUsing.getNode(), 1))
                    {
                        if (!nodeBank.Contains(rulesUsing.getNode()))
                        {
                            nodeBank.Add(rulesUsing.getNode());
                        }
                        trePlus = 0;
                        initialState(rulesUsing.getNode(), "-");
                        file.WriteLine(". Back, OK.");

                        iteration++;
                        rulesUsed.Add(rulesUsing);
                        goal = true;
                    }
                }

                if (goal)
                {
                    nodeBank.Add(nodes[lastPoint]);
                    initialState(nodes[lastPoint], "");
                    file.WriteLine(". OK.");
                }
                if (rulesUsing != null && !goal)
                {
                    rulesUsed.Clear();
                    goto START0;
                }
Endofit:
                break;
            }
        }
Ejemplo n.º 2
0
        static bool Procedure_Search2(Node goalNode, int step)
        {
            earlyInfered = goalNode;
            string       tre      = new string('-', step);
            List <Rules> usedOnes = new List <Rules>();

START1:
            if (nodeBank.Contains(goalNode))
            {
                return(true);
            }
            Rules rulesUsing = PickRule(goalNode, usedOnes, tre);

            usedOnes.Add(rulesUsing);
            if (rulesUsing != null)
            {
                file.Write("   " + iteration + ") " + tre + "Goal " + goalNode.getName() + ". Find R" + rulesUsing.getRuleNo() + ":");
                iteration++;


                if (rulesUsing.getRulElem() == 3)
                {
                    rulesUsing.getNode().calledP();

                    file.WriteLine(rulesUsing.getNode().getName() + "," + rulesUsing.getNode2().getName() + "," + rulesUsing.getNode3().getName() +
                                   "->" + rulesUsing.getAim().getName() + ". New goals " +
                                   rulesUsing.getNode().getName() + ", " + rulesUsing.getNode2().getName() + ", " + rulesUsing.getNode3().getName() + ".");
                    if (Procedure_Search2(rulesUsing.getNode(), step + 1))
                    {
                        if (!nodeBank.Contains(rulesUsing.getNode()))
                        {
                            nodeBank.Add(rulesUsing.getNode());
                        }
                        rulesUsing.getNode2().calledP();

                        if (Procedure_Search2(rulesUsing.getNode2(), step + 2))
                        {
                            if (!nodeBank.Contains(rulesUsing.getNode2()))
                            {
                                nodeBank.Add(rulesUsing.getNode2());
                            }

                            rulesUsing.getNode3().calledP();
                            if (Procedure_Search2(rulesUsing.getNode3(), step + 3))
                            {
                                if (earlyInfered == rulesUsing.getNode3() && trePlus < 1)
                                {
                                    trePlus++;
                                }
                                if (!nodeBank.Contains(rulesUsing.getNode3()))
                                {
                                    nodeBank.Add(rulesUsing.getNode3());
                                }
                                initialState(rulesUsing.getNode3(), tre);
                                iteration++;
                                rulesUsed.Add(rulesUsing);
                                file.WriteLine(". Back, OK.");
                                return(true);
                            }
                        }
                        else
                        {
                            nodeBank.Remove(rulesUsing.getNode2());
                        }
                    }
                    nodeBank.Remove(rulesUsing.getNode());
                }
                else if (rulesUsing.getRulElem() == 2)
                {
                    rulesUsing.getNode().calledP();

                    file.WriteLine(rulesUsing.getNode().getName() + "," + rulesUsing.getNode2().getName() +
                                   "->" + rulesUsing.getAim().getName() + ". New goals " +
                                   rulesUsing.getNode().getName() + "," + rulesUsing.getNode2().getName() + ".");
                    if (Procedure_Search2(rulesUsing.getNode(), step + 1))
                    {
                        if (!nodeBank.Contains(rulesUsing.getNode()))
                        {
                            nodeBank.Add(rulesUsing.getNode());
                        }
                        rulesUsing.getNode2().calledP();
                        if (Procedure_Search2(rulesUsing.getNode2(), step + 2))
                        {
                            if (earlyInfered == rulesUsing.getNode2() && trePlus < 1)
                            {
                                trePlus++;
                            }
                            if (!nodeBank.Contains(rulesUsing.getNode2()))
                            {
                                nodeBank.Add(rulesUsing.getNode2());
                            }
                            initialState(rulesUsing.getNode2(), tre);
                            iteration++;
                            file.WriteLine(". Back, OK.");
                            rulesUsed.Add(rulesUsing);
                            return(true);
                        }
                    }
                    else
                    {
                        nodeBank.Remove(rulesUsing.getNode());
                    }
                }
                else
                {
                    rulesUsing.getNode().calledP();
                    file.WriteLine(rulesUsing.getNode().getName() +
                                   "->" + rulesUsing.getAim().getName() + ". New goal " +
                                   rulesUsing.getNode().getName() + ".");
                    if (Procedure_Search2(rulesUsing.getNode(), step + 1))
                    {
                        if (earlyInfered == rulesUsing.getNode() && trePlus < 1)
                        {
                            trePlus++;
                        }
                        if (!nodeBank.Contains(rulesUsing.getNode()))
                        {
                            nodeBank.Add(rulesUsing.getNode());
                        }
                        initialState(rulesUsing.getNode(), tre);
                        iteration++;
                        file.WriteLine(". Back, OK.");
                        rulesUsed.Add(rulesUsing);
                        return(true);
                    }
                }
            }

            if (rulesUsing == null)
            {
                return(false);
            }
            else
            {
                goto START1;
            }
        }