Ejemplo n.º 1
0
        public static void checkForRuleFile(ruleSet rs, List <string> ruleFiles, string str)
        {
            if (!str.EndsWith(".cs"))
            {
                str += ".cs";
            }
            if (ruleFiles.Contains(str))
            {
                SearchIO.output(rs.name + " already contains a reference to code file, " + str + ".");
            }

            else if (!File.Exists(rs.rulesDir + str))
            {
                var result =
                    MessageBox.Show("Source File " + rs.rulesDir + str
                                    + " not found. Would you like to create it?", "File not found.",
                                    MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result == MessageBoxResult.Yes)
                {
                    createRulesSourceFile(rs.rulesDir + str);
                    ruleFiles.Add(str);
                }
            }
            else
            {
                SearchIO.output("Code file, " + str + " found: Adding file reference to ruleset.");
                ruleFiles.Add(str);
            }
        }
Ejemplo n.º 2
0
        internal void Update(ruleSet RuleSet, ruleSetWindow rsW)
        {
            SelectedRuleSet = RuleSet;
            txtName.Text    = rsW.Title;
            for (int i = 0; i < GSApp.settings.rulesets.GetLength(0); i++)
            {
                if (SelectedRuleSet.Equals(GSApp.settings.rulesets[i]))
                {
                    txtName.Text += " (set to RuleSet #" + i + ")";
                    break;
                }
            }

            txtTriggerRuleNo.Text = SelectedRuleSet.TriggerRuleNum.ToString();

            cmdChoiceMethod.SelectedIndex = cmdChoiceMethod.Items.IndexOf(SelectedRuleSet.choiceMethod);

            cmdInterimCandidates.SelectedIndex = cmdInterimCandidates.Items.IndexOf(SelectedRuleSet.interimCandidates);
            cmdFinalCandidates.SelectedIndex   = cmdFinalCandidates.Items.IndexOf(SelectedRuleSet.finalCandidates);

            cmdAfterNormalCycle.SelectedIndex = cmdAfterNormalCycle.Items.IndexOf(SelectedRuleSet.generationAfterNormal);
            cmdChoiceSendsStop.SelectedIndex  = cmdChoiceSendsStop.Items.IndexOf(SelectedRuleSet.generationAfterChoice);
            cmdNoOfCallsReached.SelectedIndex =
                cmdNoOfCallsReached.Items.IndexOf(SelectedRuleSet.generationAfterCycleLimit);
            cmdNoRulesRecognized.SelectedIndex =
                cmdNoRulesRecognized.Items.IndexOf(SelectedRuleSet.generationAfterNoRules);
            cmdTriggerRuleInvoked.SelectedIndex =
                cmdTriggerRuleInvoked.Items.IndexOf(SelectedRuleSet.generationAfterTriggerRule);
            txtRecognizeSourceFiles.Text = StringCollectionConverter.Convert(SelectedRuleSet.recognizeSourceFiles);
            txtApplySourceFiles.Text     = StringCollectionConverter.Convert(SelectedRuleSet.applySourceFiles);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Loads the default seed and rule sets.
 /// </summary>
 public void LoadDefaultSeedAndRuleSets()
 {
     try
     {
         rulesets = new ruleSet[numOfRuleSets];
         SearchIO.output("There are " + numOfRuleSets + " rulesets.");
         var filename = getOpenFilename(InputDirAbs, DefaultSeedFileName);
         if (filename != "")
         {
             var graphAndCanvas = filer.Open(filename, true);
             if (graphAndCanvas == null)
             {
                 seed = null;
                 DefaultSeedFileName = "";
                 SearchIO.MessageBoxShow("The seed graph was not found. Please change to valid file"
                                         + " in settings.", "Seed Graph Not Found.", "Error");
             }
             else
             {
                 seed = (designGraph)graphAndCanvas[0];
                 DefaultSeedFileName = filename;
                 SearchIO.addAndShowGraphWindow(graphAndCanvas,
                                                "SEED: " + Path.GetFileNameWithoutExtension(filename));
                 SearchIO.output("Seed graph, " + Path.GetFileNameWithoutExtension(filename) + " ,successfully opened.");
             }
         }
         for (var i = 0; i < numOfRuleSets; i++)
         {
             var RSFileName = "";
             if (i < defaultRSFileNames.Count)
             {
                 RSFileName = defaultRSFileNames[i];
             }
             filename = getOpenFilename(RulesDirAbs, RSFileName);
             if (filename == "")
             {
                 continue;
             }
             object objRS = filer.Open(filename, true);
             if (objRS == null)
             {
                 rulesets[i]           = null;
                 defaultRSFileNames[i] = "";
                 SearchIO.output("No Rule Set found at #" + i + ".");
             }
             else
             {
                 rulesets[i] = (ruleSet)((object[])objRS)[0];
                 SearchIO.addAndShowRuleSetWindow(new object[] { rulesets[i], filename },
                                                  "RS" + i + ": " + Path.GetFileNameWithoutExtension(filename));
                 // SearchIO.output("Rule Set #" + i + " sucessfully opened.");
             }
         }
     }
     catch (Exception exc)
     {
         ErrorLogger.Catch(exc);
     }
 }
Ejemplo n.º 4
0
        public ruleSetDisplay(ruleSet rules, string formTitle)
        {
            this.MdiParent = Program.main;
            InitializeComponent();

            ruleset   = rules;
            this.Text = formTitle;

            rules.initPropertiesBag();
            this.propertyGrid1.SelectedObject = rules.Bag;
            this.GotFocus += new EventHandler(ruleSetDisplay_Enter);
            this.Enter    += new EventHandler(ruleSetDisplay_Enter);
        }
Ejemplo n.º 5
0
        public void addAndShowRuleSetWindow(object obj, string title = null)
        {
            var    rs       = new ruleSet();
            string filename = null;

            if (obj == null)
            {
                rs = null;
            }
            else if (obj is ruleSet)
            {
                rs = (ruleSet)obj;
            }
            else if (obj is object[])
            {
                var objArray = (object[])obj;
                if (objArray.GetLength(0) > 0)
                {
                    if (objArray[0] is ruleSet)
                    {
                        rs = (ruleSet)objArray[0];
                    }
                    else if (objArray[0] is string)
                    {
                        filename = (string)objArray[0];
                    }
                }
                if (objArray.GetLength(0) > 1)
                {
                    if (objArray[1] is ruleSet)
                    {
                        rs = (ruleSet)objArray[1];
                    }
                    else if (objArray[1] is string)
                    {
                        filename = (string)objArray[1];
                    }
                }
            }
            if (title == null)
            {
                title = rs.name;
            }
            if (!windowsMgr.FindAndFocusFileInCollection(filename, WindowType.RuleSet))
            {
                var rSW = new ruleSetWindow(rs, filename, title);
                windowsMgr.AddandShowWindow(rSW);
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 ///   Runs the search process.
 /// </summary>
 public void RunSearchProcess()
 {
     if ((numOfRuleSets > 0) && (RequiredNumRuleSets > 0))
     {
         rulesets = new ruleSet[settings.numOfRuleSets];
         for (var i = 0; i < settings.numOfRuleSets; i++)
         {
             rulesets[i] = settings.rulesets[i];
         }
         ruleSet.loadAndCompileSourceFiles(rulesets, settings.RecompileRuleConditions,
                                           settings.CompiledRuleFunctions, GlobalSettings.ExecDir);
     }
     Run();
     rulesets = null;
 }
Ejemplo n.º 7
0
        /// <summary>
        ///   Opens the rule set.
        /// </summary>
        /// <param name = "filename">The filename.</param>
        /// <returns></returns>
        public virtual ruleSet OpenRuleSet(string filename)
        {
            ruleSet      newRuleSet = null;
            StreamReader ruleReader = null;

            try
            {
                ruleReader = new StreamReader(filename);
                var ruleDeserializer = new XmlSerializer(typeof(ruleSet));
                newRuleSet          = (ruleSet)ruleDeserializer.Deserialize(ruleReader);
                newRuleSet.rulesDir = Path.GetDirectoryName(filename) + Path.DirectorySeparatorChar;
                newRuleSet.filer    = this;
                var numRules = newRuleSet.ruleFileNames.Count;
                int numLoaded;
                newRuleSet.rules = LoadRulesFromFileNames(newRuleSet.rulesDir,
                                                          newRuleSet.ruleFileNames, out numLoaded);

                SearchIO.output(Path.GetFileName(filename) + " successfully loaded");
                if (numRules == numLoaded)
                {
                    SearchIO.output(" and all (" + numLoaded + ") rules loaded successfully.");
                }
                else
                {
                    SearchIO.output("     but "
                                    + (numRules - numLoaded) + " rules did not load.");
                }

                if ((string.IsNullOrWhiteSpace(newRuleSet.name)) || (newRuleSet.name == "Untitled"))
                {
                    newRuleSet.name = Path.GetFileNameWithoutExtension(filename);
                }
            }
            catch (Exception ioe)
            {
                SearchIO.output("***XML Serialization Error***");
                SearchIO.output(ioe.ToString());
            }
            finally
            {
                if (ruleReader != null)
                {
                    ruleReader.Close();
                }
            }

            return(newRuleSet);
        }
Ejemplo n.º 8
0
        /// <summary>
        ///   Reloads the specific rule.
        /// </summary>
        /// <param name = "rs">The rs.</param>
        /// <param name = "i">The i.</param>
        public virtual void ReloadSpecificRule(ruleSet rs, int i)
        {
            var rulePath = rs.rulesDir + rs.ruleFileNames[i];

            SearchIO.output("Loading " + rs.ruleFileNames[i]);
            object ruleObj = Open(rulePath);

            if (ruleObj is grammarRule)
            {
                rs.rules[i] = (grammarRule)ruleObj;
            }
            else if (ruleObj is object[] &&
                     ((object[])ruleObj)[0] is grammarRule)
            {
                rs.rules[i] = ((grammarRule)((object[])ruleObj)[0]);
            }
        }
Ejemplo n.º 9
0
 public override void ReloadSpecificRule(ruleSet rs, int i)
 {
     lock (fileTransfer)
     {
         dispatch.Invoke((ThreadStart) delegate
         {
             var rulePath = rs.rulesDir + rs.ruleFileNames[i];
             SearchIO.output("Loading " + rs.ruleFileNames[i]);
             object ruleObj = Open(rulePath);
             if (ruleObj is grammarRule)
             {
                 rs.rules[i] = (grammarRule)ruleObj;
             }
             else if (ruleObj is object[] &&
                      ((object[])ruleObj)[0] is grammarRule)
             {
                 rs.rules[i] = ((grammarRule)((object[])ruleObj)[0]);
             }
         });
     }
 }
Ejemplo n.º 10
0
        public ruleSetWindow(ruleSet rs, string filename, string title)
        {
            try
            {
                /* the following is common to all GS window types. */
                InitializeComponent();
                Owner         = main;
                ShowInTaskbar = false;
                foreach (CommandBinding cb in main.CommandBindings)
                {
                    CommandBindings.Add(cb);
                }
                foreach (InputBinding ib in main.InputBindings)
                {
                    InputBindings.Add(ib);
                }
                /***************************************************/
                this.Ruleset  = rs;
                this.Filename = !string.IsNullOrEmpty(filename) ? filename : "Untitled";
                Title         = !string.IsNullOrEmpty(title) ? title : Path.GetFileNameWithoutExtension(this.Filename);

                listBoxOfRules.Items.Clear();
                for (var i = 1; i <= rs.rules.Count; i++)
                {
                    var li = new ListBoxItem
                    {
                        Content = i + ". " + rs.ruleFileNames[(i - 1)]
                    };
                    listBoxOfRules.Items.Add(li);
                }
                initializeFileWatcher(rs.rulesDir);
            }
            catch (Exception exc)
            {
                ErrorLogger.Catch(exc);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        ///   Saves the rule set.
        /// </summary>
        /// <param name = "filename">The filename.</param>
        /// <param name = "ruleSetToSave">The rule set to save.</param>
        protected void SaveRuleSet(string filename, ruleSet ruleSetToSave)
        {
            StreamWriter ruleWriter = null;

            try
            {
                //ruleSetToSave.name = Path.GetFileNameWithoutExtension(filename);
                ruleWriter = new StreamWriter(filename);
                var ruleSerializer = new XmlSerializer(typeof(ruleSet));
                ruleSerializer.Serialize(ruleWriter, ruleSetToSave);
            }
            catch (Exception ioe)
            {
                SearchIO.output("***XML Serialization Error***");
                SearchIO.output(ioe.ToString());
            }
            finally
            {
                if (ruleWriter != null)
                {
                    ruleWriter.Close();
                }
            }
        }
Ejemplo n.º 12
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);
            }
        }
Ejemplo n.º 13
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string filename;

            try
            {
                filename = getOpenFilename(Program.settings.workingDirectory);
            }
            catch { filename = ""; }
            if (filename != "" && filename != null)
            {
                /* Load the file. */
                XmlDocument doc = new XmlDocument();
                doc.Load(filename);
                /* create prefix<->namespace mappings (if any)  */
                XmlNamespaceManager nsMgr = new XmlNamespaceManager(doc.NameTable);
                /* Query the document */
                if (doc.SelectNodes("/grammarRule", nsMgr).Count > 0)
                {
                    grammarRule rule = grammarRule.openRuleFromXml(filename);
                    grammarDisplays.Add(new grammarRuleDisplay(rule, Path.GetFileName(filename)));
                    grammarDisplays[grammarChildCount].Show();
                }
                else if (doc.SelectNodes("/ruleSet", nsMgr).Count > 0)
                {
                    ruleSet rs = ruleSet.openRuleSetFromXml(filename, Program.settings.defaultGenSteps);
                    ruleSetDisplays.Add(new ruleSetDisplay(rs, Path.GetFileName(filename)));
                    ruleSetDisplays[ruleSetChildCount].Show();
                }
                else if (doc.SelectNodes("/designGraph", nsMgr).Count > 0)
                {
                    designGraph graph = designGraph.openGraphFromXml(filename);
                    addAndShowGraphDisplay(graph, Path.GetFileName(filename));
                }
                else if (doc.SelectNodes("/candidate", nsMgr).Count > 0)
                {
                    string    tempString = "";
                    candidate c          = candidate.openCandidateFromXml(filename);
                    SearchIO.output("The candidate found in " + filename, 0);
                    if (c.performanceParams.Count > 0)
                    {
                        tempString = "has the following performance parameters";
                        foreach (double a in c.performanceParams)
                        {
                            tempString += ": " + a.ToString();
                        }
                        SearchIO.output(tempString, 0);
                    }
                    if (c.age > 0)
                    {
                        SearchIO.output("The candidate has existed for " + c.age.ToString() + " iterations.", 0);
                    }
                    SearchIO.output("It's generation ended in RuleSet #" + c.activeRuleSetIndex.ToString(), 0);
                    tempString = "Generation terminated with";
                    foreach (GenerationStatuses a in c.GenerationStatus)
                    {
                        tempString += ": " + a.ToString();
                    }
                    SearchIO.output(tempString, 0);

                    addAndShowGraphDisplay(c.graph, "Candidate in " + Path.GetFileName(filename));
                }
                else
                {
                    MessageBox.Show("The XML files that you have attempted to open contains an unknown" +
                                    "type (not designGraph, grammarRule, ruleSet, or candidate).", "XML Serialization Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
Ejemplo n.º 14
0
 public void addAndShowRuleSetDisplay(ruleSet rs, string title)
 {
     ruleSetDisplays.Add(new ruleSetDisplay(rs, title));
     ruleSetDisplays[ruleSetChildCount].Show();
 }