Esempio n. 1
0
        /// <summary>
        /// Evaluation procedure -- implementation for modules without layers
        /// </summary>
        /// <param name="input">The input.</param>
        /// <param name="wRecord">The w record.</param>
        /// <returns></returns>
        public override ISpiderModuleData evaluate(ISpiderModuleData input, modelSpiderSiteRecord wRecord)
        {
            List <spiderLink>             output  = new List <spiderLink>();
            spiderModuleData <spiderLink> outdata = new spiderModuleData <spiderLink>();

            moduleDLCRecord       moduleLevelReportTable    = ((spiderModuleData <spiderLink>)input).moduleDLC;
            moduleIterationRecord moduleDLCRecordTableEntry = ((spiderModuleData <spiderLink>)input).moduleDLCRecordTableEntry;

            if (imbWEMManager.settings.directReportEngine.DR_ReportModules)
            {
                //dataInput.moduleDLCRecordTableEntry = dataInput.moduleDLC.GetOrCreate(wRecord.iteration.ToString("D3") + module.name);
                moduleDLCRecordTableEntry.reportEvaluateStart(input as spiderModuleData <spiderLink>, wRecord, this); // <--- module level report --- start
            }

            input.active.ForEach(x => output.Add(x as spiderLink)); // ----- this is part where the layer modules are emulated

            if (imbWEMManager.settings.directReportEngine.DR_ReportModules)
            {
                moduleDLCRecordTableEntry.reportEvaluateEnd(output, wRecord, this);                                                             // <--- module level report --- start
            }
            outdata.active.AddRange(rankLinks(output, wRecord.iteration));


            if (imbWEMManager.settings.directReportEngine.DR_ReportModules)
            {
                moduleDLCRecordTableEntry.reportEvaluateAlterRanking(outdata.active, wRecord, this);                                                            // <--- module level report --- start
            }
            return(outdata);
        }
Esempio n. 2
0
        /// <summary>
        /// Evaluates the specified input with links
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns></returns>
        public spiderModuleData <spiderLink> evaluate(spiderModuleData <spiderLink> input, modelSpiderSiteRecord wRecord)
        {
            // wRecord.lastInput = input.Clone();

            //  moduleDLCRecord moduleLevelReportTable = wRecord.frontierDLC[this.name];

            //     moduleIterationRecord moduleDLCRecordTableEntry = null;

            moduleIterationRecord moduleDLCRecordTableEntry = input.moduleDLCRecordTableEntry;

            if (imbWEMManager.settings.directReportEngine.DR_ReportModules)
            {
                moduleDLCRecordTableEntry.reportEvaluateStart(input, wRecord, this);
            }

            wRecord.logBuilder.Append(input.GetInlineDescription("Input (" + name + ") "));

            spiderModuleData <spiderLink> output = new spiderModuleData <spiderLink>();

            output.inactive.AddRange(input.inactive);

            List <spiderLink> rest = new List <spiderLink>();

            // < --- starting iteration for the layer rules
            foreach (layerDistributionActiveRuleBase aRule in layerActiveRules)
            {
                aRule.startIteration(wRecord.iteration, wRecord);
            }


            // << ---- learning about the links
            foreach (spiderLink link in input.active)
            {
                foreach (layerDistributionActiveRuleBase activeRule in layerActiveRules)
                {
                    activeRule.learn(link);
                }
            }

            // <<----- evaluation of the links
            foreach (spiderLink link in input.active)
            {
                bool                      assigned   = false;
                layerCollection           assignedTo = null;
                layerDistributionRuleBase layerRule  = null;
                foreach (layerDistributionPassiveRuleBase passiveRule in layerPassiveRules)
                {
                    spiderEvalRuleResult lres = link.marks[passiveRule];
                    if (lres == null)
                    {
                        lres = passiveRule.evaluate(link);
                        link.marks.deploy(lres);
                    }

                    if (lres.layer > -1)
                    {
                        assignedTo = layers[lres.layer];
                        assigned   = true;
                        layers[lres.layer].Push <spiderLink>(link);
                        layerRule = passiveRule;
                        break;
                    }
                }
                if (!assigned)
                {
                    foreach (layerDistributionActiveRuleBase activeRule in layerActiveRules)
                    {
                        spiderEvalRuleResult lres = activeRule.evaluate(link);
                        link.marks.deploy(lres);

                        if (lres.layer > -1)
                        {
                            assignedTo = layers[lres.layer];
                            assigned   = true;
                            layers[lres.layer].Push <spiderLink>(link);
                            layerRule = activeRule;
                            break;
                        }
                    }
                }

                if (!assigned)
                {
                    rest.Add(link);
                }
                else
                {
                    wRecord.logBuilder.AppendLine("Link [" + link.url + "] => " + assignedTo.name + "(" + assignedTo.Count + ") [" + layerRule.tagName + "]");
                }
            }

            switch (restPolicy)
            {
            case spiderLayerModuleEvaluationRestPolicy.assignToTheInactive:
                output.inactive.AddRange(rest);
                break;

            case spiderLayerModuleEvaluationRestPolicy.assignToTheDeepestLayer:
                output.inactive.AddRange(layers.Deepest.Push <spiderLink>(rest));
                break;
            }


            //  wRecord.logBuilder.Append(layers.GetInlineDescription());



            List <spiderLink> result = layers.Pull <spiderLink>(pullLimit, doTakeFromLower);

            if (imbWEMManager.settings.directReportEngine.DR_ReportModules)
            {
                moduleDLCRecordTableEntry.reportEvaluateEnd(result, wRecord, this);
                //  input.moduleDLC.reportEvaluateEnd(result, wRecord, moduleDLCRecordTableEntry, this);
            }

            wRecord.logBuilder.AppendLine("Module output => layers[" + layers.layer_id + "].Pull(" + pullLimit + ", " + doTakeFromLower + ") => " + result.Count);

            // <<----- ranking
            result = rankLinks(result, wRecord.iteration);

            if (imbWEMManager.settings.directReportEngine.DR_ReportModules)
            {
                moduleDLCRecordTableEntry.reportEvaluateAlterRanking(result, wRecord, this);
                //moduleLevelReportTable.reportEvaluateAlterRanking(result, wRecord, moduleDLCRecordTableEntry, this); // ------ module level report -- after ranking
                // moduleLevelReportTable.AddOrUpdate(moduleDLCRecordTableEntry);
            }

            if (result.Any())
            {
                output.active.AddRange(result);
                output.isModuleGaveUp = false;
            }
            else
            {
                output.active.AddRange(input.active);
                output.isModuleGaveUp = true;
            }

            wRecord.logBuilder.Append(output.GetInlineDescription("Output"));



            return(output);
        }