コード例 #1
0
        /// <summary>
        /// Builds a full triarc in this.triarc following sequence of boundary from constructor.
        /// </summary>
        private void reconstructTriarc()
        {
            List <VertexStack> active = triarc.ActiveVertices();
            long boundaryFromActive   = (LongBinaryStatesWithHashSet.VerticesToStateStatic(active)).BoundaryToStandardizedForm();
            int  countOfActiveWithLessThanThreeNeighbours = CountOfVerticesWithLessThanThreeNeighbours(active);

            #region if triarc has been finished
            if (countOfActiveWithLessThanThreeNeighbours == 0 && triarc.FaceSizes.Contains(active.Count))
            {
                triarc.Faces.Add(active.Select(x => x.ID).ToList());
                Console.WriteLine("Triarc has been found, reconstructed and will be saved.");
                ExtractResult();
                if (Global.Count3Connectivity)
                {
                    var conn = "Graph " + (ReconstructionGraph.ThreeConnected.IsGraph3Connected(triarc) ? "is" : "isn't") + " 3-connected";
                    Console.WriteLine(conn);
                }
                found = true;
                return;
            }
            #endregion


            //If this state isn't the one solution suggests.
            if (boundaryFromActive != SequenceOfStatesLeadingToResult.Last() || (countOfActiveWithLessThanThreeNeighbours == 0))
            {
                return;                 //jsme ve špatné větvi výpočtu
            }
            //Else remove it to signal that it has been gone trough.
            SequenceOfStatesLeadingToResult.RemoveAt(SequenceOfStatesLeadingToResult.Count - 1);

            SequencesOfVerticesLeaidngToResult.Add(string.Join <string>(", ", active.Select(
                                                                            x => { return(x.ID.ToString() + (x.HasAllThreeNeighbours() == true ? "out" : "in")); })));

            #region  If there is a restriction on maximal count of vertices, defaultly set to int.maxValue
            if (triarc.CountOfVertices > maxNumberOfVertices)
            {
                Console.WriteLine("Triarc won't be reconstructed due to having more vertices than allowed.");
                Console.WriteLine("The limit is set to " + maxNumberOfVertices);
                return;
            }
            #endregion

            states.Add(active);

            if (countOfActiveWithLessThanThreeNeighbours > 1 && !found)
            {
                var selectWhatToChange = OrderOfExecution(SelectWhatToChange(active).ToArray());
                foreach (var selected in selectWhatToChange)
                {
                    //Conditional debug statements
                    //	WriteDepthAndVertices(active, "active ", true, depth);
                    //	WriteDepthAndVertices(selected, "selected  ", false, depth);

                    foreach (var faceSize in triarc.FaceSizes)
                    {
                        //Skips invalid states
                        if (triarc.FaceSizes[triarc.FaceSizes.Count - 1] < selected.Count)
                        {
                            return;
                        }

                        //Skips invalid state
                        if (faceSize < selected.Count)
                        {
                            continue;
                        }

                        //Prevents multipleEdges and loops
                        if ((selected[0].A == selected[selected.Count - 1] || selected[0].B == selected[selected.Count - 1]) && selected.Count == faceSize)
                        {
                            continue;
                        }

                        int NumberOfVerticesInTriarc = triarc.CountOfVertices;
                        int localRoot = triarc.ActiveRootID;
                        List <VertexStack> replacedBy;

                        Replace(selected, out replacedBy, faceSize);

                        //Conditional debug statements.
                        //		WriteDepthAndVertices(replacedBy, "replaced by", false, depth);

                        triarc.ActiveRootID = selected[0].ID;
                        List <VertexStack> activeNew = triarc.ActiveVertices();

                        string localDepth = depth;
                        depth += ".";

                        //Recursive calling
                        reconstructTriarc();

                        depth = localDepth;

                        if (found)
                        {
                            return;
                        }

                        //Undo changes done by this method before returning
                        triarc.Faces.RemoveAt(triarc.Faces.Count - 1);
                        foreach (var item in selected)
                        {
                            item.Pop();
                        }
                        triarc.vertices.RemoveRange(NumberOfVerticesInTriarc, faceSize - selected.Count);
                        triarc.CountOfVertices = NumberOfVerticesInTriarc;
                        triarc.ActiveRootID    = localRoot;
                    }
                }
            }
        }
コード例 #2
0
 public StatesParserContext(IStates states, string promptPrefix)
 {
     _promptPrefix = promptPrefix;
     Commands      = new[]
     {
         new CommandInformation()
         {
             ArgumentCount         = 1,
             CommandText           = "clear",
             CommandImplementation = (args, parserContextManager) =>
             {
                 states.Clear();
                 return(false);
             }
         },
         new CommandInformation()
         {
             ArgumentCount         = 1,
             CommandText           = "print",
             CommandImplementation = (args, parserContextManager) =>
             {
                 states.ToList().ForEach(state => Console.WriteLine(state.Name));
                 return(false);
             }
         },
         new CommandInformation()
         {
             ArgumentCount         = 2,
             CommandText           = "add",
             CommandImplementation = (args, parserContextManager) =>
             {
                 if (states.Any(state => state.Name == args[1]))
                 {
                     Console.WriteLine($"Duplicate state ignored: {args[1]}");
                 }
                 else
                 {
                     var state = new TestCases.PublicObjects.State()
                     {
                         Name = args[1]
                     };
                     states.Add(state);
                 }
                 return(false);
             }
         },
         new CommandInformation()
         {
             ArgumentCount         = 2,
             CommandText           = "delete",
             CommandImplementation = (args, parserContextManager) =>
             {
                 var item = states.SingleOrDefault(state => state.Name == args[1]);
                 if (item == default(IState))
                 {
                     Console.WriteLine($"Missing state not deleted: {args[1]}");
                 }
                 else
                 {
                     states.Remove(item);
                 }
                 return(false);
             }
         }
     };
 }