/// <summary> /// Evaluate this statement against the specified instance. /// </summary> /// <param name="instance">Instance.</param> public GeneticObject Evaluate(ref EntBehaviorManager instance) { GeneticObject leftHandObject = this.leftHandSide.Evaluate(ref instance); GeneticObject rightHandObject = this.rightHandSide.Evaluate(ref instance); return(GeneticObject.EvaluateOperator(this.operatorSignature, leftHandObject, rightHandObject)); }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyCSharp.Scripts.EntLogic.Attributes.MethodSignature"/> class. /// </summary> /// <param name="reader">Reader.</param> public MethodSignature(FileIOManager reader) { string nextLine = reader.ReadNextContentLineAndTrim(); this.MethodId = (EntMethodEnum)Enum.Parse(typeof(EntMethodEnum), nextLine); nextLine = reader.ReadNextContentLineAndTrim(); this.returnType = GeneticObject.ParseType(nextLine); int numberOfParameters; nextLine = reader.ReadNextContentLineAndTrim(); if (!int.TryParse(nextLine, out numberOfParameters)) { CommonHelperMethods.ThrowStatementParseException( nextLine, reader, "An integer representing the number of parameters"); } for (int i = 0; i < numberOfParameters; ++i) { nextLine = reader.ReadNextContentLineAndTrim(); Type parsedType = GeneticObject.ParseType(nextLine); this.parameterTypes.Add(parsedType); } }
public GeneticAlgoritm(int numberOfGeneticValues, int numberOfIterations, int maxValue, GeneticObject perfectObject) { _maxValue = maxValue; PerfectObject = perfectObject; _numberOfIterations = numberOfIterations; NumberOfGeneticValues = numberOfGeneticValues; }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyCSharp.Scripts.EntLogic.Attributes.VariableSignature"/> class. /// </summary> /// <param name="reader">Reader.</param> public VariableSignature(FileIOManager reader) { string nextLine = reader.ReadNextContentLineAndTrim(); this.variableType = GeneticObject.ParseType(nextLine); this.VariableId = (EntVariableEnum)Enum.Parse(typeof(EntVariableEnum), reader.ReadNextContentLineAndTrim()); }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyCSharp.Scripts.EntLogic.SerializationObjects.LiteralValue"/> class. /// </summary> /// <param name="reader">Reader.</param> public LiteralValue(FileIOManager reader) { string nextLine = reader.ReadNextContentLineAndTrim(); this.type = GeneticObject.ParseType(nextLine); nextLine = reader.ReadNextContentLineAndTrim(); this.value = GeneticObject.ParseValue(this.type, nextLine); }
void CreateInitialPopulation() { for (int i = 0; i < m_PopulationCount; i++) // For the population count { GeneticObject gCircle = ( GeneticObject )Instantiate(m_GeneticObjectPrefab); // Create new genetic object from the prefab gCircle.Initialize(); // Initialize the new object m_CurrentPopulation.Add(gCircle); // Add it to the current population list } }
private List<LibNoteMessage> GeneticObjectToLibNoteMessage(GeneticObject gObject, int velocity, int channel) { int[] tempValues = gObject.GetValues(); List<LibNoteMessage> tempNotes = new List<LibNoteMessage>(); foreach(int integer in tempValues) { tempNotes.Add(new NoteOn(pitch[integer - 1], velocity, temporaryTime++, channel)); } return tempNotes; }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyCSharp.Scripts.EntLogic.SerializationObjects.LiteralValue"/> class. /// </summary> /// <param name="returnType">Return type.</param> public LiteralValue(Type returnType) { if (returnType == null) { LogUtility.LogError("Cannot create literal value with null return type"); } this.type = returnType; this.value = GeneticObject.CreateTypeAtRandom(this.type); }
public static bool InitializeGame() { if (!GameIsInitialized) { EntBehaviorManager.RegisterGeneticMembers(); GeneticObject.RegisterOperatorsForAllTypes(); } return(true); }
/// <summary> /// Evaluates the condition. /// </summary> /// <param name="instance">The instance to evaluate against.</param> public GeneticBool Evaluate(ref EntBehaviorManager instance) { GeneticObject evaluatedObject = this.rightStatement.Evaluate(ref instance); if (evaluatedObject is GeneticBool) { return((GeneticBool)evaluatedObject); } throw new InvalidOperationException("Condition statement did not evaluate to a GeneticBool"); }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyCSharp.Scripts.EntLogic.Attributes.OperatorSignature"/> class. /// </summary> /// <param name="reader">Reader.</param> public OperatorSignature(FileIOManager reader) { string nextLine = reader.ReadNextContentLineAndTrim(); this.Value = nextLine; nextLine = reader.ReadNextContentLineAndTrim(); this.returnType = GeneticObject.ParseType(nextLine); nextLine = reader.ReadNextContentLineAndTrim(); this.lhsType = GeneticObject.ParseType(nextLine); nextLine = reader.ReadNextContentLineAndTrim(); this.rhsType = GeneticObject.ParseType(nextLine); }
/// <summary> /// Writes to variable. /// </summary> /// <param name="signature">Signature.</param> /// <param name="value">Value.</param> public void WriteToVariable(VariableSignature signature, GeneticObject value) { if (signature.VariableId == EntVariableEnum.HelperInt1) { this.HelperInt1 = value as GeneticInt; return; } if (signature.VariableId == EntVariableEnum.HelperInt2) { this.HelperInt2 = value as GeneticInt; return; } if (signature.VariableId == EntVariableEnum.HelperBool1) { this.HelperBool1 = value as GeneticBool; return; } if (signature.VariableId == EntVariableEnum.HelperBool2) { this.HelperBool2 = value as GeneticBool; return; } if (signature.VariableId == EntVariableEnum.HelperGridDirection1) { this.HelperGridDirection1 = value as GeneticGridDirection; return; } if (signature.VariableId == EntVariableEnum.HelperGridDirection2) { this.HelperGridDirection2 = value as GeneticGridDirection; return; } LogUtility.LogErrorFormat( "No implementation found for writable variable: {0}", signature); }
// Breeds two parents together GeneticObject Breed( GeneticObject parent1, GeneticObject parent2 ) { GeneticObject childObject = ( GeneticObject )Instantiate( m_GeneticObjectPrefab ); // Create a child object childObject.Initialize(); // Initialize the child object if( m_BreedingMethod == BreedingMethod.Mix ) // Depending on the breeding method, call the appropriate DNA breeding funtion { childObject.m_DNA.Mix( parent1.m_DNA, parent2.m_DNA ); } else { childObject.m_DNA.RandomSplice( parent1.m_DNA, parent2.m_DNA ); } childObject.m_DNA.Mutate( m_MutationRate ); // Check for mutations childObject.InitializeDNA(); return childObject; }
void BreedMatingPool() { List <GeneticObject> newGeneration = new List <GeneticObject>(); // Create a list of genetic objects for the new generation for (int i = 0; i < m_PopulationCount; i++) // Create offspring up to the population count so we have a stable population { float rand1 = Random.Range(0f, 1f); // Generate a random number to select the first parent float rand2 = Random.Range(0f, 1f); // Generate a random number to select the second parent GeneticObject parent1 = m_SelectedPopulation[0]; GeneticObject parent2 = m_SelectedPopulation[1]; for (int j = 0; j < m_SelectedPopulation.Count; j++) // Find both parents { if (rand1 > m_SelectedPopulation[j].m_SelectionRangeStart && rand1 < m_SelectedPopulation[j].m_SelectionRangeEnd) // If the random number is within the bounds of the objects selection range { parent1 = m_SelectedPopulation[j]; // Select as parent 1 } if (rand2 > m_SelectedPopulation[j].m_SelectionRangeStart && rand2 < m_SelectedPopulation[j].m_SelectionRangeEnd) // If the random number is within the bounds of the objects selection range { parent2 = m_SelectedPopulation[j]; // Select as parent 1 } } newGeneration.Add(Breed(parent1, parent2)); // Add the bred parents offspring to the new generation } for (int i = 0; i < m_SelectedPopulation.Count; i++) { Destroy(m_SelectedPopulation[i].gameObject); // Destroy all parents so only the children remain } m_CurrentPopulation.Clear(); // Clear the current population list m_SelectedPopulation.Clear(); // Clear the selected population list m_CurrentPopulation = newGeneration.ToList(); // Make the current population the new generation m_Generation++; // Increment the generation count }
// Breeds two parents together GeneticObject Breed(GeneticObject parent1, GeneticObject parent2) { GeneticObject childObject = ( GeneticObject )Instantiate(m_GeneticObjectPrefab); // Create a child object childObject.Initialize(); // Initialize the child object if (m_BreedingMethod == BreedingMethod.Mix) // Depending on the breeding method, call the appropriate DNA breeding funtion { childObject.m_DNA.Mix(parent1.m_DNA, parent2.m_DNA); } else { childObject.m_DNA.RandomSplice(parent1.m_DNA, parent2.m_DNA); } childObject.m_DNA.Mutate(m_MutationRate); // Check for mutations childObject.InitializeDNA(); return(childObject); }
private void Breed(GeneticObject object1, GeneticObject object2) { int[] tempValues1, tempValues2, newValues = new int[NumberOfGeneticValues]; for (int index = 0; index < 2; index++) { tempValues1 = object1.GetValues(); tempValues2 = object2.GetValues(); for (int j = 0; j < NumberOfGeneticValues; j++) { switch (r.Next(9)) { case 0: newValues[j] = r.Next(1,_maxValue + 1); break; case 1: case 2: case 3: case 4: newValues[j] = tempValues1[j]; break; case 5: case 6: case 7: case 8: newValues[j] = tempValues2[j]; break; } } currentObjects.Add(new GeneticObject(newValues)); _numberOfObjectsToRemove++; } }
/// <summary> /// Writes to this variable. /// </summary> /// <param name="instance">The instance to execute against.</param> /// <param name="payload">The value to write.</param> public void WriteToVariable(ref EntBehaviorManager instance, RightStatement payload) { GeneticObject value = payload.Evaluate(ref instance); instance.WriteToVariable(this.signature, value); }
public void AddObject(GeneticObject gObject) { if (gObject.GetValues().Count() == NumberOfGeneticValues) { currentObjects.Add(gObject); } }