Solving dependency constraints

前端 未结 1 1194
感动是毒
感动是毒 2021-02-05 16:12

I have a classic dependency solving problem. I thought I was headed in the right direction, but now I\'ve hit a roadblock and I am not sure how to proceed.

Background

相关标签:
1条回答
  • 2021-02-05 16:33

    I'm not expert on the problem, I'm proposing a complete solution that is not optimal, as there are many things that can be optimized ..

    The algorithm is simple, it's ideally a recursive set . intersection DFS :

    Algorithm

    Def

    Define: Name as String on format [ .* ]
    Define: Version as String on format [ dd.dd.dd ]
    Define: Revision as { Name, Version, Requirement }
    Define: Range<T> as { min<T>, max<T> }
    Define: Condition as { Name, Range<Version> }
    Define: Requirement as Set<Revision> OR as Set<Condition>
    Define: Component as { Name, Range<Version>, Requirement }
    Define: System as Set<Component>
    

    Input

    Input: T as System aka basis
    Input: C as Set<Condition> aka conditions to apply
    

    Initialization

    Init: S as Set<Condition> = { S[i] as Condition | S[i] = {T[i].Name,T[i].Range} }
    Init: Q as Stack<Condition> = { push(q) | q[i] = C[i] }
    

    Process

    for (Condition c in C)
    {
        S.find(c.Name).apply(c)
    }
    
    While (Q.size > 0)
    {
        Condition q = Q.pop()
    
        switch (T.assert(S.find(q.Name),q))
        {
          case VALID:
            S.find(q.Name).apply(q)
            q.push(S.find(q.Name).Requirement)
    
          case INVALID:
            S.find(q.Name).set(INVALID)
    
          case IDENTICAL:
          case SKIP:
        }
    }
    
    return S aka Solution
    

    Operations

    Stack.push insert an item at the front of a stack

    Stack.pop remove an item from the front of a stack

    System.assert(Condition a, Condition b):
        if (a is INVALID) then return SKIP
        else if (b.Range = a.Range) then IDENTICAL
        else if (b.Range - a.Range = {}) then VALID
        else INVALID
    

    Set.find(x) search an item based on condition x

    Condition.apply(Condition b) = { this.Name, intersection(this.Range,b.Range) }
    
    0 讨论(0)
提交回复
热议问题