Ejemplo n.º 1
0
        public FileParsingResult ParseFiles(string netPath, string specPath)
        {
            ParseRuleResponse conditionAndExperiments;
            var links = GetConditionAndExperiments(netPath, specPath, out conditionAndExperiments);

            var automates =
                conditionAndExperiments.Experiments.ToDictionary(s => s.Key,
                                                                 s => new AutomataFromExperimentCreator().CreateAutomata(s.Value));

            var res              = new List <GeneNode>();
            var availableNodes   = new Stack <GeneNode>(automates.Select(a => a.Value).ToList());
            var backTrackingNode = AutomataMergeLogic.CreateBackTrackingNodeFromStack(availableNodes, 0);

            // find merges
            var automataMergeLogic = new AutomataMergeLogic();

            automataMergeLogic
            .GetFinalMerges(availableNodes, links, res, backTrackingNode);

            // handle not merged experiments
            availableNodes.Where(d => NotExistInMerges(d, res)).ToList().ForEach(f =>
            {
                f = automataMergeLogic.ApplyAllPossibleLoops(f, links);
                res.Add(f);
            });

            var merges = res
                         .Take(100)
                         .Select(a => a.ToFullViewAutomata(automates))
                         .ToList();

            logger.Info($"Finish merges found {merges.Count} valid merges");


            /*   var allMerges = new AutomataMergeLogic()
             *     .GetMerges(automates.Select(a => a.Value).ToList())
             *     .Take(100)
             *     .Select(a => a.ToViewAutomata())
             *     .ToList();
             */

            var automatesView = automates
                                .ToDictionary(a => a.Key, a => a.Value.ToViewAutomata());

            var backTrackingAutomata = backTrackingNode?.ToViewAutomata();

            logger.Info("BackTracing");
            logger.Info(JsonConvert.SerializeObject(backTrackingAutomata, Formatting.Indented));
            return(new FileParsingResult()
            {
                GeneLinks = links,
                Conditions = conditionAndExperiments.Conditions,
                Experiments = conditionAndExperiments.Experiments,
                Automates = automatesView,
                Merges = merges,
                BackTrackingNode = backTrackingAutomata,
                MergeObjects = res
                               //AllMerges = allMerges
            });
        }
Ejemplo n.º 2
0
        public void TestToyMultipleLoopTest()
        {
            var automata1 = new GeneNode()
            {
                NodeName         = "a0",
                CurrentCondition = new Condition()
                {
                    { "A", true }, { "B", true }, { "C", true }, { "S1", false }, { "S2", true }
                },
                Transitions = new List <GeneTransition>()
                {
                    new GeneTransition()
                    {
                        Node = new GeneNode()
                        {
                            NodeName         = "a1",
                            CurrentCondition = new Condition()
                            {
                                { "A", false }, { "B", true }, { "C", true }, { "S1", false }, { "S2", true }
                            },
                            Transitions = new List <GeneTransition>()
                            {
                                new GeneTransition()
                                {
                                    Node = new GeneNode()
                                    {
                                        NodeName         = "a2",
                                        CurrentCondition = new Condition()
                                        {
                                            { "A", false }, { "B", true }, { "C", true }, { "S1", false }, { "S2", true }
                                        },
                                        Transitions = new List <GeneTransition>()
                                        {
                                            new GeneTransition()
                                            {
                                                Node = new GeneNode()
                                                {
                                                    NodeName         = "a3",
                                                    CurrentCondition = new Condition()
                                                    {
                                                        { "A", false }, { "B", true }, { "C", true }, { "S1", false }, { "S2", true }
                                                    },
                                                }
                                            },
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            List <GeneLink> booleanNetwok = new List <GeneLink>()
            {
                new GeneLink()
                {
                    From = "S2", To = "B", IsPositive = true
                },
                new GeneLink()
                {
                    From = "S1", To = "A", IsPositive = true
                },
                new GeneLink()
                {
                    From = "S1", To = "S1", IsPositive = true
                },
                new GeneLink()
                {
                    From = "S2", To = "S2", IsPositive = true
                },
            };

            var mergeLogic = new AutomataMergeLogic();
            var res        = mergeLogic.ApplyAllPossibleLoops(automata1, booleanNetwok);

            Assert.IsNotNull(res);
        }