Ejemplo n.º 1
0
    public static TempVariables TempVariables(string pattern, int dayHours, int weekHours)
    {
        TempVariables temp = new TempVariables();

        int baseMaximo = dayHours;

        temp.HorasRestantes = weekHours;
        int exponente = 0;


        for (var i = 0; i < Constants.PatternLenght; i++)
        {
            var actualCaracter = pattern.Substring(i, 1);

            if (actualCaracter == "?")
            {
                temp.ValorMaximo += baseMaximo * Convert.ToInt32(Math.Pow(10, exponente));
                temp.ValorMinimo += 0;
                exponente++;
                temp.NumberOfQuestions++;
            }
            else
            {
                temp.HorasRestantes -= int.Parse(actualCaracter);
            }
        }
        return(temp);
    }
Ejemplo n.º 2
0
        /// <summary>
        /// The statistics related to the variables and computations in this block
        /// </summary>
        public Dictionary <string, string> GetStatistics()
        {
            var stats = new Dictionary <string, string>();

            var inputVarsTotalCount  = _inputVariables.Count;
            var inputVarsUsedCount   = _inputVariables.Count(inputVar => inputVar.IsUsed);
            var inputVarsUnUsedCount = inputVarsTotalCount - inputVarsUsedCount;

            stats.Add("Used Input Variables: ", inputVarsUsedCount.ToString());
            stats.Add("Unused Input Variables: ", inputVarsUnUsedCount.ToString());
            stats.Add("Total Input Variables: ", inputVarsTotalCount.ToString());

            var tempVarsCount           = TempVariables.Count();
            var tempVarsSubExprCount    = TempVariables.Count(item => item.IsFactoredSubExpression);
            var tempVarsNonSubExprCount = tempVarsCount - tempVarsSubExprCount;

            stats.Add("Common Subexpressions Temp Variables: ", tempVarsSubExprCount.ToString());
            stats.Add("Generated Temp Variables: ", tempVarsNonSubExprCount.ToString());
            stats.Add("Total Temp Variables: ", tempVarsCount.ToString());

            stats.Add("Total Output Variables: ", OutputVariables.Count().ToString());

            stats.Add("Total Computed Variables: ", ComputedVariables.Count.ToString());

            stats.Add("Target Temp Variables: ", TargetTempVarsCount.ToString());

            var computationsCountTotal =
                ComputedVariables
                .Select(computedVar => computedVar.RhsExpr.ComputationsCount)
                .Sum();

            var computationsCountAverage =
                computationsCountTotal / (double)ComputedVariables.Count;

            stats.Add("Avg. Computations Count: ", computationsCountAverage.ToString("0.000"));
            stats.Add("Total Computations Count: ", computationsCountTotal.ToString());

            var memreadsCountTotal =
                ComputedVariables
                .Select(computedVar => computedVar.RhsVariablesCount)
                .Sum();

            var memreadsCountAverage =
                memreadsCountTotal / (double)ComputedVariables.Count;

            stats.Add("Avg. Memory Reads: ", memreadsCountAverage.ToString("0.000"));
            stats.Add("Total Memory Reads: ", memreadsCountTotal.ToString());

            return(stats);
        }
Ejemplo n.º 3
0
    public static List <string> findCombinations(TempVariables patternInfo, int workHours, int dayHours, string originalPattern)
    {
        int auxiliarPattern = patternInfo.ValorMinimo;

        List <string> patrones = new List <string>();

        while (auxiliarPattern <= patternInfo.ValorMaximo)
        {
            var stringPattern = auxiliarPattern.ToString().PadLeft(patternInfo.NumberOfQuestions, '0');

            if (CheckPattern(stringPattern, dayHours, patternInfo.HorasRestantes))
            {
                patrones.Add(createPattern(originalPattern, stringPattern));
            }
            auxiliarPattern = auxiliarPattern + 1;
        }
        return(patrones);
    }
Ejemplo n.º 4
0
        /// <summary>
        /// Try to get a temporary variable by its low-level name
        /// </summary>
        /// <param name="lowLevelVarName"></param>
        /// <param name="tempVar"></param>
        /// <returns></returns>
        public bool TryGetTempVariable(string lowLevelVarName, out GMacCbTempVariable tempVar)
        {
            if (VariablesDictionary.Count == 0)
            {
                tempVar = TempVariables.FirstOrDefault(item => item.LowLevelName == lowLevelVarName);
                return(tempVar != null);
            }

            GMacCbVariable result;

            if (VariablesDictionary.TryGetValue(lowLevelVarName, out result) == false)
            {
                tempVar = null;
                return(false);
            }

            tempVar = result as GMacCbTempVariable;
            return(tempVar != null);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// The statistics related to the variables and computations in this block as a single string
        /// </summary>
        /// <returns></returns>
        public string GetStatisticsReport()
        {
            var s = new StringBuilder();

            var inputVarsTotalCount  = _inputVariables.Count;
            var inputVarsUsedCount   = _inputVariables.Count(inputVar => inputVar.IsUsed);
            var inputVarsUnUsedCount = inputVarsTotalCount - inputVarsUsedCount;

            s.Append("Input Variables: ")
            .Append(inputVarsUsedCount)
            .Append(" used, ")
            .Append(inputVarsUnUsedCount)
            .Append(" not used, ")
            .Append(inputVarsTotalCount)
            .AppendLine(" total.")
            .AppendLine();

            var tempVarsCount           = TempVariables.Count();
            var tempVarsSubExprCount    = TempVariables.Count(item => item.IsFactoredSubExpression);
            var tempVarsNonSubExprCount = tempVarsCount - tempVarsSubExprCount;

            s.Append("Temp Variables: ")
            .Append(tempVarsSubExprCount)
            .Append(" sub-expressions, ")
            .Append(tempVarsNonSubExprCount)
            .Append(" generated temps, ")
            .Append(tempVarsCount)
            .AppendLine(" total.")
            .AppendLine();

            if (TargetTempVarsCount > 0)
            {
                s.Append("Target Temp Variables: ")
                .Append(TargetTempVarsCount)
                .AppendLine(" total.")
                .AppendLine();
            }

            var outputVarsCount = OutputVariables.Count();

            s.Append("Output Variables: ")
            .Append(outputVarsCount)
            .AppendLine(" total.")
            .AppendLine();

            var computationsCountTotal =
                ComputedVariables
                .Select(computedVar => computedVar.RhsExpr.ComputationsCount)
                .Sum();

            var computationsCountAverage =
                computationsCountTotal / (double)ComputedVariables.Count;

            s.Append("Computations: ")
            .Append(computationsCountAverage)
            .Append(" average, ")
            .Append(computationsCountTotal)
            .AppendLine(" total.")
            .AppendLine();

            var memreadsCountTotal =
                ComputedVariables
                .Select(computedVar => computedVar.RhsVariablesCount)
                .Sum();

            var memreadsCountAverage =
                memreadsCountTotal / (double)ComputedVariables.Count;

            s.Append("Memory Reads: ")
            .Append(memreadsCountAverage)
            .Append(" average, ")
            .Append(memreadsCountTotal)
            .AppendLine(" total.")
            .AppendLine();

            s.Append("Memory Writes: ")
            .Append(ComputedVariables.Count)
            .AppendLine(" total.")
            .AppendLine();

            return(s.ToString());
        }