private void ConnectCentralMachineToOtherNodes(IEnumerable <uint> nodesIdConnectedToCentralMachine, uint centralMachineId) { foreach (var nodeId in nodesIdConnectedToCentralMachine) { var price = ChannelParamsGenerator.GetRandomPrice(); var capacity = ChannelParamsGenerator.GetCapactity(price) / 3; var channel = new Channel { Id = Guid.NewGuid(), FirstNodeId = centralMachineId, SecondNodeId = nodeId, ConnectionType = ConnectionType.Duplex, ChannelType = ChannelType.Satellite, ErrorChance = AllConstants.RandomGenerator.NextDouble(), Price = price, IsBusy = false, Capacity = capacity }; var metropolitanNode = _network.GetNodeById(nodeId); metropolitanNode.NodeType = NodeType.MainMetropolitanMachine; _network.AddChannel(channel); } }
private Channel GenerateChannel(uint currentNodeId) { while (true) { var destinationNodeId = _network.Nodes .Select(n => n.Id) .ElementAt(AllConstants.RandomGenerator.Next(_network.Nodes.Length)); if (destinationNodeId == currentNodeId || _network.GetChannel(currentNodeId, destinationNodeId) != null) { continue; } var price = ChannelParamsGenerator.GetRandomPrice(); var capacity = ChannelParamsGenerator.GetCapactity(price); var channel = new Channel { Id = Guid.NewGuid(), FirstNodeId = currentNodeId, SecondNodeId = destinationNodeId, ChannelType = ChannelType.Ground, ConnectionType = ConnectionType.Duplex, ErrorChance = Math.Floor(AllConstants.RandomGenerator.NextDouble() * 100.0) / 100.0, Price = price, IsBusy = false, Capacity = capacity }; return(channel); } }