/// <summary>
        /// Moves the walker
        /// </summary>
        /// <returns>Node where walker moved onto.</returns>
        public Node Next()
        {
            if (mathUtils.Test(jump))
            {
                current    = Utils.Extensions.GetAtRandom(mnet.GetNodes());
                justJumped = true;
                noAction   = false;
            }
            else
            {
                Layer flattened   = mnet.GetLayer("flattenedNetwork");
                var   layerId     = layerIds[current.Layer.Id];
                var   layerIdTest = mathUtils.Test(transitions, layerId);
                var   newLayer    = mnet.GetLayers().Except(new HashSet <Layer>()
                {
                    flattened
                }).ElementAt(layerIdTest);

                if (current.Layer == newLayer)
                {
                    // Inside same layer.
                    var neigh = mnet.Neighbors(current, EdgeMode.Out);
                    if (neigh.Count == 0)
                    {
                        // Cant move.
                        // No action.
                        noAction = true;
                        return(current);
                    }

                    var rand = mathUtils.GetRandomInt(neigh.Count);
                    current    = neigh.ElementAt(rand);
                    justJumped = false;
                    noAction   = false;
                }
                else
                {
                    // Changing to another node with this actor.
                    var nextNode = mnet.GetNode(current.Actor, newLayer);
                    if (nextNode == null)
                    {
                        // No other nodes with this actor.
                        noAction = true;
                        return(current);
                    }

                    current    = nextNode;
                    justJumped = false;
                    noAction   = false;
                }
            }

            return(current);
        }
        /// <summary>
        /// Flatten layers into single layer.
        /// </summary>
        /// <param name="mnet">Multilayer network.</param>
        /// <param name="newLayerName">Name of the new layer.</param>
        /// <param name="layers">Layers to flatten.</param>
        /// <param name="forceDirected">True if new edges should be directed, false if not.</param>
        /// <param name="forceActors">True if all actors should be on the new layer, false if not.</param>
        /// <returns>Flattened layer.</returns>
        public Layer FlattenUnweighted(MultilayerNetwork mnet, string newLayerName, HashSet <Layer> layers,
                                       bool forceDirected = false, bool forceActors = false)
        {
            var newLayer = createLayer(mnet, newLayerName, layers, forceDirected, forceActors);
            var directed = mnet.IsDirected(newLayer, newLayer);

            foreach (var layer1 in layers)
            {
                foreach (var layer2 in layers)
                {
                    foreach (var edge in mnet.GetEdges(layer1, layer2))
                    {
                        var node1   = mnet.GetNode(edge.V1.Actor, newLayer);
                        var node2   = mnet.GetNode(edge.V2.Actor, newLayer);
                        var newEdge = mnet.GetEdge(node1, node2);

                        if (newEdge == null)
                        {
                            newEdge = mnet.AddEdge(node1, node2);
                        }

                        // If new layer is directed, undirected edges must be added twice in both directions.
                        if (directed && edge.Directionality == EdgeDirectionality.Undirected)
                        {
                            newEdge = mnet.GetEdge(node2, node1);
                            if (newEdge == null)
                            {
                                newEdge = mnet.AddEdge(node2, node1);
                            }
                        }
                    }
                }
            }

            return(newLayer);
        }