Dependency Algorithm - find a minimum set of packages to install

前端 未结 10 1994
别那么骄傲
别那么骄傲 2021-02-02 17:23

I\'m working on an algorithm which goal is to find a minimum set of packages to install package \"X\".

I\'ll explain better with an example:



        
10条回答
  •  渐次进展
    2021-02-02 17:49

    "I dint get the problem with "or" (the image is not loading for me). Here is my reasoning . Say we take standard shortest route algo like Dijkstras and then use equated weightage to find the best path . Taking your example Select the best Xr from below 2 options

    Xr= X+Ar+Er
    Xr= X+Ar+Cr
    

    where Ar = is the best option from the tree A=H(and subsequent child's) or A=Y(and subsequent childs)

    The idea is to first assign standard weight for each or option (since and option is not a problem) . And later for each or option we repeat the process with its child nodes till we reach no more or option .

    However , we need to first define , what best choice means, assume that least number of dependencies ie shortest path is the criteria . The by above logic we assign weight of 1 for X. There onwards

    X=1
    X=A and E or C hence X=A1+E1 and X=A1+C1
    A= H or Y, assuming H and Y are  leaf node hence A get final weight as 1
    hence , X=1+E1 and X=1+C1
    
    Now for E and C
    E1=B1+Z1 and B1+Y1 . C1=A1 and C=K1.
    Assuming B1,Z1,Y1,A1and K1 are leaf node 
    
    E1=1+1 and 1+1 . C1=1 and C1=1
    ie E=2 and C=1
    
    Hence
    X=1+2 and X=1+1 hence please choose X=>C as the best route
    

    Hope this clears it . Also we need to take care of cyclical dependencies X=>Y=>Z=>X , here we may assign such nodes are zero at parent or leaf node level and take care of dependecy."

提交回复
热议问题