private IDictionary <int, RlmCyclecompleteArgs> RunOneSession(RlmNetwork network, IEnumerable <KeyValuePair <string, Resource> > resourceInputs, bool learn = true, bool showCycleOutput = false) { CycleOutputs.Clear(); SessionOutputs.Clear(); IDictionary <int, RlmCyclecompleteArgs> cycleOutputDic = new Dictionary <int, RlmCyclecompleteArgs>(); TrainingVariables["SessionScore"].Value = 0; long sessId = network.SessionStart(); List <object> outputList = new List <object>(); //TODO: check later for multiple inputs int min = 0; int max = 0; var resIn = resourceInputs.First(); Resource res = resIn.Value; Dictionary <string, int> inputRange = GetInputRange(res); min = inputRange["Min"]; max = inputRange["Max"]; bool usedExcludeSolutions = false; for (int j = min; j <= max; j++) { RlmCyclecompleteArgs result; List <long> excludeSolutions = null; while (true) { //Populate input values var invs = new List <RlmIOWithValue>(); foreach (var a in network.Inputs) { invs.Add(new RlmIOWithValue(a, j.ToString())); CycleInputs[a.Name] = j; } //Build and run a new RlmCycle var Cycle = new RlmCycle(); result = Cycle.RunCycle(network, sessId, invs, learn, excludeSolutions: excludeSolutions); //TODO: check later for multiple outputs var rlmOut = network.Outputs.First(); var value = result.CycleOutput.Outputs.First(b => b.Name == rlmOut.Name).Value; if (!AllowDuplicates && !learn) { bool hasDup = false; foreach (var rlmOutputs in SessionOutputs) { if (rlmOutputs.Value.Any(a => a.ToString() == value)) { if (excludeSolutions == null) { excludeSolutions = new List <long>(); } excludeSolutions.Add(result.CycleOutput.SolutionID); hasDup = true; System.Diagnostics.Debug.WriteLine("Duplicate found!"); break; } } if (hasDup) { usedExcludeSolutions = true; continue; } } //set current rn and sl cycleOutputDic[j] = result; CycleOutputs[rlmOut.Name] = value; outputList.Add(value); SessionOutputs[rlmOut.Name] = outputList; break; } double cycleScore = ScoreCycle(); if (showCycleOutput) { //if (j == min && PredictData.Count() > min) //{ // PredictData.Clear(); //} //// exposed cyclescore on predict //PredictData.Add(cycleScore.ToString()); } network.ScoreCycle(result.CycleOutput.CycleID, cycleScore); TrainingVariables["CycleScore"].Value = 0; } double sessionScore = ScoreSession(); LastScore = sessionScore; if (LastScore > HighScore) { HighScore = LastScore; } network.SessionEnd(sessionScore); TraceLogObjectsIf(!learn && !usedExcludeSolutions && sessionScore < HighScore, $"{network.DatabaseName}_BestSolutions_InMemory", network.MemoryManager.BestSolutions.SelectMany(a => a.Value.Values)); TraceLog($"Score: {string.Format("{0:n}", sessionScore)}"); // exposed session data //SessionData.Add(sessionScore.ToString()); return(cycleOutputDic); }