public override void Run()
        {
            if (link == null)
            {
                link = workspace.PickRandomMeasureLinkByRecencyAndStrength();
            }

            if (link == null)
            {
                return;
            }

            Measure m1 = link.m1;
            Measure m2 = link.m2;

            // Check if the measures are adjacent. Otherwise, we can't group.
            if (Math.Abs(m1.number - m2.number) != 1)
            {
                return;
            }

            // Check if either measure is in another group. If so, we can't group.
            //if (m1.hasParent || m2.hasParent)
            //	return;

            // Add to attention history.
            workspace.RecordCodeletAttentionHistory(this, m1.Location);
            workspace.RecordCodeletAttentionHistory(this, m2.Location);

            double r = Utilities.rand.NextDouble() * 100;

            // Try to group if the link is strong enough.
            if (r < link.strength)
            {
                //Group g = workspace.CreateAndAddGroup(m1, m2);

                TemporaryGroup tmpG = new TemporaryGroup(workspace, m1, m2);

                // Record the grouping reason.
                GroupReason reason;
                // Are measures identical?
                if (m1.IsExactlyEqualTo(m2))
                {
                    reason = new GroupReasonComponentsIdentical(tmpG);
                }
                else
                {
                    reason = new GroupReasonComponentsSimilar(tmpG, link.strength);
                }
                tmpG.AddGroupReason(reason);

                // Try to add!
                workspace.AddGroup(tmpG);
            }
        }
        public override void Run()
        {
            if (group == null)
            {
                group = workspace.PickRandomGroupByRecency();
            }

            if (group == null)
            {
                return;
            }

            if (!workspace.groups.Contains(group))
            {
                return;
            }

            // Add to attention history.
            workspace.RecordCodeletAttentionHistory(this, group.MinLocation, group.MaxLocation);


            // Compute the similarity of each pair of subcomponents, left to right, and average.
            // Similarity determined by measure links, for measures, or analogies, for groups.
            double score = ComputeSimilarity();

            if (score < 50)
            {
                return;                 // not good enough
            }
            // Record the grouping reason.
            GroupReason reason;

            if (score > 99.99)
            {
                reason = new GroupReasonComponentsIdentical(group);
            }
            else
            {
                reason = new GroupReasonComponentsSimilar(group, score);
            }
            group.AddGroupReason(reason);
        }