Exemple #1
0
        /// <summary>
        /// Returns whether the graph violates angle or carboxyl-blocking constraints.
        /// </summary>
        private static bool IsValidChild(candidate cand, option opt)
        {
            var newCand = cand.copy();
            var newOpt  = opt.copy();

            SearchProcess.transferLmappingToChild(newCand.graph, cand.graph, newOpt);
            newOpt.apply(newCand.graph, null);

            var mol     = OBFunctions.designgraphtomol(newCand.graph);
            var mapping = OBFunctions.findcarboxylates(mol);

            if (mapping.Count < 2)
            {
                return(true);
            }

            var carbA  = mol.GetAtom(mapping[0][1]); // carbon in carboxylate
            var aA     = mol.GetAtom(mapping[0][3]); // atom that the carbon connects to
            var carbB  = mol.GetAtom(mapping[1][1]);
            var aB     = mol.GetAtom(mapping[1][3]);
            var pAngle = OBFunctions.pairwiseangle(carbA, aA, carbB, aB); // angle between carboxylates

            return(!OBFunctions.carboxylatesBlocked(mol, aA, carbA, aB, carbB) && pAngle >= AngleFloor);
        }
Exemple #2
0
        public static void LoadPlugins()
        {
            Assembly searchAssembly = null;

            Type[] searchprocesses;
            var    potentialAssemblies = getPotentialAssemblies(settings.SearchDirAbs);

            potentialAssemblies.Add("thisEXE");
            if (potentialAssemblies.Count == 0)
            {
                return;
            }

            foreach (string filepath in potentialAssemblies)
            {
                try
                {
                    if (filepath == "thisEXE")
                    {
                        searchAssembly = Assembly.GetExecutingAssembly();
                    }
                    else
                    {
                        searchAssembly = Assembly.LoadFrom(filepath);
                    }
                    searchprocesses = searchAssembly.GetExportedTypes();
                    foreach (Type spt in searchprocesses)
                    {
                        if (!spt.IsAbstract && SearchProcess.IsInheritedType(spt) &&
                            !SearchAlgorithms.Any(w => w.GetType().FullName.Equals(spt.FullName)))
                        {
                            LoadSearchAlgo(spt);
                        }
                    }
                }
                catch (Exception exc)
                {
                    if (exc.Message.Equals("Assembly with same name is already loaded"))
                    {
                        continue;
                    }
                    if (searchAssembly == null)
                    {
                        SearchIO.output("Unable to open " + filepath + ": " + exc.Message);
                    }
                    else
                    {
                        SearchIO.output("Unable to open " + searchAssembly.FullName + "(" + filepath + "): " +
                                        exc.Message);
                    }
                }
            }
            //load from this exe
            searchAssembly  = Assembly.GetExecutingAssembly();
            searchprocesses = searchAssembly.GetExportedTypes();
            foreach (Type spt in searchprocesses)
            {
                if (!spt.IsAbstract && SearchProcess.IsInheritedType(spt) &&
                    !SearchAlgorithms.Any(w => w.GetType().FullName.Equals(spt.FullName)))
                {
                    LoadSearchAlgo(spt);
                }
            }
        }
Exemple #3
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);
            }
        }
Exemple #4
0
        public void setUpSearchProcessMenu()
        {
            SearchIO.output("Setting Up Search Process Algorithms");
            var k = 0;

            SearchCommands   = new List <RoutedUICommand>();
            SearchAlgorithms = new List <SearchProcess>();
            while (DesignDropDown.Items.Count > 14)
            {
                DesignDropDown.Items.RemoveAt(14);
            }

            var potentialAssemblies = getPotentialAssemblies(GSApp.settings.SearchDirAbs);

            potentialAssemblies.Add("thisEXE");

            foreach (string filepath in potentialAssemblies)
            {
                Assembly searchAssembly = null;
                try
                {
                    if (filepath == "thisEXE")
                    {
                        searchAssembly = Assembly.GetExecutingAssembly();
                    }
                    else
                    {
                        searchAssembly = Assembly.LoadFrom(filepath);
                    }
                    var searchprocesses = searchAssembly.GetTypes();
                    foreach (Type spt in searchprocesses)
                    {
                        if (!spt.IsAbstract && SearchProcess.IsInheritedType(spt) &&
                            !SearchAlgorithms.Any(w => w.GetType().FullName.Equals(spt.FullName)))
                        {
                            try
                            {
                                var        constructor = spt.GetConstructor(new[] { typeof(GlobalSettings) });
                                var        searchAlgo  = (SearchProcess)constructor.Invoke(new object[] { GSApp.settings });
                                KeyGesture kg          = null;
                                if (k < endOfFKeys)
                                {
                                    kg = new KeyGesture((Key)(k + keyNumOffset), ModifierKeys.None);
                                }
                                else if (k < 2 * endOfFKeys)
                                {
                                    kg = new KeyGesture((Key)(k + keyNumOffset - endOfFKeys), ModifierKeys.Shift);
                                }
                                else if (k < 3 * endOfFKeys)
                                {
                                    kg = new KeyGesture((Key)(k + keyNumOffset - 2 * endOfFKeys),
                                                        ModifierKeys.Control | ModifierKeys.Shift);
                                }
                                else
                                {
                                    MessageBox.Show(
                                        "No shortcut has been assigned to " + searchAlgo.text +
                                        ". That sure is an awful lot "
                                        +
                                        " of search process algorithms! Consider reducing the number included in the plugins directory",
                                        "No ShortCut Assigned", MessageBoxButton.OK);
                                }
                                SearchAlgorithms.Add(searchAlgo);
                                var newSearchCommand = new RoutedUICommand(searchAlgo.text, spt.Name,
                                                                           GetType(), new InputGestureCollection {
                                    kg
                                });
                                SearchCommands.Add(newSearchCommand);
                                CommandBindings.Add(new CommandBinding(newSearchCommand, RunSearchProcessOnExecuted,
                                                                       RunSearchProcessCanExecute));
                                DesignDropDown.Items.Add(new MenuItem {
                                    Command = newSearchCommand
                                });
                                k++;
                                SearchIO.output("\t" + spt.Name + " loaded successfully.");
                            }
                            catch (Exception exc)
                            {
                                SearchIO.output("Unable to load " + spt.Name + ": " + exc.Message);
                            }
                        }
                    }
                }
                catch (Exception exc)
                {
                    if (exc.Message.Equals("Assembly with same name is already loaded"))
                    {
                        continue;
                    }
                    if (searchAssembly == null)
                    {
                        SearchIO.output("Unable to open " + filepath + ": " + exc.Message);
                    }
                    else
                    {
                        SearchIO.output("Unable to open " + searchAssembly.FullName + "(" + filepath + "): " +
                                        exc.Message);
                    }
                }
            }
            if (Directory.Exists(GSApp.settings.SearchDirAbs))
            {
                sWatcher                       = new FileSystemWatcher(GSApp.settings.SearchDirAbs, "*.dll");
                sWatcher.Changed              += SearchDir_Changed;
                sWatcher.Created              += SearchDir_Changed;
                sWatcher.Deleted              += SearchDir_Changed;
                sWatcher.Renamed              += SearchDir_Changed;
                sWatcher.EnableRaisingEvents   = true;
                sWatcher.IncludeSubdirectories = true;
                sWatcher.NotifyFilter          = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                                                 | NotifyFilters.FileName;
            }
        }