Пример #1
0
 public RecognizeChooseApply(designGraph _seed, ruleSet[] _rulesets, int[] _maxNumOfCalls, Boolean _display)
 {
     SearchIO.output("initializing generation:", 4);
     this.numOfRuleSets = _rulesets.GetLength(0);
     this.rulesets      = new ruleSet[numOfRuleSets];
     for (int i = 0; i != numOfRuleSets; i++)
     {
         rulesets[i] = _rulesets[i].copy();
     }
     SearchIO.output("There are " + numOfRuleSets + " rule sets.", 4);
     this.seed = new candidate(_seed.copy(), numOfRuleSets);
     SearchIO.output("Seed = " + seed.graph.name, 4);
     maxNumOfCalls = _maxNumOfCalls;
     this.display  = _display;
     SearchIO.output("It is " + display.ToString() + " that the SearchIO will be displayed.", 4);
 }
Пример #2
0
        public static void Run(designGraph seed, grammarRule rule, Relaxation RelaxationTemplate = null)
        {
            try
            {
                if (RelaxationTemplate == null)
                {
                    RelaxationTemplate = new Relaxation(0);
                }
                var rnd             = new Random();
                int k               = 0;
                var continueTesting = true;

                SearchIO.output("begin recognizing rule: " + rule.name + "on graph :" + seed.name, 2);
                var dummyRS = new ruleSet();
                dummyRS.Add(rule);
                if (SearchIO.GetTerminateRequest(Thread.CurrentThread.ManagedThreadId))
                {
                    return;
                }
                var options = dummyRS.recognize(seed, false, RelaxationTemplate.copy());
                if (SearchIO.GetTerminateRequest(Thread.CurrentThread.ManagedThreadId))
                {
                    return;
                }
                var numOptions = options.Count;
                if (numOptions == 0)
                {
                    if (MessageBox.Show("There were no recognized options. Should the rule be relaxed?", "Test Rule Status",
                                        MessageBoxButton.YesNo, MessageBoxImage.Asterisk, MessageBoxResult.No) ==
                        MessageBoxResult.Yes)
                    {
                        Run(seed, rule, new Relaxation(RelaxationTemplate.NumberAllowable + 1));
                    }
                    return;
                }
                do
                {
                    var status = "There ";
                    int choice = -1;
                    switch (numOptions)
                    {
                    case 0: throw new Exception("Should not be able to reach here. (Test Rule Chooser, zero options.)");

                    case 1:
                        status += "was only one recognized option and it applied as shown.\n";
                        choice  = 0;
                        status += options[choice].Relaxations.RelaxationSummary;
                        break;

                    default:
                        status += "were " + numOptions + " recognized locations.\n";
                        choice  = rnd.Next(options.Count);
                        status += options[choice].Relaxations.RelaxationSummary;
                        option.AssignOptionConfluence(options, new candidate(seed, 0), ConfluenceAnalysis.Full);
                        var numberWithConfluence = options.Count(o => (o.confluence.Count > 0));
                        var maxConfluence        = options.Max(o => o.confluence.Count);
                        var withMaxConfluence    = options.Count(o => (o.confluence.Count == maxConfluence));
                        if (numberWithConfluence > 0)
                        {
                            status += "Confluence existed between " + numberWithConfluence + " of them";
                            if (maxConfluence > 1)
                            {
                                status += "; \nwith " + withMaxConfluence + " options having a confluence with "
                                          + maxConfluence + " other options.\n";
                            }
                            else
                            {
                                status += ".\n";
                            }
                        }
                        status += "Option #" + choice + " was randomly chosen, and invoked.\n";
                        break;
                    }
                    if (!continueTesting)
                    {
                        continue;
                    }
                    if (SearchIO.GetTerminateRequest(Thread.CurrentThread.ManagedThreadId))
                    {
                        return;
                    }
                    var chosenOption = options[choice];
                    {
                        var seedCopy = seed.copy();
                        SearchProcess.transferLmappingToChild(seedCopy, seed, chosenOption);
                        seed = seedCopy;
                    }
                    chosenOption.apply(seed, null);
                    SearchIO.output("Rule sucessfully applied", 4);
                    SearchIO.addAndShowGraphWindow(seed, "After calling " + ++k + " rules");
                    if (SearchIO.GetTerminateRequest(Thread.CurrentThread.ManagedThreadId))
                    {
                        return;
                    }
                    options = dummyRS.recognize(seed, true, RelaxationTemplate.copy());
                    if (SearchIO.GetTerminateRequest(Thread.CurrentThread.ManagedThreadId))
                    {
                        return;
                    }
                    numOptions = options.Count;
                    switch (numOptions)
                    {
                    case 0:
                        status         += "There are no recognized locations on the new graph";
                        continueTesting = false;
                        MessageBox.Show(status, "Test Rule Status", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                        break;

                    case 1:
                        status         += "There is one recognized location on the new graph. Would you like to invoke it?";
                        continueTesting = (MessageBox.Show(status, "Continue Applying?", MessageBoxButton.YesNo,
                                                           MessageBoxImage.Asterisk, MessageBoxResult.No) ==
                                           MessageBoxResult.Yes);
                        break;

                    default:
                        status += "There are " + options.Count + " recognized locations on the new graph. Would you "
                                  + "like to randomly invoke one?";
                        continueTesting = (MessageBox.Show(status, "Continue Applying?", MessageBoxButton.YesNo,
                                                           MessageBoxImage.Asterisk, MessageBoxResult.No) ==
                                           MessageBoxResult.Yes);
                        break;
                    }
                } while (continueTesting);
            }
            catch (Exception exc)
            {
                ErrorLogger.Catch(exc);
            }
        }