Example #1
0
        public Queue <NodeSequence> getQueue(int indexReduction, int indexIncrease, NodeSequence node, Queue <NodeSequence> queue)
        {
            List <int> sequence       = node.sequence;
            var        lengthSequence = sequence.FindLastIndex(x => x != 0);

            if (indexIncrease != indexReduction && indexReduction > 0 && indexReduction < lengthSequence &&
                sequence[indexReduction] - 1 >= sequence[indexReduction + 1] ||
                indexReduction == lengthSequence &&
                sequence[indexIncrease] - sequence[indexReduction] == 0 ||
                indexReduction == lengthSequence && indexReduction - indexIncrease == 1)
            {
                if (indexIncrease > 0 && sequence[indexIncrease - 1] >= sequence[indexIncrease] + 1 || indexIncrease == 0)
                {
                    List <int> newSequence = Clone(sequence);
                    newSequence[indexReduction] -= 1;
                    newSequence[indexIncrease]  += 1;
                    if (isGraphicSequence(newSequence, lengthSequence))
                    {
                        var l = newSequence.FindLastIndex(x => x != 0);
                        int[,] matrix = getAdjacencyMatrix(newSequence, l + 1);
                        var nodeSequence = new NodeSequence(newSequence);;
                        node.children.Add(nodeSequence);
                        nodeSequence.parents.Add(new Tuple <int, int>(indexIncrease, indexReduction), node);
                        if (!used.Contains(nodeSequence.name))
                        {
                            used.Add(nodeSequence.name);
                            nodeSequence.matrix = matrix;
                            queue.Enqueue(nodeSequence);
                        }
                    }
                }
            }

            return(queue);
        }
Example #2
0
        public void drawingSequence(Queue <NodeSequence> sequences)
        {
            while (sequences.Count != 0)
            {
                NodeSequence sequence = sequences.Dequeue();
                foreach (var graph in sequence.graphs)
                {
                    var graphViz = new GraphvizAlgorithm <int, Edge <int> >(graph, @".\", GraphvizImageType.Png);
                    graphViz.FormatVertex += FormatVertex;
                    graphViz.FormatEdge   += FormatEdge;
                    graphViz.Generate(new FileDotEngine(), sequence.name);
                    foreach (var parent in sequence.parents)
                    {
                        var copyGraph = graph.Clone();
                        var soure     = parent.Key.Item1;
                        var target    = parent.Key.Item2;
                        if (copyGraph.VertexCount < soure)
                        {
                            copyGraph.AddVertex(soure);
                        }
                        for (var i = 0; i < sequence.matrix.GetLength(0); i++)
                        {
                            if (sequence.matrix[soure, i] == 1 && i != target)
                            {
                                copyGraph.AddEdge(new Edge <int>(target + 1, i + 1));
                                foreach (var edge in copyGraph.Edges)
                                {
                                    if (edge.Source == soure + 1 && edge.Target == i + 1 || edge.Source == i + 1 && edge.Target == soure + 1)
                                    {
                                        copyGraph.RemoveEdge(edge);
                                        break;
                                    }
                                }

                                break;
                            }
                        }
                        parent.Value.graphs.Add(copyGraph);
                        sequences.Enqueue(parent.Value);
                    }
                }
            }
        }
Example #3
0
        public void bfs(NodeSequence nodeSequence)
        {
            Queue <NodeSequence> queue = new Queue <NodeSequence>();

            queue.Enqueue(nodeSequence);
            while (queue.Count != 0)
            {
                NodeSequence currentSequence = queue.Dequeue();
                var          lengthSequence  = currentSequence.sequence.FindLastIndex(x => x != 0);
                for (var i = 0; i < lengthSequence; i++)
                {
                    var index = currentSequence.sequence.FindIndex(x => x < currentSequence.sequence[i]);
                    queue = getQueue(index, i, currentSequence, queue);
                    index = currentSequence.sequence.FindLastIndex(x => x == currentSequence.sequence[i]);
                    queue = getQueue(index, i, currentSequence, queue);
                    index = currentSequence.sequence.FindLastIndex(x => x != currentSequence.sequence[i]);
                    queue = getQueue(index, i, currentSequence, queue);
                    if (i == lengthSequence - 1 && currentSequence.children.Count == 0)
                    {
                        nodeSequence.maximumGraphicsSequence.Add(currentSequence);
                    }
                }
            }
        }