Example #1
0
 /// <summary>
 /// list musí mít 63 a méně vrcholů
 /// </summary>
 /// <param name="list"></param>
 /// <returns></returns>
 public long VerticesToState(IList <VertexStack> list)
 {
     return(LongBinaryStatesWithHashSet.VerticesToStateStatic(list));
 }
        /// <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;
                    }
                }
            }
        }