/// <summary> /// Measures the equality of two informations /// </summary> /// <param name="other">the other information</param> /// <returns>a value between 0 and 1. if the value is 0, the two items are exactly the same, /// if the value is bigger than zero the two are not the same, if the value has reached 1, the two are /// as different as possible</returns> public float MeasureEquality(BirdInformation other) { float value = 1; if (other.type == this.type) { // the type defines which dimensions can be compared if (type == BirdInformationType.FOOD) { // the vector containing the comparable information of this float[] infoVectorA = new float[] { this.age, this.foodSourceSize, this.foodSourcePosition.x, this.foodSourcePosition.y, this.foodSourcePosition.z }; // the vector containing the comparable information of other float[] infoVectorB = new float[] { other.age, other.foodSourceSize, other.foodSourcePosition.x, other.foodSourcePosition.y, other.foodSourcePosition.z }; int foodProperties = infoVectorA.Length; // the number of comparable food properties float[] infoVectorDistance = new float[foodProperties]; float sqrMagnitude = 0; for (int i = 0; i < foodProperties; i++) { infoVectorDistance[i] = infoVectorA[i] - infoVectorB[i]; sqrMagnitude += infoVectorDistance[i] * infoVectorDistance[i]; } value = Mathf.Sqrt(sqrMagnitude); // to make indifferent to environment circumstances, calculate value in range (0,1) value = value / maxFoodDifferenceVectorMagnitude; } } return value; }
/// <summary> /// Copies the information to a new instance of BirdInformation /// </summary> /// <returns>returns a new instance of BirdInformation with the same info</returns> public BirdInformation Copy() { // create instance BirdInformation newInfo = new BirdInformation(); // copy values newInfo.hops = this.hops; newInfo.certainty = this.certainty; newInfo.firstSeenTimestamp = this.firstSeenTimestamp; newInfo.gatheredTimestamp = -1; // still needs to be set newInfo.type = this.type; newInfo.foodId = this.foodId; newInfo.foodSourcePosition = this.foodSourcePosition; newInfo.foodSourceSize = this.foodSourceSize; if (!foodIdCounts.ContainsKey(foodId)) { foodIdCounts.Add(foodId, 1); } else { foodIdCounts[foodId] += 1; } return newInfo; }