public static void Main(string[] args) { _graph = new NetworkGraph(); if (args[0] == "gen") { _graph.GenerateNetworkGraph(Utility.MaxNodes, 100); } else if (args[0] == "xml" || args.Length == 0) { var deser = new Deserializer(); var graphData = deser.LoadGraph(); _graph = NetworkGraph.BuildGraphFromXmlGraph(graphData); } else { Console.WriteLine("Invalid command line argument valid options are: 'gen', 'xml', and ''"); return; } while (true) { _graph.KillNode(); Thread.Sleep(2000); } }
public void TrainNetwork(NetworkGraph graph) { teacher = new BackPropagationLearning(network); InputData = GetXvals(); OutputData = GetSinWavePoints(); double error = int.MaxValue; int iteration = 1; while (error > .001) { error = teacher.RunEpoch(InputData, OutputData); graph.AddTitle(string.Format("SIN(x) Iteration {0}-{1:0.00} Error", iteration, error)); graph.ResetData(); int i = 0; foreach (var x in InputData) { graph.AddPoint(x[0], OutputData[i][0], network.Compute(x)[0]); i++; } graph.Update(); Thread.Sleep((int)Math.Max(error, 10)); iteration++; } var asdf = 0; }
public static void traverseDoD(NetworkGraph g) { //starting at 721 print out providers to DoD people. AsNode DoDMain = g.GetNode(721); List <UInt32> DoDProviders = new List <UInt32>(); List <UInt32> DoDPeers = new List <UInt32>(); List <UInt32> DoDASNs = new List <UInt32>(); Queue <UInt32> ASesToProcess = new Queue <UInt32>(); DoDASNs.Add(721); ASesToProcess.Enqueue(721); while (ASesToProcess.Count > 0) { AsNode curr = g.GetNode(ASesToProcess.Dequeue()); Console.WriteLine("Processing: " + curr.NodeNum); foreach (var provider in curr.GetNeighborsByType(RelationshipType.CustomerOf)) { if (!DoDASNs.Contains(provider.NodeNum) && !DoDProviders.Contains(provider.NodeNum)) { DoDProviders.Add(provider.NodeNum); Console.WriteLine(curr.NodeNum + " has non-DoD provider: " + provider.NodeNum); Console.ReadLine(); } } foreach (var customer in curr.GetNeighborsByType(RelationshipType.ProviderTo)) { if (!DoDASNs.Contains(customer.NodeNum) && !ASesToProcess.Contains(customer.NodeNum)) { ASesToProcess.Enqueue(customer.NodeNum); DoDASNs.Add(customer.NodeNum); } } foreach (var peer in curr.GetNeighborsByType(RelationshipType.PeerOf)) { if (!DoDASNs.Contains(peer.NodeNum)) { DoDPeers.Add(peer.NodeNum); } } } Console.WriteLine("DoDProviders: "); foreach (var provider in DoDProviders) { if (!DoDASNs.Contains(provider)) { Console.Write(provider + ", "); } } Console.WriteLine(); Console.WriteLine("DoDPeers: "); foreach (var peer in DoDPeers) { Console.Write(peer + ", "); } Console.WriteLine(); }
public NetworkGraph findFinalGraph() { NetworkGraph returnGraph = new NetworkGraph(); Dictionary <NetworkNode, NodeConnections> endPoints = new Dictionary <NetworkNode, NodeConnections>(); foreach (NetworkNode existingNode in this.nodes.Keys.ToList()) { returnGraph.insertNode(existingNode); if (this.nodes[existingNode].Count > 0) { foreach (NodeConnections connection in this.nodes[existingNode]) { if (endPoints.ContainsKey(connection.getEndNode()) == true) { NodeConnections test = endPoints[connection.getEndNode()]; if (endPoints[connection.getEndNode()].getConnectionLength() >= connection.getConnectionLength()) { endPoints[connection.getEndNode()] = connection; } } else { endPoints.Add(connection.getEndNode(), connection); } } } } foreach (NetworkNode endPoint in endPoints.Keys.ToList()) { returnGraph.insertConnection(endPoints[endPoint].getStartNode(), endPoints[endPoint]); } return(returnGraph); }
public virtual async Task <IActionResult> NetworkPlanningPostAsync([FromBody] NetworkGraph body) { // Feel free to change any implementation of the code to suit your style. // *As long as endpoint locations are not altered* List <Node> res = await this.simulator.FindCritialGateways(body); return(new ObjectResult(res)); }
public static LSTMNetwork Create(int hiddenNeuronCount, int inputDim) { var graph = new NetworkGraph(); var inputs = graph.Block("inputs", inputDim, "", true); var previousH = graph.Block("previousH", hiddenNeuronCount, "ht", true); var previousC = graph.Block("previousC", hiddenNeuronCount, "ct_tanh", true); var f_gate_W = graph.NeuronLayer("f_gate_W", hiddenNeuronCount); var f_gate_U = graph.NeuronLayer("f_gate_U", hiddenNeuronCount); var i_gate_W = graph.NeuronLayer("i_gate_W", hiddenNeuronCount); var i_gate_U = graph.NeuronLayer("i_gate_U", hiddenNeuronCount); var o_gate_W = graph.NeuronLayer("o_gate_W", hiddenNeuronCount); var o_gate_U = graph.NeuronLayer("o_gate_U", hiddenNeuronCount); var c_gate_W = graph.NeuronLayer("c_gate_W", hiddenNeuronCount); var c_gate_U = graph.NeuronLayer("c_gate_U", hiddenNeuronCount); var plus = graph.Operation("plus", new AddOperation()); var multiply = graph.Operation("multiply", new MultiplyOperation()); var sigmoid = graph.Operation("sigmoid", new SigmoidOperation()); var tanh = graph.Operation("tanh", new TanhOperation()); var fc = graph.Operation("fc", new FullConnectionOperation()); var f_gate_W_fc_out = graph.Connect("f_gate_W_fc_out", new GraphNode[] { inputs, f_gate_W }, new GraphNode[] { fc }); var i_gate_W_fc_out = graph.Connect("i_gate_W_fc_out", new GraphNode[] { inputs, i_gate_W }, new GraphNode[] { fc }); var o_gate_W_fc_out = graph.Connect("o_gate_W_fc_out", new GraphNode[] { inputs, o_gate_W }, new GraphNode[] { fc }); var c_gate_W_fc_out = graph.Connect("c_gate_W_fc_out", new GraphNode[] { inputs, c_gate_W }, new GraphNode[] { fc }); var f_gate_U_fc_out = graph.Connect("f_gate_U_fc_out", new GraphNode[] { previousH, f_gate_U }, new GraphNode[] { fc }); var i_gate_U_fc_out = graph.Connect("i_gate_U_fc_out", new GraphNode[] { previousH, i_gate_U }, new GraphNode[] { fc }); var o_gate_U_fc_out = graph.Connect("o_gate_U_fc_out", new GraphNode[] { previousH, o_gate_U }, new GraphNode[] { fc }); var c_gate_U_fc_out = graph.Connect("c_gate_U_fc_out", new GraphNode[] { previousH, c_gate_U }, new GraphNode[] { fc }); var f_value = graph.Connect("f_value", new GraphNode[] { f_gate_W_fc_out, f_gate_U_fc_out }, new GraphNode[] { plus, sigmoid }); var i_value = graph.Connect("i_value", new GraphNode[] { i_gate_W_fc_out, i_gate_U_fc_out }, new GraphNode[] { plus, sigmoid }); var o_value = graph.Connect("o_value", new GraphNode[] { o_gate_W_fc_out, o_gate_U_fc_out }, new GraphNode[] { plus, sigmoid }); var c1_value = graph.Connect("c1_value", new GraphNode[] { c_gate_W_fc_out, c_gate_U_fc_out }, new GraphNode[] { plus, tanh }); var f_c_value = graph.Connect("f_c_value", new GraphNode[] { f_value, previousC }, new GraphNode[] { multiply }); var i_c1_value = graph.Connect("i_c1_value", new GraphNode[] { i_value, c1_value }, new GraphNode[] { multiply }); var ct_tanh = graph.Connect("ct_tanh", new GraphNode[] { f_c_value, i_c1_value }, new GraphNode[] { plus, tanh }, true); var ht = graph.Connect("ht", new GraphNode[] { ct_tanh, o_value }, new GraphNode[] { multiply }, true); ct_tanh.IsMonitoringNode = true; ht.IsMonitoringNode = true; graph.Compile(); LSTMNetwork network = new LSTMNetwork(graph); return(network); }
static void Main(string[] args) { var graph = NetworkGraph.ComposeFromTextFile(filePath); var calculator = new SequantionalEdmondKarpMaxFlow(); Console.WriteLine(calculator.GetMaxFlow(graph)); Console.ReadLine(); }
public Node(string id) { this.id = id; neighbors = new List <Node>(); packets = new List <int>(); netGraph = new NetworkGraph(15); netGraph.AddEdge(id); connections = new Dictionary <string, string>(); connections.Add(id, id); }
public void ReceivePacket(Packet packet) { if (!packets.Contains(packet.GetNumber())) { packets.Add(packet.GetNumber()); netGraph = packet.GetNetwork(); connections = Dijkstra.DijkstraAlgorithm(netGraph, id); SendPacket(packet); } }
/// <summary> /// Creates a new instance of WiFiMonitor. /// </summary> /// <param name="readTimeout">The timeout for reading packets.</param> /// <param name="constructNetworkGraph"> /// If set to true, a graph of the network will be constructed, allowing for /// the capturing of Nonces, which can in turn be used for decrypting /// IEEE 802.11 data frames. /// </param> public WiFiMonitor(int readTimeout = 1000, bool constructNetworkGraph = false) { _readTimeout = readTimeout; if (constructNetworkGraph) { _networkGraph = new NetworkGraph(); PacketArrived += _networkGraph.HandlePacketArrived; } }
public async Task SetNetworkGraph(NetworkGraph g, CancellationToken ct = default) { if (g == null) { throw new ArgumentNullException(nameof(g)); } using var tx = await _engine.OpenTransaction(ct); var table = tx.GetTable(DBKeys.NetworkGraph); await table.Insert(DBKeys.NetworkGraphVersion, g.ToBytes()); }
public void ReceiveNewPacket(Packet packet) { if (!packets.Contains(packet.GetNumber())) { Console.WriteLine("Updated node " + id + " with packet " + packet.GetNumber()); packets.Add(packet.GetNumber()); netGraph = packet.GetNetwork(); connections = Dijkstra.DijkstraAlgorithm(netGraph, id); Thread.Sleep(3000); SendNewPacket(packet); } }
static void Main(string[] args) { var networkGraph = new NetworkGraph(); new Thread(() => { var nn = new NeuralNetwork(); nn.CreateNetwork(); nn.TrainNetwork(networkGraph); }).Start(); Application.EnableVisualStyles(); // Application.SetCompatibleTextRenderingDefault(false); Application.Run(networkGraph); }
public async Task <NetworkGraph?> GetNetworkGraph(CancellationToken ct = default) { using var tx = await _engine.OpenTransaction(ct); var t = tx.GetTable(DBKeys.NetworkGraph); var row = await t.Get(DBKeys.NetworkGraphVersion); if (row is null) { return(null); } var b = await row.ReadValue(); return(NetworkGraph.FromBytes(b.ToArray())); }
public int GetMaxFlow(NetworkGraph graph) { var answer = 0; List <NetworkEdge> path; while ((path = graph.GetAugmentedPathBFS()) != null) { var currentFlow = path.Min(x => x.Capacity); answer += currentFlow; for (var i = 0; i < path.Count; ++i) { path[i].Flow += currentFlow; } } return(answer); }
private Packet GeneratePacket(Node node) { NetworkGraph tempNet = node.GetNetwork(); foreach (var edge in tempNet.GetEdges()) { netGraph.AddEdge(edge); foreach (var neighbor in tempNet.GetNeighbors(edge)) { netGraph.AddEdge(neighbor); netGraph.SetLink(edge, neighbor, tempNet.GetWeight(edge, neighbor)); } } return(new Packet(Packet.GetCounter(), id, netGraph)); }
public void SerializeTest1() { NetworkGraph graph = new NetworkGraph(); Layer layer1 = new FullyConnectedLayer(new Shape(new[] { 1, 2, 3, 1 }), 5, MatrixLayout.ColumnMajor, null); Layer layer2 = new FullyConnectedLayer(new Shape(new[] { 2, 3, 4, 1 }), 6, MatrixLayout.ColumnMajor, null); Edge <Layer> edge1 = new Edge <Layer>(layer1, layer2); Edge <Layer> edge2 = new Edge <Layer>(layer1, layer2); graph.AddEdges(new Edge <Layer>[] { edge1, edge2 }); string s1 = graph.SaveToString(); NetworkGraph graph2 = NetworkGraph.FromString(s1); string s2 = graph2.SaveToString(); Assert.AreEqual(s1, s2); }
/// <summary> /// Returns all nodes of type Gateway that if removed together with their connected edges would leave nodes of type Device, without edges to any Gateway. /// </summary> /// <param name="graph"></param> /// <returns></returns> public Task <List <Node> > FindCritialGateways(NetworkGraph graph) { var output = new List <Node>(); var devices = graph.Graphs[0].Nodes.Where(x => x.Type == "Device"); var gateways = graph.Graphs[0].Nodes.Where(x => x.Type == "Gateway"); foreach (var node in devices) { var edges = graph.Graphs[0].Edges.Where(x => x.Source == node.Id); if (edges.Count() == 1) { var edge = edges.FirstOrDefault(); var gateway = gateways.Where(x => x.Id == edge.Target).FirstOrDefault(); if (!output.Contains(gateway)) { output.Add(gateway); } } } return(Task.FromResult(output)); }
public static void Main() { _window = new GameWindow(GameWindowSettings.Default, _nativeWindowSettings); var cfg = NetworkGraphConfig.Default; cfg.LabelDisplayMode = LabelDisplayMode.SelectedAndAdjacent; _graph = NetGraphGenerator.GenerateNetworkGraph(cfg); var aspect = (float)_window.ClientSize.X / _window.ClientSize.Y; _graph.Camera.Target.AspectRatio = aspect; _graph.Camera.Current.AspectRatio = aspect; _control = new GraphGlfwWindowControl <string>(_window, _graph.State); _control.BindToEvents(); GLDebugLog.Message += OnMessage; _window.RenderFrame += OnRenderFrame; _window.UpdateFrame += OnUpdate; _window.Run(); }
private NetworkGraph input(string[] pieces) { if (pieces.Length < 2) { return(null); } NetworkGraph g = new NetworkGraph(); if (!File.Exists(pieces[1])) { pieces[1] = "C:\\Users\\phillipa\\Desktop\\adoptTraffic\\AugmentedGraphs\\" + pieces[1]; } if (File.Exists(pieces[1])) { InputFileReader ifr = new InputFileReader(pieces[1], g); ifr.ProcessFile(); Console.WriteLine("read graph: " + g.EdgeCount + " edges " + g.NodeCount + " nodes"); return(g); } return(null); }
public async Task <ActionResult <NetworkGraph> > Post([FromBody] NodeLinks NodeLinks) { if (NodeLinks.nodes != null) { JsonSerializerOptions options = new JsonSerializerOptions(); options.WriteIndented = true; var newNetworkGraph = new NetworkGraph { schema = JsonSerializer.Serialize(NodeLinks, options), shortId = Guid.NewGuid().ToString().Substring(0, 8) }; await _db.NetworkGraph.AddAsync(newNetworkGraph); await _db.SaveChangesAsync(); return(CreatedAtAction(nameof(Get), new NetworkGraph { Id = newNetworkGraph.Id, shortId = newNetworkGraph.shortId, schema = newNetworkGraph.schema, updateCount = newNetworkGraph.updateCount })); } return(BadRequest("Node Object was null")); }
private static bool initDestination(ref NetworkGraph g, ref Destination d, string dest) { UInt32 destNum; if (!UInt32.TryParse(dest, out destNum)) { /* * Console.WriteLine("Invalid ASN!"); */ return(false); } if (g.GetNode(destNum) == null) { /* * Console.WriteLine("WARNING: Could not retrieve destination " + d + " from the graph."); */ return(false); } /* * Console.WriteLine("Initializing variables and running RTA"); */ MiniDestination miniDest = SimulatorLibrary.initMiniDestination(g, destNum, false); d = new Destination(miniDest); bool[] tempS = new bool[Constants._numASNs]; for (int i = 0; i < tempS.Length; i++) { tempS[i] = false; } d.UpdatePaths(tempS); /* * Console.WriteLine("Done initializing. Current active destination is: " + destNum); */ return(true); }
/// <summary> /// Returns all nodes of type Gateway that if removed together with their connected edges would leave nodes of type Device, without edges to any Gateway. /// </summary> /// <param name="graph"></param> /// <returns></returns> public Task <List <Node> > FindCritialGateways(NetworkGraph graph) { var network = graph.Graphs[0]; var gateways = network.Nodes.Where(node => node.Type.Equals("Gateway")); var devices = network.Nodes.Where(node => node.Type.Equals("Device")); var disconnected = devices.Where(node => getEdges(network, node.Id).Count() == 1); var failures = disconnected.Select(node => getEdges(network, node.Id).First().Target).ToList <string>(); //var failureNodes = failures.Select(id => network.Nodes.FirstOrDefault(node => node.Id == id)); var failureNodes = new HashSet <Node>(); foreach (var s in failures) { var gateway = gateways.FirstOrDefault(node => node.Id.Equals(s)); if (gateway != null) { failureNodes.Add(gateway); } } return(Task.FromResult(failureNodes.ToList())); }
public async void FindCritialGateways2(NetworkGraph graph) { var res = await new NetworkSimulatorService().FindCritialGateways(graph); Assert.Null(res.FirstOrDefault()); }
public async void FindCritialGateways(NetworkGraph graph) { var res = await new NetworkSimulatorService().FindCritialGateways(graph); Assert.Equal("gw001", res.FirstOrDefault().Id); }
private NetworkGraph GraphRandom_Setup() { //Lets make new data graph instance dataGraph = new NetworkGraph(); return dataGraph; }
private void btnChangeState_Click(object sender, RoutedEventArgs e) { if (_selectedVertex.IsEnabled) { _selectedVertexEvent.VertexControl.Foreground = Brushes.Red; _selectedVertex.IsEnabled = false; } else { _selectedVertexEvent.VertexControl.Foreground = Brushes.Black; _selectedVertex.IsEnabled = true; } Graph = (NetworkGraph)logicCore.Graph; btnApply_Click(null, null); VertexBox.Visibility = Visibility.Collapsed; }
/// <summary> /// remove degree 1 diamonds and diamonds not used for traffic. /// </summary> /// <param name="diamonds"></param> private static void removeBadDiamonds(ref Hashtable diamonds, UInt32 point, int diamondType, resultObject Result) { NetworkGraph g = Result.g; //Remove level 1 diamonds. var keysToRemove = new List <UInt32>(); foreach (var key in diamonds.Keys) { if (((List <UInt32>)diamonds[key]).Count == 1) { keysToRemove.Add((UInt32)key); } } foreach (var key in keysToRemove) { diamonds.Remove(key); } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); int keysProcessed = 0; keysToRemove = new List <uint>(); //for diamonds that arer peer nad provider make sure //the point doesn't have a better path // to the stub. foreach (var key in diamonds.Keys) { Destination k = ObjectToText.destinationFromText(bucketTableFile + key + ".csv"); if (diamondType == _peerDiamonds) { if (k.BestRelation[point] == Destination._CUSTOMERCOLUMN) { keysToRemove.Add((UInt32)key); } } else if (diamondType == _providerDiamonds) { if (k.BestRelation[point] == Destination._CUSTOMERCOLUMN) { keysToRemove.Add((UInt32)key); } else if (k.BestRelation[point] == Destination._PEERCOLUMN) { keysToRemove.Add((UInt32)key); } } if (!keysToRemove.Contains((UInt32)key) && !checkFlipOrder(k, (List <UInt32>)diamonds[key], point, Result)) { keysToRemove.Add((UInt32)key); } keysProcessed++; if (keysProcessed % 500 == 0) { Console.WriteLine("processed " + keysProcessed + " out of " + diamonds.Count + " in " + stopwatch.ElapsedMilliseconds + " ms" + DateTime.Now); } } stopwatch.Stop(); Console.WriteLine("processed " + diamonds.Count + " in " + stopwatch.ElapsedMilliseconds + " ms"); foreach (var key in keysToRemove) { diamonds.Remove(key); } }
public MainWindow() { InitializeComponent(); //Customize Zoombox a bit //Set minimap (overview) window to be visible by default ZoomControl.SetViewFinderVisibility(zoomctrl, Visibility.Visible); //Set Fill zooming strategy so whole graph will be always visible zoomctrl.ZoomToFill(); var modes = new List<string>() { "By hopes", "By speed" }; protocols = new List<string>() { "TCP", "UDP" }; routingModeBox.ItemsSource = modes; routingModeBox.SelectedItem = modes[0]; protocolBox.ItemsSource = protocols; protocolBox.SelectedItem = protocols[0]; //Lets setup GraphArea settings GraphAreaExample_Setup(); zoomctrl.MouseRightButtonUp += ((o, s) => { VertexInputBox.Visibility = Visibility.Visible; }); //Vertex settings Area.VertexSelected += ((h, j) => { _selectedVertexEvent = j; _selectedVertex = (DataVertex)j.VertexControl.Vertex; VertexBox.Visibility = Visibility.Visible; }); Area.EdgeSelected += ((h, j) => { _selectedEdgeEvent = j; _selectedEdge = (DataEdge)j.EdgeControl .Edge; EdgeBox.Visibility = Visibility.Visible; }); Area.EdgeMouseEnter += ((h,j) => { foreach (var item in logicCore.Graph.Edges) { if (item.Equals(j.EdgeControl.Edge)) { j.EdgeControl.ToolTip = item.GetEdgeType(); } } }); //Vertex tooltip Area.VertexMouseEnter += ((h,j) => { foreach(var item in logicCore.Graph.Vertices) { if(item.Text == j.VertexControl.Vertex.ToString()) { if (item.IsEnabled) { j.VertexControl.ToolTip = item.Text + "\n\n" + item.Routing; StatsText.Text = ""; StatsText.Text += " " + item.Text + Environment.NewLine; StatsText.Text += " Recieved TCP" + Environment.NewLine + " control packets: " + item.RecievedTCPControlPackets + Environment.NewLine; StatsText.Text += " Recieved TCP" + Environment.NewLine + " data packets: " + item.RecievedTCPDataPackets + Environment.NewLine; StatsText.Text += " Sended TCP" + Environment.NewLine + " control packets: " + item.SendedTCPControlPackets + Environment.NewLine; StatsText.Text += " Sended TCP" + Environment.NewLine + " data packets: " + item.SendedTCPDataPackets + Environment.NewLine; StatsText.Text += " Recieved UDP" + Environment.NewLine + " data packets: " + item.RecivedUDPPackets + Environment.NewLine; StatsText.Text += " Sended UDP" + Environment.NewLine + " data packets: " + item.SendedUDPPackets + Environment.NewLine; CurrentIterBox.Text = " Current iteration: " + Environment.NewLine + " " + _iterationNumber; } else j.VertexControl.ToolTip = item.Text; } } }); Area.VertexMouseLeave += ((h,j) => { StatsText.Text = ""; CurrentIterBox.Text = ""; }); gg_but_randomgraph.Click += gg_but_randomgraph_Click; gg_but_relayout.Click += gg_but_relayout_Click; Loaded += MainWindow_Loaded; Graph = NetworkGraph.GetDefaultGraph(); SearchShortestWay(true); }
public static Dictionary <string, string> DijkstraAlgorithm(NetworkGraph G, string source) { string[] routers = G.GetEdges(); int[] dist = new int[routers.Length]; string[] queue = new string[routers.Length]; Dictionary <string, string> pred = new Dictionary <string, string>(); bool[] visited = new bool[routers.Length]; for (int i = 0; i < dist.Length; i++) { dist[i] = int.MaxValue; queue[i] = routers[i]; if (routers[i].Equals(source)) { dist[i] = 0; } } for (int i = 0; i < dist.Length; i++) { int next = minVertex(dist, visited); if (next != -1) { visited[next] = true; string[] neighbors = G.GetNeighbors(routers[next]); for (int j = 0; j < neighbors.Length; j++) { int nr = 0; for (int h = 0; h < routers.Length; h++) { if (routers[h].Equals(neighbors[j])) { nr = h; } } int d = dist[next] + G.GetWeight(routers[next], routers[nr]); if (dist[nr] > d) { dist[nr] = d; queue[nr] = queue[next] + seperator + queue[nr]; } } } } foreach (string str in queue) { string[] parts = str.Split(seperator); if (parts.Length != 1) { pred[parts[parts.Length - 1]] = parts[1]; } else { pred[parts[0]] = parts[0]; } } return(pred); }
private void btnSubmitEdge_Click(object sender, RoutedEventArgs e) { EdgeInputBox.Visibility = Visibility.Collapsed; if (!string.IsNullOrWhiteSpace(EdgeTextBox.Text) && !string.IsNullOrWhiteSpace(NVertexTextBox.Text)) { int weight; if (int.TryParse(EdgeTextBox.Text, out weight)) { var ver = logicCore.Graph.Vertices.Where(x => x.Text == NVertexTextBox.Text); if (ver.Count() != 0) { if (isRegionalCheck.IsChecked.Value) { if (isDuplexCheck.IsChecked.Value) { var newEdge = new DataEdge(_selectedVertex, ver.First()) { Text = EdgeTextBox.Text, Weight = weight, IsSatelite = true, IsDuplex = true }; _selectedVertex.Edges.Add(newEdge); ver.First().Edges.Add(newEdge); logicCore.Graph.AddEdge(newEdge); Graph = (NetworkGraph)logicCore.Graph; } else { var newEdge = new DataEdge(_selectedVertex, ver.First()) { Text = EdgeTextBox.Text, Weight = weight, IsSatelite = true, IsDuplex = false }; _selectedVertex.Edges.Add(newEdge); ver.First().Edges.Add(newEdge); logicCore.Graph.AddEdge(newEdge); Graph = (NetworkGraph)logicCore.Graph; } } else { if (isDuplexCheck.IsChecked.Value) { var newEdge = new DataEdge(_selectedVertex, ver.First()) { Text = EdgeTextBox.Text, Weight = weight, IsSatelite = false,IsDuplex = true }; _selectedVertex.Edges.Add(newEdge); ver.First().Edges.Add(newEdge); logicCore.Graph.AddEdge(newEdge); Graph = (NetworkGraph)logicCore.Graph; } else { var newEdge = new DataEdge(_selectedVertex, ver.First()) { Text = EdgeTextBox.Text, Weight = weight, IsSatelite = false, IsDuplex = false }; _selectedVertex.Edges.Add(newEdge); ver.First().Edges.Add(newEdge); logicCore.Graph.AddEdge(newEdge); Graph = (NetworkGraph)logicCore.Graph; } } btnApply_Click(null, null); gg_but_randomgraph_Click(null, null); } } else { WarningBox.Visibility = Visibility.Visible; } } else { WarningBox.Visibility = Visibility.Visible; } NVertexTextBox.Text = null; EdgeTextBox.Text = null; }
public void testSPInterface() { SimulatorLibrary.setHash(true); SimulatorLibrary.setUtilityComputation(UtilityComputationType.outgoing); Console.WriteLine("Welcome to the short paths testing interface: "); bool exitNow = false; while (!exitNow) { Console.Write(">>"); string command = Console.ReadLine().ToLower(); string[] pieces = command.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (command.IndexOf("input") == 0) { g = input(pieces); } else if (command.IndexOf("getpath") == 0) { getpath(pieces); } else if (command.IndexOf("setstate") == 0) { S = setstate(pieces); } else if (command.IndexOf("init") == 0) { List <UInt32> ea = new List <uint>(); ea.Add(1239); gs = SimulatorLibrary.initGlobalState(g, ea); } else if (command.IndexOf("iterate") == 0) { List <MiniDestination> miniDs = new List <MiniDestination>(); foreach (var AS in g.GetAllNodes()) { miniDs.Add(SimulatorLibrary.initMiniDestinationSP(g, AS.NodeNum, false)); Console.WriteLine("initialized AS " + AS.NodeNum); } List <Message> results = new List <Message>(); foreach (var mD in miniDs) { results.Add(SimulatorLibrary.ComputeOnDestination(mD, gs)); Console.WriteLine("computed on: " + mD.destination); } Console.WriteLine("updating global state."); Int64[] Before = new Int64[Constants._numASNs]; Int64[] After = new Int64[Constants._numASNs]; SimulatorLibrary.updateGlobalState(ref gs, results, (float)0, ref Before, ref After); for (int i = 0; i < gs.S.Length; i++) { if (gs.S[i]) { Console.WriteLine("AS " + i + " is on."); } } } } }
public LSTMNetwork(NetworkGraph graph) { this.graph = graph; }
private void btnSubmit_Click(object sender, RoutedEventArgs e) { VertexInputBox.Visibility = Visibility.Collapsed; if(!string.IsNullOrWhiteSpace(VertexTextBox.Text)) { var newVertex = new DataVertex(VertexTextBox.Text); logicCore.Graph.AddVertex(newVertex); Graph = (NetworkGraph)logicCore.Graph; gg_but_randomgraph_Click(null, null); } VertexTextBox.Text = null; }
public static void neverOn(string[] commandPieces) { string[] ResultDirs = Directory.GetDirectories(ResultsExplorer.defaultResultsDirectory); List <UInt32> neverOn = new List <UInt32>(); StreamWriter output = new StreamWriter(Console.OpenStandardOutput()); if (commandPieces.Length > 1) { output.Close(); output = new StreamWriter(ResultsExplorer.defaultOutputDirectory + commandPieces[1]); } bool includestubs = false; if (commandPieces.Length > 2 && commandPieces[2].IndexOf("stubs") >= 0) { includestubs = true; } NetworkGraph g = new NetworkGraph(); foreach (var reDir in ResultDirs) { if (File.Exists(reDir + "\\params.txt")) { resultObject curr = ResultsExplorer.readParamsFile(reDir + "\\params.txt"); double u = -1; int f = -1; int k = -1; double.TryParse(curr.u, out u); int.TryParse(curr.f, out f); int.TryParse(curr.k, out k); if (u == 0 && f == 0 && k == 9)//for simplicity vanilla graph + k=9 { if (File.Exists(reDir + "\\" + curr.precursor + ".S200000.csv")) { curr.state = ResultsExplorer.readStateFromFile(reDir + "\\" + curr.precursor + ".S200000.csv"); } if (neverOn.Count == 0)//init the set of nodes that are never on if needed. { if (File.Exists(ResultsExplorer.defaultGraphDirectory + curr.graphFile)) { InputFileReader ifr = new InputFileReader(ResultsExplorer.defaultGraphDirectory + curr.graphFile, g); ifr.ProcessFile(); } var nonstubs = g.getNonStubs(); foreach (var n in g.GetAllNodes()) { if (includestubs || nonstubs.Contains(n.NodeNum)) { neverOn.Add(n.NodeNum); } } } //go through and remove anyone we saw as on from the set of nodes that are never on. bool[] lastState = curr.state[curr.state.Count - 1]; for (int i = 0; i < lastState.Length; i++) { if (lastState[i]) { if (neverOn.Contains((UInt32)i)) { neverOn.Remove((UInt32)i); } } } } } } foreach (var no in neverOn) { output.WriteLine(no); } output.Close(); double avgDegreeOfNeverOn = 0; foreach (var no in neverOn) { double deg = g.GetNode(no).GetAllNeighbors().Count(); avgDegreeOfNeverOn += deg; } avgDegreeOfNeverOn /= neverOn.Count; Console.WriteLine(neverOn.Count + " nodes never turn on. their average degree is " + avgDegreeOfNeverOn); /** See who has competition **/ List <UInt32> haveCompetition = new List <UInt32>(); foreach (var no in neverOn) { var alwaysOffNode = g.GetNode(no); var customers = alwaysOffNode.GetNeighborsByType(RelationshipType.ProviderTo); foreach (var c in customers) { var providers = c.GetNeighborsByType(RelationshipType.CustomerOf); if (providers.Count() > 1 && !haveCompetition.Contains(no))//this customer of the never on guy has more than 1 provider. this never on guy had competition. { haveCompetition.Add(no); } } } //convert from list of nodes with competition to nodes without competition. List <UInt32> nocompetition = new List <uint>(); foreach (var no in neverOn) { if (!haveCompetition.Contains(no)) { nocompetition.Add(no); } } Console.WriteLine(nocompetition.Count + " of these guys had no competition for their customers."); /** See who is next to ASes with no competition **/ List <UInt32> nexttonocompetition = new List <UInt32>(); foreach (var no in neverOn) { if (!nocompetition.Contains(no)) { //this guy had competition. see if he is connected to someone without competition. var alwaysOffNode = g.GetNode(no); foreach (var neighbor in alwaysOffNode.GetAllNeighbors()) { if (nocompetition.Contains(neighbor.NodeNum) && !nexttonocompetition.Contains(no)) { nexttonocompetition.Add(no); } } } } Console.WriteLine(nexttonocompetition.Count + " of the remaining " + haveCompetition.Count + " ASes are next to one with no competition."); output = new StreamWriter(ResultsExplorer.defaultOutputDirectory + "neveron-withcomp.txt"); List <UInt32> withCompetitionNotNextToNoCompetition = new List <UInt32>(); foreach (var asn in haveCompetition) { if (!nexttonocompetition.Contains(asn)) { output.WriteLine(asn); withCompetitionNotNextToNoCompetition.Add(asn); } } output.Close(); /** See which of the remaining ASes are a part of the "jump level" topology **/ List <UInt32> inJumpLevel = new List <uint>(); foreach (var asn in withCompetitionNotNextToNoCompetition) { var alwaysOffNode = g.GetNode(asn); var providers = alwaysOffNode.GetNeighborsByType(RelationshipType.CustomerOf); List <UInt32> providerASNs = new List <uint>(); foreach (var p in providers) { providerASNs.Add(p.NodeNum); } foreach (var c in alwaysOffNode.GetNeighborsByType(RelationshipType.ProviderTo)) { var customersProviders = c.GetNeighborsByType(RelationshipType.CustomerOf); foreach (var cP in customersProviders) { if (providerASNs.Contains(cP.NodeNum) && !inJumpLevel.Contains(asn)) { inJumpLevel.Add(asn); } } } } output = new StreamWriter(ResultsExplorer.defaultOutputDirectory + "neveron-nojumplevel.txt"); foreach (var asn in withCompetitionNotNextToNoCompetition) { if (!inJumpLevel.Contains(asn)) { output.WriteLine(asn); } } output.Close(); /** to be continued***/ Console.WriteLine(inJumpLevel.Count + " of the remaining " + withCompetitionNotNextToNoCompetition.Count + " ASes are in jump level topologies"); }
private NetworkGraph GraphExample_Setup() { dataGraph = NetworkGraph.GetDefaultGraph(); return dataGraph; }