Example #1
0
        public ExpectedGroup GenerateExpectedGroupBasedOn(Group group, int offset, float expectationStrength, bool compete)
        {
            // First check other competing expectation groups. Delete them and add this one if we win.
            // Note that ALL other expectation groups are considered "competing". i.e. only 1 set of expectations can be
            // active at one time.

            double str = group.ComputeStrength();

            // Look for conflicts and resolve.

            if (compete)
            {
                /*
                 * foreach (Group g2 in groups) {
                 *      if (Utilities.FightItOut(g2.ComputeStrength(), str, workspace.Temperature)) {
                 *              // Lost fight.
                 *              return null;
                 *      }
                 * }*/
                ExpectedGroup eGroup = FindLargestExpectationGroup();
                if (eGroup != null)
                {
                    if (Utilities.FightItOut(eGroup.ComputeStrength(), str, workspace.Temperature))
                    {
                        // Lost fight.
                        return(null);
                    }
                }

                // Won all fights. Clean out expectations.
                RemoveAllExpectations();
                this.offset      = offset;
                this.sourceGroup = group;
            }


            // Copy the group structure, recursively.
            ExpectedGroup expectedGroup = MakeNewExpectedGroup(group.MinLocation + offset, group.MaxLocation + offset, group.Level, group.ComputeStrength());


            foreach (GroupElement e in group.GroupElements)
            {
                if (e is Measure)
                {
                    GenerateExpectedMeasureBasedOn((Measure)e, offset, group.ComputeStrength());
                }
                else
                {
                    GenerateExpectedGroupBasedOn((Group)e, offset, expectationStrength, false);
                }
            }

            return(expectedGroup);
        }
Example #2
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....
             * }
             */
        }