How to resolve the algorithm Functional coverage tree step by step in the Julia programming language

Published on 22 June 2024 08:30 PM

How to resolve the algorithm Functional coverage tree step by step in the Julia programming language

Table of Contents

Problem Statement

Functional coverage is a measure of how much a particular function of a system has been verified as correct. It is used heavily in tracking the completeness of the verification of complex System on Chip (SoC) integrated circuits, where it can also be used to track how well the functional requirements of the system have been verified. This task uses a sub-set of the calculations sometimes used in tracking functional coverage but uses a more familiar(?) scenario. The head of the clean-up crews for "The Men in a very dark shade of grey when viewed at night" has been tasked with managing the cleansing of two properties after an incident involving aliens. She arranges the task hierarchically with a manager for the crews working on each house who return with a breakdown of how they will report on progress in each house. The overall hierarchy of (sub)tasks is as follows, The head of cleanup knows that her managers will report fractional completion of leaf tasks (tasks with no child tasks of their own), and she knows that she will want to modify the weight of values of completion as she sees fit. Some time into the cleaning, and some coverage reports have come in and she thinks see needs to weight the big house2 60-40 with respect to coverage from house1 She prefers a tabular view of her data where missing weights are assumed to be 1.0 and missing coverage 0.0. The coverage of a node in the tree is calculated as the weighted average of the coverage of its children evaluated bottom-upwards in the tree. The task is to calculate the overall coverage of the cleaning task and display the coverage at all levels of the hierarchy on this page, in a manner that visually shows the hierarchy, weights and coverage of all nodes. After calculating the coverage for all nodes, one can also calculate the additional/delta top level coverage that would occur if any (sub)task were to be fully covered from its current fractional coverage. This is done by multiplying the extra coverage that could be gained

1 − c o v e r a g e

{\displaystyle 1-coverage}

for any node, by the product of the powers of its parent nodes from the top down to the node. The power of a direct child of any parent is given by the power of the parent multiplied by the weight of the child divided by the sum of the weights of all the direct children. The pseudo code would be: Followed by a call to:

Note: to aid in getting the data into your program you might want to use an alternative, more functional description of the starting data given on the discussion page.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Functional coverage tree step by step in the Julia programming language

This code is a data analysis and manipulation script written in Julia programming language. It processes a CSV file containing data about coverage and weighting of some items, organized in a hierarchical structure indicating which items are children of which other items. The code updates the coverage values and identifies potential increases in coverage based on their weight and hierarchical relationships.

  1. Function updatecoverage:

    • Input: dfname (string) - Name of the input CSV file, and outputname (string) - Name of the output CSV file.
    • Process:
      • Reads the input CSV file using the CSV module and stores it in a DataFrame df.
      • Initializes a dictionary dchild that maps each parent item (index) to a vector of its child item (indices).
      • Iterates through each row in the DataFrame df and updates the dchild dictionary accordingly.
      • Defines a function coverage that calculates the coverage for each item based on its children's coverage and weight. It recursively traverses the parent-child hierarchy to calculate the coverage.
      • Updates the COVERAGE column of df using the coverage function.
      • Defines a function possibleincrease that calculates the potential increase in coverage if a particular item were to have full coverage. It considers the hierarchy and weight of the items. It returns 0 if the item already has children.
      • Adds a new column POTENTIAL to df containing the potential increase in coverage for each item.
      • Writes the updated DataFrame df to the output CSV file.
  2. Function displaycoveragedb:

    • Input: dfname (string) - Name of the CSV file containing the coverage information.
    • Process:
      • Reads the input CSV file using the CSV module and stores it in a DataFrame df.
      • Calculates the indentation level for each row based on its hierarchical position.
      • Formats the output strings to display the data in a hierarchical and readable way, including the index, name, weight, coverage, and potential increase in coverage (if available).
  3. Main Program Flow:

    • Defines constant dbname as the name of the input coverage CSV file and newdbname as the name of the output coverage CSV file.
    • Calls displaycoveragedb with dbname to display the input coverage data.
    • Calls updatecoverage with dbname and newdbname to update the coverage and potential increase values.
    • Calls displaycoveragedb with newdbname to display the updated coverage data.

In summary, this code updates coverage values and identifies potential coverage increases based on a hierarchical structure of items and their weights. It then displays the input and updated coverage information in a formatted and readable manner.

Source code in the julia programming language

using CSV, DataFrames, Formatting

function updatecoverage(dfname, outputname)
    df = CSV.read(dfname)
    dchild = Dict{Int, Vector{Int}}([i => Int[] for i in 0:maximum(df[!, 1])])

    for row in eachrow(df)
        push!(dchild[row[3]], row[1])
    end

    function coverage(t)
        return dchild[t] == [] ? df[t, :COVERAGE] * df[t, :WEIGHT] :
            sum(coverage, dchild[t]) / sum(x -> df[x, :WEIGHT], dchild[t]) * df[t, :WEIGHT]
    end

    df[!, :COVERAGE] .= coverage.(df.NUMBER)

    function possibleincrease(t)
        if !isempty(dchild[t])
            return 0.0
        else
            newcoverage = deepcopy(df.COVERAGE)
            newcoverage[t] = 1.0
            oldcoverage = newcoverage[1]
            function potentialcoverage(t)
                return dchild[t] == [] ? newcoverage[t] * df[t, :WEIGHT] :
                    sum(potentialcoverage, dchild[t]) / sum(x -> df[x, :WEIGHT],
                        dchild[t]) * df[t, :WEIGHT]
            end

            newcoverage .= potentialcoverage.(df[!, 1])
            return newcoverage[1] - oldcoverage
        end
    end

    df.POTENTIAL = possibleincrease.(df[!, 1])

    CSV.write(outputname, df)
end

function displaycoveragedb(dfname)
    df = CSV.read(dfname)
    indentlevel(t) = (i = 0; while (j = df[t, 3]) != 0 i += 1; t = j end; i)
    indent1 = [indentlevel(i) for i in df.NUMBER]
    maxindent = maximum(indent1)
    indent2 = maxindent .- indent1
    showpot = size(df)[2] == 6
    println("INDEX       NAME_HIERARCHY                         WEIGHT      COVERAGE    (POTENTIAL INCREASE)")
    for (i, row) in enumerate(eachrow(df))
        println(rpad(row[1], 7), "       "^indent1[i], rpad(row[2], 20), "       "^indent2[i],
            rpad(row[4], 8), rpad(format(row[5]), 12), showpot && row[6] != 0 ? format(row[6]) : "")
    end
end

const dbname = "coverage.csv"
const newdbname = "coverageupdated.csv"

println("Input data:")
displaycoveragedb(dbname)
updatecoverage(dbname, newdbname)
println("\nUpdated data:")
displaycoveragedb(newdbname)


  

You may also check:How to resolve the algorithm Strip control codes and extended characters from a string step by step in the Mathematica/Wolfram Language programming language
You may also check:How to resolve the algorithm Queue/Usage step by step in the Phix programming language
You may also check:How to resolve the algorithm Sum and product of an array step by step in the Lingo programming language
You may also check:How to resolve the algorithm Keyboard input/Keypress check step by step in the Haskell programming language
You may also check:How to resolve the algorithm Truncatable primes step by step in the Ruby programming language