Ejemplo n.º 1
0
        public WINConnection findOrInsertConnectionWithProperties(IdGenerator idGen, PropertyObject prop)
        {
            //the very first thing we must do, is attempt to find our object
            //in order to do this, we need a uniqueID to find, and a neuronType
            //we assume both of these are provided

            WINConnection conn = findWINConnection(prop);

            //we found it, then return it if you don't mind
            if (conn != null)
            {
                return(conn);
            }

            //we weren't able to find the node, now we must create it and return it (since we are find or insert!)
            //this should create the appropriate ID for this object
            conn = createWINConnection(prop);

            //now we should take into account that our idGenerator needs to know about new innovations
            idGen.mostRecentInnovationID(conn.UniqueID);

            //might want this to be async in the future, but for now we make it synchronous
            //property objects should have everything we need to identify the WINNode
            return(conn);
        }
Ejemplo n.º 2
0
        private string tryGetValue(string key, PropertyObject prop)
        {
            string val;

            prop.TryGetValue(key, out val);
            return(val);
        }
Ejemplo n.º 3
0
        private long tryGetLong(string valString, PropertyObject prop)
        {
            string val = tryGetValue(valString, prop);

            if (val != null)
            {
                return(long.Parse(val));
            }
            else
            {
                return(-1);
            }
        }
Ejemplo n.º 4
0
        private NeuronType tryGetNeuronType(PropertyObject prop)
        {
            string val = tryGetValue(WINObject.SUniqueString, prop);

            if (val != null)
            {
                return((NeuronType)Enum.Parse(typeof(NeuronType), val));
            }
            else
            {
                return(NeuronType.Undefined);
            }
        }
Ejemplo n.º 5
0
        private double tryGetDouble(string valString, PropertyObject prop)
        {
            string val = tryGetValue(valString, prop);

            if (val != null)
            {
                return(double.Parse(val));
            }
            else
            {
                return(-1);
            }
        }
Ejemplo n.º 6
0
        //uniqueID and neuronType are assumed here!
        /// <summary>
        /// We are trying to find a node here. For now, we just check our local cache. In real WIN, we'll check against the database of entries.
        /// </summary>
        /// <param name="prop"></param>
        /// <returns></returns>
        public WINNode findWINNode(PropertyObject prop)
        {
            long       uniqueID   = tryGetUnique(prop);
            NeuronType neuronType = tryGetNeuronType(prop);

            WINNode node;

            if (winNodes.TryGetValue(nodeKey(uniqueID, neuronType), out node))
            {
                return(node);
            }

            return(null);
        }
Ejemplo n.º 7
0
        public WINConnection createWINConnection(PropertyObject prop, IdGenerator idGen = null)
        {
            WINConnection conn;

            lock (winConnections)
            {
                //here we would head out to the server, and get a newly created connection, since we couldn't find one
                //call the server and get back our new unique id AND object, instead, we'll generate it ourselves for now
                long uniqueID = tryGetUnique(prop);
                if (uniqueID == -1)
                {
                    uniqueID = nextConnectionUniqueID();
                }

                //if we have sent in an idgenerator, we should update the object with our nextID object
                if (idGen != null)
                {
                    idGen.mostRecentInnovationID(uniqueID);
                }

                //parse out our source and target, which are obviously required for creating a connection
                long sourceID = tryGetSourceID(prop);
                long targetID = tryGetTargetID(prop);

                //double weight = tryGetDouble(WINConnection.SWeight, prop);

                //need to return a WINNode object
                conn = new WINConnection()
                {
                    //Parsed the source and target, which are required
                    SourceID = sourceID,
                    TargetID = targetID,
                    //Weight = weight,
                    //set the parameters for posterity, this might be unncessary
                    Parameters = prop,
                    //set the uniqueID, which should be passed in
                    UniqueID = uniqueID
                };

                //temporarily cache this information, duh!
                //also, we use a combination of our uniqueID and nodetype to create a unique string
                //when we move to databases, this won't matter as much since we will query all properties at the same time
                winConnections.Add(connectionKey(conn.SourceID, conn.TargetID), conn);
            }

            //then send it back
            return(conn);
        }
Ejemplo n.º 8
0
        public WINConnection findWINConnection(PropertyObject prop)
        {
            //we have three uniquely defining properties, the unique id, the source and the target
            //really, any connection that connects a unique source and target should be enough to define it. The unique ID should shortcut
            //the search process

            //long uniqueID = tryGetUnique(prop);
            long sourceID = tryGetSourceID(prop);
            long targetID = tryGetTargetID(prop);

            WINConnection conn;

            if (winConnections.TryGetValue(connectionKey(sourceID, targetID), out conn))
            {
                return(conn);
            }

            return(null);
        }
Ejemplo n.º 9
0
        public WINNode createWINNode(PropertyObject prop, IdGenerator idGen = null)
        {
            WINNode node;

            lock (winNodes)
            {
                //here we would head out to the server, and get a new created node, since we couldn't find one
                //call the server and get back our new unique id AND object, instead, we'll generate it ourselves for now
                long uniqueID = tryGetUnique(prop);
                if (uniqueID == -1)
                {
                    uniqueID = nextNodeUniqueID();
                }

                //if we have sent in an idgenerator, we should update the object with our nextID object
                if (idGen != null)
                {
                    idGen.mostRecentInnovationID(uniqueID);
                }

                //Get our neurontype, which is assumed to have been sent in, it would be silly otherwise
                NeuronType neuronType = tryGetNeuronType(prop);


                //need to return a WINNode object
                node = new WINNode()
                {
                    //Parsed the neuron type before entering function, required
                    NodeType = neuronType,
                    //set the parameters for posterity, this might be unncessary
                    Parameters = prop,
                    //set the uniqueID, which should be passed in
                    UniqueID = uniqueID
                };

                //temporarily cache this information, duh!
                //also, we use a combination of our uniqueID and nodetype to create a unique string
                //when we move to databases, this won't matter as much since we will query all properties at the same time
                winNodes.Add(nodeKey(node.UniqueID, node.NodeType), node);
            }
            //then send it back
            return(node);
        }
Ejemplo n.º 10
0
 private long tryGetUnique(PropertyObject prop)
 {
     return(tryGetLong(WINObject.SUniqueString, prop));
 }
Ejemplo n.º 11
0
 private long tryGetTargetID(PropertyObject prop)
 {
     return(tryGetLong(WINConnection.STargetID, prop));
 }
Ejemplo n.º 12
0
 private long tryGetSourceID(PropertyObject prop)
 {
     return(tryGetLong(WINConnection.SSourceID, prop));
 }