コード例 #1
0
        public void LoadTemporalNetworkTest()
        {
            TemporalNetwork net = ExampleData.GetTestNetwork();

            TemporalNetwork.SaveToFile("test.net", net);

            TemporalNetwork net2 = TemporalNetwork.ReadFromFile("test.net");

            Assert.AreEqual(net, net2);
        }
コード例 #2
0
        public static void Run(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("Usage: TempNet filter [temporal_network_original] [filter_file] [temporal_network_new] [undirected=true]");
                return;
            }

            string file_orig = args[1];
            string filter    = args[2];
            string file_new  = args[3];

            bool undirected = true;

            if (args.Length >= 5)
            {
                undirected = Boolean.Parse(args[4]);
            }

            Console.Write("Reading temporal network as {0} network...", undirected?"undirected":"directed");
            TemporalNetwork temp_net = TemporalNetwork.ReadFromFile(file_orig, undirected: undirected);

            Console.WriteLine("done.");

            string[] filtered_edges = System.IO.File.ReadAllLines(filter);

            foreach (string x in filtered_edges)
            {
                if (x.Contains(";"))
                {
                    string[] comps = x.Split(';');
                    temp_net.Remove(new Tuple <string, string>(comps[0], comps[1]));
                }
            }

            TemporalNetwork.SaveToFile(file_new, temp_net);
        }
コード例 #3
0
        /// <summary>
        /// Creates the simple example network with betweenness preference that can be seen in the paper in Figure 2 (right)
        /// </summary>
        /// <param name="args"></param>
        public static void Run(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Usage: TempNet example [output_file]");
                return;
            }

            string out_file = args[1];

            if (!CmdlTools.PromptExistingFile(out_file))
            {
                Console.WriteLine("User opted to exit.");
                return;
            }

            TemporalNetwork temporal_net = new TemporalNetwork();

            int k = 0;

            for (int i = 0; i < 1; i++)
            {
                // Add edges according to two paths
                temporal_net.AddTemporalEdge(k++, "c", "e");
                temporal_net.AddTemporalEdge(k++, "e", "f");

                temporal_net.AddTemporalEdge(k++, "a", "e");
                temporal_net.AddTemporalEdge(k++, "e", "g");

                temporal_net.AddTemporalEdge(k++, "c", "e");
                temporal_net.AddTemporalEdge(k++, "e", "f");

                temporal_net.AddTemporalEdge(k++, "a", "e");
                temporal_net.AddTemporalEdge(k++, "e", "g");

                temporal_net.AddTemporalEdge(k++, "c", "e");
                temporal_net.AddTemporalEdge(k++, "e", "f");

                // Note that the next added edge additionally continues a two-path e -> f -> e
                temporal_net.AddTemporalEdge(k++, "f", "e");
                temporal_net.AddTemporalEdge(k++, "e", "b");

                // An additional edge that will be filtered during preprocessing
                temporal_net.AddTemporalEdge(k++, "e", "b");

                temporal_net.AddTemporalEdge(k++, "c", "e");
                temporal_net.AddTemporalEdge(k++, "e", "f");

                temporal_net.AddTemporalEdge(k++, "b", "e");
                temporal_net.AddTemporalEdge(k++, "e", "g");

                temporal_net.AddTemporalEdge(k++, "c", "e");
                temporal_net.AddTemporalEdge(k++, "e", "f");

                temporal_net.AddTemporalEdge(k++, "c", "e");
                temporal_net.AddTemporalEdge(k++, "e", "f");
            }

            Console.Write("Saving to file ...");
            TemporalNetwork.SaveToFile(out_file, temporal_net);
            Console.WriteLine(" done.");
        }
コード例 #4
0
        public static void Run(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("Usage: TempNet scc [temporal_network_original] [temporal_network_new] [undirected=false] [absolutTime=false]");
                return;
            }

            string file_orig = args[1];
            string file_new  = args[2];

            bool undirected = false;

            bool absoluteTime = false;

            if (args.Length >= 4)
            {
                undirected = Boolean.Parse(args[3]);
            }

            if (args.Length >= 5)
            {
                absoluteTime = Boolean.Parse(args[4]);
            }

            Console.Write("Reading temporal network as {0} network...", undirected?"undirected":"directed");
            TemporalNetwork temp_net = TemporalNetwork.ReadFromFile(file_orig, undirected: undirected);

            Console.WriteLine("done.");

            Console.Write("Extracting two paths and reducing original sequence...");
            temp_net.ReduceToTwoPaths(false, absoluteTime);
            Console.WriteLine("done.");

            Console.Write("Building second order aggregate network...");
            WeightedNetwork net = temp_net.SecondOrderAggregateNetwork;

            Console.WriteLine("done.");

            Console.Write("Extracting largest SCC...");
            net.ReduceToLargestStronglyConnectedComponent();
            Console.WriteLine("done.");

            Console.WriteLine("SCC has {0} nodes", net.VertexCount);

            Console.WriteLine("Filtering disconnected edges in temporal network ... ");
            foreach (var t in temp_net.Keys)
            {
                // Iterate through all edges in this time step
                foreach (var edge in temp_net[t].ToArray())
                {
                    string node = "(" + edge.Item1 + ";" + edge.Item2 + ")";
                    // If this edge is not a node in the second order network
                    if (!net.Vertices.Contains(node))
                    {
                        temp_net[t].Remove(edge);
                    }
                }
            }
            Console.WriteLine("done.");

            Console.Write("Saving new temporal network ... ");
            TemporalNetwork.SaveToFile(file_new, temp_net);
            Console.WriteLine("done.");
        }
