Example #1
0
	public void AddConnection ( OGLineNode node, Vector3[] segments ) {
		List< Connection > tmp = new List< Connection > ( connections );
		
		tmp.Add ( new Connection ( node, segments ) );

		connections = tmp.ToArray ();
	}
Example #2
0
        //Constructors
        public Cell(Vector2 centre, int index, int[] d)
        {
            color = new Color(new Vector3(1f, 0.8f, 0.5f));
            SetHazardLevel(1);
            indexInGrid = index;
            this.centre = centre;
            passable = (Rnd.r.NextDouble() > 0.2);
            hasTower = false;

            connections = new Connection[6];

            connections[Dir.East].targetCell = d[Dir.East];
            connections[Dir.NorthEast].targetCell = d[Dir.NorthEast];
            connections[Dir.NorthWest].targetCell = d[Dir.NorthWest];
            connections[Dir.West].targetCell = d[Dir.West];
            connections[Dir.SouthWest].targetCell = d[Dir.SouthWest];
            connections[Dir.SouthEast].targetCell = d[Dir.SouthEast];

            for (int i = 0; i < 6; i++)
                if (connections[i].targetCell >= 0)
                {
                    connections[i].exists = true;
                    connections[i].passable = true;
                }

            safestWay = Dir.None;

            shortestWay = Dir.None;
        }
Example #3
0
 public Matrix(params string[] stringMatrixes)
 {
     _values = ParseForValues(stringMatrixes);
     _dimension = _values.First().Length;
     _nodes = Enumerable.Range(0, _dimension).Select(i => new Node(i)).ToArray();
     _connections = SetConnections().ToArray();
     _transitions = SetTransitions().ToArray();
 }
Example #4
0
        /// <summary>
        /// Generates a rotor from a mapping input.
        /// </summary>
        /// <param name="mapping">A rotor wiring such as "HQZGPJTMOBLNCIFDYAWVEUSRKX"</param>
        /// <param name="type">The rotor's type (rotor, stator, reflector)</param>
        public Rotor(string mapping, string type)
        {
            this.mapping = GenerateConnectionsFromMapping(mapping);

            CalculateReverseOffsets();

            this.initialMapping = this.mapping;

            this.length = this.mapping.Length;

            SetRotorType(type);
        }
Example #5
0
        public Rotor(string mapping, RotorType type, bool ignoreInvalidMapping = false)
        {
            this.mapping = GenerateConnectionsFromMapping(mapping, ignoreInvalidMapping);

            CalculateReverseOffsets();

            this.initialMapping = this.mapping;

            this.length = this.mapping.Length;

            this.type = type;
        }
Example #6
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        public Rotor()
        {
            // Use the default rotor type.
            type = RotorType.Rotor;

            mapping = GenerateReverseAlphabeticalConnections(26);

            CalculateReverseOffsets();

            length = 26;
            this.initialMapping = mapping;
        }
Example #7
0
	public void SetConnection ( int i, OGLineNode node, Vector3[] segments ) {
		List< Connection > tmp = new List< Connection > ( connections );

		if ( i >= tmp.Count ) {
			for ( int n = tmp.Count; n <= i; n++ ) {
				tmp.Add ( null );
			}
		}

		tmp[i] = new Connection ( node, segments );

		connections = tmp.ToArray ();
	}
Example #8
0
        public Rotor(RotorDescriptor descriptor)
        {
            this.Descriptor = descriptor;

            this.mapping = GenerateConnectionsFromMapping(descriptor.Mapping);

            CalculateReverseOffsets();

            this.initialMapping = this.mapping;

            this.length = this.mapping.Length;

            SetRotorType(descriptor.Type);
        }
Example #9
0
        void ChangeConnections (int newIndex)
        {
            // Debug.Print ("Switching to " + newIndex);

            if (connections != null) {
                foreach (var c in connections) {
                    c.Disconnect ();
                }
            }

            connections = groups[newIndex];
            connectedIndex = newIndex;

            if (connections != null) {
                foreach (var c in connections) {
                    c.Connect ();
                }
            }
        }
