public override Option <float> FloatObs(BaseAgent agent) { if (ObserveAsBool) { return((agent.GetComponent <ObservableFields>().FieldsHash.ContainsKey(FieldName) ? 1f : 0f) .SomeNotNull()); } else { float f = 0; agent.GetComponent <ObservableFields>().FieldsHash.TryGetValue(FieldName, out f); return(f.SomeNotNull()); } }
public override void AddReward(BaseAgent agent, float[] vectorActions) { if (agent.GetComponent <ObservableFields>().FieldsHash.ContainsKey(Label)) { agent.AddReward(Reward / (float)agent.agentParameters.maxStep); } }
public override void Initialize(BaseAgent agent) { if (agent.gameObject.CompareTag(Tag)) { agent.GetComponent <ObservableFields>().FieldsHash.Add(Label, Time.time); } }
/* * Reproduction: método que tramita la reproducción de los agentes. Si la reproducción sale bien, llamarán al método CrossOver que se * encargará de instanciar a los nuevos agentes. */ public bool Reproduction(BaseAgent otherParent) { waitingTime = 0; if (otherParent.tag == "Pez") { if (gameObject.GetComponent <Fish>().juvenile || otherParent.GetComponent <Fish>().juvenile) { return(false); } } else if (otherParent.tag == "Rana") { if (Mathf.Pow(transform.position.x, 2) + Mathf.Pow(transform.position.y, 2) > Mathf.Pow(20.5f, 2)) { return(false); } } float other = otherParent.CalculateFitness(); double av = (CalculateFitness() + other) / 2; // Las posibilidades de reproduccion son mas altas conforme mayor sea el fitness de ambos if (Random.Range(0, 100) < av) { float offspringNumber = Random.Range(1, (dna[3] + otherParent.dna[3]) / 2); //Debug.Log(offspringNumber); for (int i = 0; i < offspringNumber; i++) { Crossover(otherParent); } timesReproduced++; return(true); } return(false); }