예제 #1
0
        public override void Run()
        {
            if (rt == null)
            {
                rt = workspace.PickRandomTranspositionRelationshipByRecencyAndStrength();
            }

            if (rt == null)
            {
                return;
            }

            if (!workspace.relationships.Contains(rt))
            {
                return;
            }

            // Verify adjacency.
            if (rt.LHS.MaxLocation + 1 != rt.RHS.MinLocation)
            {
                return;
            }

            // Add to attention history.
            workspace.RecordCodeletAttentionHistory(this, rt.LHS.MinLocation, rt.RHS.MaxLocation);

            // Check for existing group.
            foreach (Group g in workspace.groups)
            {
                if (g.GroupElements.Count == 2)
                {
                    if (g.GroupElements[0] == rt.LHS && g.GroupElements[1] == rt.RHS)
                    {
                        return;
                    }
                }
            }

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

            // Make tmp group.
            TemporaryGroup tmpG  = new TemporaryGroup(workspace, rt.LHS, rt.RHS);
            float          score = 75;

            tmpG.AddGroupReason(new GroupReasonNumberOfSubelements(tmpG, 75));
            tmpG.AddGroupReason(new GroupReasonComponentsIdentical(tmpG));


            // Group if the score is strong enough.
            if (r < score)
            {
                // Check for conflicts, and decide whether to kill conflicting.
                workspace.AddGroup(tmpG);
            }
        }
        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);
            }
        }
예제 #3
0
        private Group TemporaryCopyExistingGroupOrFindExisting(Group g)
        {
            Group tempG = workspace.FindEquivalentGroup(g, false);

            if (tempG != null)
            {
                return(tempG);
            }

            tempG = new TemporaryGroup(workspace);

            foreach (GroupElement ge in g.GroupElements)
            {
                if (ge is Group)
                {
                    tempG.AddGroupElement(TemporaryCopyExistingGroupOrFindExisting((Group)ge));
                }
                else
                {
                    tempG.AddGroupElement(ge);
                }
            }

            foreach (GroupReason r in g.Reasons)
            {
                tempG.AddGroupReason(r);
                r.ReplaceGroup(tempG);
            }
            foreach (GroupPenaltyReason r in g.PenaltyReasons)
            {
                tempG.AddGroupPenaltyReason(r);
                r.ReplaceGroup(tempG);
            }

            return(tempG);
        }
예제 #4
0
        public override void Run()
        {
            if (g1 == null)
            {
                g1 = workspace.PickRandomGroupByRecencyAndStrength();
            }

            if (g1 == null)
            {
                return;
            }

            if (g2 == null)
            {
                // pick one adjacent to g1....
                g2 = workspace.PickRandomGroupAdjacentTo(g1);
            }

            if (g2 == null || g1 == g2)
            {
                return;
            }

            if (!workspace.groups.Contains(g1) || !workspace.groups.Contains(g2))
            {
                return;
            }

            if (g1.MinLocation > g2.MinLocation)
            {
                Group tmp = g1;
                g1 = g2;
                g2 = tmp;
            }

            // Check if the groups are adjacent. Otherwise, we can't group.
            int m1 = g1.MaxLocation;
            int m2 = g2.MinLocation;

            if (m2 - m1 != 1)
            {
                return;
            }

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

            // Check if group already exists!
            // TODO>


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


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

            // TODO! Score group strenght reasonably.


            // TODODODODODODOODODODODODODO

            // Make tmp group.
            TemporaryGroup tmpG  = new TemporaryGroup(workspace, g1, g2);                                  // TODO: tmp group messes up g1 and g2 parents
            float          score = 75 / (1 + (Math.Abs(g2.GroupElements.Count - g1.GroupElements.Count))); //MetaGroupStrength;

            tmpG.AddGroupReason(new GroupReasonNumberOfSubelements(tmpG, score));

            if (a != null)
            {
                tmpG.AddGroupReason(new GroupReasonAnalogySupport(tmpG, a.Strength, a));
            }

            // Group if the score is strong enough.
            if (r < score)
            {
                Group newGroup = workspace.AddGroup(tmpG);
                if (newGroup != null)
                {
                    // TODO: add reasons....
                }
            }
        }
