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.
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 as { min, max }
Define: Condition as { Name, Range }
Define: Requirement as Set OR as Set
Define: Component as { Name, Range, Requirement }
Define: System as Set
Input
Input: T as System aka basis
Input: C as Set aka conditions to apply
Initialization
Init: S as Set = { S[i] as Condition | S[i] = {T[i].Name,T[i].Range} }
Init: Q as Stack = { 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) }