Example #10
0
        public Backpropagate(Network network, double learningRate = 0.5, int microBatchSize = 1) {
            Network = network;
            LearningRate = learningRate;
            MicroBatchSize = microBatchSize;

            //Loop trough all network connections and add them to ConnectionInfluence list
            ConnectionInfluence = new ConcurrentDictionary<Connection, double?[]>();
            var fillAllCollections = new List<Connection>();
            for(int layer = 1; layer < Network.Nodes.Length; layer++) { //Skips input layer
                for(int index = 0; index < Network.Nodes[layer].Length; index++) {
                    //Loop trough current nodes incomming connections
                    foreach(Connection con in Network.Nodes[layer][index].GetIncommingConnections()) {
                        ConnectionInfluence.TryAdd(con, new double?[MicroBatchSize]);
                        fillAllCollections.Add(con);
                    }
                }
            }

            AllConnections = fillAllCollections.ToArray();
        }
		public void AddConnection (Connection c) {
			Connection[] tmp = new Connection[connections.Length+1];
			for (int i=0;i<connections.Length;i++) {
				tmp[i] = connections[i];
			}
			tmp[connections.Length] = c;
			connections = tmp;
			GenerateEnabledConnections ();
		}
		public void GenerateEnabledConnections () {
			Connection[] tmp = new Connection[connections.Length];
			int c =0;
			for (int i=0;i<connections.Length;i++) {
				if (connections[i].enabled) {
					tmp[c] = connections[i];
					c++;
				}
			}
			
			enabledConnections = new Connection[c];
			for (int i=0;i<c;i++) {
				enabledConnections[i] = tmp[i];
			}
		}