コード例 #5
0
        /// <summary>
        /// Outputs a simple example temporal network
        /// </summary>
        /// <param name="args"></param>
        public static void Run(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("Usage: TempNet aggregate [temporal_network_file] [output_file] [aggregationWindow=1] [weighted_aggregate_networks=false]");
                return;
            }

            string out_file          = args[2];
            bool   two_path          = false;
            int    aggregationWindow = 1;

            if (args.Length >= 4)
            {
                aggregationWindow = int.Parse(args[3]);
            }

            if (args.Length >= 5)
            {
                two_path = bool.Parse(args[4]);
            }

            if (!CmdlTools.PromptExistingFile(out_file))
            {
                Console.WriteLine("User opted to exit.");
                return;
            }

            Console.Write("Reading temporal network as undirected...");
            TemporalNetwork temp_net = TemporalNetwork.ReadFromFile(args[1], undirected: true);

            Console.WriteLine(" done.");

            Console.WriteLine(temp_net.Length);
            Console.Write("Applying agggregation window [{0}] ...", aggregationWindow);
            temp_net.AggregateTime(aggregationWindow);
            Console.WriteLine("done.");
            Console.WriteLine(temp_net.Length);

            Console.Write("Reducing to two path networks ...");
            temp_net.ReduceToTwoPaths();
            Console.WriteLine("done.");

            if (!two_path)
            {
                Console.Write("Saving temporal network ...");
                TemporalNetwork.SaveToFile(out_file, temp_net);
                Console.WriteLine(" done.");
            }
            else
            {
                //WeightedNetwork net = new WeightedNetwork();
                //foreach(string tp in temp_net.TwoPathWeights.Keys)
                //{
                //    string[] comps = tp.Split(',');
                //    net.AddEdge(comps[0], comps[2], EdgeType.Directed, temp_net.TwoPathWeights[tp]);
                //}
                Console.Write("Saving weighted first-order aggregate network ...");
                WeightedNetwork.SaveToFile(out_file + ".1.edges", temp_net.AggregateNetwork);
                Console.WriteLine(" done.");

                Console.Write("Saving weighted second-order aggregate network ...");
                WeightedNetwork.SaveToFile(out_file + ".2.edges", temp_net.SecondOrderAggregateNetwork);
                Console.WriteLine(" done.");
            }
        }
コード例 #6
0
        /// <summary>
        /// Creates randomized temporal networks based on a shuffling of edges or two-paths
        /// </summary>
        /// <param name="args"></param>
        public static void Run(string[] args)
        {
            if (args.Length < 4)
            {
                Console.WriteLine("Usage: TempNet shuffle [what] [original_net_file] [output_file] [undirected=false] [length=0]");
                Console.WriteLine("... where [what] is ...");
                Console.WriteLine("\t 'twopaths' \t Shuffle the two-paths in the original network. Preserves the aggregate network and the betweenness preference distribution.");
                Console.WriteLine("\t 'edges' \t Shuffles the edges in the original network. Preserves the aggregate network only.");
                Console.WriteLine("");
                return;
            }
            string shuffling = args[1];
            string out_file  = args[3];

            if (!CmdlTools.PromptExistingFile(out_file))
            {
                Console.WriteLine("User opted to exit.");
                return;
            }

            bool undirected = false;

            if (args.Length >= 5)
            {
                undirected = bool.Parse(args[4]);
            }

            int length = 0;

            if (args.Length == 6)
            {
                length = int.Parse(args[5]);
            }

            TemporalNetwork output = null;

            Console.Write("Reading temporal network as {0} network...", undirected ? "undirected" : "directed");
            TemporalNetwork temp_net = TemporalNetwork.ReadFromFile(args[2], undirected: undirected);

            Console.WriteLine(" done.");

            Console.Write("Extracting two paths and building aggregate network...");

            temp_net.ReduceToTwoPaths();

            Console.WriteLine(" done.");

            if (shuffling == "twopaths")
            {
                Console.Write("Shuffling two paths ...");

                output = TemporalNetworkEnsemble.ShuffleTwoPaths(temp_net, length);

                Console.WriteLine(" done.");
            }
            else if (shuffling == "edges")
            {
                Console.Write("Shuffling edges ...");

                output = TemporalNetworkEnsemble.ShuffleEdges(temp_net, length);

                Console.WriteLine(" done.");
            }
            else
            {
                Console.WriteLine("{0} is not a valid parameter!", shuffling);
            }

            if (output != null)
            {
                Console.Write("Saving temporal network to {0}...", out_file);
                TemporalNetwork.SaveToFile(out_file, output);
                Console.WriteLine(" done.");
            }
        }