/// <summary> /// Required: UniqueID property, NeuronType /// </summary> /// <param name="prop"></param> /// <returns></returns> public WINNode findOrInsertNodeWithProperties(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 WINNode node = findWINNode(prop); //we found it, then return it if you don't mind if (node != null) { return(node); } //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 node = createWINNode(prop); //now we should take into account that our idGenerator needs to know about new innovations idGen.mostRecentInnovationID(node.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(node); }
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); }