百分比和树木 [英] Percentages and trees

查看:97
本文介绍了百分比和树木的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一棵无序的树. 每个节点代表一个可以完成的任务(1),不能完成的任务(0)或具有子任务.

I have an unordered tree. Each node represents a task that can be done (1), not done (0) or have children tasks.

例如:

1
-1.1
-1.2
--1.2.1
--1.2.2
-1.3
2
3
-3.1
4
-4.1
--4.1.1
5

假设叶子1.2.1、3.1和5已完成

Suppose that the leaves 1.2.1, 3.1 and 5 are done

1
-1.1
-1.2
--1.2.1*
--1.2.2
-1.3
2
3
-3.1*
4
-4.1
--4.1.1
5*

我想计算每个节点的完整性百分比.树叶很容易以0%或100%计算,但是如何计算所有其他树叶?

I want to calculate the percentage of completeness of each node. The leaves are easily calculated with 0% or 100%, but how to compute all the others?

此刻,我从树叶上走过树,并且每个结点都是根据孩子完整度的百分比来计算的.例如:

At the moment, I walk the tree from the leaves on and each node is calculated based on the percentage of completeness of the children. For example:

1      50%
-1.1*  100%
-1.2   0%
2      0%
3      33%
-3.1*  100%
-3.2   0%
-3.3   0%

现在,更多的子级被添加到1.2(不再是叶子,而是成为节点).如果孩子未完成",则1.2始终为0%,因此1始终为50%,但我希望1变得 ,然后降为50%,例如,降入他的孩子和孙辈要使任务完成100%所需完成的任务数量就更多了!

Now, more children are added to 1.2 (that is no more a leaf but becomes a node). If the children are "not done", 1.2 is always 0% and so 1 is 50%, but I would like 1 to be less then 50%, as, descending into his children and grand-children the number of tasks to be completed in order for it to the done 100% is greater!

1       50%
-1.1*   100%
-1.2    0%
--1.2.1 0%
--1.2.2 0%
2       0%
3       33%
-3.1*   100%
-3.2    0%
-3.3    0%

什么是最好的计算方法?谢谢

What is the best way to calculate this? Thanks

推荐答案

您可以将%done定义为完成的总(子)节点除以总(子)节点.仅数叶子.

You can define the %done as total (sub)nodes done divided by total (sub) nodes. Counting only the leaves.

在这种情况下:

       1  (1/2 = 50%)
      / \
   1.1*  1.2

添加额外的节点:

       1  (1/3 = 33%)
      / \
   1.1*  1.2 (0/2 = 0%)
         / \
    1.2.1   1.2.2

如果这还不够,您可以为每个任务添加一个权重,然后计算完成的权重除以总权重.

If that is not enough, you can add a weight to each task and calculate the completed weight divided by the total weight.

这篇关于百分比和树木的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