/// <summary> /// Adds the given reason-for-grouping to a group. Only one reason of a particular type is allowed. /// If the reason conflicts with a previous reason, the previous is removed and replaced with the new reason. /// TODO: consider removing lowest-scoring, and keeping only highest-scoring reason.... /// /// </summary> /// <param name="reason"></param> public void AddGroupReason(GroupReason reason) { GroupReason reasonToRemove = null; Type reasonType = reason.GetType(); foreach (GroupReason r in reasons) { Type t2 = r.GetType(); if (reasonType.IsAssignableFrom(t2)) { // Conflict found. reasonToRemove = r; break; } } if (reasonToRemove != null) { reasons.Remove(reasonToRemove); } reasons.Add(reason); }
public override void Run() { if (ge1 == null) { ge1 = workspace.PickRandomGroupByStrength(); } if (ge1 == null || !(ge1 is Group)) { return; } Group g1 = (Group)ge1; if (ge2 == null) { ge2 = workspace.PickRandomGroupAdjacentTo(g1); } if (ge2 == null || ge2 == ge1 || !(ge2 is Group)) { return; } Group g2 = (Group)ge2; // Reorder in time if out-of-order. m1 comes first. if (g1.Location > g2.Location) { Group tmp = g1; g1 = g2; g2 = tmp; } // Add to attention history. workspace.RecordCodeletAttentionHistory(this, g1.MinLocation, g1.MaxLocation); workspace.RecordCodeletAttentionHistory(this, g2.MinLocation, g2.MaxLocation); // Make sure groups are non-overlapping!!! if (g1.Overlaps(g2)) { return; } //////////////// // Check for ending dominant in 1st, tonic in 2nd. GroupReason gr1 = null; foreach (GroupReason gr in g1.Reasons) { if (gr is GroupReasonEndDominant) { gr1 = gr; break; } } if (gr1 == null) { return; } GroupReason gr2 = null; foreach (GroupReason gr in g2.Reasons) { if (gr is GroupReasonEndTonic) { gr2 = gr; break; } } if (gr2 == null) { return; } // Got a dom->tonic. double strength = (gr1.ReasonStrength + gr2.ReasonStrength) / 2; double r = Utilities.rand.NextDouble() * 100; if (r < strength) { workspace.AddRelationship(new RelationshipAntecedentConsequentTonality(g1, g2, (float)strength)); // TODO: specicy analogy or relationship: AddRelationshipsToAnalogyCodelet arac = new AddRelationshipsToAnalogyCodelet(100, this, coderack, workspace, slipnet); coderack.AddCodelet(arac); } }