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
        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);
        }