Example #13
0
		// returns port.
		public void Start(int port, int max_connections = 100)
		{
			_connections = new Connection[max_connections];
			for (int i = 0; i < max_connections; i++)
				_free_connections.Add(max_connections - i - 1);

			IPEndPoint localEP = new IPEndPoint(0, port);
            _listener = new Socket(localEP.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
			_listener.Bind(localEP);
			_listener.Listen(100);
			_listener.BeginAccept(OnAsyncAccepted, _listener);

			localEP = (IPEndPoint)_listener.LocalEndPoint;
		}
Example #14
0
        /// <summary>
        /// Begins listening for and accepting socket connections.
        /// </summary>
        /// <param name="backLog">Maximum amount of pending connections</param>
        public void Listen(int backLog = 25, int maximumConnections = 60)
        {
            _connections = new Connection[maximumConnections];

            var listenerThread = new Thread(() =>
            {
                int index = -1;

                if (_socketAddress == null) throw new Exception("You must specifiy the socket address before calling the listen method!");
                if (!MainSocket.IsBound) throw new Exception("You must bind the socket before calling the listen method!");

                MainSocket.Listen(backLog);

                Console.WriteLine("[NettyServer] Server listening on address: " + MainSocket.LocalEndPoint);

                while (true)
                {
                    var incomingSocket = MainSocket.Accept();

                    for (int i = 0; i < maximumConnections; i++)
                    {
                        if (_connections[i] == null)
                        {
                            _connections[i] = new Connection(incomingSocket, this)
                            {
                                Socket = { NoDelay = MainSocket.NoDelay }
                            };

                            index = i;
                            break;
                        }
                    }

                    Console.WriteLine("[NettyServer] Received a connection from: " + incomingSocket.RemoteEndPoint);

                    if (Handle_NewConnection != null) Handle_NewConnection.Invoke(index);

                    try
                    {
                        Thread recThread = new Thread(x => BeginReceiving(incomingSocket, index));
                        recThread.Name = incomingSocket.RemoteEndPoint + ": incoming data thread.";
                        recThread.Start();
                    }
                    catch (ObjectDisposedException)
                    {
                    }
                }
            }) { Name = "NettyServer Incoming Connection Thread" };

            listenerThread.Start();
        }
Example #15
0
 public void Generate(int ncount, int incount,int i2ncount, int n2ncount, int n2ocount)
 {
     List<PosStruct> nodes = new List<PosStruct>();
     for (int i = 0; i < ncount; i++)
     {
         PosStruct p = new PosStruct();
         bool run = true;
         while (run)
         {
             run = false;
             p.x = r.Next(20);
             p.y = r.Next(10);
             p.state = 0;
             for (int j = 0; j < i; j++)
                 if (nodes[j].x == p.x && nodes[j].y == p.y)
                 {
                     run = true;
                     break;
                 }
         }
         nodes.Add(p);
     }
     NeuroNodes = nodes.ToArray();
     List<PosStruct> instates = new List<PosStruct>();
     for (int i = 0; i < incount; i++)
     {
         PosStruct p = new PosStruct();
         p.x = r.Next(10);
         p.y = r.Next(10);
         p.state = 0;
         instates.Add(p);
     }
     InNodes = instates.ToArray();
     OutStates = new int[1];
     List<Connection> in2nodcon = new List<Connection>();
     for (int i = 0; i < i2ncount; i++)
     {
         Connection con = new Connection();
         con.start = r.Next(incount);
         con.end = r.Next(ncount);
         if (r.NextDouble() >= 0.5f)
             con.xor = true;
         in2nodcon.Add(con);
     }
     In2Nod = in2nodcon.ToArray();
     List<Connection> n2nlist = new List<Connection>();
     for (int i = 0; i < n2ncount; i++)
     {
         Connection n2n = new Connection();
         n2n.start = r.Next(ncount);
         n2n.end = r.Next(ncount);
         if (r.NextDouble() >= 0.5f)
             n2n.xor = true;
         n2nlist.Add(n2n);
     }
     Nod2Nod = n2nlist.ToArray();
     List<Connection> n2olist = new List<Connection>();
     for (int i = 0; i < n2ncount; i++)
     {
         Connection n2o = new Connection();
         n2o.start = r.Next(ncount);
         n2o.end = 0;
         if (r.NextDouble() >= 0.5f)
             n2o.xor = true;
         n2olist.Add(n2o);
     }
     Nod2Out = n2olist.ToArray();
 }
Example #16
0
 public void Load(string path)
 {
     MemoryStream m = new MemoryStream(File.ReadAllBytes(path));
     m.Seek(0, 0);
     int m1 = ReadInt(m);
     int m2 = ReadInt(m);
     if (m1 != 0x7249416D || m2 != 0x31765F30)
         return;
     int count = ReadInt(m);
     NeuroNodes = new PosStruct[count];
     for (int i = 0; i < count; i++)
         NeuroNodes[i] = ReadPosStruct(m);
     count = ReadInt(m);
     InNodes = new PosStruct[count];
     for (int i = 0; i < count; i++)
         InNodes[i] = ReadPosStruct(m);
     count = ReadInt(m);
     In2Nod = new Connection[count];
     for (int i = 0; i < count; i++)
         In2Nod[i] = ReadConnection(m);
     count = ReadInt(m);
     Nod2Nod = new Connection[count];
     for (int i = 0; i < count; i++)
         Nod2Nod[i] = ReadConnection(m);
     count = ReadInt(m);
     Nod2Out = new Connection[count];
     for (int i = 0; i < count; i++)
         Nod2Out[i] = ReadConnection(m);
     OutStates = new int[1];
 }
 public PuzzlePieceConnections(Connection[] connections)
 {
     this.connections = connections;
 }
Example #18
0
    public virtual void ReBuild()
    {
        if (m_nodeId <= 0)
            m_nodeId = Random.Range(0, int.MaxValue);

            Node[] otherNodes = FindObjectsOfType<Node>();
        List<Node> nodeList = new List<Node>(otherNodes);
        nodeList.Remove(this);
        nodeList.Sort((a, b) =>
        {
            float aCost = (a.transform.position - transform.position).magnitude;
            float bCost = (b.transform.position - transform.position).magnitude;

            if (aCost > bCost)
                return 1;
            else if(aCost < bCost)
                return -1;
            else
                return 0;
        });

        if (m_connections == null || m_connections.Length < 4)
        {
            m_connections = new Connection[4];
        }
        else
        {
            for (int i = 0; i < m_connections.Length; i++)
            {
                if(m_connections[i] != null && !m_connections[i].IsStatic)
                    m_connections[i] = null;
            }
        }

        int directionFillCount = 0;
        foreach (Node node in nodeList)
        {
            Vector2 offset = (node.transform.position - transform.position);
            Vector2 direction = offset.normalized;
            float cost = offset.magnitude;
            if (cost > m_maxBuildCost)
                break;

            if (m_useCostOverride)
            {
                if (node.m_useCostOverride)
                    cost = m_fromCostOverride + node.m_toCostOverride;
                else
                    cost = m_fromCostOverride;
            }
            else if (node.m_useCostOverride)
            {
                cost = node.m_toCostOverride;
            }

            if (Vector2.Dot(direction, Vector2.up) > 0.99f)
            {
                if(m_connections[0] == null)
                {
                    directionFillCount++;
                    m_connections[0] = new Connection(node, cost);
                }
            }
            else if (Vector2.Dot(direction, Vector2.right) > 0.99f)
            {
                if (m_connections[1] == null)
                {
                    directionFillCount++;
                    m_connections[1] = new Connection(node, cost);
                }
            }
            else if (Vector2.Dot(direction, Vector2.down) > 0.99f)
            {
                if (m_connections[2] == null)
                {
                    directionFillCount++;
                    m_connections[2] = new Connection(node, cost);
                }
            }
            else if (Vector2.Dot(direction, Vector2.left) > 0.99f)
            {
                if (m_connections[3] == null)
                {
                    directionFillCount++;
                    m_connections[3] = new Connection(node, cost);
                }
            }

            if (directionFillCount >= 4)
                break;
        }

        for (int i = 0; i < m_connections.Length; i++)
        {
            Connection connection = m_connections[i];
            if (connection == null || connection.IsStatic)
                continue;

            RaycastHit2D hit = Physics2D.Linecast(connection.TargetNode.transform.position, transform.position, LayerMask.GetMask("Wall"));
            if (hit.collider != null)
                m_connections[i] = null;
        }
    }
Example #19
0
            /// <summary>
            /// Removes all entries from the list with peerIps that are not present in both lists.
            /// </summary>
            /// <param name="connectionsList">The connections list to sync with</param>
            public void syncIps(ConnectionsList connectionsList)
            {
                List<Connection> connectionsNew = new List<Connection>();
                HashSet<uint> ips = new HashSet<uint>();

                //first parse the list to sync with
                foreach (Connection connection in connectionsList.connections)
                {
                    ips.Add(connection.peerIp);
                }

                //now clean up own list
                foreach (Connection connection in _connections)
                {
                    if (ips.Contains(connection.peerIp) == true)
                    {
                        connectionsNew.Add(connection);
                    }
                }

                _connections = connectionsNew.ToArray();
            }
Example #20
0
 private void parseIntegerArray(int[,] rawConnections, bool hasTimestamp)
 {
     _connections = new Connection[rawConnections.GetLength(0)];
     for (int i = 0; i < rawConnections.GetLength(0); i++)
     {
         uint timestamp;
         if (hasTimestamp)
         {
             timestamp = (uint)rawConnections[i, 4];
         }
         else
         {
             timestamp = (uint)0xFFFFFFFF;
         }
         _connections[i] = new Connection((uint)rawConnections[i, 0], (ushort)rawConnections[i, 1], (ushort)rawConnections[i, 2], (TIpProtocol)rawConnections[i, 3], timestamp);
     }
 }
 public ConnectedNeuron(ActivationFunction activationFunction, Connection[] inputConnections)
 {
     _activationFunction = activationFunction;
     _inputConnections = inputConnections;
     Value = 0;
 }
Example #22
0
 /// <summary>
 /// Resets the rotor to its original position (The "A" position)
 /// Same as setting the rotor key to "A"
 /// </summary>
 public void Reset()
 {
     mapping = initialMapping;
     offset = 0;
 }
Example #23
0
        /// <summary>
        /// Offsets the rotor of x steps clockwise. That is, the rotor key is translated to an offset.
        /// In reality, makes the drum rotate of x notches, setting new paths for the current.
        /// </summary>
        public void OffsetRotor(int offset)
        {
            // Rebuilds the rotor
            Connection[] incrementedRotor = new Connection[length];

            for (int i = 0; i < length; i++)
            {
                incrementedRotor[i] = initialMapping[(i + offset) % length];
            }

            this.offset = offset;
            mapping = incrementedRotor;
        }
Example #24
0
 public Neuron()
 {
     Output = 0D;
     Connections = new Connection[0];
 }