예제 #5
0
        public override void Run()
        {
            if (ge1 == null)
            {
                ge1 = workspace.PickRandomGroupElementByRecencyAndStrength();
            }

            if (ge1 == null)
            {
                return;
            }

            if (ge2 == null)
            {
                // pick one adjacent to g1....
                ge2 = workspace.PickRandomGroupElementAdjacentTo(ge1);
            }

            if (ge2 == null || ge1 == ge2)
            {
                return;
            }

            if (!workspace.GroupElements.Contains(ge1) || !workspace.GroupElements.Contains(ge2))
            {
                return;
            }

            if (ge1.MinLocation > ge2.MinLocation)
            {
                GroupElement tmp = ge1;
                ge1 = ge2;
                ge2 = tmp;
            }

            // Check if the group elements are adjacent. Otherwise, we can't group.
            int m1 = ge1.MaxLocation;
            int m2 = ge2.MinLocation;

            if (m2 - m1 != 1)
            {
                return;
            }

            //Make sure they are both of same level, or we can't group.
            if (ge1.Level != ge2.Level)
            {
                return;
            }

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

            // Check if group already exists!
            // TODO>

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

            // TODO! Score group strenght reasonably.
            // TODODODODODODOODODODODODODO

            // Make tmp group.
            TemporaryGroup tmpG  = new TemporaryGroup(workspace, ge1, ge2);
            float          score = 50;   // 75 / (1 + (Math.Abs(ge2.GroupElements.Count - ge1.GroupElements.Count))); //MetaGroupStrength;

            tmpG.AddGroupReason(new GroupReasonNumberOfSubelements(tmpG, score));


            // Group if the score is strong enough.
            if (r < score)
            {
                // Check for conflicts, and decide whether to kill conflicting.
                workspace.AddGroup(tmpG);

                // TODO: add reasons....
            }
        }
예제 #6
0
        public override void Run()
        {
            if (eg == null)
            {
                // Pick a 1st level group starting now.
                eg = workspace.expectations.PickRandomGroupWithConditions(workspace.measures.Count - 1, 1);
            }

            if (eg == null)
            {
                return;
            }

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

            // 2 conditions: expected group starts now, or it started earlier.

            // Case 1:
            if (eg.MinLocation == workspace.measures.Count - 1)
            {
                // Check level. Level 1, or metagroup?
                if (eg.Level == 1)
                {
                    // Suggest a group that matches the expected group.
                    TemporaryGroup tmpG = new TemporaryGroup(workspace, workspace.measures[workspace.measures.Count - 1]);
                    tmpG.AddGroupReason(new GroupReasonExpected(tmpG, eg.ComputeStrength(), eg));
                    Group newGroup = workspace.AddGroup(tmpG);
                    if (newGroup == null)
                    {
                        return;
                    }

                    // TODO

                    /*
                     * //Also add any metagroups above this one.
                     * List<ExpectedGroup> metagroups = new List<ExpectedGroup>();
                     * metagroups = FindExpectedGroupsAbove(eg);
                     * Group child = newGroup;
                     * foreach (ExpectedGroup meta in metagroups) {
                     *      tmpG = new TemporaryGroup(workspace, child);
                     *      tmpG.AddGroupReason(new GroupReasonExpected(tmpG, meta.ComputeStrength(), meta));
                     *      newGroup = workspace.AddGroup(tmpG);
                     *      if (newGroup == null)
                     *              return;
                     *      child = newGroup;
                     * }
                     */
                }
                else
                {
                    // Metagroup.
                    // TODO.
                }
            }
            else
            {
                // Case 2: expected group started earlier.

                // Check level.
                // TODO.
            }



            /*
             * double r = Utilities.rand.NextDouble() * 100;
             *
             * // TODO! Score group strenght reasonably.
             * // TODODODODODODOODODODODODODO
             *
             * // Make tmp group.
             * float score = 75 / (1 + (Math.Abs(g2.GroupElements.Count - g1.GroupElements.Count))); //MetaGroupStrength;
             *
             *
             *
             * // Group if the score is strong enough.
             * if (r < score) {
             *      workspace.AddGroup(tmpG);
             *
             *      // TODO: add reasons....
             * }
             */
        }