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);


            // Check out the subcomponents of this group, and penalize based on the ratio of lengths (do it foreach pair of subcomponents)
            int num = group.GroupElements.Count;

            for (int i = 0; i < num - 1; i++)
            {
                // Compute the 2 lengths of this pair.
                int len1 = group.GroupElements[i].LengthInMeasures;
                int len2 = group.GroupElements[i + 1].LengthInMeasures;
                if (len1 == len2)
                {
                    return;
                }

                // Sort in order so that len 1 is shorter than len2.
                if (len1 > len2)
                {
                    int tmp = len2;
                    len2 = len1;
                    len1 = tmp;
                }
                double x = (float)len1 / len2;

                // coefficients: generated by http://zunzun.com   using Logistic B: y = a / (1.0 + (x/b)
                // input data: x = 0, y = 1
                //				.5 => .8
                //				.8 => .1
                //				1.0 => 0
                double b        = 0.6;
                double c        = 7.74;
                double strength = 100.0 / (1.0 + Math.Pow(x / b, c));

                group.AddGroupPenaltyReason(new GroupPenaltySubcomponentLength(group, strength));
            }
        }
Esempio n. 2
0
        public override void Run()
        {
            if (group == null)
            {
                group = workspace.PickRandomGroupByRecency();
            }

            if (group == null)
            {
                return;
            }

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

            if (workspace.barlines.Count < 1)
            {
                return;
            }

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

            // Check if this group crosses a hierarchy border that is greater than those at the group ends.

            // Find min of the hierarchy strenghts of start and end.

            int startHierarchy = 0;

            if (workspace.barlines.Count > group.MinLocation)
            {
                startHierarchy = workspace.barlines[group.MinLocation];
            }
            int endHierarchy = workspace.barlines[0];

            if (workspace.barlines.Count > group.MaxLocation + 1)
            {
                endHierarchy = workspace.barlines[group.MaxLocation + 1];
            }

            int minHierarchy = Math.Min(startHierarchy, endHierarchy);

            // Look for the maximal hierarhcy level inside group (excluding endpoints)
            int max = -1;

            for (int i = group.MinLocation + 1; i <= group.MaxLocation && i < workspace.barlines.Count; i++)
            {
                if (workspace.barlines[i] > max)
                {
                    max = workspace.barlines[i];
                }
            }
            if (max < minHierarchy)
            {
                return;
            }

            // Penalize based on difference; include a small penalty for same height internally as at ends.
            // This promotes powers-of-two ideas.

            double strength = Constants.PENALTY_PER_LEVEL_HIERARCHY_CROSSING * (max - minHierarchy + 1);

            group.AddGroupPenaltyReason(new GroupPenaltyHierarchyCrossing(group, strength));
        }